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;
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;
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;
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) {
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);
public void _addMDFlow(CommandInterpreter ci) {
NodeBuilder tn = createTestNode(ci.nextArgument());
- FlowBuilder tf = createTestFlow(tn);
+ FlowBuilder tf = createTestFlow(tn, ci.nextArgument());
writeFlow(ci, tf, tn);
}
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);