DO-NOT-MERGE-YET: Port description is not getting udpated when port removed from... 71/14671/1
authorAnil Vishnoi <vishnoianil@gmail.com>
Mon, 2 Feb 2015 08:26:40 +0000 (00:26 -0800)
committerAnil Vishnoi <vishnoianil@gmail.com>
Mon, 2 Feb 2015 08:27:33 +0000 (00:27 -0800)
If user removed port from openflow switch, it generated port status message with reason - DELETE
But this message is not properly hooked to onNodeUpdateRemoved notification defined in inventory
models. This patch fixes the issue.

Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/PortStatusMessageToNodeConnectorUpdatedTranslator.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/PortTranslatorUtil.java

index 73bec508642cfc856910326d4d35d22340f1d97f..c425c08f375d8e5db93c6b97ddcfc865f7793c6b 100644 (file)
@@ -57,6 +57,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
@@ -181,6 +182,7 @@ public class MDController implements IMDController, AutoCloseable {
         addMessagePopListener(TableFeaturesErrorNotification.class, notificationPopListener);
         addMessagePopListener(TableModErrorNotification.class, notificationPopListener);
         addMessagePopListener(NodeConnectorUpdated.class,notificationPopListener);
+        addMessagePopListener(NodeConnectorRemoved.class,notificationPopListener);
         addMessagePopListener(PacketReceived.class,notificationPopListener);
         addMessagePopListener(TransmitPacketInput.class, notificationPopListener);
         addMessagePopListener(NodeUpdated.class, notificationPopListener);
index b8ab73e32487dff270ebce2280a5ec6634a84bfe..e061643c7cc02a3cebb1fc1c5caaf7f5ca755131 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator
 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.openflow.md.util.PortTranslatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -23,7 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * translates {@link PortStatusMessage} from OF-API model to MD-SAL model, 
+ * translates {@link PortStatusMessage} from OF-API model to MD-SAL model,
  * supports OF-{1.0; 1.3}
  */
 public class PortStatusMessageToNodeConnectorUpdatedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
@@ -39,8 +40,14 @@ public class PortStatusMessageToNodeConnectorUpdatedTranslator implements IMDMes
             BigInteger datapathId = sc.getFeatures().getDatapathId();
             Long portNo = port.getPortNo();
             Short version = port.getVersion();
-            LOG.debug("PortStatusMessage: version {}  dataPathId {} portNo {}",version, datapathId,portNo);
-            list.add(PortTranslatorUtil.translatePort(version, datapathId, portNo, port));
+            if(port.getReason() == PortReason.OFPPRDELETE){
+                LOG.debug("PortStatusMessage: version {}  dataPathId {} portNo {} reason {}",version, datapathId,portNo,port.getReason());
+                list.add(PortTranslatorUtil.translatePortRemoved(version, datapathId, portNo, port));
+
+            }else{
+                LOG.debug("PortStatusMessage: version {}  dataPathId {} portNo {}",version, datapathId,portNo);
+                list.add(PortTranslatorUtil.translatePort(version, datapathId, portNo, port));
+            }
             return list;
         } else {
             // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here?
index dfcad7657481e9a4d1db29eb054fe93bc3290a7c..d9a4afb78e1339bd9b16d678fb762c7e60dfb7b7 100644 (file)
@@ -8,11 +8,16 @@
 package org.opendaylight.openflowplugin.openflow.md.util;
 
 import java.math.BigInteger;
+
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemovedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
@@ -144,4 +149,11 @@ public abstract class PortTranslatorUtil {
         builder.addAugmentation(FlowCapableNodeConnectorUpdated.class, fcncub.build());
         return builder.build();
     }
+
+    public static NodeConnectorRemoved translatePortRemoved(Short version, BigInteger datapathId, Long portNumber, PortGrouping port) {
+        OpenflowVersion ofVersion = OpenflowVersion.get(version);
+        NodeConnectorRemovedBuilder builder = new NodeConnectorRemovedBuilder();
+        builder.setNodeConnectorRef(InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(datapathId, portNumber, ofVersion));
+        return builder.build();
+    }
 }