Acl-flow fixed 47/11847/1
authorShuva Jyoti Kar <[email protected]>
Thu, 9 Oct 2014 06:11:17 +0000 (11:41 +0530)
committerShuva Jyoti Kar <[email protected]>
Thu, 9 Oct 2014 06:12:20 +0000 (11:42 +0530)
Signed-off-by: Shuva Jyoti Kar <[email protected]>
Change-Id: I10a5db61e73502b27644448310bb2fd571763e72
Signed-off-by: Shuva Jyoti Kar <[email protected]>
sfcofl2/src/main/java/org/opendaylight/ofsfc/provider/OpenflowAclDataListener.java
sfcofl2/src/main/java/org/opendaylight/ofsfc/provider/OpenflowSfcFlowProgrammer.java

index 016131ee769fcb491d049db3dbb7591d66d70f0a..0dbeb97767635b92f654764cbfb7e5120e6b3d83 100644 (file)
@@ -17,6 +17,8 @@ import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.ofsfc.provider.utils.SfcInstanceIdentifierUtils;
 import org.opendaylight.ofsfc.provider.utils.SfcOfL2APIUtil;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.acl.rev140701.access.lists.access.list.access.list.entries.actions.SfcAction;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.acl.rev140520.access.lists.access.list.access.list.entries.Actions;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.acl.rev140701.Actions1;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.acl.rev140701.access.lists.access.list.access.list.entries.actions.SfcAction;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.acl.rev140701.access.lists.access.list.access.list.entries.actions.sfc.action.AclServiceFunctionPath;
@@ -87,36 +89,53 @@ public class OpenflowAclDataListener extends OpenflowAbstractDataListener {
     }
 
     private void configureAclFlows(AccessListEntries createdAccessListEntries, boolean isAddFlow) {
+        Matches matches;
+        AceIp aceIp;
+        AceIpv4 aceIpv4;
+        Short srcPort = 0;
+        Short dstPort = 0;
+        String srcIpAddress = null;
+        String dstIpAddress = null;
+        byte protocol = (byte) 0;
 
-        AclServiceFunctionPath sfcAction = (AclServiceFunctionPath) (SfcAction) createdAccessListEntries.getActions();
+        OpenflowSfcFlowProgrammer flowProgrammer = OpenflowSfcFlowProgrammer.getInstance();
+        SfcAction sfcAction = createdAccessListEntries.getActions().getAugmentation(Actions1.class).getSfcAction();
+        String aclServicePathName = ((AclServiceFunctionPath) sfcAction).getServiceFunctionPath();
 
-        String sfpName = sfcAction.getServiceFunctionPath();
-        ServiceFunctionPath servicefunctionPath = SfcOfL2APIUtil.readServiceFunctionPath(getDataBroker(), sfpName);
+        ServiceFunctionPath servicefunctionPath = SfcOfL2APIUtil.readServiceFunctionPath(getDataBroker(),
+                aclServicePathName);
 
         Long pathId = servicefunctionPath.getPathId();
 
-        Matches matches;
-        AceIp aceIp;
-        AceIpv4 aceIpv4;
-
         matches = createdAccessListEntries.getMatches();
         aceIp = (AceIp) matches.getAceType();
         aceIpv4 = (AceIpv4) aceIp.getAceIpVersion();
 
-        String srcIpAddress = aceIpv4.getSourceIpv4Address().getValue();
-        String dstIpAddress = aceIpv4.getDestinationIpv4Address().getValue();
-
-        Short srcPort = aceIp.getSourcePortRange().getLowerPort().getValue().shortValue();
-        Short dstPort = aceIp.getDestinationPortRange().getLowerPort().getValue().shortValue();
-
-        byte protocol = aceIp.getIpProtocol().byteValue();
+        if (aceIpv4.getSourceIpv4Address() != null) {
+            srcIpAddress = aceIpv4.getSourceIpv4Address().getValue();
+        }
+        if (aceIpv4.getDestinationIpv4Address() != null) {
+            dstIpAddress = aceIpv4.getDestinationIpv4Address().getValue();
+        }
 
+        if (aceIp != null) {
+            if (aceIp.getSourcePortRange() != null) {
+                srcPort = aceIp.getSourcePortRange().getLowerPort().getValue().shortValue();
+            }
+            if (aceIp.getDestinationPortRange() != null) {
+                dstPort = aceIp.getDestinationPortRange().getLowerPort().getValue().shortValue();
+            }
+            if (aceIp.getIpProtocol() != null) {
+                protocol = aceIp.getIpProtocol().byteValue();
+            }
+        }
         List<ServicePathHop> servicePathHopList = servicefunctionPath.getServicePathHop();
 
         for (ServicePathHop servicePathHop : servicePathHopList) {
-            OpenflowSfcFlowProgrammer.getInstance().setNodeInfo(servicePathHop.getServiceFunctionForwarder());
-            OpenflowSfcFlowProgrammer.getInstance().configureClassificationFlow(srcIpAddress, (short) 32, dstIpAddress,
-                    (short) 32, srcPort, dstPort, protocol, pathId, isAddFlow);
+
+            flowProgrammer.setNodeInfo(servicePathHop.getServiceFunctionForwarder());
+            flowProgrammer.configureClassificationFlow(srcIpAddress, (short) 32, dstIpAddress, (short) 32, srcPort,
+                    dstPort, protocol, pathId, isAddFlow);
         }
     }
 
index 955d47428b3cf80f907fd302322cd6517d916104..636a27dc92b19ab79efe70b0196cf57d9d70ac00 100644 (file)
@@ -147,7 +147,7 @@ public class OpenflowSfcFlowProgrammer {
     private String sffNodeName;
 
     private static final int SCHEDULED_THREAD_POOL_SIZE = 1;
-    private static final int QUEUE_SIZE = 16;
+    private static final int QUEUE_SIZE = 50;
     private static final int ASYNC_THREAD_POOL_CORE_SIZE = 1;
     private static final int ASYNC_THREAD_POOL_MAX_SIZE = 1;
     private static final int ASYNC_THREAD_POOL_KEEP_ALIVE_TIME_SECS = 300;
@@ -259,6 +259,8 @@ public class OpenflowSfcFlowProgrammer {
 
                 LOG.trace("+++++++++++++++++  SfcProviderSffFlowWriter.writeSffAcl() SFPid {}", sfpId);
 
+                boolean isIpMatch = false;
+                boolean isPortMatch = false;
                 //
                 // Create the 5-tuple matching criteria
 
@@ -268,33 +270,58 @@ public class OpenflowSfcFlowProgrammer {
                 ethTypeBuilder.setType(new EtherType(0x0800L));
                 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
                 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
+                MatchBuilder match = new MatchBuilder();
+                match.setEthernetMatch(ethMatchBuilder.build());
 
                 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
-                ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(longToIp(srcIp, srcMask)));
-                ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(longToIp(dstIp, dstMask)));
+                if (srcIp != null) {
+                    ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(longToIp(srcIp, srcMask)));
+                    isIpMatch = true;
+                }
+                if (dstIp != null) {
+                    ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(longToIp(dstIp, dstMask)));
+                    isIpMatch = true;
+                }
+                if (isIpMatch == true) {
+                    match.setLayer3Match(ipv4MatchBuilder.build());
+                }
 
                 IpMatchBuilder ipmatch = new IpMatchBuilder();
-                ipmatch.setIpProtocol((short) protocol);
-
-                MatchBuilder match = new MatchBuilder();
-                match.setEthernetMatch(ethMatchBuilder.build());
-                match.setLayer3Match(ipv4MatchBuilder.build());
-                match.setIpMatch(ipmatch.build());
-
-                if (protocol == 6) {
-                    TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
-                    // There must be a bug in
-                    // setTcpSource/DestinationPort(), because its
-                    // looking at the upper 2 bytes of the port and thinks
-                    // its out of range
-                    tcpMatch.setTcpSourcePort(new PortNumber(new Integer(0x0000FFFF & srcPort)));
-                    tcpMatch.setTcpDestinationPort(new PortNumber(new Integer(0x0000FFFF & dstPort)));
-                    match.setLayer4Match(tcpMatch.build());
-                } else {
-                    UdpMatchBuilder udpMatch = new UdpMatchBuilder();
-                    udpMatch.setUdpSourcePort(new PortNumber(new Integer(0x0000FFFF & srcPort)));
-                    udpMatch.setUdpDestinationPort(new PortNumber(new Integer(0x0000FFFF & dstPort)));
-                    match.setLayer4Match(udpMatch.build());
+                if (protocol != 0) {
+                    ipmatch.setIpProtocol((short) protocol);
+                    match.setIpMatch(ipmatch.build());
+
+                    if (protocol == 6) {
+                        TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
+                        // There must be a bug in
+                        // setTcpSource/DestinationPort(), because its
+                        // looking at the upper 2 bytes of the port and thinks
+                        // its out of range
+                        if (srcPort != 0) {
+                            tcpMatch.setTcpSourcePort(new PortNumber(new Integer(0x0000FFFF & srcPort)));
+                            isPortMatch = true;
+                        }
+                        if (dstPort != 0) {
+                            tcpMatch.setTcpDestinationPort(new PortNumber(new Integer(0x0000FFFF & dstPort)));
+                            isPortMatch = true;
+                        }
+                        if (isPortMatch == true) {
+                            match.setLayer4Match(tcpMatch.build());
+                        }
+                    } else {
+                        UdpMatchBuilder udpMatch = new UdpMatchBuilder();
+                        if (srcPort != 0) {
+                            udpMatch.setUdpSourcePort(new PortNumber(new Integer(0x0000FFFF & srcPort)));
+                            isPortMatch = true;
+                        }
+                        if (dstPort != 0) {
+                            udpMatch.setUdpDestinationPort(new PortNumber(new Integer(0x0000FFFF & dstPort)));
+                            isPortMatch = true;
+                        }
+                        if (isPortMatch == true) {
+                            match.setLayer4Match(udpMatch.build());
+                        }
+                    }
                 }
 
                 //
@@ -508,7 +535,7 @@ public class OpenflowSfcFlowProgrammer {
                 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
                 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
                 ethSourceBuilder.setAddress(new MacAddress(srcMac));
-                ethernetMatch.setEthernetType(ethtype.setType(type).build());
+                // ethernetMatch.setEthernetType(ethtype.setType(type).build());
                 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
                 match.setEthernetMatch(ethernetMatch.build());
 
@@ -731,7 +758,7 @@ public class OpenflowSfcFlowProgrammer {
                 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
                 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
                 EtherType type = new EtherType(0x0800L);
-                ethmatch.setEthernetType(ethtype.setType(type).build());
+                // ethmatch.setEthernetType(ethtype.setType(type).build());
 
                 match.setEthernetMatch(ethmatch.build());
                 // Create the Actions
@@ -857,8 +884,7 @@ public class OpenflowSfcFlowProgrammer {
                 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
                 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
                 ethDestinationBuilder.setAddress(new MacAddress(dstMac));
-
-                //ethernetMatch.setEthernetType(ethtype.setType(type).build());
+                // ethernetMatch.setEthernetType(ethtype.setType(type).build());
                 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
                 matchBuilder.setEthernetMatch(ethernetMatch.build());