Merge "Fix NPE caused by ElanServiceProvider"
[netvirt.git] / vpnservice / aclservice / impl / src / main / java / org / opendaylight / netvirt / aclservice / utils / AclServiceOFFlowBuilder.java
index 9a79c70f0d38bc869d4dfc83fbe67a1b484fb1c9..9e8b4a6f49be97d49d70d73b9031f35c024a4b16 100644 (file)
@@ -17,6 +17,8 @@ import org.opendaylight.genius.mdsalutil.MatchFieldType;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
 import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
+import org.opendaylight.genius.mdsalutil.NxMatchInfo;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4;
@@ -42,7 +44,10 @@ public class AclServiceOFFlowBuilder {
     public static Map<String, List<MatchInfoBase>> programIpFlow(Matches matches) {
         if (matches != null) {
             AceIp acl = (AceIp) matches.getAceType();
-            if (acl.getProtocol() == NwConstants.IP_PROT_TCP) {
+            Short protocol = acl.getProtocol();
+            if (protocol == null) {
+                return programEtherFlow(acl);
+            } else if (acl.getProtocol() == NwConstants.IP_PROT_TCP) {
                 return programTcpFlow(acl);
             } else if (acl.getProtocol() == NwConstants.IP_PROT_UDP) {
                 return programUdpFlow(acl);
@@ -55,6 +60,20 @@ public class AclServiceOFFlowBuilder {
         return null;
     }
 
+    /** Converts ether  matches to flows.
+     * @param acl the access control list
+     * @return the map containing the flows and the respective flow id
+     */
+    public static Map<String,List<MatchInfoBase>> programEtherFlow(AceIp acl) {
+        List<MatchInfoBase> flowMatches = new ArrayList<>();
+        flowMatches.addAll(addSrcIpMatches(acl));
+        flowMatches.addAll(addDstIpMatches(acl));
+        String flowId = "ETHER" + acl.getProtocol();
+        Map<String,List<MatchInfoBase>> flowMatchesMap = new HashMap<>();
+        flowMatchesMap.put(flowId,flowMatches);
+        return flowMatchesMap;
+    }
+
     /** Converts generic protocol matches to flows.
      *
      * @param acl the access control list
@@ -153,10 +172,8 @@ public class AclServiceOFFlowBuilder {
                 List<MatchInfoBase> flowMatches = new ArrayList<>();
                 flowMatches.addAll(addSrcIpMatches(acl));
                 flowMatches.addAll(addDstIpMatches(acl));
-                flowMatches.add(new MatchInfo(MatchFieldType.tcp_src,
-                    new long[] { port}));
-                /*flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_tcp_src_with_mask,
-                    new long[] {  port, portMaskMap.get(port) }));*/
+                flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_tcp_src_with_mask,
+                    new long[] {  port, portMaskMap.get(port) }));
                 flowMatches.add(new MatchInfo(MatchFieldType.ip_proto,
                     new long[] { acl.getProtocol() }));
                 String flowId = "TCP_SOURCE_" + port + "_" + portMaskMap.get(port);
@@ -170,10 +187,8 @@ public class AclServiceOFFlowBuilder {
                 List<MatchInfoBase> flowMatches = new ArrayList<>();
                 flowMatches.addAll(addSrcIpMatches(acl));
                 flowMatches.addAll(addDstIpMatches(acl));
-                flowMatches.add(new MatchInfo(MatchFieldType.tcp_dst,
-                        new long[] { port}));
-                /*flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_tcp_dst_with_mask,
-                    new long[] {  port, portMaskMap.get(port) }));*/
+                flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_tcp_dst_with_mask,
+                    new long[] {  port, portMaskMap.get(port) }));
                 flowMatches.add(new MatchInfo(MatchFieldType.ip_proto,
                     new long[] { acl.getProtocol() }));
                 String flowId = "TCP_DESTINATION_" + port + "_" + portMaskMap.get(port);
@@ -208,10 +223,8 @@ public class AclServiceOFFlowBuilder {
                 List<MatchInfoBase> flowMatches = new ArrayList<>();
                 flowMatches.addAll(addSrcIpMatches(acl));
                 flowMatches.addAll(addDstIpMatches(acl));
-                flowMatches.add(new MatchInfo(MatchFieldType.udp_src,
-                    new long[] { port}));
-                /*flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_udp_src_with_mask,
-                    new long[] {  port, portMaskMap.get(port) }));*/
+                flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_udp_src_with_mask,
+                    new long[] {  port, portMaskMap.get(port) }));
                 flowMatches.add(new MatchInfo(MatchFieldType.ip_proto,
                     new long[] { acl.getProtocol() }));
                 String flowId = "UDP_SOURCE_" + port + "_" + portMaskMap.get(port);
@@ -225,10 +238,8 @@ public class AclServiceOFFlowBuilder {
                 List<MatchInfoBase> flowMatches = new ArrayList<>();
                 flowMatches.addAll(addSrcIpMatches(acl));
                 flowMatches.addAll(addDstIpMatches(acl));
-                flowMatches.add(new MatchInfo(MatchFieldType.udp_dst,
-                    new long[] { port}));
-                /*flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_udp_dst_with_mask,
-                    new long[] {  port, portMaskMap.get(port) }));*/
+                flowMatches.add(new NxMatchInfo(NxMatchFieldType.nx_udp_dst_with_mask,
+                    new long[] {  port, portMaskMap.get(port) }));
                 flowMatches.add(new MatchInfo(MatchFieldType.ip_proto,
                     new long[] { acl.getProtocol() }));
                 String flowId = "UDP_DESTINATION_" + port + "_" + portMaskMap.get(port);
@@ -249,7 +260,7 @@ public class AclServiceOFFlowBuilder {
             flowMatches.add(new MatchInfo(MatchFieldType.eth_type,
                 new long[] { NwConstants.ETHTYPE_IPV4 }));
             Ipv4Prefix srcNetwork = ((AceIpv4)acl.getAceIpVersion()).getSourceIpv4Network();
-            if (null != srcNetwork) {
+            if (null != srcNetwork && !srcNetwork.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
                 String[] ipaddressValues = srcNetwork.getValue().split("/");
                 flowMatches.add(new MatchInfo(MatchFieldType.ipv4_source,
                     new String[] {ipaddressValues[0], ipaddressValues[1]}));
@@ -259,7 +270,8 @@ public class AclServiceOFFlowBuilder {
                 new long[] { NwConstants.ETHTYPE_IPV6 }));
             Ipv6Prefix srcNetwork = ((AceIpv6)acl.getAceIpVersion()).getSourceIpv6Network();
             if (null != srcNetwork) {
-                // TODO Ipv6 Match.
+                flowMatches.add(new MatchInfo(MatchFieldType.ipv6_source,
+                    new String[] {srcNetwork.getValue()}));
             }
         }
         return flowMatches;
@@ -275,7 +287,7 @@ public class AclServiceOFFlowBuilder {
             flowMatches.add(new MatchInfo(MatchFieldType.eth_type,
                 new long[] { NwConstants.ETHTYPE_IPV4 }));
             Ipv4Prefix dstNetwork = ((AceIpv4)acl.getAceIpVersion()).getDestinationIpv4Network();
-            if (null != dstNetwork) {
+            if (null != dstNetwork && !dstNetwork.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
                 String[] ipaddressValues = dstNetwork.getValue().split("/");
                 flowMatches.add(new MatchInfo(MatchFieldType.ipv4_destination,
                     new String[] {ipaddressValues[0], ipaddressValues[1]}));
@@ -285,7 +297,8 @@ public class AclServiceOFFlowBuilder {
                 new long[] { NwConstants.ETHTYPE_IPV6 }));
             Ipv6Prefix dstNetwork = ((AceIpv6)acl.getAceIpVersion()).getDestinationIpv6Network();
             if (null != dstNetwork) {
-             // TODO Ipv6 Match.
+                flowMatches.add(new MatchInfo(MatchFieldType.ipv6_destination,
+                    new String[] {dstNetwork.getValue()}));
             }
         }
         return flowMatches;