added another flows 21/3421/1
authorMichal Rehak <mirehak@cisco.com>
Wed, 4 Dec 2013 01:43:49 +0000 (02:43 +0100)
committerMichal Rehak <mirehak@cisco.com>
Wed, 4 Dec 2013 01:44:21 +0000 (02:44 +0100)
drop+ipv4Src
drop+ethernetSrc

Change-Id: I15c29fd6ec6774e9f162c2b3f616d9b0e52dc8e3
Signed-off-by: Michal Rehak <mirehak@cisco.com>
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestCommandProvider.java

index 7eed21942c1bda86cd97ea18b09b9ec947b68abc..e73545f7789492f81ac06d7f99051220f2a53084 100644 (file)
@@ -22,8 +22,11 @@ import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows;
@@ -42,6 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
@@ -50,10 +54,15 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 
 public class OpenflowpluginTestCommandProvider implements CommandProvider {
+    
+    private static final Logger LOG = LoggerFactory
+            .getLogger(OpenflowpluginTestCommandProvider.class);
 
        private DataBrokerService dataBrokerService;
        private ProviderContext pc;
@@ -71,7 +80,7 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
            pc = session;
                dataBrokerService = session.getSALService(DataBrokerService.class);
                ctx.registerService(CommandProvider.class.getName(), this, null);
-               createTestFlow(createTestNode(null));
+               createTestFlow(createTestNode(null), null);
     }
 
        private NodeBuilder createTestNode(String nodeId) {
@@ -90,73 +99,161 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
            return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
        }
 
-       private FlowBuilder createTestFlow(NodeBuilder nodeBuilder) {
+       private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg) {
 
-        long id = 123;
-        FlowKey key = new FlowKey(id, new NodeRef(new NodeRef(nodeBuilderToInstanceId(nodeBuilder))));
         FlowBuilder flow = new FlowBuilder();
-        flow.setKey(key);
-        MatchBuilder match = new MatchBuilder();
-        Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
-        // ipv4Match.setIpv4Destination(new Ipv4Prefix(cliInput.get(4)));
-        Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
-        ipv4Match.setIpv4Destination(prefix);
-        Ipv4Match i4m = ipv4Match.build();
-        match.setLayer3Match(i4m);
+        long id = 123;
         
-        EthernetMatchBuilder eth = new EthernetMatchBuilder();
-        EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
-        ethTypeBuilder.setType(new EtherType(0x0800L));
-        eth.setEthernetType(ethTypeBuilder.build());
-        match.setEthernetMatch(eth.build());
+        String flowType = flowTypeArg;
+        if (flowType == null) {
+            flowType = "f1";
+        }
         
-        flow.setMatch(match.build());
-
-        // Create a drop action
-        /*
-         * Note: We are mishandling drop actions
-        DropAction dropAction = new DropActionBuilder().build();
-        ActionBuilder ab = new ActionBuilder();
-        ab.setAction(dropAction);
-        */
+        switch (flowType) {
+        case "f1":
+            id += 1;
+            flow.setMatch(createMatch1().build());
+            flow.setInstructions(createDecNwTtlInstructions().build());
+            break;
+        case "f2":
+            id += 2;
+            flow.setMatch(createMatch2().build());
+            flow.setInstructions(createDropInstructions().build());
+            break;
+        case "f3":
+            id += 3;
+            flow.setMatch(createMatch3().build());
+            flow.setInstructions(createDropInstructions().build());
+            break;
+        default:
+                LOG.warn("flow type not understood: {}", flowType);
+        }
+        
+        FlowKey key = new FlowKey(id, new NodeRef(new NodeRef(nodeBuilderToInstanceId(nodeBuilder))));
+        flow.setKey(key);
+        flow.setPriority(2);
+        flow.setFlowName(originalFlowName+"_"+flowType);
+        testFlow = flow;
+        return flow;
+       }
 
+    /**
+     * @return
+     */
+    private static InstructionsBuilder createDecNwTtlInstructions() {
         DecNwTtlBuilder ta = new DecNwTtlBuilder();
         DecNwTtl decNwTtl = ta.build();
         ActionBuilder ab = new ActionBuilder();
         ab.setAction(decNwTtl);
-
+        
         // Add our drop action to a list
         List<Action> actionList = new ArrayList<Action>();
         actionList.add(ab.build());
-
+        
         // Create an Apply Action
         ApplyActionsBuilder aab = new ApplyActionsBuilder();
         aab.setAction(actionList);
-
+        
         // Wrap our Apply Action in an Instruction
         InstructionBuilder ib = new InstructionBuilder();
         ib.setInstruction(aab.build());
-
+        
         // Put our Instruction in a list of Instructions
         InstructionsBuilder isb = new InstructionsBuilder();
         List<Instruction> instructions = new ArrayList<Instruction>();
         instructions.add(ib.build());
         isb.setInstruction(instructions);
+        return isb;
+    }
+    
+
+    /**
+     * @return
+     */
+    private static InstructionsBuilder createDropInstructions() {
+        DropActionBuilder dab = new DropActionBuilder();
+        DropAction dropAction = dab.build();
+        ActionBuilder ab = new ActionBuilder();
+        ab.setAction(dropAction);
+        
+        // Add our drop action to a list
+        List<Action> actionList = new ArrayList<Action>();
+        actionList.add(ab.build());
+        
+        // Create an Apply Action
+        ApplyActionsBuilder aab = new ApplyActionsBuilder();
+        aab.setAction(actionList);
+        
+        // Wrap our Apply Action in an Instruction
+        InstructionBuilder ib = new InstructionBuilder();
+        ib.setInstruction(aab.build());
+        
+        // Put our Instruction in a list of Instructions
+        InstructionsBuilder isb = new InstructionsBuilder();
+        List<Instruction> instructions = new ArrayList<Instruction>();
+        instructions.add(ib.build());
+        isb.setInstruction(instructions);
+        return isb;
+    }
 
-        // Add our instructions to the flow
-        flow.setInstructions(isb.build());
-
-
-        flow.setPriority(2);
-        flow.setFlowName(originalFlowName);
-        testFlow = flow;
-        return flow;
-       }
+    /**
+     * @return
+     */
+    private static MatchBuilder createMatch1() {
+        MatchBuilder match = new MatchBuilder();
+        Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
+        Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
+        ipv4Match.setIpv4Destination(prefix);
+        Ipv4Match i4m = ipv4Match.build();
+        match.setLayer3Match(i4m);
+        
+        EthernetMatchBuilder eth = new EthernetMatchBuilder();
+        EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
+        ethTypeBuilder.setType(new EtherType(0x0800L));
+        eth.setEthernetType(ethTypeBuilder.build());
+        match.setEthernetMatch(eth.build());
+        return match;
+    }
+    
+    /**
+     * @return
+     */
+    private static MatchBuilder createMatch2() {
+        MatchBuilder match = new MatchBuilder();
+        Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
+        Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
+        ipv4Match.setIpv4Source(prefix);
+        Ipv4Match i4m = ipv4Match.build();
+        match.setLayer3Match(i4m);
+        
+        EthernetMatchBuilder eth = new EthernetMatchBuilder();
+        EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
+        ethTypeBuilder.setType(new EtherType(0x0800L));
+        eth.setEthernetType(ethTypeBuilder.build());
+        match.setEthernetMatch(eth.build());
+        return match;
+    }
+    
+    /**
+     * @return
+     */
+    private static MatchBuilder createMatch3() {
+        MatchBuilder match = new MatchBuilder();
+        EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
+        EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
+        //TODO: use HEX, use binary form
+        //Hex.decodeHex("000000000001".toCharArray());
+        ethSourceBuilder.setAddress(new MacAddress(new String(new byte[]{0,0,0,0,0,1})));
+        ethernetMatch.setEthernetSource(ethSourceBuilder.build());
+        match.setEthernetMatch(ethernetMatch.build());
+        
+        return match;
+    }
 
        public void _removeMDFlow(CommandInterpreter ci) {
            DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
            NodeBuilder tn = createTestNode(ci.nextArgument());
-           FlowBuilder tf = createTestFlow(tn);
+           FlowBuilder tf = createTestFlow(tn, ci.nextArgument());
         InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Flows.class).child(Flow.class, tf.getKey()).toInstance();
         modification.removeOperationalData(nodeBuilderToInstanceId(tn));
         modification.removeOperationalData(path1);
@@ -179,7 +276,7 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
 
        public void _addMDFlow(CommandInterpreter ci) {
         NodeBuilder tn = createTestNode(ci.nextArgument());
-        FlowBuilder tf = createTestFlow(tn);
+        FlowBuilder tf = createTestFlow(tn, ci.nextArgument());
         writeFlow(ci, tf, tn);
     }
 
@@ -207,7 +304,7 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
 
        public void _modifyMDFlow(CommandInterpreter ci) {
         NodeBuilder tn = createTestNode(ci.nextArgument());
-           FlowBuilder tf = createTestFlow(tn);
+           FlowBuilder tf = createTestFlow(tn, ci.nextArgument());
            tf.setFlowName(updatedFlowName);
            writeFlow(ci, tf,tn);
            tf.setFlowName(originalFlowName);