Bug 7453 - FlowRemoved doesn't have Removed Reason Information 80/51280/1
authoreeiillu <suja.t@ericsson.com>
Thu, 12 Jan 2017 04:59:18 +0000 (10:29 +0530)
committerD Arunprakash <d.arunprakash@ericsson.com>
Wed, 1 Feb 2017 06:34:18 +0000 (06:34 +0000)
On flow being removed from switch on idle timeout, onFlowRemoved() api was
invoked and while conversion reason was not being converted and added, so
the application using API onFlowRemoved() was not getting the reason for
flow being removed from the switch.
This change will provide the reason invoking onFlowRemoved() API

Change-Id: Id8b957b5b2cc581215fb84b8ca84d1d9a04e5619
Signed-off-by: eeiillu <suja.t@ericsson.com>
(cherry picked from commit 80cee5d71d306b8806d9316d12dceb5c1d1d63e6)

model/model-flow-base/src/main/yang/opendaylight-flow-types.yang
model/model-flow-service/src/main/yang/sal-flow.yang
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslator.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java

index 9de9cb7215173d72f6cf923efc0d4ca66986c6c8..ad70cda6016cce94aba516361bc3b024438ccd38 100644 (file)
@@ -122,15 +122,27 @@ module opendaylight-flow-types {
             bit SEND_FLOW_REM;
         }
     }
+     typedef removed-flow-reason {
+            type enumeration {
+                enum OFPRR_IDLE_TIMEOUT{
+                    value 0;
+                    description "Flow idle time exceeded idle_timeout.";
+                }
+                enum OFPRR_HARD_TIMEOUT {
+                    value 1;
+                    description "Time exceeded hard_timeout.";
+                }
+                enum OFPRR_DELETE {
+                    value 2;
+                    description "Evicted by a DELETE flow mod.";
+                }
+                enum OFPRR_GROUP_DELETE {
+                    value 3;
+                    description "Group was removed.";
+                }
 
-    typedef removed_reason_flags {
-        type bits {
-            bit IDLE_TIMEOUT;
-            bit HARD_TIMEOUT;
-            bit DELETE;
-            bit GROUP_DELETE;
-        }
-    }
+            }
+     }
     
     grouping generic_flow_attributes {
         leaf priority {
@@ -245,7 +257,7 @@ module opendaylight-flow-types {
         uses generic_flow_attributes;
         
         leaf removed_reason {
-            type removed_reason_flags;
+            type removed-flow-reason;
         }
 
         leaf duration_nsec {
index 4cabb74ea55cd81e6e6c7a6a15de8c78b79e06df..2fe3c117edbac23f8fc4629303295d568b1b9d85 100644 (file)
@@ -4,7 +4,7 @@ module sal-flow {
 
     import yang-ext {prefix ext; revision-date "2013-07-09";}
     import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
-    import opendaylight-flow-types {prefix types;revision-date "2013-10-26";}    
+    import opendaylight-flow-types {prefix types;revision-date "2013-10-26";}
     import opendaylight-group-types {prefix group-type;revision-date "2013-10-18";}
     import opendaylight-meter-types {prefix meter-type;revision-date "2013-09-18";}
     import flow-capable-transaction {prefix tr; revision-date "2015-03-04";}
@@ -157,6 +157,9 @@ module sal-flow {
         leaf flow-ref {
             type types:flow-ref;
         }
+        leaf reason {
+            type types:removed-flow-reason;
+        }
         uses node-flow;
         uses tr:transaction-aware;
     }
index eb9ff12296554045022cffdf270f6c08fc0be45f..86d4c9c3a40983334157f3a031b8bb1bd69f7787 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.impl.translator;
 
+import java.util.Objects;
 import java.util.Optional;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
@@ -14,16 +15,19 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorE
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedFlowReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * translate {@link FlowRemoved} message to FlowRemoved notification (omit instructions)
  */
 public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> {
     private final ConvertorExecutor convertorExecutor;
-
+    private static final Logger logger = LoggerFactory.getLogger(FlowRemovedTranslator.class);
     public FlowRemovedTranslator(ConvertorExecutor convertorExecutor) {
         this.convertorExecutor = convertorExecutor;
     }
@@ -41,6 +45,10 @@ public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org
                 .setPriority(input.getPriority())
                 .setTableId(translateTableId(input));
 
+        if(Objects.nonNull(input.getReason())) {
+            flowRemovedBld.setReason(translateReason(input));
+        }
+
         return flowRemovedBld.build();
     }
 
@@ -64,4 +72,22 @@ public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org
     protected Short translateTableId(FlowRemoved flowRemoved) {
         return flowRemoved.getTableId().getValue().shortValue();
     }
+
+
+    private RemovedFlowReason translateReason(FlowRemoved removedFlow) {
+        logger.debug("--Entering translateReason within FlowRemovedTranslator with reason:{} " + removedFlow.getReason());
+        switch (removedFlow.getReason()) {
+            case OFPRRIDLETIMEOUT:
+                return RemovedFlowReason.OFPRRIDLETIMEOUT;
+            case OFPRRHARDTIMEOUT:
+                return RemovedFlowReason.OFPRRHARDTIMEOUT;
+            case OFPRRDELETE:
+                return RemovedFlowReason.OFPRRDELETE;
+            case OFPRRGROUPDELETE:
+                return RemovedFlowReason.OFPRRGROUPDELETE;
+            default:
+                logger.debug("The flow is being deleted for some unknown reason  ");
+                return RemovedFlowReason.OFPRRDELETE;
+        }
+    }
 }
index 493771c3a1e497dd279e7a4c2a7ec2fe60b51089..6a5298b2580ebe0e64694ce7d43d7e87ca111d9c 100644 (file)
@@ -14,6 +14,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Objects;
 import java.util.concurrent.CopyOnWriteArrayList;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.openflowplugin.api.OFConstants;
@@ -34,7 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemovedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedReasonFlags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedFlowReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
@@ -63,7 +64,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpOp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpSha;
@@ -147,6 +147,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanPcpCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst;
@@ -190,14 +191,10 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
             salFlowRemoved.setHardTimeout(ofFlow.getHardTimeout());
             salFlowRemoved.setPacketCount(ofFlow.getPacketCount());
             salFlowRemoved.setByteCount(ofFlow.getByteCount());
-            RemovedReasonFlags removeReasonFlag = new RemovedReasonFlags(
-                    FlowRemovedReason.OFPRRDELETE.equals(ofFlow.getReason()),
-                    FlowRemovedReason.OFPRRGROUPDELETE.equals(ofFlow.getReason()),
-                    FlowRemovedReason.OFPRRHARDTIMEOUT.equals(ofFlow.getReason()),
-                    FlowRemovedReason.OFPRRIDLETIMEOUT.equals(ofFlow.getReason())
-            );
 
-            salFlowRemoved.setRemovedReason(removeReasonFlag);
+            if(Objects.nonNull(ofFlow.getReason())) {
+                salFlowRemoved.setRemovedReason(translateReason(ofFlow));
+            }
 
             OpenflowVersion ofVersion = OpenflowVersion.get(sc.getPrimaryConductor().getVersion());
             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match ofMatch = ofFlow
@@ -220,7 +217,22 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
             return Collections.emptyList();
         }
     }
-
+    private RemovedFlowReason translateReason(FlowRemoved removedFlow) {
+        LOG.debug("--Entering translateReason within FlowRemovedTranslator with reason:{} " + removedFlow.getReason());
+        switch (removedFlow.getReason()) {
+            case OFPRRIDLETIMEOUT:
+                return RemovedFlowReason.OFPRRIDLETIMEOUT;
+            case OFPRRHARDTIMEOUT:
+                return RemovedFlowReason.OFPRRHARDTIMEOUT;
+            case OFPRRDELETE:
+                return RemovedFlowReason.OFPRRDELETE;
+            case OFPRRGROUPDELETE:
+                return RemovedFlowReason.OFPRRGROUPDELETE;
+            default:
+                LOG.debug("The flow being default and hence deleting it ");
+                return RemovedFlowReason.OFPRRDELETE;
+        }
+    }
 
     public Match fromMatch(final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match ofMatch,
                            final BigInteger datapathid, final OpenflowVersion ofVersion) {