Friday, April 25, 2014

Opendayligtht (ODL) Controller: Read all Flow entries from the Switches

 public List getAllSwitchFlows(NodeBuilder tn) {
        List swFlows = new ArrayList();

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

        short tablesAmount = 64;
        String nextArgument = "";

        System.out.println("Getting all Flow Entries present on Switch");
        for (short tableId = 0; tableId < tablesAmount; tableId++) {
            InstanceIdentifier pathToSwitchTable = InstanceIdentifier.builder(Nodes.class)
                        .child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class)
                        .child(Table.class, new TableKey(tableId)).build();
            Table stbl = (Table) smodification.readOperationalData(pathToSwitchTable);
            if (stbl != null) {
                for (Flow flow : stbl.getFlow()) {
                    if(flow != null) {
                        swFlows.add(flow);
                        //LOG.info("getAllFlows: flow {}=", flow);
                        System.out.println("=======================================");
                        System.out.println("getAllSFlows: flow= " + flow.toString());
                    }
                }
            }
        }
        System.out.println("=======================================");
        return swFlows;
    }