itm and mdsal porting
[vpnservice.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / vpnservice / mdsalutil / MatchFieldType.java
old mode 100644 (file)
new mode 100755 (executable)
index 178ba18..24cdb3d
@@ -1,7 +1,9 @@
 /*
- * Copyright (c) 2013 Ericsson AB.  All rights reserved.
- *
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.mdsalutil;
 
@@ -43,14 +45,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Match
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SalOpenflowBasicClass;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId;
 
@@ -161,8 +160,8 @@ public enum MatchFieldType {
         @Override
         public void setMatch(MatchBuilder matchBuilderInOut, MatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
 
-            StringBuffer nodeConnectorId = new StringBuffer().append("openflow:").append(matchInfo.getMatchValues()[0])
-            .append(':').append(matchInfo.getMatchValues()[1]);
+            StringBuffer nodeConnectorId = new StringBuffer().append("openflow:").append(matchInfo.getBigMatchValues()[0])
+            .append(':').append(matchInfo.getBigMatchValues()[1]);
             matchBuilderInOut.setInPort(new NodeConnectorId(nodeConnectorId.toString()));
         }
     },
@@ -252,6 +251,64 @@ public enum MatchFieldType {
             }
         }
     },
+    
+    ipv4_destination {
+        @Override
+        protected Class<? extends MatchField> getMatchType() {
+            return Ipv4Dst.class;
+        }
+
+        @Override
+        public void createInnerMatchBuilder(MatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+            Ipv4MatchBuilder ipv4MatchBuilder = (Ipv4MatchBuilder) mapMatchBuilder.get(Ipv4MatchBuilder.class);
+
+            if (ipv4MatchBuilder == null) {
+                ipv4MatchBuilder = new Ipv4MatchBuilder();
+                mapMatchBuilder.put(Ipv4MatchBuilder.class, ipv4MatchBuilder);
+            }
+
+            String[] prefix = matchInfo.getStringMatchValues();
+            ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(prefix[0] + "/" + prefix[1])).build();
+        }
+
+        @Override
+        public void setMatch(MatchBuilder matchBuilderInOut, MatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+            Ipv4MatchBuilder ipv4MatchBuilder = (Ipv4MatchBuilder) mapMatchBuilder.remove(Ipv4MatchBuilder.class);
+
+            if (ipv4MatchBuilder != null) {
+                matchBuilderInOut.setLayer3Match(ipv4MatchBuilder.build());
+            }
+        }
+    },
+
+    ipv4_source {
+        @Override
+        protected Class<? extends MatchField> getMatchType() {
+            return Ipv4Src.class;
+        }
+
+        @Override
+        public void createInnerMatchBuilder(MatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+            Ipv4MatchBuilder ipv4MatchBuilder = (Ipv4MatchBuilder) mapMatchBuilder.get(Ipv4MatchBuilder.class);
+
+            if (ipv4MatchBuilder == null) {
+                ipv4MatchBuilder = new Ipv4MatchBuilder();
+                mapMatchBuilder.put(Ipv4MatchBuilder.class, ipv4MatchBuilder);
+            }
+
+            String[] prefix = matchInfo.getStringMatchValues();
+            ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(prefix[0] + "/" + prefix[1])).build();
+        }
+
+        @Override
+        public void setMatch(MatchBuilder matchBuilderInOut, MatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+            Ipv4MatchBuilder ipv4MatchBuilder = (Ipv4MatchBuilder) mapMatchBuilder.remove(Ipv4MatchBuilder.class);
+
+            if (ipv4MatchBuilder != null) {
+                matchBuilderInOut.setLayer3Match(ipv4MatchBuilder.build());
+            }
+        }
+    },
 
     arp_op {
         @Override
@@ -551,7 +608,11 @@ public enum MatchFieldType {
             }
 
             BigInteger[] tunnelIdValues = matchInfo.getBigMatchValues();
-            tunnelBuilder.setTunnelId(tunnelIdValues[0]).setTunnelMask(tunnelIdValues[1]).build();
+            tunnelBuilder.setTunnelId(tunnelIdValues[0]);
+            if(tunnelIdValues.length > 1){
+                tunnelBuilder.setTunnelMask(tunnelIdValues[1]);
+            }
+            tunnelBuilder.build();
         }
 
         @Override