Modified Match and Action utilities to support Nicira extension required 33/40233/2
authorAswin Suryanarayanan <asuryana@redhat.com>
Mon, 13 Jun 2016 10:11:16 +0000 (15:41 +0530)
committerAswin Suryanarayanan <asuryana@redhat.com>
Tue, 14 Jun 2016 12:40:57 +0000 (18:10 +0530)
for connection tracking.

Change-Id: Id92c251d0b8379e23aa99a013ec7c10e6818bc3e
Signed-off-by: Aswin Suryanarayanan <asuryana@redhat.com>
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/ActionType.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/FlowEntity.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/MDSALUtil.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/MatchInfo.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/MatchInfoBase.java [new file with mode: 0644]
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NxMatchFieldType.java [new file with mode: 0644]
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NxMatchInfo.java [new file with mode: 0644]

index 4d46d12c77e10303eaa7cb862d9b9bfd6159abea..eb69d0dd83c915fae4404857d097b9b0273aa8a0 100644 (file)
@@ -53,6 +53,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.add.group.input.buckets.bucket.action.action.NxActionResubmitRpcAddGroupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionConntrackNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.NxConntrack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.NxConntrackBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
 
 public enum ActionType {
@@ -425,6 +428,28 @@ public enum ActionType {
             ActionBuilder ab = new ActionBuilder();
             return null;
         }
+    },
+    nx_conntrack {
+        @Override
+        public Action buildAction(ActionInfo actionInfo) {
+            String[] actionValues = actionInfo.getActionValues();
+            Integer flags = new Integer(actionValues[0]);
+            Long zoneSrc = new Long(actionValues[1]);
+            Integer conntrackZone = new Integer(actionValues[2]);
+            Short recircTable = new Short(actionValues[3]);
+            NxConntrackBuilder ctb = new NxConntrackBuilder()
+                    .setFlags(flags)
+                    .setZoneSrc(zoneSrc)
+                    .setConntrackZone(conntrackZone)
+                    .setRecircTable(recircTable);
+            ActionBuilder ab = new ActionBuilder();
+            ab.setAction(new NxActionConntrackNodesNodeTableFlowApplyActionsCaseBuilder()
+                .setNxConntrack(ctb.build()).build());
+            ab.setKey(new ActionKey(actionInfo.getActionKey()));
+            return ab.build();
+
+        }
+
     };
 
     private static final int RADIX_HEX = 16;
index 4e9f1cefdf702f386e84993fc0f2c1c4ce6c8d80..f43e4632fba8f03f83bad674e412ab9ee86b242d 100644 (file)
@@ -26,7 +26,7 @@ public class FlowEntity extends AbstractSwitchEntity {
     private int m_nIdleTimeOut;
     private int m_nHardTimeOut;
     private BigInteger m_biCookie;
-    private List<MatchInfo> m_listMatchInfo;
+    private List<? extends MatchInfoBase> m_listMatchInfo;
     private List<InstructionInfo> m_listInstructionInfo;
 
     private boolean m_bStrictFlag;
@@ -71,7 +71,7 @@ public class FlowEntity extends AbstractSwitchEntity {
         return m_listInstructionInfo;
     }
 
-    public List<MatchInfo> getMatchInfoList() {
+    public List<? extends MatchInfoBase> getMatchInfoList() {
         return m_listMatchInfo;
     }
 
@@ -152,7 +152,7 @@ public class FlowEntity extends AbstractSwitchEntity {
         m_flowBuilder = null;
     }
 
-    public void setMatchInfoList(List<MatchInfo> listMatchInfo) {
+    public void setMatchInfoList(List<? extends MatchInfoBase> listMatchInfo) {
         m_listMatchInfo = listMatchInfo;
         m_flowBuilder = null;
     }
index 06f623d1d0ae6c6ed40f3b5f2974c5c7b6cf41b0..f39c1f45a61f7fd532b3782f7db0c6609384df89 100644 (file)
@@ -105,7 +105,7 @@ public class MDSALUtil {
     private static final Logger logger = LoggerFactory.getLogger(MDSALUtil.class);
 
     public static FlowEntity buildFlowEntity(BigInteger dpnId, short tableId, String flowId, int priority, String flowName,
-            int idleTimeOut, int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo,
+            int idleTimeOut, int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase>  listMatchInfoBase,
             List<InstructionInfo> listInstructionInfo) {
 
         FlowEntity flowEntity = new FlowEntity(dpnId);
@@ -117,7 +117,7 @@ public class MDSALUtil {
         flowEntity.setIdleTimeOut(idleTimeOut);
         flowEntity.setHardTimeOut(hardTimeOut);
         flowEntity.setCookie(cookie);
-        flowEntity.setMatchInfoList(listMatchInfo);
+        flowEntity.setMatchInfoList(listMatchInfoBase);
         flowEntity.setInstructionInfoList(listInstructionInfo);
 
         return flowEntity;
@@ -125,16 +125,16 @@ public class MDSALUtil {
 
     // TODO: CHECK IF THIS IS USED
     public static Flow buildFlow(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
-            int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo, List<InstructionInfo> listInstructionInfo) {
+            int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> listMatchInfoBase, List<InstructionInfo> listInstructionInfo) {
         return MDSALUtil.buildFlow(tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie,
-                listMatchInfo, listInstructionInfo, true);
+                listMatchInfoBase, listInstructionInfo, true);
     }
 
     public static Flow buildFlow(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
-            int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo,
+            int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase>  listMatchInfoBase,
             List<InstructionInfo> listInstructionInfo, boolean isStrict) {
         FlowKey key = new FlowKey(new FlowId(flowId));
-        return new FlowBuilder().setMatch(buildMatches(listMatchInfo)).setKey(key)
+        return new FlowBuilder().setMatch(buildMatches(listMatchInfoBase)).setKey(key)
                 .setPriority(Integer.valueOf(priority)).setInstructions(buildInstructions(listInstructionInfo))
                 .setBarrier(false).setInstallHw(true).setHardTimeout(hardTimeOut).setIdleTimeout(idleTimeOut)
                 .setFlowName(flowName).setTableId(Short.valueOf(tableId)).setStrict(isStrict)
@@ -146,16 +146,16 @@ public class MDSALUtil {
     }
 
     public static Flow buildFlowNew(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
-                                 int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo, List<Instruction> listInstructionInfo) {
+                                 int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase>  listMatchInfoBase, List<Instruction> listInstructionInfo) {
         return MDSALUtil.buildFlowNew(tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie,
-                listMatchInfo, listInstructionInfo, true);
+                listMatchInfoBase, listInstructionInfo, true);
     }
 
     private static Flow buildFlowNew(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
-                                  int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo,
+                                  int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase>  listMatchInfoBase,
                                   List<Instruction> listInstructionInfo, boolean isStrict) {
         FlowKey key = new FlowKey(new FlowId(flowId));
-        return new FlowBuilder().setMatch(buildMatches(listMatchInfo)).setKey(key)
+        return new FlowBuilder().setMatch(buildMatches(listMatchInfoBase)).setKey(key)
                 .setPriority(Integer.valueOf(priority)).setInstructions(new InstructionsBuilder().setInstruction(listInstructionInfo).build())
                 .setBarrier(false).setInstallHw(true).setHardTimeout(hardTimeOut).setIdleTimeout(idleTimeOut)
                 .setFlowName(flowName).setTableId(Short.valueOf(tableId)).setStrict(isStrict)
@@ -281,17 +281,17 @@ public class MDSALUtil {
         return EMPTY_Instructions;
     }
 
-    public static Match buildMatches(List<MatchInfo> listMatchInfo) {
-        if (listMatchInfo != null) {
+    public static Match buildMatches(List<? extends MatchInfoBase> listMatchInfoBase) {
+        if (listMatchInfoBase != null) {
             MatchBuilder matchBuilder = new MatchBuilder();
             Map<Class<?>, Object> mapMatchBuilder = new HashMap<Class<?>, Object>();
 
-            for (MatchInfo matchInfo : listMatchInfo) {
-                matchInfo.createInnerMatchBuilder(mapMatchBuilder);
+            for (MatchInfoBase MatchInfoBase : listMatchInfoBase) {
+                MatchInfoBase.createInnerMatchBuilder(mapMatchBuilder);
             }
 
-            for (MatchInfo matchInfo : listMatchInfo) {
-                matchInfo.setMatch(matchBuilder, mapMatchBuilder);
+            for (MatchInfoBase MatchInfoBase : listMatchInfoBase) {
+                MatchInfoBase.setMatch(matchBuilder, mapMatchBuilder);
             }
 
             return matchBuilder.build();
index ad6c55cceb70ee42426f70234d4cb8c3b2a21cde..225afa35e3ccac6832fe1bfc00e9674ca20431a0 100644 (file)
@@ -13,7 +13,7 @@ import java.util.Map;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
 
-public class MatchInfo implements Serializable {
+public class MatchInfo implements Serializable, MatchInfoBase {
     private static final long serialVersionUID = 1L;
 
     private final MatchFieldType m_matchField;
@@ -36,10 +36,12 @@ public class MatchInfo implements Serializable {
         m_asMatchValues = alStringMatchValues;
     }
 
+    @Override
     public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder) {
         m_matchField.createInnerMatchBuilder(this, mapMatchBuilder);
     }
 
+    @Override
     public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder) {
         m_matchField.setMatch(matchBuilder, this, mapMatchBuilder);
     }
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/MatchInfoBase.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/MatchInfoBase.java
new file mode 100644 (file)
index 0000000..cdcd47f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016 RedHat Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.mdsalutil;
+
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+
+/**
+ *  This interface helps in creating the openflow matches.
+ */
+
+public interface MatchInfoBase {
+
+    /**
+     * Creater the inner match object
+     *
+     * @param mapMatchBuilder the map which holds the matches.
+     */
+    public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder);
+
+    /**
+     * Set the match to the match builder.
+     * @param matchBuilder the matchbuilder to set the match
+     * @param mapMatchBuilder the map containing the matches
+     */
+    public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder);
+
+}
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NxMatchFieldType.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NxMatchFieldType.java
new file mode 100644 (file)
index 0000000..d16a196
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2016 RedHat Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.mdsalutil;
+
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
+
+import com.google.common.collect.ImmutableList;
+
+public enum NxMatchFieldType {
+
+    ct_state {
+        @Override
+        protected Class<? extends MatchField> getMatchType() {
+            return NxmNxReg.class;
+        }
+
+        @Override
+        public void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+            NxmNxCtStateBuilder ctStateBuilder = (NxmNxCtStateBuilder) mapMatchBuilder.get(NxmNxCtStateBuilder.class);
+
+            if (ctStateBuilder == null) {
+                ctStateBuilder = new NxmNxCtStateBuilder();
+                mapMatchBuilder.put(NxmNxCtStateBuilder.class, ctStateBuilder);
+            }
+
+            ctStateBuilder.setCtState(matchInfo.getMatchValues()[0]);
+            ctStateBuilder.setMask(matchInfo.getMatchValues()[1]);
+        }
+
+        @Override
+        public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
+                             Map<Class<?>, Object> mapMatchBuilder) {
+            NxmNxCtStateBuilder ctStateBuilder = (NxmNxCtStateBuilder) mapMatchBuilder
+                    .remove(NxmNxCtStateBuilder.class);
+
+            if (ctStateBuilder != null) {
+                NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
+                        .setNxmNxCtState(ctStateBuilder.build())
+                        .build();
+                GeneralAugMatchNodesNodeTableFlow genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
+                        .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
+                                                       .setExtensionKey(NxmNxCtStateKey.class)
+                                                       .setExtension(new ExtensionBuilder()
+                                                       .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
+                                                                         .build()).build())).build();
+                matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
+            }
+        }
+    },
+    ct_zone {
+        @Override
+        protected Class<? extends MatchField> getMatchType() {
+            return NxmNxReg.class;
+        }
+
+        @Override
+        public void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+            NxmNxCtZoneBuilder ctZoneBuilder = (NxmNxCtZoneBuilder) mapMatchBuilder.get(NxmNxCtZoneBuilder.class);
+
+            if (ctZoneBuilder == null) {
+                ctZoneBuilder = new NxmNxCtZoneBuilder();
+                mapMatchBuilder.put(NxmNxCtStateBuilder.class, ctZoneBuilder);
+            }
+
+            ctZoneBuilder.setCtZone((int)matchInfo.getMatchValues()[0]);
+        }
+
+        @Override
+        public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
+                             Map<Class<?>, Object> mapMatchBuilder) {
+            NxmNxCtZoneBuilder ctZoneBuilder = (NxmNxCtZoneBuilder) mapMatchBuilder.remove(NxmNxCtZoneBuilder.class);
+
+            if (ctZoneBuilder != null) {
+                NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
+                        .setNxmNxCtZone(ctZoneBuilder.build())
+                        .build();
+                GeneralAugMatchNodesNodeTableFlow genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
+                        .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
+                                                       .setExtensionKey(NxmNxCtStateKey.class)
+                                                       .setExtension(new ExtensionBuilder()
+                                                       .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
+                                                                         .build()).build())).build();
+                matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
+            }
+        }
+
+    };
+
+    public abstract void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder);
+
+    public abstract void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
+            Map<Class<?>, Object> mapMatchBuilder);
+
+    protected abstract Class<? extends MatchField> getMatchType();
+
+    protected boolean hasMatchFieldMask() {
+        // Override this to return true
+                return false;
+    }
+
+}
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NxMatchInfo.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NxMatchInfo.java
new file mode 100644 (file)
index 0000000..0db4550
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2016 RedHat Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.mdsalutil;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+
+/**
+ *  This class defines the nicira extension matches.
+ */
+
+public class NxMatchInfo implements Serializable, MatchInfoBase {
+
+
+    private static final long serialVersionUID = 1L;
+
+    private final NxMatchFieldType m_matchField;
+    private long[] m_alMatchValues;
+    private BigInteger[] m_aBigIntValues;
+    private String[] m_asMatchValues;
+
+    public NxMatchInfo(NxMatchFieldType matchField, long[] alMatchValues) {
+        m_matchField = matchField;
+        m_alMatchValues = alMatchValues;
+    }
+
+    public NxMatchInfo(NxMatchFieldType matchField, BigInteger[] alBigMatchValues) {
+        m_matchField = matchField;
+        m_aBigIntValues = alBigMatchValues;
+    }
+
+    public NxMatchInfo(NxMatchFieldType matchField, String[] alStringMatchValues) {
+        m_matchField = matchField;
+        m_asMatchValues = alStringMatchValues;
+    }
+
+    @Override
+    public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder) {
+        m_matchField.createInnerMatchBuilder(this, mapMatchBuilder);
+    }
+
+    @Override
+    public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder) {
+        m_matchField.setMatch(matchBuilder, this, mapMatchBuilder);
+    }
+
+    public NxMatchFieldType getMatchField() {
+        return m_matchField;
+    }
+
+    public long[] getMatchValues() {
+        return m_alMatchValues;
+    }
+
+    public BigInteger[] getBigMatchValues() {
+        return m_aBigIntValues;
+    }
+
+    public String[] getStringMatchValues() {
+        return m_asMatchValues;
+    }
+}