Drop flows with actions to non-existing group id
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / util / FrmUtil.java
index 4ef0316175eb0dfbc793483349475fa6a7597fed..ff8183d3da885029ba66057eeb39191c0989f7dd 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
@@ -38,6 +39,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.arbitrator.reconcile.service.rev180227.GetActiveBundleOutput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,7 +61,7 @@ public final class FrmUtil {
         return flowRef.getValue().firstKeyOf(Flow.class).getId().getValue();
     }
 
-    public static short getTableId(final FlowTableRef flowTableRef) {
+    public static Uint8 getTableId(final FlowTableRef flowTableRef) {
         return flowTableRef.getValue().firstKeyOf(Table.class).getId();
     }
 
@@ -68,7 +71,7 @@ public final class FrmUtil {
         return new BigInteger(dpId);
     }
 
-    public static Long isFlowDependentOnGroup(final Flow flow) {
+    public static Uint32 isFlowDependentOnGroup(final Flow flow) {
         LOG.debug("Check if flow {} is dependent on group", flow);
         if (flow.getInstructions() != null) {
             List<Instruction> instructions = flow.getInstructions().getInstruction();
@@ -78,6 +81,10 @@ public final class FrmUtil {
                         .equals(ActionType.APPLY_ACTION.getActionType())) {
                     actions = ((ApplyActionsCase) instruction.getInstruction())
                             .getApplyActions().getAction();
+                } else if (instruction.getInstruction().implementedInterface()
+                        .equals(ActionType.WRITE_ACTION.getActionType())) {
+                    actions = ((WriteActionsCase)instruction.getInstruction())
+                            .getWriteActions().getAction();
                 }
                 for (Action action : actions) {
                     if (action.getAction().implementedInterface()
@@ -92,7 +99,7 @@ public final class FrmUtil {
     }
 
     public static InstanceIdentifier<Group> buildGroupInstanceIdentifier(
-            final InstanceIdentifier<FlowCapableNode> nodeIdent, final Long groupId) {
+            final InstanceIdentifier<FlowCapableNode> nodeIdent, final Uint32 groupId) {
         NodeId nodeId = getNodeIdFromNodeIdentifier(nodeIdent);
         InstanceIdentifier<Group> groupInstanceId = InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class)
@@ -120,7 +127,7 @@ public final class FrmUtil {
     }
 
     public static boolean isGroupExistsOnDevice(final InstanceIdentifier<FlowCapableNode> nodeIdent,
-            final Long groupId, final ForwardingRulesManager provider) {
+            final Uint32 groupId, final ForwardingRulesManager provider) {
         NodeId nodeId = getNodeIdFromNodeIdentifier(nodeIdent);
         return provider.getDevicesGroupRegistry().isGroupPresent(nodeId, groupId);
     }