OutputPackage Test impl 02/3802/4
authorVaclav Demcak <vdemcak@cisco.com>
Thu, 12 Dec 2013 10:13:43 +0000 (11:13 +0100)
committerVaclav Demcak <vdemcak@cisco.com>
Thu, 19 Dec 2013 16:31:00 +0000 (17:31 +0100)
OutputPacket basic test + ping flow implementation (not finished yet)
Fix Port_Nr conversion
Fix transmit packet method from ModelDrivenSwitchImpl

Change-Id: Ief1be2e2279be6636e5c257ef38d4e04de8482ad
Signed-off-by: Vaclav Demcak <vdemcak@cisco.com>
drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestActivator.xtend
drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestCommandProvider.java [new file with mode: 0644]
drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestUtil.xtend [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/OFConstants.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginGroupTestCommandProvider.java

index 4ef7a7358ab203289c34bd4caa7236b3c43b4fd1..7812534adbe8770f371cba1a85cf3f633e1e7062 100644 (file)
@@ -11,26 +11,39 @@ import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService
+import org.opendaylight.openflowplugin.outputtest.OutputTestCommandProvider
 import org.osgi.framework.BundleContext
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
 
 class DropTestActivator extends AbstractBindingAwareProvider {
 
+    static Logger LOG = LoggerFactory.getLogger(DropTestActivator);
+
     static var DropTestProvider provider = new DropTestProvider();
     
     static var DropTestCommandProvider cmdProvider
+    static var OutputTestCommandProvider outCmdProvider
 
     override onSessionInitiated(ProviderContext session) {
+        LOG.debug("Activator DropAllPack INIT")
         provider.dataService = session.getSALService(DataProviderService)
         provider.notificationService = session.getSALService(NotificationProviderService)
         cmdProvider.onSessionInitiated(session);
+        
+        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);
+        outCmdProvider = new OutputTestCommandProvider(ctx);
     }
 
     override protected stopImpl(BundleContext context) {
+//        LOG.info("--------------------------------------    DROP ALL PACK TEST STOPED --------------------------- ")
         provider.close();
     }
 
diff --git a/drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestCommandProvider.java b/drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestCommandProvider.java
new file mode 100644 (file)
index 0000000..d3f8a4c
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.outputtest;
+
+import org.eclipse.osgi.framework.console.CommandInterpreter;
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OutputTestCommandProvider implements CommandProvider {
+
+    private PacketProcessingService packetProcessingService;
+    private ProviderContext pc;
+    private BundleContext ctx;
+    private boolean sessionInitiated = false;
+    private static Logger LOG = LoggerFactory.getLogger(OutputTestCommandProvider.class);
+
+    public OutputTestCommandProvider(BundleContext ctx) {
+        this.ctx = ctx;
+    }
+
+    public void onSessionInitiated(ProviderContext session) {
+        pc = session;
+        packetProcessingService = session
+                .getRpcService(PacketProcessingService.class);
+        ctx.registerService(CommandProvider.class.getName(), this, null);
+        this.sessionInitiated = true;
+    }
+
+    public void _sendOutputMsg(CommandInterpreter ci) {
+        /* Sending package OUT */
+        LOG.info("SendOutMsg");
+        if (sessionInitiated) {
+            String inNodeKey = ci.nextArgument();
+            
+//            String resultOfPingFlow = OutputTestUtil.makePingFlowForNode(inNodeKey, pc);
+//            ci.println(resultOfPingFlow);
+            
+            TransmitPacketInput input = OutputTestUtil.buildTransmitInputPacket(
+                                inNodeKey, 
+                                new String("BRM").getBytes(), 
+                                "0xfffffffd", // port
+                                "0");
+
+            packetProcessingService.transmitPacket(input);
+        } else {
+            ci.println("Session not initiated, try again in a few seconds");
+        }
+    }
+
+    public void _sendOutTopologyMsg(CommandInterpreter ci) {
+        /* Sending package OUT */
+        LOG.info("SendOutTopologyMsg");
+        
+        
+    }
+    
+    @Override
+    public String getHelp() {
+        StringBuilder strBuf = new StringBuilder("-------------- OUT Package ----------\n")
+                .append(" sendOutputMsg command + nodeId as param sends empty package out \n ");
+        return strBuf.toString();
+    }
+}
diff --git a/drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestUtil.xtend b/drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestUtil.xtend
new file mode 100644 (file)
index 0000000..e4446f9
--- /dev/null
@@ -0,0 +1,173 @@
+package org.opendaylight.openflowplugin.outputtest
+
+import java.math.BigInteger
+import java.util.ArrayList
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder
+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.action.types.rev131112.action.list.ActionKey
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey
+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.flow.types.rev131026.instruction.list.InstructionKey
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
+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.node.NodeConnectorKey
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
+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.packet.service.rev130709.TransmitPacketInputBuilder
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
+import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext
+import java.util.concurrent.ExecutionException
+
+class OutputTestUtil {
+    
+    private new() {
+        throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
+    }
+    
+    public static def buildTransmitInputPacket(String nodeId, byte[] packValue, String outPort, String inPort) {
+        var ref = createNodeRef(nodeId);
+        var nEgressConfRef = new NodeConnectorRef(createNodeConnRef(nodeId, outPort));
+        var nIngressConRef = new NodeConnectorRef(createNodeConnRef(nodeId, inPort));
+        var tPackBuilder = new TransmitPacketInputBuilder
+        tPackBuilder.setPayload(packValue);
+        tPackBuilder.setNode(ref);
+        // TODO VD P2 missing cookies in Test
+        tPackBuilder.setCookie(null);
+        tPackBuilder.setEgress(nEgressConfRef)
+        tPackBuilder.setIngress(nIngressConRef)
+        return tPackBuilder.build
+    }
+
+    public static def makePingFlowForNode(String nodeId, ProviderContext pc) {
+        var nodeBuilder = createNodeBuilder(nodeId)
+        var flowBuilder = createFlowBuilder(1235, null, "ping")
+        
+        var dataBrokerService = pc.getSALService(DataBrokerService)
+        var modif = dataBrokerService.beginTransaction
+        
+        var path = InstanceIdentifier
+                    .builder(Nodes)
+                    .child(Node, nodeBuilder.getKey)
+                    .augmentation(FlowCapableNode)
+                    .child(Table, new TableKey(flowBuilder.getTableId))
+                    .child(Flow, flowBuilder.getKey()).build;
+        
+        modif.putConfigurationData(path, flowBuilder.build)
+        var commitFuture = modif.commit
+        
+        try {
+            var resutl = commitFuture.get
+            var status = resutl.result
+            return "Status of Flow Data Loaded Transaction: " + status
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            return e.class.name
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+            return e.class.name
+        }
+    }
+    
+    private static def createNodeRef(String nodeId) {
+        var key = new NodeKey(new NodeId(nodeId));
+        var path = InstanceIdentifier.builder(Nodes).child(Node, key).toInstance
+        return new NodeRef(path)
+    }
+    
+    private static def createNodeConnRef(String nodeId, String port) {
+        var sBuild = new StringBuilder(nodeId).append(":").append(port);
+        var nConKey = new NodeConnectorKey(new NodeConnectorId(sBuild.toString));
+        var path = InstanceIdentifier.builder(Nodes)
+                .child(Node, new NodeKey(new NodeId(nodeId)))
+                .child(NodeConnector, nConKey).toInstance()
+        return new NodeConnectorRef(path)
+    }
+    
+    
+    
+    private static def createNodeBuilder(String nodeId) {
+        var builder = new NodeBuilder()
+        builder.setId(new NodeId(nodeId))
+        builder.setKey(new NodeKey(builder.getId()))
+        return builder
+    }
+    
+    private static def createFlowBuilder(long flowId, String tableId, String flowName) {
+        var fBuild = new FlowBuilder();
+        fBuild.setMatch(new MatchBuilder().build)
+        fBuild.setInstructions(createPingInstructionsBuilder().build)
+        
+        var key = new FlowKey(new FlowId(flowId));
+        fBuild.setBarrier(false);
+        // flow.setBufferId(new Long(12));
+        var value = new BigInteger("10", 10);
+        fBuild.setCookie(value);
+        fBuild.setCookieMask(value);
+        fBuild.setHardTimeout(0);
+        fBuild.setIdleTimeout(0);
+        fBuild.setInstallHw(false);
+        fBuild.setStrict(false);
+        fBuild.setContainerName(null);
+        fBuild.setFlags(new FlowModFlags(false, false, false, false, false));
+        fBuild.setId(new FlowId(new Long(12)));
+        fBuild.setTableId(checkTableId(tableId));
+        fBuild.setOutGroup(new Long(2));
+        fBuild.setOutPort(value);
+
+        fBuild.setKey(key);
+        fBuild.setPriority(2);
+        fBuild.setFlowName(flowName);
+        return fBuild
+    }
+
+    private static def createPingInstructionsBuilder() {
+        var aList = new ArrayList<Action>
+        var aBuild = new ActionBuilder
+
+        var output = new OutputActionBuilder
+        output.setMaxLength(56)
+        output.setOutputNodeConnector(new Uri("CONTROLLER"))
+        aBuild.setAction(new OutputActionCaseBuilder().setOutputAction(output.build).build)
+        aBuild.setOrder(0)
+        aBuild.setKey(new ActionKey(0))
+        aList.add(aBuild.build)
+        var asBuild = new ApplyActionsBuilder(); asBuild.setAction(aList)
+
+        var iBuild = new InstructionBuilder
+        iBuild.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(asBuild.build).build);
+        iBuild.setOrder(0);
+        iBuild.setKey(new InstructionKey(0));
+        
+        var instr = new ArrayList<Instruction>(); instr.add(iBuild.build)
+        return new InstructionsBuilder().setInstruction(instr) 
+    }
+    
+    private static def checkTableId(String tableId) {
+        try {
+            return Short.parseShort(tableId)
+        } catch (Exception ex) {
+            return Short.parseShort("2")
+        }
+    }
+}
\ No newline at end of file
index 4b7ca20b1fa7be889caff1a53227c2fb5964ab22..c61f350c26a5090443a7eecf6318f9af5a4114b8 100644 (file)
@@ -27,4 +27,5 @@ public class OFConstants {
     public static final Long OFPQ_ANY = ANY;
     public static final BigInteger DEFAULT_COOKIE = BigInteger.ZERO;
     public static final BigInteger DEFAULT_COOKIE_MASK = BigInteger.ZERO;
+    public static final Long OFP_NO_BUFFER = 0xffffffffL;
 }
index e2e8184fd16c322320b5bee90290e21249e1a814..404f5abcf7f68fba56b59e621f61ae58cc791ef8 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Future;
 
+import org.opendaylight.controller.sal.common.util.Arguments;
 import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
 import org.opendaylight.openflowplugin.openflow.md.OFConstants;
@@ -27,6 +28,8 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.Matc
 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
@@ -61,7 +64,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
@@ -69,6 +71,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
@@ -88,7 +91,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
@@ -111,6 +116,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
@@ -118,6 +131,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
@@ -129,6 +143,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
@@ -155,7 +171,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
@@ -180,6 +195,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.Upd
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
@@ -285,7 +301,6 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
        // Convert the AddMeterInput to MeterModInput
         MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
 
-
        // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
        // the request can be routed through any connection to the switch
 
@@ -429,7 +444,75 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
     @Override
     public Future<RpcResult<Void>> transmitPacket(TransmitPacketInput input) {
         LOG.info("TransmitPacket - {}",input);
-        return null;
+       // Convert TransmitPacket to PacketOutInput
+        
+       // TODO VD create PacketConvertor and move convert logic there
+        
+        // Build Port ID from TransmitPacketInput.Ingress
+        PortNumber inPortNr = null;
+        
+        List<PathArgument> inArgs = input.getIngress().getValue().getPath();
+        if (inArgs.size() >= 3) {
+            InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(inArgs.get(2), InstanceIdentifier.IdentifiableItem.class);
+            NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class);
+            String[] split = key.getId().getValue().split(":");
+            Long port = Long.decode(split[split.length-1]);
+            inPortNr = new PortNumber(port);
+        } else {
+            // TODO Ed could by in this way or Exception or something else ?
+            inPortNr = new PortNumber(0xfffffffdL);
+        }
+        
+        // Build Buffer ID from TransmitPacketInput.Ingress
+        // TODO VD P! find how to fix PacketIn to add BufferID to augmetation
+        Long bufferId = OFConstants.OFP_NO_BUFFER;
+        
+        PortNumber outPort = null;
+        NodeConnectorRef outRef = input.getEgress();
+        List<PathArgument> outArgs = outRef.getValue().getPathArguments();
+        if (outArgs.size() >= 3) {
+            InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(outArgs.get(2), InstanceIdentifier.IdentifiableItem.class);
+            NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class);
+            String[] split = key.getId().getValue().split(":");
+            Long port = Long.decode(split[split.length-1]);
+            outPort = new PortNumber(port);
+        } else {
+            new Exception("PORT NR not exist in Egress"); //TODO : P4 search for some normal exception
+        }
+        
+        // TODO VD P! wait for way to move Actions (e.g. augmentation)
+        
+        // TODO VD implementation for testing PacketIn (REMOVE IT)
+        List<ActionsList> actions = new ArrayList<ActionsList>();
+        ActionsListBuilder asBuild = new ActionsListBuilder();
+        ActionBuilder aBuild = new ActionBuilder();
+        aBuild.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
+        PortActionBuilder paBuild = new PortActionBuilder();
+        paBuild.setPort(outPort);        
+        aBuild.addAugmentation(PortAction.class, paBuild.build());
+        MaxLengthActionBuilder mlBuild = new MaxLengthActionBuilder();
+        mlBuild.setMaxLength(0xffff);
+        aBuild.addAugmentation(MaxLengthAction.class, mlBuild.build());
+        asBuild.setAction(aBuild.build());
+        actions.add(asBuild.build());
+        
+       PacketOutInputBuilder builder = new PacketOutInputBuilder();
+       builder.setActionsList(actions);
+       builder.setData(input.getPayload());
+        builder.setVersion(version);
+        builder.setXid(sessionContext.getNextXid());
+        builder.setInPort(inPortNr);
+        builder.setBufferId(bufferId);
+        // --------------------------------------------------------
+        
+        PacketOutInput message = builder.build();
+       
+       // TODO VD NULL for yet  - find how to translate cookie from TransmitPacketInput
+//     SwitchConnectionDistinguisher cookie = ( "what is need to do" ) input.getCookie();
+       SwitchConnectionDistinguisher cookie = null ;
+       
+       LOG.debug("Calling the transmitPacket RPC method");
+       return messageService.packetOut(message, cookie);
     }
 
     private FlowModInputBuilder toFlowModInputBuilder(Flow source) {
index 3e79ddaa0b13cd2a39ccfdbb588efa1015c72649..e7cad9140a38530f9bc57e3b20e6a974fb4a20e5 100644 (file)
@@ -223,4 +223,8 @@ public class OpenflowpluginGroupTestCommandProvider implements CommandProvider {
 
         return new NodeRef(path);
     }
+    
+    private static void removeMeImFaick() {
+        
+    }
 }