Added isPortSecurityEnabled check to enable/disable SG. 49/38049/1
authorAswin Suryanarayanan <aswinsuryan@gmail.com>
Mon, 25 Apr 2016 16:37:11 +0000 (22:07 +0530)
committerAswin Suryanarayanan <aswinsuryan@gmail.com>
Mon, 25 Apr 2016 16:44:39 +0000 (22:14 +0530)
The fixed and custom security group rules will be added only if
isPortSecurityEnabled is enabled. This applies for add/remove/update of
SecurityGroup/ security rules.

Cherry picked from ovsdb repo

Signed-off-by: Aswin Suryanarayanan <aswinsuryan@gmail.com>
13 files changed:
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/OF13Provider.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java
openstack/net-virt-providers/src/test/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclServiceTest.java
openstack/net-virt-providers/src/test/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclServiceTest.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/PortSecurityHandler.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/EgressAclProvider.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/IngressAclProvider.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/SecurityServicesManager.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/NeutronL3Adapter.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityServicesImpl.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/translator/NeutronPort.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/translator/crud/impl/NeutronPortInterface.java

index 85be27b31af2762b3284f9c651e29d33f055b335..356be18770cd1bd0f53506b459b23d2fd67ff1ca 100644 (file)
@@ -1000,49 +1000,43 @@ public class OF13Provider implements ConfigInterface, NetworkingProvider {
     }
 
     private void programLocalSecurityGroupRules(String attachedMac, Node node, OvsdbTerminationPointAugmentation intf,
-                                 Long dpid,long localPort, String segmentationId,
-                                 boolean write) {
+                                                Long dpid,long localPort, String segmentationId,
+                                                boolean write) {
 
         LOG.debug("programLocalRules: Program fixed security group rules for interface {}", intf.getName());
+        boolean isPortSecurityEnabled = securityServicesManager.isPortSecurityEnabled(intf);
+        if (!isPortSecurityEnabled) {
+            LOG.info("Port security is not enabled" + intf);
+            return;
+        }
         NeutronPort dhcpPort = securityServicesManager.getDhcpServerPort(intf);
-        boolean isComputePort = false;
-        boolean isLastPortinBridge = false;
-        boolean isLastPortinSubnet = false;
         List<Neutron_IPs> srcAddressList = null;
         if (null != dhcpPort) {
-            isComputePort = securityServicesManager.isComputePort(intf);
-            isLastPortinBridge = securityServicesManager.isLastPortinBridge(node, intf);
-            isLastPortinSubnet = false;
-            if (isComputePort) {
-                isLastPortinSubnet = securityServicesManager.isLastPortinSubnet(node, intf);
-                srcAddressList = securityServicesManager.getIpAddressList(intf);
-                if (null == srcAddressList) {
-                    LOG.warn("programLocalRules: No Ip address assigned {}", intf);
-                    return;
-                }
+            srcAddressList = securityServicesManager.getIpAddressList(intf);
+            if (null == srcAddressList) {
+                LOG.warn("programLocalRules: No Ip address assigned {}", intf);
+                return;
             }
             ingressAclProvider.programFixedSecurityGroup(dpid, segmentationId, dhcpPort.getMacAddress(), localPort,
-                                                       isLastPortinSubnet, isComputePort, attachedMac, write);
+                                                         attachedMac, write);
             egressAclProvider.programFixedSecurityGroup(dpid, segmentationId, attachedMac, localPort,
-                                                      srcAddressList, isLastPortinBridge, isComputePort,write);
+                                                        srcAddressList, write);
             /* If the network type is tunnel based (VXLAN/GRRE/etc) with Neutron Port Security ACLs */
             /* TODO SB_MIGRATION */
 
             LOG.debug("Neutron port has a Port Security Group");
             // Retrieve the security group from the Neutron Port and apply the rules
-            if (securityServicesManager.isPortSecurityReady(intf)) {
-                //Associate the security group flows.
-                List<NeutronSecurityGroup> securityGroupListInPort = securityServicesManager
-                        .getSecurityGroupInPortList(intf);
-                String neutronPortId = southbound.getInterfaceExternalIdsValue(intf,
-                                                                               Constants.EXTERNAL_ID_INTERFACE_ID);
-                for (NeutronSecurityGroup securityGroupInPort:securityGroupListInPort) {
-                    ingressAclProvider.programPortSecurityGroup(dpid, segmentationId, attachedMac, localPort,
-                                                              securityGroupInPort, neutronPortId, write);
-                    egressAclProvider.programPortSecurityGroup(dpid, segmentationId, attachedMac, localPort,
-                                                             securityGroupInPort, neutronPortId, write);
-                }
+            List<NeutronSecurityGroup> securityGroupListInPort = securityServicesManager
+                    .getSecurityGroupInPortList(intf);
+            String neutronPortId = southbound.getInterfaceExternalIdsValue(intf,
+                                                                           Constants.EXTERNAL_ID_INTERFACE_ID);
+            for (NeutronSecurityGroup securityGroupInPort:securityGroupListInPort) {
+                ingressAclProvider.programPortSecurityGroup(dpid, segmentationId, attachedMac, localPort,
+                                                            securityGroupInPort, neutronPortId, write);
+                egressAclProvider.programPortSecurityGroup(dpid, segmentationId, attachedMac, localPort,
+                                                           securityGroupInPort, neutronPortId, write);
             }
+
         } else {
             LOG.warn("programLocalRules: No DCHP port seen in  network of {}", intf);
         }
index 47fdc7029db4e62054078920927d4edae899b6b5..e7ac0c244e0c0ba4b4719d77c0c8f0185a0b7469 100644 (file)
@@ -230,41 +230,39 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
 
     @Override
     public void programFixedSecurityGroup(Long dpid, String segmentationId, String attachedMac,
-                                        long localPort, List<Neutron_IPs> srcAddressList,
-                                        boolean isLastPortinBridge, boolean isComputePort ,boolean write) {
-        // If it is the only port in the bridge add the rule to allow any DHCP client traffic
-        //if (isLastPortinBridge) {
-        egressAclDhcpAllowClientTrafficFromVm(dpid, write, Constants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY);
-        egressAclDhcpv6AllowClientTrafficFromVm(dpid, write, Constants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY);
-        // }
-        if (isComputePort) {
-            programArpRule(dpid, segmentationId, localPort, attachedMac, write);
-            if (securityServicesManager.isConntrackEnabled()) {
-                programEgressAclFixedConntrackRule(dpid, segmentationId, localPort, attachedMac, write);
-            }
-            // add rule to drop the DHCP server traffic originating from the vm.
-            egressAclDhcpDropServerTrafficfromVm(dpid, localPort, write,
-                                                 Constants.PROTO_DHCP_CLIENT_SPOOF_MATCH_PRIORITY_DROP);
-            egressAclDhcpv6DropServerTrafficfromVm(dpid, localPort, write,
-                                                   Constants.PROTO_DHCP_CLIENT_SPOOF_MATCH_PRIORITY_DROP);
-            //Adds rule to check legitimate ip/mac pair for each packet from the vm
-            for (Neutron_IPs srcAddress : srcAddressList) {
-                try {
-                    InetAddress address = InetAddress.getByName(srcAddress.getIpAddress());
-                    if (address instanceof Inet4Address) {
-                        String addressWithPrefix = srcAddress.getIpAddress() + HOST_MASK;
-                        egressAclAllowTrafficFromVmIpMacPair(dpid, localPort, attachedMac, addressWithPrefix,
-                                                             Constants.PROTO_VM_IP_MAC_MATCH_PRIORITY,write);
-                    } else if (address instanceof Inet6Address) {
-                        String addressWithPrefix = srcAddress.getIpAddress() + V6_HOST_MASK;
-                        egressAclAllowTrafficFromVmIpV6MacPair(dpid, localPort, attachedMac, addressWithPrefix,
-                                                               Constants.PROTO_VM_IP_MAC_MATCH_PRIORITY,write);
-                    }
-                } catch (UnknownHostException e) {
-                    LOG.warn("Invalid IP address {}", srcAddress.getIpAddress(), e);
+                                          long localPort, List<Neutron_IPs> srcAddressList, boolean write) {
+
+        egressAclDhcpAllowClientTrafficFromVm(dpid, write, localPort,
+                                              Constants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY);
+        egressAclDhcpv6AllowClientTrafficFromVm(dpid, write, localPort,
+                                                Constants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY);
+        programArpRule(dpid, segmentationId, localPort, attachedMac, write);
+        if (securityServicesManager.isConntrackEnabled()) {
+            programEgressAclFixedConntrackRule(dpid, segmentationId, localPort, attachedMac, write);
+        }
+        // add rule to drop the DHCP server traffic originating from the vm.
+        egressAclDhcpDropServerTrafficfromVm(dpid, localPort, write,
+                                             Constants.PROTO_DHCP_CLIENT_SPOOF_MATCH_PRIORITY_DROP);
+        egressAclDhcpv6DropServerTrafficfromVm(dpid, localPort, write,
+                                               Constants.PROTO_DHCP_CLIENT_SPOOF_MATCH_PRIORITY_DROP);
+        //Adds rule to check legitimate ip/mac pair for each packet from the vm
+        for (Neutron_IPs srcAddress : srcAddressList) {
+            try {
+                InetAddress address = InetAddress.getByName(srcAddress.getIpAddress());
+                if (address instanceof Inet4Address) {
+                    String addressWithPrefix = srcAddress.getIpAddress() + HOST_MASK;
+                    egressAclAllowTrafficFromVmIpMacPair(dpid, localPort, attachedMac, addressWithPrefix,
+                                                         Constants.PROTO_VM_IP_MAC_MATCH_PRIORITY,write);
+                } else if (address instanceof Inet6Address) {
+                    String addressWithPrefix = srcAddress.getIpAddress() + V6_HOST_MASK;
+                    egressAclAllowTrafficFromVmIpV6MacPair(dpid, localPort, attachedMac, addressWithPrefix,
+                                                           Constants.PROTO_VM_IP_MAC_MATCH_PRIORITY,write);
                 }
+            } catch (UnknownHostException e) {
+                LOG.warn("Invalid IP address {}", srcAddress.getIpAddress(), e);
             }
         }
+
     }
 
     private void programArpRule(Long dpid, String segmentationId, long localPort, String attachedMac, boolean write) {
@@ -683,16 +681,18 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      *
      * @param dpidLong the dpid
      * @param write whether to write or delete the flow
+     * @param localPort the local port.
      * @param priority the priority
      */
     private void egressAclDhcpAllowClientTrafficFromVm(Long dpidLong,
-                                                       boolean write, Integer priority) {
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+                                                       boolean write, long localPort, Integer priority) {
         String flowName = "Egress_DHCP_Client"  + "_Permit_";
         MatchBuilder matchBuilder = new MatchBuilder();
+        MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
         MatchUtils.createDhcpMatch(matchBuilder, DHCP_DESTINATION_PORT, DHCP_SOURCE_PORT);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         syncFlow(flowBuilder ,nodeBuilder, write);
     }
 
@@ -701,16 +701,18 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      *
      * @param dpidLong the dpid
      * @param write whether to write or delete the flow
+     * @param localPort the local port
      * @param priority the priority
      */
     private void egressAclDhcpv6AllowClientTrafficFromVm(Long dpidLong,
-                                                         boolean write, Integer priority) {
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+                                                         boolean write, long localPort, Integer priority) {
         String flowName = "Egress_DHCPv6_Client"  + "_Permit_";
         MatchBuilder matchBuilder = new MatchBuilder();
+        MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
         MatchUtils.createDhcpv6Match(matchBuilder, DHCPV6_DESTINATION_PORT, DHCPV6_SOURCE_PORT);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         syncFlow(flowBuilder ,nodeBuilder, write);
     }
 
index d0d3cf03ef6817c4a79e1c649fd28b6056715a94..ce9155ca9c81fd84d924bf80530df187b0115df8 100644 (file)
@@ -215,21 +215,17 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
 
     @Override
     public void programFixedSecurityGroup(Long dpid, String segmentationId, String dhcpMacAddress,
-                                        long localPort, boolean isLastPortinSubnet,
-                                        boolean isComputePort, String attachMac, boolean write) {
-        //If this port is the only port in the compute node add the DHCP server rule.
-        if (isLastPortinSubnet && isComputePort ) {
-            ingressAclDhcpAllowServerTraffic(dpid, segmentationId,dhcpMacAddress,
-                                             write,Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
-            ingressAclDhcpv6AllowServerTraffic(dpid, segmentationId,dhcpMacAddress,
-                                               write,Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
-        }
-        if (isComputePort) {
-            if (securityServicesManager.isConntrackEnabled()) {
-                programIngressAclFixedConntrackRule(dpid, segmentationId, attachMac, localPort, write);
-            }
-            programArpRule(dpid, segmentationId, localPort, attachMac, write);
+                                        long localPort, String attachMac, boolean write) {
+
+        ingressAclDhcpAllowServerTraffic(dpid, segmentationId,dhcpMacAddress, attachMac,
+                                         write,Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
+        ingressAclDhcpv6AllowServerTraffic(dpid, segmentationId,dhcpMacAddress, attachMac,
+                                           write,Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
+
+        if (securityServicesManager.isConntrackEnabled()) {
+            programIngressAclFixedConntrackRule(dpid, segmentationId, attachMac, localPort, write);
         }
+        programArpRule(dpid, segmentationId, localPort, attachMac, write);
     }
 
     private void programArpRule(Long dpid, String segmentationId, long localPort, String attachMac, boolean write) {
@@ -654,18 +650,21 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param dpidLong the dpid
      * @param segmentationId the segmentation id
      * @param dhcpMacAddress the DHCP server mac address
+     * @param attachMac the mac address of  the port
      * @param write is write or delete
      * @param protoPortMatchPriority the priority
      */
     private void ingressAclDhcpAllowServerTraffic(Long dpidLong, String segmentationId, String dhcpMacAddress,
-                                                  boolean write, Integer protoPortMatchPriority) {
+                                                  String attachMac, boolean write, Integer protoPortMatchPriority) {
 
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         MatchBuilder matchBuilder = new MatchBuilder();
-        MatchUtils.createDhcpServerMatch(matchBuilder, dhcpMacAddress, 67, 68).build();
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,dhcpMacAddress,attachMac,
+                                                             MatchUtils.ETHERTYPE_IPV4);
+        MatchUtils.addLayer4Match(matchBuilder, MatchUtils.UDP_SHORT, 67, 68);
         String flowId = "Ingress_DHCP_Server" + segmentationId + "_" + dhcpMacAddress + "_Permit_";
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         syncFlow(flowBuilder ,nodeBuilder, write);
     }
 
@@ -675,18 +674,21 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param dpidLong the dpid
      * @param segmentationId the segmentation id
      * @param dhcpMacAddress the DHCP server mac address
+     * @param attachMac the mac address of  the port
      * @param write is write or delete
      * @param protoPortMatchPriority the priority
      */
     private void ingressAclDhcpv6AllowServerTraffic(Long dpidLong, String segmentationId, String dhcpMacAddress,
-                                                    boolean write, Integer protoPortMatchPriority) {
+                                                    String attachMac, boolean write, Integer protoPortMatchPriority) {
 
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         MatchBuilder matchBuilder = new MatchBuilder();
-        MatchUtils.createDhcpv6ServerMatch(matchBuilder, dhcpMacAddress, 547, 546).build();
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,dhcpMacAddress,attachMac,
+                                                             MatchUtils.ETHERTYPE_IPV6);
+        MatchUtils.addLayer4Match(matchBuilder, MatchUtils.UDP_SHORT, 547, 546);
         String flowId = "Ingress_DHCPv6_Server" + segmentationId + "_" + dhcpMacAddress + "_Permit_";
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         syncFlow(flowBuilder ,nodeBuilder, write);
     }
 
index 48f6717168288aeb861b21f21608005c20341cab..3bbd1d84e21079032020b1c0442203a5963b4c92 100644 (file)
@@ -48,6 +48,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.api.support.membermodification.MemberModifier;
@@ -1504,40 +1505,13 @@ public class EgressAclServiceTest {
     }
 
     /**
-     *  Test With isConntrackEnabled false isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLAdd1() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(false);
-
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, false, true);
-
-        verify(writeTransaction, times(2)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
-        verify(writeTransaction, times(2)).submit();
-        verify(commitFuture, times(2)).checkedGet();
-    }
-    /**
-     *  Test With isConntrackEnabled false isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLRemove1() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(false);
-
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, false, false);
-
-        verify(writeTransaction, times(2)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(2)).submit();
-        verify(commitFuture, times(2)).get();
-    }
-
-    /**
-     *  Test With isConntrackEnabled false isComputeNode true
+      *  Test With isConntrackEnabled false
      */
     @Test
     public void testProgramFixedSecurityACLAdd2() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(false);
 
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, true, true);
+        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, true);
 
         verify(writeTransaction, times(9)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
         verify(writeTransaction, times(9)).submit();
@@ -1545,13 +1519,13 @@ public class EgressAclServiceTest {
     }
 
     /**
-     *  Test With isConntrackEnabled false isComputeNode true
+     *  Test With isConntrackEnabled false
      */
     @Test
     public void testProgramFixedSecurityACLRemove2() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(false);
 
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, true, false);
+        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false);
 
         verify(writeTransaction, times(9)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
         verify(writeTransaction, times(9)).submit();
@@ -1559,41 +1533,13 @@ public class EgressAclServiceTest {
     }
 
     /**
-     *  Test With isConntrackEnabled true isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLAdd3() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(true);
-
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, false, true);
-
-        verify(writeTransaction, times(2)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
-        verify(writeTransaction, times(2)).submit();
-        verify(commitFuture, times(2)).checkedGet();
-    }
-
-    /**
-     *  Test With isConntrackEnabled true isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLRemove3() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(true);
-
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, false, false);
-
-        verify(writeTransaction, times(2)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(2)).submit();
-        verify(commitFuture, times(2)).get();
-    }
-
-    /**
-     *  Test With isConntrackEnabled true isComputeNode true
+     *  Test With isConntrackEnabled true
      */
     @Test
     public void testProgramFixedSecurityACLAdd4() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(true);
 
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, true, true);
+        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, true);
 
         verify(writeTransaction, times(14)).put(any(LogicalDatastoreType.class),
                                                any(InstanceIdentifier.class), any(Node.class), eq(true));
@@ -1602,13 +1548,13 @@ public class EgressAclServiceTest {
     }
 
     /**
-     *  Test With isConntrackEnabled true isComputeNode true
+     *  Test With isConntrackEnabled true
      */
     @Test
     public void testProgramFixedSecurityACLRemove4() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(true);
 
-        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false, true, false);
+        egressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", MAC_ADDRESS, 1, neutronDestIpList, false);
 
         verify(writeTransaction, times(14)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
         verify(writeTransaction, times(14)).submit();
index 5d2e75d7d04b035efb59fbdb90977b7e8add0ee3..e5d3b061d1eda5d49224cd350ffd9a6fa922f62b 100644 (file)
@@ -1536,108 +1536,56 @@ public class IngressAclServiceTest {
     }
 
     /**
-     *  Test With isConntrackEnabled false isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLAdd1() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(false);
-
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, false, MAC_ADDRESS, true);
-
-        verify(writeTransaction, times(0)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
-        verify(writeTransaction, times(0)).submit();
-        verify(commitFuture, times(0)).get();
-    }
-    /**
-     *  Test With isConntrackEnabled false isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLRemove1() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(false);
-
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, false, MAC_ADDRESS, false);
-
-        verify(writeTransaction, times(0)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(0)).submit();
-        verify(commitFuture, times(0)).get();
-    }
-    /**
-     *  Test With isConntrackEnabled false isComputeNode false
+     *  Test With isConntrackEnabled false
      */
     @Test
     public void testProgramFixedSecurityACLAdd2() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(false);
 
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, true, MAC_ADDRESS, true);
+        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, MAC_ADDRESS, true);
 
-        verify(writeTransaction, times(1)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
-        verify(writeTransaction, times(1)).submit();
-        verify(commitFuture, times(1)).checkedGet();
+        verify(writeTransaction, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
+        verify(writeTransaction, times(3)).submit();
+        verify(commitFuture, times(3)).checkedGet();
     }
     /**
-     *  Test With isConntrackEnabled false isComputeNode false
+     *  Test With isConntrackEnabled false
      */
     @Test
     public void testProgramFixedSecurityACLRemove2() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(false);
 
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, true, MAC_ADDRESS, false);
+        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, MAC_ADDRESS, false);
 
-        verify(writeTransaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(1)).submit();
-        verify(commitFuture, times(1)).get();
-    }
-    /**
-     *  Test With isConntrackEnabled true isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLAdd3() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(true);
-
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, false, MAC_ADDRESS, true);
-
-        verify(writeTransaction, times(0)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
-        verify(writeTransaction, times(0)).submit();
-        verify(commitFuture, times(0)).get();
-    }
-    /**
-     *  Test With isConntrackEnabled true isComputeNode false
-     */
-    @Test
-    public void testProgramFixedSecurityACLRemove3() throws Exception {
-        when(securityServices.isConntrackEnabled()).thenReturn(true);
-
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, false, MAC_ADDRESS, false);
-
-        verify(writeTransaction, times(0)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(0)).submit();
-        verify(commitFuture, times(0)).get();
+        verify(writeTransaction, times(3)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        verify(writeTransaction, times(3)).submit();
+        verify(commitFuture, times(3)).get();
     }
     /**
-     *  Test With isConntrackEnabled true isComputeNode true
+     *  Test With isConntrackEnabled true
      */
     @Test
     public void testProgramFixedSecurityACLAdd4() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(true);
 
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, true, MAC_ADDRESS, true);
+        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, MAC_ADDRESS, true);
 
-        verify(writeTransaction, times(6)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
-        verify(writeTransaction, times(6)).submit();
-        verify(commitFuture, times(6)).checkedGet();
+        verify(writeTransaction, times(8)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), eq(true));
+        verify(writeTransaction, times(8)).submit();
+        verify(commitFuture, times(8)).checkedGet();
     }
     /**
-     *  Test With isConntrackEnabled true isComputeNode true
+     *  Test With isConntrackEnabled true
      */
     @Test
     public void testProgramFixedSecurityACLRemove4() throws Exception {
         when(securityServices.isConntrackEnabled()).thenReturn(true);
 
-        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, false, true, MAC_ADDRESS, false);
+        ingressAclServiceSpy.programFixedSecurityGroup(Long.valueOf(1554), "2", DHCP_MAC_ADDRESS, 1, MAC_ADDRESS, false);
 
-        verify(writeTransaction, times(6)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(6)).submit();
-        verify(commitFuture, times(6)).get();
+        verify(writeTransaction, times(8)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        verify(writeTransaction, times(8)).submit();
+        verify(commitFuture, times(8)).get();
     }
 
 }
index 0d3d8b370a8ecf78b68c34e474c184c0443cc5d8..78e1c4276b1e78c34a5e9e17ff500fcbc54a2852 100644 (file)
@@ -154,7 +154,10 @@ public class PortSecurityHandler extends AbstractHandler
 
     private void syncSecurityGroup(NeutronSecurityRule  securityRule,NeutronPort port,
                                    boolean write) {
-
+        if (!port.getPortSecurityEnabled()) {
+            LOG.info("Port security not enabled port", port);
+            return;
+        }
         if (null != securityRule.getSecurityRemoteGroupID()) {
             List<Neutron_IPs> vmIpList  = securityServicesManager
                     .getVmListForSecurityGroup(port.getID(), securityRule.getSecurityRemoteGroupID());
@@ -169,17 +172,17 @@ public class PortSecurityHandler extends AbstractHandler
     private List<NeutronPort> getPortWithSecurityGroup(String securityGroupUuid) {
 
         List<NeutronPort> neutronPortList = neutronPortCache.getAllPorts();
-        List<NeutronPort> neutronPortInSG = new ArrayList<NeutronPort>();
+        List<NeutronPort> neutronPortInSg = new ArrayList<NeutronPort>();
         for (NeutronPort neutronPort:neutronPortList) {
             List<NeutronSecurityGroup> securityGroupList = neutronPort.getSecurityGroups();
             for (NeutronSecurityGroup neutronSecurityGroup:securityGroupList) {
                 if (neutronSecurityGroup.getID().equals(securityGroupUuid)) {
-                    neutronPortInSG.add(neutronPort);
+                    neutronPortInSg.add(neutronPort);
                     break;
                 }
             }
         }
-        return neutronPortInSG;
+        return neutronPortInSg;
     }
 
     @Override
index d82f30aa90316eec29abf13f770368737c64a3c9..1f049b0838f4a526f79fae201576ebf9a7fe87a4 100644 (file)
@@ -55,11 +55,8 @@ public interface EgressAclProvider {
      * @param attachedMac the attached mac
      * @param localPort the local port
      * @param srcAddressList the list of source ip address assigned to vm
-     * @param isLastPortinBridge is this the last port in the bridge
-     * @param isComputePort indicates whether this port is a compute port or not
      * @param write is this flow writing or deleting
      */
     void programFixedSecurityGroup(Long dpid, String segmentationId,String attachedMac, long localPort,
-                                  List<Neutron_IPs> srcAddressList, boolean isLastPortinBridge,
-                                  boolean isComputePort, boolean write);
+                                  List<Neutron_IPs> srcAddressList, boolean write);
 }
\ No newline at end of file
index a4005e0c028fcad308ed0694b631e9742b8018ca..b587a245d13634f377673537ad3fe4fd84c47f9d 100644 (file)
@@ -52,11 +52,9 @@ public interface IngressAclProvider {
      * @param segmentationId the segmentation id
      * @param attachedMac the dhcp mac
      * @param localPort the local port
-     * @param isLastPortinSubnet is this the last port in the subnet
-     * @param isComputePort indicates whether this port is a compute port or not
      * @param attachedMac2 the src mac
      * @param write is this flow writing or deleting
      */
     void programFixedSecurityGroup(Long dpid, String segmentationId, String attachedMac, long localPort,
-                                  boolean isLastPortinSubnet, boolean isComputePort, String attachedMac2, boolean write);
+                                  String attachedMac2, boolean write);
 }
\ No newline at end of file
index 09d452ccc6f0a22ef18d5661bf6da0614b2838b1..2418792b289e82cfad7d0c0b40f5ff69ba2039f5 100644 (file)
@@ -70,7 +70,7 @@ public interface SecurityServicesManager {
     /**
      * Is this the last port in the subnet to which interface belongs to.
      * @param node The node to which the intf is connected.
-     * @param intf the intf
+     * @param intf the interface
      * @return whether last port in the subnet
      */
     boolean isLastPortinSubnet(Node node, OvsdbTerminationPointAugmentation intf);
@@ -116,4 +116,11 @@ public interface SecurityServicesManager {
      * @return whether connection tracking enabled.
      */
     boolean isConntrackEnabled();
+    /**
+     * Is the port a PortSecurity Enabled.
+     *
+     * @param intf the port
+     * @return  whether it is a compute port or not
+     */
+    boolean isPortSecurityEnabled(OvsdbTerminationPointAugmentation intf);
 }
\ No newline at end of file
index d9a601338b3e9b7236873d53b27cf6b3b37b3dfc..13b535448aa30f0d9a865d560ef1eb2a5cee68e3 100644 (file)
@@ -428,7 +428,9 @@ public class NeutronL3Adapter extends AbstractHandler implements GatewayMacResol
         if (action == UPDATE) {
             // FIXME: Bug 4971 Move cleanup cache to SG Impl
             this.updatePortInCleanupCache(neutronPort, neutronPort.getOriginalPort());
-            this.processSecurityGroupUpdate(neutronPort);
+            if (neutronPort.getPortSecurityEnabled()) {
+                this.processSecurityGroupUpdate(neutronPort);
+            }
         }
 
         if (!this.enabled) {
index e853b4843ad38bc84589acee4dedc99076c4d978..fc2486aa91e4431923d5a15419f1c6df61fb6358 100644 (file)
@@ -575,6 +575,21 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         return null;
     }
 
+    @Override
+    public boolean isPortSecurityEnabled(OvsdbTerminationPointAugmentation intf) {
+        NeutronPort neutronPort = getNeutronPortFromCache(intf);
+        if (null == neutronPort) {
+            LOG.error("Neutron Port is null: " + intf);
+            return false;
+        }
+        if (neutronPort.getPortSecurityEnabled()) {
+            LOG.info("Port Security is enabled for Port: " + neutronPort);
+            return true;
+        }
+        LOG.info("Port Security is  not enabled for Port: " + neutronPort);
+        return false;
+    }
+
     @Override
     public void setDependencies(ServiceReference serviceReference) {
         neutronL3Adapter =
index 903c388d27419ebeb9ae1e07b912b5e1ba562ced..a7b4a6196fff1c84e751d809cab3db4c580d34fb 100644 (file)
@@ -83,6 +83,11 @@ public class NeutronPort implements Serializable, INeutronObject {
     @XmlElement (name = "extra_dhcp_opts")
     List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
 
+    //Port security is enabled by default for backward compatibility.
+    @XmlElement (defaultValue = "true", name = "port_security_enabled")
+    Boolean portSecurityEnabled;
+
+
     NeutronPort originalPort;
 
     public NeutronPort() {
@@ -233,6 +238,18 @@ public class NeutronPort implements Serializable, INeutronObject {
         this.bindingvifType = bindingvifType;
     }
 
+    public Boolean getPortSecurityEnabled() {
+        if (portSecurityEnabled == null) {
+            return true;
+        }
+        return portSecurityEnabled;
+    }
+
+    public void setPortSecurityEnabled(Boolean newValue) {
+        portSecurityEnabled = newValue;
+    }
+
+
     public NeutronPort getOriginalPort() {
         return originalPort;
     }
@@ -288,12 +305,16 @@ public class NeutronPort implements Serializable, INeutronObject {
             if ("security_groups".equals(field)) {
                 ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups()));
             }
+            if ("port_security_enabled".equals(field)) {
+                ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
+            }
         }
         return ans;
     }
 
     public void initDefaults() {
         adminStateUp = true;
+        portSecurityEnabled = true;
         if (status == null) {
             status = "ACTIVE";
         }
@@ -309,6 +330,6 @@ public class NeutronPort implements Serializable, INeutronObject {
                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
                 + tenantID + ", securityGroups=" + securityGroups
                 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
-                + ", bindingvnicType=" + bindingvnicType + "]";
+                + ", bindingvnicType=" + bindingvnicType + ", portSecurityEnabled=" + portSecurityEnabled +"]";
     }
 }
index 8814fb39736d5b8a47bef747dcc91b7e08425823..e2dbab6d227f76e075592a0d58c1156e3f46981c 100644 (file)
@@ -38,6 +38,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.por
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtensionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.framework.BundleContext;
@@ -151,6 +153,13 @@ public class NeutronPortInterface extends AbstractNeutronInterface<Port, Neutron
         result.setBindingvnicType(binding.getVnicType());
     }
 
+    private void portSecurityExtension(Port port, NeutronPort result) {
+        PortSecurityExtension portSecurity = port.getAugmentation(PortSecurityExtension.class);
+        if(portSecurity != null && portSecurity.isPortSecurityEnabled() != null) {
+            result.setPortSecurityEnabled(portSecurity.isPortSecurityEnabled());
+        }
+    }
+
     protected NeutronPort fromMd(Port port) {
         NeutronPort result = new NeutronPort();
         result.setAdminStateUp(port.isAdminStateUp());
@@ -209,6 +218,7 @@ public class NeutronPortInterface extends AbstractNeutronInterface<Port, Neutron
         }
         result.setPortUUID(String.valueOf(port.getUuid().getValue()));
         addExtensions(port, result);
+        portSecurityExtension(port, result);
         return result;
     }
 
@@ -239,9 +249,14 @@ public class NeutronPortInterface extends AbstractNeutronInterface<Port, Neutron
             bindingBuilder.setVnicType(neutronPort.getBindingvnicType());
         }
 
+        PortSecurityExtensionBuilder portSecurityBuilder = new PortSecurityExtensionBuilder();
+        if (neutronPort.getPortSecurityEnabled() != null) {
+            portSecurityBuilder.setPortSecurityEnabled(neutronPort.getPortSecurityEnabled());
+        }
         PortBuilder portBuilder = new PortBuilder();
         portBuilder.addAugmentation(PortBindingExtension.class,
                                     bindingBuilder.build());
+        portBuilder.addAugmentation(PortSecurityExtension.class, portSecurityBuilder.build());
         portBuilder.setAdminStateUp(neutronPort.isAdminStateUp());
         if(neutronPort.getAllowedAddressPairs() != null) {
             List<AllowedAddressPairs> listAllowedAddressPairs = new ArrayList<>();