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
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")
}
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);
}
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) {
}
}
+ 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;
}
}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
+
+
--- /dev/null
+/*
+ * 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());
+ }
+
+}