add learn action
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / NxMatchFieldType.java
index 24d350f112d18766df3ce424d9279ad14cf188b5..620aac772b85c6c5041ce019852236d6eca808e9 100644 (file)
@@ -15,8 +15,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
@@ -28,23 +26,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 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.NxmNxCtZoneKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpDstKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpSrcKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpDstKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpSrcKey;
 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.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.src.grouping.NxmOfTcpSrcBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.dst.grouping.NxmOfTcpDstBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.src.grouping.NxmOfTcpSrcBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.dst.grouping.NxmOfUdpDstBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.src.grouping.NxmOfUdpSrcBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
-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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
 
 public enum NxMatchFieldType {
 
@@ -69,18 +62,17 @@ public enum NxMatchFieldType {
 
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
-                             Map<Class<?>, Object> mapMatchBuilder) {
+                Map<Class<?>, Object> mapMatchBuilder) {
             NxmNxCtStateBuilder ctStateBuilder = (NxmNxCtStateBuilder) mapMatchBuilder
                     .remove(NxmNxCtStateBuilder.class);
 
             if (ctStateBuilder != null) {
                 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
-                        .setNxmNxCtState(ctStateBuilder.build())
-                        .build();
-                GeneralAugMatchNodesNodeTableFlow existingAugmentations =
-                        matchBuilderInOut.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
+                        .setNxmNxCtState(ctStateBuilder.build()).build();
+                GeneralAugMatchNodesNodeTableFlow existingAugmentations = matchBuilderInOut
+                        .getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
                 GeneralAugMatchNodesNodeTableFlow genAugMatch = generalAugMatchBuilder(existingAugmentations,
-                    nxAugMatch, NxmNxCtStateKey.class);
+                        nxAugMatch, NxmNxCtStateKey.class);
                 matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
             }
         }
@@ -101,22 +93,21 @@ public enum NxMatchFieldType {
                 mapMatchBuilder.put(NxmNxCtZoneBuilder.class, ctZoneBuilder);
             }
 
-            ctZoneBuilder.setCtZone((int)matchInfo.getMatchValues()[0]);
+            ctZoneBuilder.setCtZone((int) matchInfo.getMatchValues()[0]);
         }
 
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
-                             Map<Class<?>, Object> mapMatchBuilder) {
+                Map<Class<?>, Object> mapMatchBuilder) {
             NxmNxCtZoneBuilder ctZoneBuilder = (NxmNxCtZoneBuilder) mapMatchBuilder.remove(NxmNxCtZoneBuilder.class);
 
             if (ctZoneBuilder != null) {
                 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
-                        .setNxmNxCtZone(ctZoneBuilder.build())
-                        .build();
-                GeneralAugMatchNodesNodeTableFlow existingAugmentations =
-                        matchBuilderInOut.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
+                        .setNxmNxCtZone(ctZoneBuilder.build()).build();
+                GeneralAugMatchNodesNodeTableFlow existingAugmentations = matchBuilderInOut
+                        .getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
                 GeneralAugMatchNodesNodeTableFlow genAugMatch = generalAugMatchBuilder(existingAugmentations,
-                    nxAugMatch, NxmNxCtZoneKey.class);
+                        nxAugMatch, NxmNxCtZoneKey.class);
                 matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
             }
         }
@@ -136,21 +127,20 @@ public enum NxMatchFieldType {
                 tcpSrcBuilder = new NxmOfTcpSrcBuilder();
                 mapMatchBuilder.put(NxmOfTcpSrcBuilder.class, tcpSrcBuilder);
             }
-            tcpSrcBuilder.setPort(new PortNumber((int)matchInfo.getMatchValues()[0]));
-            tcpSrcBuilder.setMask((int)matchInfo.getMatchValues()[1]);
+            tcpSrcBuilder.setPort(new PortNumber((int) matchInfo.getMatchValues()[0]));
+            tcpSrcBuilder.setMask((int) matchInfo.getMatchValues()[1]);
         }
 
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
-                             Map<Class<?>, Object> mapMatchBuilder) {
+                Map<Class<?>, Object> mapMatchBuilder) {
             NxmOfTcpSrcBuilder tcpSrcBuilder = (NxmOfTcpSrcBuilder) mapMatchBuilder.remove(NxmOfTcpSrcBuilder.class);
 
             if (tcpSrcBuilder != null) {
                 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
-                        .setNxmOfTcpSrc(tcpSrcBuilder.build())
-                        .build();
-                GeneralAugMatchNodesNodeTableFlow existingAugmentations =
-                        matchBuilderInOut.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
+                        .setNxmOfTcpSrc(tcpSrcBuilder.build()).build();
+                GeneralAugMatchNodesNodeTableFlow existingAugmentations = matchBuilderInOut
+                        .getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
                 GeneralAugMatchNodesNodeTableFlow genAugMatch = generalAugMatchBuilder(existingAugmentations,
                         nxAugMatch, NxmOfTcpSrcKey.class);
                 matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
@@ -172,21 +162,20 @@ public enum NxMatchFieldType {
                 tcpDstBuilder = new NxmOfTcpDstBuilder();
                 mapMatchBuilder.put(NxmOfTcpDstBuilder.class, tcpDstBuilder);
             }
-            tcpDstBuilder.setPort(new PortNumber((int)matchInfo.getMatchValues()[0]));
-            tcpDstBuilder.setMask((int)matchInfo.getMatchValues()[1]);
+            tcpDstBuilder.setPort(new PortNumber((int) matchInfo.getMatchValues()[0]));
+            tcpDstBuilder.setMask((int) matchInfo.getMatchValues()[1]);
         }
 
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
-                             Map<Class<?>, Object> mapMatchBuilder) {
+                Map<Class<?>, Object> mapMatchBuilder) {
             NxmOfTcpDstBuilder tcpDstBuilder = (NxmOfTcpDstBuilder) mapMatchBuilder.remove(NxmOfTcpDstBuilder.class);
 
             if (tcpDstBuilder != null) {
                 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
-                        .setNxmOfTcpDst(tcpDstBuilder.build())
-                        .build();
-                GeneralAugMatchNodesNodeTableFlow existingAugmentations =
-                        matchBuilderInOut.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
+                        .setNxmOfTcpDst(tcpDstBuilder.build()).build();
+                GeneralAugMatchNodesNodeTableFlow existingAugmentations = matchBuilderInOut
+                        .getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
                 GeneralAugMatchNodesNodeTableFlow genAugMatch = generalAugMatchBuilder(existingAugmentations,
                         nxAugMatch, NxmOfTcpDstKey.class);
                 matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
@@ -208,21 +197,20 @@ public enum NxMatchFieldType {
                 udpSrcBuilder = new NxmOfUdpSrcBuilder();
                 mapMatchBuilder.put(NxmOfUdpSrcBuilder.class, udpSrcBuilder);
             }
-            udpSrcBuilder.setPort(new PortNumber((int)matchInfo.getMatchValues()[0]));
-            udpSrcBuilder.setMask((int)matchInfo.getMatchValues()[1]);
+            udpSrcBuilder.setPort(new PortNumber((int) matchInfo.getMatchValues()[0]));
+            udpSrcBuilder.setMask((int) matchInfo.getMatchValues()[1]);
         }
 
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
-                             Map<Class<?>, Object> mapMatchBuilder) {
+                Map<Class<?>, Object> mapMatchBuilder) {
             NxmOfUdpSrcBuilder udpSrcBuilder = (NxmOfUdpSrcBuilder) mapMatchBuilder.remove(NxmOfUdpSrcBuilder.class);
 
             if (udpSrcBuilder != null) {
                 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
-                        .setNxmOfUdpSrc(udpSrcBuilder.build())
-                        .build();
-                GeneralAugMatchNodesNodeTableFlow existingAugmentations =
-                        matchBuilderInOut.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
+                        .setNxmOfUdpSrc(udpSrcBuilder.build()).build();
+                GeneralAugMatchNodesNodeTableFlow existingAugmentations = matchBuilderInOut
+                        .getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
                 GeneralAugMatchNodesNodeTableFlow genAugMatch = generalAugMatchBuilder(existingAugmentations,
                         nxAugMatch, NxmOfUdpSrcKey.class);
                 matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
@@ -244,21 +232,20 @@ public enum NxMatchFieldType {
                 udpDstBuilder = new NxmOfUdpDstBuilder();
                 mapMatchBuilder.put(NxmOfUdpDstBuilder.class, udpDstBuilder);
             }
-            udpDstBuilder.setPort(new PortNumber((int)matchInfo.getMatchValues()[0]));
-            udpDstBuilder.setMask((int)matchInfo.getMatchValues()[1]);
+            udpDstBuilder.setPort(new PortNumber((int) matchInfo.getMatchValues()[0]));
+            udpDstBuilder.setMask((int) matchInfo.getMatchValues()[1]);
         }
 
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
-                             Map<Class<?>, Object> mapMatchBuilder) {
+                Map<Class<?>, Object> mapMatchBuilder) {
             NxmOfUdpDstBuilder udpDstBuilder = (NxmOfUdpDstBuilder) mapMatchBuilder.remove(NxmOfUdpDstBuilder.class);
 
             if (udpDstBuilder != null) {
                 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
-                        .setNxmOfUdpDst(udpDstBuilder.build())
-                        .build();
-                GeneralAugMatchNodesNodeTableFlow existingAugmentations =
-                        matchBuilderInOut.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
+                        .setNxmOfUdpDst(udpDstBuilder.build()).build();
+                GeneralAugMatchNodesNodeTableFlow existingAugmentations = matchBuilderInOut
+                        .getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
                 GeneralAugMatchNodesNodeTableFlow genAugMatch = generalAugMatchBuilder(existingAugmentations,
                         nxAugMatch, NxmOfUdpDstKey.class);
                 matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
@@ -310,17 +297,22 @@ public enum NxMatchFieldType {
     /**
      * Creates the match builder object and add it to the map.
      *
-     * @param matchInfo the match info object
-     * @param mapMatchBuilder the match builder object
+     * @param matchInfo
+     *            the match info object
+     * @param mapMatchBuilder
+     *            the match builder object
      */
     public abstract void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder);
 
     /**
-     *  Retrieves the match from the map and set in the matchBuilder.
+     * Retrieves the match from the map and set in the matchBuilder.
      *
-     * @param matchBuilderInOut the match builder
-     * @param matchInfo the match info
-     * @param mapMatchBuilder the map containing the matches
+     * @param matchBuilderInOut
+     *            the match builder
+     * @param matchInfo
+     *            the match info
+     * @param mapMatchBuilder
+     *            the map containing the matches
      */
     public abstract void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
             Map<Class<?>, Object> mapMatchBuilder);
@@ -332,22 +324,20 @@ public enum NxMatchFieldType {
         return false;
     }
 
-    protected GeneralAugMatchNodesNodeTableFlow generalAugMatchBuilder(GeneralAugMatchNodesNodeTableFlow
-                                   existingAugmentations, NxAugMatchNodesNodeTableFlow nxAugMatch,
-                                   Class<? extends ExtensionKey> extentionKey ) {
+    protected GeneralAugMatchNodesNodeTableFlow generalAugMatchBuilder(
+            GeneralAugMatchNodesNodeTableFlow existingAugmentations, NxAugMatchNodesNodeTableFlow nxAugMatch,
+            Class<? extends ExtensionKey> extentionKey) {
         List<ExtensionList> extensions = null;
-        if (existingAugmentations != null ) {
+        if (existingAugmentations != null) {
             extensions = existingAugmentations.getExtensionList();
         }
         if (extensions == null) {
             extensions = Lists.newArrayList();
         }
-        extensions.add(new ExtensionListBuilder()
-                .setExtensionKey(extentionKey)
-                .setExtension(new ExtensionBuilder()
-                .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
-                .build()).build());
-        return new GeneralAugMatchNodesNodeTableFlowBuilder()
-                .setExtensionList(extensions).build();
+        extensions.add(new ExtensionListBuilder().setExtensionKey(extentionKey)
+                .setExtension(
+                        new ExtensionBuilder().addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch).build())
+                .build());
+        return new GeneralAugMatchNodesNodeTableFlowBuilder().setExtensionList(extensions).build();
     }
 }