Pass the appropriate PortModInput to portMod 06/5706/3
authorMoiz Raja <moraja@cisco.com>
Fri, 21 Mar 2014 07:15:06 +0000 (00:15 -0700)
committerMichal Rehak <mirehak@cisco.com>
Fri, 21 Mar 2014 13:16:23 +0000 (14:16 +0100)
In ModelDrivenSwitchImpl we were building an input but the built input was not passed to portMod. This had issues like missing Xid on the PortModInput
which caused NPE's downstream in the open flow java code

Also we were not correctly population ConfigV10, MaskV10 and FeaturesV10 on the PortModInput which caused NPE in the open flow java code when using
open flow 10

This commit fixes both of those problems. After this updatePort actually works.

Change-Id: Ie2548a36b2ba06f1d1ce0ccf833627bc7cbaf785
Signed-off-by: Moiz Raja <moraja@cisco.com>
Signed-off-by: Michal Rehak <mirehak@cisco.com>
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/PortConvertor.java

index 1aac6133bda25142e76c72646d663cf52d582581..63072174a0975c9dcbe21704d344290736354b38 100644 (file)
@@ -7,13 +7,8 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Future;
-
+import com.google.common.base.Objects;
+import com.google.common.util.concurrent.Futures;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
@@ -183,8 +178,12 @@ import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 
-import com.google.common.base.Objects;
-import com.google.common.util.concurrent.Futures;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Future;
 
 /**
  * RPC implementation of MD-switch
@@ -1252,20 +1251,11 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
             // Insert the Xid ( transaction Id) before calling the RPC on the
             // OFLibrary
 
-            PortModInputBuilder mdInput = new PortModInputBuilder();
+            PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
             mdInput.setXid(Xid);
-            mdInput.setVersion(ofPortModInput.getVersion());
-            mdInput.setPortNo(ofPortModInput.getPortNo());
-            mdInput.setMaskV10(ofPortModInput.getMaskV10());
-            mdInput.setMask(ofPortModInput.getMask());
-            mdInput.setHwAddress(ofPortModInput.getHwAddress());
-            mdInput.setConfigV10(ofPortModInput.getConfigV10());
-            mdInput.setConfig(ofPortModInput.getConfig());
-            mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10());
-            mdInput.setAdvertise(ofPortModInput.getAdvertise());
 
             LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
-            Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie);
+            Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(mdInput.build(), cookie);
 
             try {
                 rpcResultFromOFLib = resultFromOFLib.get();
index 5ef457b594e659478d6914fc2d1e0f3be72e2f61..a3d41bdf4196868122e55b65ae9c883c304da843 100644 (file)
@@ -11,7 +11,9 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
 
 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.openflow.common.types.rev130731.PortConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
@@ -45,17 +47,23 @@ public final class PortConvertor {
             short version) {
 
 
-        PortConfig config = null;
+        PortConfig config = maskPortConfigFields(source.getConfiguration());
+        PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
 
         PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
         portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
         portModInputBuilder.setPortNo(new PortNumber(source.getPortNumber()));
-        config = maskPortConfigFields(source.getConfiguration());
+
         portModInputBuilder.setConfig(config);
-        portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
-        config = maskPortConfigFields(source.getMask());
         portModInputBuilder.setMask(config);
+
+        portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
+
         portModInputBuilder.setVersion(version);
+
+        portModInputBuilder.setConfigV10(configV10);
+        portModInputBuilder.setMaskV10(configV10);
+        portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
         return portModInputBuilder.build();
 
     }
@@ -79,6 +87,24 @@ public final class PortConvertor {
 
     }
 
+    private static PortConfigV10 maskPortConfigV10Fields(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
+        Boolean portDown = false;
+        Boolean noRecv = false;
+        Boolean noFwd = false;
+        Boolean noPacketIn = false;
+        if (configData.isNOFWD())
+            noFwd = true;
+        if (configData.isNOPACKETIN())
+            noPacketIn = true;
+        if (configData.isNORECV())
+            noRecv = true;
+        if (configData.isPORTDOWN())
+            portDown = true;
+
+        return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
+
+    }
     private static PortFeatures getPortFeatures(
             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
 
@@ -90,6 +116,15 @@ public final class PortConvertor {
                 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
     }
 
+    private static PortFeaturesV10 getPortFeaturesV10(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
+
+        return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
+                salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
+                salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
+    }
+
+
     /*
      * This method is called as a reply to OFPMP_PORT_DESCRIPTION
      * message(OF1.3.1)