Friday, April 25, 2014

Opendayligtht (ODL) Controller: Read all Flow entries from the Controller's Cache

    public List getAllControllerFlows(NodeBuilder tn) {
        List coFlows = new ArrayList();

        DataModification, DataObject> cmodification = dataBrokerService.beginTransaction();

        short tablesAmount = 64;
        String nextArgument = "";

        System.out.println("Getting all Flow Entries present on Controller");
        for (short tableId = 0; tableId < tablesAmount; tableId++) {
            InstanceIdentifier pathToControllerTable = InstanceIdentifier.builder(Nodes.class)
                        .child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class)
                        .child(Table.class, new TableKey(tableId)).build();
            Table ctbl = (Table) cmodification.readConfigurationData(pathToControllerTable);
            if (ctbl != null) {
                for (Flow flow : ctbl.getFlow()) {
                    if(flow != null) {
                        coFlows.add(flow);
                        //LOG.info("getAllFlows: flow {}=", flow);
                        System.out.println("=======================================");
                        System.out.println("getAllCFlows: flow= " + flow.toString());
                    }
                }
            }
        }
        System.out.println("=======================================");
        return coFlows;
    }

 To read Flow entries from Switch  http://blog.disects.com/2014/04/opendayligtht-odl-controller-read-all.html