added dropAllPackets provider bypassing datastore 68/4568/2
authorMichal Rehak <mirehak@cisco.com>
Wed, 22 Jan 2014 09:15:38 +0000 (10:15 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 22 Jan 2014 11:24:20 +0000 (11:24 +0000)
required for cbench load tests:
  time consuming operations (datastore + transaction) are bypassed
  and flow is added by calling flow service rpc (directly routed back to plugin)
  so flow created this way is not visible though rest

Change-Id: I40608e6321517494f8eef2dd8d2637bb503b010b
Signed-off-by: Michal Rehak <mirehak@cisco.com>
drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestActivator.xtend
drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestCommandProvider.java
drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestRpcProvider.xtend [new file with mode: 0644]
drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestRpcSender.xtend [new file with mode: 0644]

index 7812534adbe8770f371cba1a85cf3f633e1e7062..6abef18474d2a263d74839daedf2cda959f82d72 100644 (file)
@@ -15,12 +15,14 @@ import org.opendaylight.openflowplugin.outputtest.OutputTestCommandProvider
 import org.osgi.framework.BundleContext
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
 
 class DropTestActivator extends AbstractBindingAwareProvider {
 
     static Logger LOG = LoggerFactory.getLogger(DropTestActivator);
 
     static var DropTestProvider provider = new DropTestProvider();
+    static var DropTestRpcProvider rpcProvider = new DropTestRpcProvider();
     
     static var DropTestCommandProvider cmdProvider
     static var OutputTestCommandProvider outCmdProvider
@@ -31,6 +33,9 @@ class DropTestActivator extends AbstractBindingAwareProvider {
         provider.notificationService = session.getSALService(NotificationProviderService)
         cmdProvider.onSessionInitiated(session);
         
+        rpcProvider.notificationService = session.getSALService(NotificationProviderService)
+        rpcProvider.flowService = session.getRpcService(SalFlowService)
+        
         outCmdProvider.onSessionInitiated(session);
         LOG.debug("Activator DropAllPack END")
     }
@@ -38,7 +43,7 @@ class DropTestActivator extends AbstractBindingAwareProvider {
     override startImpl(BundleContext ctx) {
         super.startImpl(ctx);
 //        LOG.info("-------------------------------------    DROP ALL PACK TEST INITIATED ------------------------ ")
-        cmdProvider = new DropTestCommandProvider(ctx,provider);
+        cmdProvider = new DropTestCommandProvider(ctx,provider,rpcProvider);
         outCmdProvider = new OutputTestCommandProvider(ctx);
     }
 
index f9b1c54de9d2226575050188e38342d4b565471b..a2c8d8e329d72a102b8739235877085505bbaa9a 100644 (file)
@@ -20,13 +20,15 @@ public class DropTestCommandProvider implements CommandProvider {
     private ProviderContext pc;
     private BundleContext ctx;
     private DropTestProvider provider;
+    private DropTestRpcProvider rpcProvider;
     private boolean on = false;
     private boolean sessionInitiated = false;
 
 
-    public DropTestCommandProvider(BundleContext ctx,DropTestProvider provider) {
+    public DropTestCommandProvider(BundleContext ctx,DropTestProvider provider,DropTestRpcProvider rpcProvider) {
         this.ctx = ctx;
         this.provider = provider;
+        this.rpcProvider = rpcProvider;
     }
 
     public void onSessionInitiated(ProviderContext session) {
@@ -62,11 +64,39 @@ public class DropTestCommandProvider implements CommandProvider {
         }
     }
 
+    public void _dropAllPacketsRpc(CommandInterpreter ci) {
+        if(sessionInitiated) {
+            String onoff = ci.nextArgument();
+            if(onoff.equals("on")) {
+                if(on == false) {
+                    rpcProvider.start();
+                    ci.println("DropAllFlows transitions to on");
+                } else {
+                    ci.println("DropAllFlows is already on");
+                }
+                on = true;
+            } else if (onoff.equals("off")) {
+                if(on == true) {
+                    rpcProvider.close();
+                    ci.println("DropAllFlows transitions to off");
+                } else {
+                    ci.println("DropAllFlows is already off");
+                }
+                on = false;
+            }
+        } else {
+            ci.println("Session not initiated, try again in a few seconds");
+        }
+    }
+    
     @Override
     public String getHelp() {
         String helpString = "----------------- dropAllPackets--------------\n"
                 + " dropAllPackets on - begin dropping all packets \n"
-                + " dropAllPackets on - stop dropping all packets \n";
+                + " dropAllPackets on - stop dropping all packets \n"
+                + " dropAllPacketsRpc on - begin dropping all packets but bypassing dataStore \n"
+                + "                      - add flow goes directly to rpc provided OFPlugin \n"
+                + " dropAllPacketsRpc on - stop dropping all packets but bypassing dataStore \n";
         return helpString;
     }
 }
diff --git a/drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestRpcProvider.xtend b/drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestRpcProvider.xtend
new file mode 100644 (file)
index 0000000..ef58e5a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * 
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.droptest
+
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
+import org.opendaylight.yangtools.concepts.Registration
+import org.opendaylight.yangtools.yang.binding.NotificationListener
+import org.slf4j.LoggerFactory
+
+class DropTestRpcProvider implements AutoCloseable {
+
+
+    static val LOG = LoggerFactory.getLogger(DropTestProvider);
+
+    @Property
+    SalFlowService flowService;
+            
+
+    
+
+    @Property
+    NotificationProviderService notificationService;
+
+    var DropTestRpcSender commiter
+
+    Registration<NotificationListener> listenerRegistration
+
+    def void start() {
+        commiter = new DropTestRpcSender(this,flowService)
+        listenerRegistration = notificationService.registerNotificationListener(commiter);
+        LOG.info("DropTestProvider Started.");
+        
+    }   
+    
+    override close() {
+       LOG.info("DropTestProvider stopped.");
+        listenerRegistration?.close();
+    }
+    
+}
+
+
diff --git a/drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestRpcSender.xtend b/drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestRpcSender.xtend
new file mode 100644 (file)
index 0000000..a549865
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * 
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.droptest
+
+import java.math.BigInteger
+import java.util.ArrayList
+import java.util.Arrays
+import org.apache.commons.codec.binary.Hex
+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.DropActionCaseBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.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.service.rev130819.AddFlowInputBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
+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.match.EthernetMatchBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
+import org.slf4j.LoggerFactory
+
+class DropTestRpcSender implements PacketProcessingListener {
+    static val LOG = LoggerFactory.getLogger(DropTestProvider);
+    @Property
+    val DropTestRpcProvider manager;
+
+    @Property
+    val SalFlowService flowService;
+
+    new(DropTestRpcProvider manager,SalFlowService flowService) {
+        _manager = manager;
+        _flowService = flowService;
+    }
+    
+    override onPacketReceived(PacketReceived notification) {
+        LOG.info("onPacketReceived - Entering - " + notification);
+        val ncr = notification.ingress // Get the Ingress nodeConnectorRef
+        val ncri = (ncr.value as InstanceIdentifier<NodeConnector>); // Get the instance identifier for the nodeConnectorRef
+        val ncKey = InstanceIdentifier.keyOf(ncri);
+        val nodeInstanceId = ncri.firstIdentifierOf(Node); // Get the instanceID for the Node in the tree above us
+        val nodeKey = InstanceIdentifier.keyOf(nodeInstanceId);
+        val rawPacket = notification.payload;
+        LOG.info("onPacketReceived - received Packet on Node {} and NodeConnector {} payload {}",nodeKey.id,ncKey.id,Hex.encodeHexString(rawPacket));
+        val srcMac = Arrays.copyOfRange(rawPacket,6,12);
+        LOG.info("onPacketReceived - received Packet on Node {} and NodeConnector {} srcMac {}",nodeKey.id,ncKey.id,Hex.encodeHexString(srcMac));
+        
+        val match = new MatchBuilder();
+        val ethernetMatch = new EthernetMatchBuilder();
+        val ethSourceBuilder = new EthernetSourceBuilder();
+        //TODO: use HEX, use binary form
+        //Hex.decodeHex("000000000001".toCharArray());
+        ethSourceBuilder.setAddress(new MacAddress(DropTestUtils.macToString(srcMac)));
+        ethernetMatch.setEthernetSource(ethSourceBuilder.build());
+        match.setEthernetMatch(ethernetMatch.build());
+        val dab = new DropActionBuilder();
+        val dropAction = dab.build();
+        val ab = new ActionBuilder();
+        ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
+        
+        // Add our drop action to a list
+        val actionList = new ArrayList<Action>();
+        actionList.add(ab.build());
+        
+        // Create an Apply Action
+        val aab = new ApplyActionsBuilder();
+        aab.setAction(actionList);
+        
+        // Wrap our Apply Action in an Instruction
+        val ib = new InstructionBuilder();
+        ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+        
+        // Put our Instruction in a list of Instructions
+        val isb = new InstructionsBuilder();
+        val instructions = new ArrayList<Instruction>();
+        instructions.add(ib.build());
+        isb.setInstruction(instructions);
+        
+        // Finally build our flow
+        val fb = new AddFlowInputBuilder
+        fb.setMatch(match.build());
+        fb.setInstructions(isb.build());
+        //fb.setId(new FlowId(Long.toString(fb.hashCode)));
+
+        // Construct the flow instance id
+        val flowInstanceId = InstanceIdentifier.builder(Nodes) // File under nodes
+            .child(Node,nodeKey).toInstance // A particular node indentified by nodeKey        
+        fb.setNode(new NodeRef(flowInstanceId));
+
+        fb.setPriority(4);
+        fb.setBufferId(0L);
+        val value = new BigInteger("10", 10);
+        fb.setCookie(value);
+        fb.setCookieMask(value);
+        fb.setHardTimeout(300);
+        fb.setIdleTimeout(240);
+        fb.setFlags(new FlowModFlags(false, false, false, false, false));
+        
+        // Construct the flow instance id
+        flowService.addFlow(fb.build());
+    }
+    
+}