Fix OuputPackage Test 73/3873/1
authorVaclav Demcak <vdemcak@cisco.com>
Fri, 20 Dec 2013 15:44:15 +0000 (16:44 +0100)
committerVaclav Demcak <vdemcak@cisco.com>
Fri, 20 Dec 2013 15:44:54 +0000 (16:44 +0100)
Fix TransmitPackage and refactoring adapter

Signed-off-by: Vaclav Demcak <vdemcak@cisco.com>
drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestCommandProvider.java
drop-test/src/main/java/org/opendaylight/openflowplugin/outputtest/OutputTestUtil.xtend
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java [new file with mode: 0644]

index d3f8a4c4dae8cc06159eebecf97903616bbf2e87..e028b3c10650ec5d0f2abeb894405d7b8d7a0554 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.openflowplugin.outputtest;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.ArrayUtils;
 import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
@@ -42,12 +46,12 @@ public class OutputTestCommandProvider implements CommandProvider {
         if (sessionInitiated) {
             String inNodeKey = ci.nextArgument();
             
-//            String resultOfPingFlow = OutputTestUtil.makePingFlowForNode(inNodeKey, pc);
-//            ci.println(resultOfPingFlow);
+//          String resultOfPingFlow = OutputTestUtil.makePingFlowForNode(inNodeKey, pc);
+//          ci.println(resultOfPingFlow);
             
             TransmitPacketInput input = OutputTestUtil.buildTransmitInputPacket(
                                 inNodeKey, 
-                                new String("BRM").getBytes(), 
+                                new String("sendOutputMsg_TEST").getBytes(),
                                 "0xfffffffd", // port
                                 "0");
 
index e4446f9d61eecbe2a222a4b746c38974b33c7eff..7dbcde8006e650363548350ed132332bea7564e3 100644 (file)
@@ -38,6 +38,7 @@ 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
+import org.apache.commons.lang.ArrayUtils
 
 class OutputTestUtil {
     
@@ -46,11 +47,24 @@ class OutputTestUtil {
     }
     
     public static def buildTransmitInputPacket(String nodeId, byte[] packValue, String outPort, String inPort) {
+        
+        var list = new ArrayList<Byte>(40);
+        var msg = (new String("sendOutputMsg_TEST")).getBytes();
+        var index =0;
+        for (byte b : msg) {
+            list.add(b);
+            if(index < 7) {index = index+1} else {index = 0}
+        }
+        while(index < 8) {
+            list.add(new Byte("0"));
+            index = index+1;
+        }
+        
         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.setPayload(ArrayUtils.toPrimitive(list));
         tPackBuilder.setNode(ref);
         // TODO VD P2 missing cookies in Test
         tPackBuilder.setCookie(null);
index d667d52f0ff8004220280d2a10fd61dff2111163..fbed99b857766983e98ef179159ae0f67d465802 100644 (file)
@@ -14,7 +14,6 @@ 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;
@@ -22,14 +21,13 @@ import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistingu
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
 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;
@@ -91,9 +89,7 @@ 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;
@@ -116,14 +112,6 @@ 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;
@@ -131,11 +119,9 @@ 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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
@@ -144,7 +130,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 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;
@@ -195,7 +180,6 @@ 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;
@@ -446,67 +430,7 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
     public Future<RpcResult<Void>> transmitPacket(TransmitPacketInput input) {
         LOG.info("TransmitPacket - {}",input);
        // 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();
+        PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid());
        
        // TODO VD NULL for yet  - find how to translate cookie from TransmitPacketInput
 //     SwitchConnectionDistinguisher cookie = ( "what is need to do" ) input.getCookie();
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java
new file mode 100644 (file)
index 0000000..b2de4e8
--- /dev/null
@@ -0,0 +1,103 @@
+package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.controller.sal.common.util.Arguments;
+import org.opendaylight.openflowplugin.openflow.md.OFConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+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.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
+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.packet.service.rev130709.TransmitPacketInput;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PacketOutConvertor {
+    private static final Logger logger = LoggerFactory.getLogger(MeterConvertor.class);
+    private static final String PREFIX_SEPARATOR = "/";
+
+    private PacketOutConvertor() {
+
+    }
+
+    // Get all the data for the PacketOut from the Yang/SAL-Layer
+    /**
+     * @param version
+     * @param Yang
+     *            Data source
+     * @return PacketOutInput required by OF Library
+     */
+    public static PacketOutInput toPacketOutInput(TransmitPacketInput inputPacket, short version, Long xid) {
+
+     // Build Port ID from TransmitPacketInput.Ingress
+        PortNumber inPortNr = null;
+        
+        List<PathArgument> inArgs = inputPacket.getIngress().getValue().getPath();
+        if (inArgs.size() >= 3) {
+            inPortNr = getPortNumber(inArgs.get(2));
+        } 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 = inputPacket.getEgress();
+        List<PathArgument> outArgs = outRef.getValue().getPathArguments();
+        if (outArgs.size() >= 3) {
+            outPort = getPortNumber(outArgs.get(2));
+        } 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)
+        
+        // FIXME 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(inputPacket.getPayload());
+        builder.setVersion(version);
+        builder.setXid(xid);
+        builder.setInPort(inPortNr);
+        builder.setBufferId(bufferId);
+        // --------------------------------------------------------
+        
+        return builder.build();
+    }
+    
+    private static PortNumber getPortNumber(PathArgument pathArgument) {
+        //FIXME VD P! find InstanceIdentifier helper 
+        InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(pathArgument, 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]);
+        return new PortNumber(port);
+    }
+}