Added support for remote security group update.
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / impl / SecurityServicesImpl.java
index c29e7adc52f85060d48f12ef734bd593bfaffc46..aace8dd861aa9faf5d475fbeae47f881a55cb831 100644 (file)
@@ -1,55 +1,59 @@
 /*
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (c) 2014, 2015 Red Hat, Inc. 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.ovsdb.openstack.netvirt.impl;
 
-import java.util.List;
+package org.opendaylight.ovsdb.openstack.netvirt.impl;
 
-import org.opendaylight.neutron.spi.INeutronPortCRUD;
-import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
-import org.opendaylight.neutron.spi.NeutronPort;
-import org.opendaylight.neutron.spi.NeutronSecurityGroup;
-import org.opendaylight.neutron.spi.NeutronSubnet;
-import org.opendaylight.neutron.spi.Neutron_IPs;
 import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.EgressAclProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.IngressAclProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.SecurityServicesManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronPort;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSecurityGroup;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSecurityRule;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSubnet;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.Neutron_IPs;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronNetworkCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronPortCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronSubnetCRUD;
 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class SecurityServicesImpl implements ConfigInterface, SecurityServicesManager {
-    static final Logger logger = LoggerFactory.getLogger(TenantNetworkManagerImpl.class);
+    private static final Logger LOG = LoggerFactory.getLogger(TenantNetworkManagerImpl.class);
     private volatile INeutronPortCRUD neutronPortCache;
     private volatile INeutronSubnetCRUD neutronSubnetCache;
     private volatile Southbound southbound;
+    private volatile INeutronNetworkCRUD neutronNetworkCache;
+    private volatile ConfigurationService configurationService;
+    private volatile IngressAclProvider ingressAclProvider;
+    private volatile EgressAclProvider egressAclProvider;
 
-    /**
-     * Is security group ready.
-     *
-     * @param terminationPointAugmentation the intf
-     * @return the boolean
-     */
+    @Override
     public boolean isPortSecurityReady(OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-            logger.error("neutron port is null");
+            LOG.error("neutron port is null");
             return false;
         }
-        logger.trace("isPortSecurityReady for {}", terminationPointAugmentation.getName());
+        LOG.trace("isPortSecurityReady for {}", terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
-                Constants.EXTERNAL_ID_INTERFACE_ID);
+                                                                       Constants.EXTERNAL_ID_INTERFACE_ID);
         if (neutronPortId == null) {
             return false;
         }
@@ -59,61 +63,95 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         String deviceOwner = neutronPort.getDeviceOwner();
         if (!deviceOwner.contains("compute")) {
-            logger.debug("Port {} is not a compute host, it is a: {}", neutronPortId, deviceOwner);
+            LOG.debug("Port {} is not a compute host, it is a: {}", neutronPortId, deviceOwner);
         }
-        logger.debug("isPortSecurityReady() is a {} ", deviceOwner);
+        LOG.debug("isPortSecurityReady() is a {} ", deviceOwner);
         List<NeutronSecurityGroup> securityGroups = neutronPort.getSecurityGroups();
         if (securityGroups.isEmpty()) {
-            logger.debug("Check for device: {} does not contain a Security Group for port: {}", deviceOwner,
-                    neutronPortId);
+            LOG.debug("Check for device: {} does not contain a Security Group for port: {}", deviceOwner,
+                      neutronPortId);
             return false;
         }
-        String vmPort = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
-                Constants.EXTERNAL_ID_VM_MAC);
-        logger.debug("Security Group Check {} DOES contain a Neutron Security Group", neutronPortId);
+        LOG.debug("Security Group Check {} does contain a Neutron Security Group", neutronPortId);
         return true;
     }
 
-    /**
-     * Gets security group in port.
-     *
-     * @param terminationPointAugmentation the intf
-     * @return the security group in port
-     */
-    public NeutronSecurityGroup getSecurityGroupInPort(OvsdbTerminationPointAugmentation terminationPointAugmentation) {
+    @Override
+    public List<NeutronSecurityGroup> getSecurityGroupInPortList(OvsdbTerminationPointAugmentation
+                                                             terminationPointAugmentation) {
+        List<NeutronSecurityGroup> neutronSecurityGroups = new ArrayList<NeutronSecurityGroup>();
         if (neutronPortCache == null) {
-            logger.error("neutron port is null");
-            return null;
+            LOG.error("neutron port is null");
+            return neutronSecurityGroups;
         }
-        logger.trace("isPortSecurityReady for {}", terminationPointAugmentation.getName());
+        LOG.trace("isPortSecurityReady for {}", terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
-                Constants.EXTERNAL_ID_INTERFACE_ID);
+                                                                       Constants.EXTERNAL_ID_INTERFACE_ID);
         if (neutronPortId == null) {
-            return null;
+            return neutronSecurityGroups;
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            return null;
+            return neutronSecurityGroups;
         }
+        neutronSecurityGroups = neutronPort.getSecurityGroups();
+        return neutronSecurityGroups;
+
+    }
 
-        List<NeutronSecurityGroup> neutronSecurityGroups = neutronPort.getSecurityGroups();
-        if (neutronSecurityGroups != null) {
-            NeutronSecurityGroup neutronSecurityGroup = (NeutronSecurityGroup) neutronSecurityGroups.toArray()[0];
-            return neutronSecurityGroup;
-        } else {
+    @Override
+    public NeutronPort getDhcpServerPort(OvsdbTerminationPointAugmentation terminationPointAugmentation) {
+        if (neutronPortCache == null) {
+            LOG.error("getDHCPServerPort: neutron port is null");
+            return null;
+        }
+        LOG.trace("getDHCPServerPort for {}",
+                  terminationPointAugmentation.getName());
+        try {
+            String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
+                                                                           Constants.EXTERNAL_ID_INTERFACE_ID);
+            if (neutronPortId == null) {
+                return null;
+            }
+            NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("getDHCPServerPort: neutron port of {} is not found", neutronPortId);
+                return null;
+            }
+            /* if the current port is a DHCP port, return the same*/
+            if (neutronPort.getDeviceOwner().contains("dhcp")) {
+                return neutronPort;
+            }
+            /*Since all the fixed ip assigned to a port should be
+             *from the same network, first port is sufficient.*/
+            List<Neutron_IPs> fixedIps = neutronPort.getFixedIPs();
+            if (null == fixedIps || 0 == fixedIps.size() ) {
+                LOG.error("getDHCPServerPort: No fixed ip is assigned");
+                return null;
+            }
+            /* Get all the ports in the subnet and identify the dhcp port*/
+            String subnetUuid = fixedIps.iterator().next().getSubnetUUID();
+            NeutronSubnet neutronSubnet = neutronSubnetCache.getSubnet(subnetUuid);
+            List<NeutronPort> ports = neutronSubnet.getPortsInSubnet();
+            for (NeutronPort port : ports) {
+                if (port.getDeviceOwner().contains("dhcp")) {
+                    return port;
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("getDHCPServerPort:getDHCPServerPort failed due to ", e);
             return null;
         }
+        return null;
     }
 
     @Override
-    public NeutronPort getDHCPServerPort(
+    public NeutronPort getNeutronPortFromDhcpIntf(
             OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-            logger.error("getDHCPServerPort: neutron port is null");
+            LOG.error("getNeutronPortFromDhcpIntf: neutron port is null");
             return null;
         }
-        logger.trace("getDHCPServerPort for {}",
-                terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(
                 terminationPointAugmentation,
                 Constants.EXTERNAL_ID_INTERFACE_ID);
@@ -121,35 +159,27 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
             return null;
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
-        //Since all the fixed ip assigned to a port should be from the same network, first port is sufficient.
-        List<Neutron_IPs> fixedIps = neutronPort.getFixedIPs();
-        if(null==fixedIps || 0 == fixedIps.size() )
-        {
-            logger.error("getDHCPServerPort: No fixed ip is assigned");
+        if (neutronPort == null) {
+            LOG.error("getNeutronPortFromDhcpIntf: neutron port of {} is not found", neutronPortId);
             return null;
         }
-        String subnetUUID = fixedIps.iterator().next().getSubnetUUID();
-        NeutronSubnet neutronSubnet = neutronSubnetCache.getSubnet(subnetUUID);
-        List<NeutronPort> ports = neutronSubnet.getPortsInSubnet();
-        for (NeutronPort port : ports) {
-            if (port.getDeviceOwner().contains("dhcp")) {
-                return port;
-            }
+        /* if the current port is a DHCP port, return true*/
+        if (neutronPort.getDeviceOwner().contains("dhcp")) {
+            LOG.trace("getNeutronPortFromDhcpIntf: neutronPort is a dhcp port", neutronPort );
+            return neutronPort;
         }
-
         return null;
-
     }
 
     @Override
     public boolean isComputePort(OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-            logger.error("neutron port is null");
+            LOG.error("neutron port is null");
             return false;
         }
-        logger.trace("isComputePort for {}", terminationPointAugmentation.getName());
+        LOG.trace("isComputePort for {}", terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
-                Constants.EXTERNAL_ID_INTERFACE_ID);
+                                                                       Constants.EXTERNAL_ID_INTERFACE_ID);
         if (neutronPortId == null) {
             return false;
         }
@@ -157,9 +187,12 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         if (neutronPort == null) {
             return false;
         }
+        /*Check the device owner and if it contains compute to identify
+         * whether it is a compute port.*/
         String deviceOwner = neutronPort.getDeviceOwner();
         if (!deviceOwner.contains("compute")) {
-            logger.debug("isComputePort : Port {} is not a DHCP server port", neutronPortId,deviceOwner);
+            LOG.debug("isComputePort : Port {} is not a DHCP server port for device owner {}",
+                      neutronPortId,deviceOwner);
             return false;
         }
         return true;
@@ -168,39 +201,48 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
     @Override
     public boolean isLastPortinSubnet(Node node, OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-            logger.error("isLastPortinSubnet: neutron port is null");
+            LOG.error("isLastPortinSubnet: neutron port is null");
             return false;
         }
-        logger.trace("isLastPortinSubnet: for {}", terminationPointAugmentation.getName());
-        String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
-                                                                       Constants.EXTERNAL_ID_INTERFACE_ID);
-        if (neutronPortId == null) {
-            return false;
-        }
-        NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
-        List<Neutron_IPs> neutronPortFixedIp = neutronPort.getFixedIPs();
-        if(null == neutronPortFixedIp || neutronPortFixedIp.isEmpty()) {
-            return false;
-        }
-        List<TerminationPoint> terminationPoints = node.getTerminationPoint();
-        if(terminationPoints != null && !terminationPoints.isEmpty()) {
-            for(TerminationPoint tp : terminationPoints) {
-                OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
-                        tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
-                if (ovsdbTerminationPointAugmentation != null && !ovsdbTerminationPointAugmentation.
-                        getName().equals(Constants.INTEGRATION_BRIDGE)) {
-                    String portId = southbound.getInterfaceExternalIdsValue(ovsdbTerminationPointAugmentation,
-                                                                            Constants.EXTERNAL_ID_INTERFACE_ID);
-                    if(null!=portId) {
-                        NeutronPort port = neutronPortCache.getPort(portId);
-                        if(null!=port) {
-                            if(!(port.getID().equals(neutronPort.getID())) && port.getDeviceOwner().contains("compute")) {
+        try {
+            LOG.trace("isLastPortinSubnet: for {}", terminationPointAugmentation.getName());
+            String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
+                                                                           Constants.EXTERNAL_ID_INTERFACE_ID);
+            if (neutronPortId == null) {
+                return false;
+            }
+            NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("isLastPortinSubnet: neutron port of {} is not found", neutronPortId);
+                return false;
+            }
+            List<Neutron_IPs> neutronPortFixedIp = neutronPort.getFixedIPs();
+            if (null == neutronPortFixedIp || neutronPortFixedIp.isEmpty()) {
+                return false;
+            }
+            /*Get all the ports in the current node and check whether there
+             * is any port belonging to the same subnet of the input
+             */
+            List<TerminationPoint> terminationPoints = node.getTerminationPoint();
+            if (terminationPoints != null && !terminationPoints.isEmpty()) {
+                for (TerminationPoint tp : terminationPoints) {
+                    OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
+                            tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
+                    if (ovsdbTerminationPointAugmentation != null && !ovsdbTerminationPointAugmentation
+                            .getName().equals(Constants.INTEGRATION_BRIDGE)) {
+                        String portId = southbound.getInterfaceExternalIdsValue(ovsdbTerminationPointAugmentation,
+                                                                                Constants.EXTERNAL_ID_INTERFACE_ID);
+                        if (null != portId) {
+                            NeutronPort port = neutronPortCache.getPort(portId);
+                            if (null != port && !(port.getID().equals(neutronPort.getID()))
+                                    && port.getDeviceOwner().contains("compute")) {
                                 List<Neutron_IPs> portFixedIp = port.getFixedIPs();
-                                if(null == portFixedIp || portFixedIp.isEmpty()) {
+                                if (null == portFixedIp || portFixedIp.isEmpty()) {
                                     return false;
                                 }
-                                if(portFixedIp.iterator().next().getSubnetUUID().equals
-                                        (neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) {
+                                if (portFixedIp.iterator().next().getSubnetUUID()
+                                        .equals(neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) {
+                                    LOG.trace("isLastPortinSubnet: Port is not the only port.");
                                     return false;
                                 }
                             }
@@ -208,25 +250,29 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                     }
                 }
             }
+        } catch (Exception e) {
+            LOG.error("isLastPortinSubnet: isLastPortinSubnet failed due to ", e);
+            return false;
         }
         return true;
     }
 
     @Override
     public boolean isLastPortinBridge(Node node, OvsdbTerminationPointAugmentation terminationPointAugmentation) {
-        logger.trace("isLastPortinBridge: for {}", terminationPointAugmentation.getName());
+        LOG.trace("isLastPortinBridge: for {}", terminationPointAugmentation.getName());
         List<TerminationPoint> terminationPoints = node.getTerminationPoint();
-        if(terminationPoints != null && !terminationPoints.isEmpty()){
-            for(TerminationPoint tp : terminationPoints){
+        /*Check whether the node has any port other than br-int*/
+        if (terminationPoints != null && !terminationPoints.isEmpty()) {
+            for (TerminationPoint tp : terminationPoints) {
                 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
                         tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
-                if(null!=ovsdbTerminationPointAugmentation)
-                {
-                    if(!(ovsdbTerminationPointAugmentation.getName().equals(Constants.INTEGRATION_BRIDGE))
-                            && !(terminationPointAugmentation.getInterfaceUuid().equals
-                                    (ovsdbTerminationPointAugmentation.getInterfaceUuid()))) {
-                        return false;
-                    }
+                if (null != ovsdbTerminationPointAugmentation
+                        && !(ovsdbTerminationPointAugmentation.getName().equals(Constants.INTEGRATION_BRIDGE))
+                        && !(terminationPointAugmentation.getInterfaceUuid()
+                        .equals(ovsdbTerminationPointAugmentation.getInterfaceUuid()))) {
+                    LOG.debug("isLastPortinBridge: it the last port in bridge {}",
+                            terminationPointAugmentation.getName());
+                    return false;
                 }
             }
         }
@@ -234,36 +280,193 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
     }
 
     @Override
-    public List<Neutron_IPs> getIpAddress(Node node,
-                                OvsdbTerminationPointAugmentation terminationPointAugmentation) {
+    public List<Neutron_IPs> getIpAddressList(Node node,
+                                          OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-            logger.error("getIpAddress: neutron port is null");
+            LOG.error("getIpAddress: neutron port is null");
             return null;
         }
-        logger.trace("getIpAddress: for {}", terminationPointAugmentation.getName());
+        LOG.trace("getIpAddress: for {}", terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
-                Constants.EXTERNAL_ID_INTERFACE_ID);
+                                                                       Constants.EXTERNAL_ID_INTERFACE_ID);
         if (neutronPortId == null) {
             return null;
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
-        List<Neutron_IPs> fixedIps = neutronPort.getFixedIPs();
-        return fixedIps;
+        if (neutronPort == null) {
+            LOG.error("getIpAddress: neutron port of {} is not found", neutronPortId);
+            return null;
+        }
+        return neutronPort.getFixedIPs();
+    }
+
+    @Override
+    public List<Neutron_IPs> getVmListForSecurityGroup(String portUuid, String securityGroupUuid) {
+        List<Neutron_IPs> vmListForSecurityGroup = new ArrayList<Neutron_IPs>();
+        /*For every port check whether security grouplist contains the current
+         * security group.*/
+        try {
+            for (NeutronPort neutronPort:neutronPortCache.getAllPorts()) {
+                if (!neutronPort.getDeviceOwner().contains("compute")) {
+                    LOG.debug("getVMListForSecurityGroup : the port {} is not "
+                            + "compute port belongs to {}", neutronPort.getID(), neutronPort.getDeviceOwner());
+                    continue;
+                }
+                if (portUuid.equals(neutronPort.getID())) {
+                    continue;
+                }
+                List<NeutronSecurityGroup> securityGroups = neutronPort.getSecurityGroups();
+                if (null != securityGroups) {
+                    for (NeutronSecurityGroup securityGroup:securityGroups) {
+                        if (securityGroup.getSecurityGroupUUID().equals(securityGroupUuid)) {
+                            LOG.debug("getVMListForSecurityGroup : adding ports with ips {} "
+                                    + "compute port", neutronPort.getFixedIPs());
+                            vmListForSecurityGroup.addAll(neutronPort.getFixedIPs());
+                        }
+                    }
+                }
+
+            }
+        } catch (Exception e) {
+            LOG.error("getVMListForSecurityGroup: getVMListForSecurityGroup"
+                    + " failed due to ", e);
+            return null;
+        }
+        return vmListForSecurityGroup;
+
+    }
+
+    @Override
+    public void syncSecurityGroup(NeutronPort port, List<NeutronSecurityGroup> securityGroupList, boolean write) {
+        LOG.trace("syncSecurityGroup:" + securityGroupList + " Write:" + Boolean.valueOf(write));
+        if (null != port && null != port.getSecurityGroups()) {
+            Node node = getNode(port);
+            NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(port.getNetworkUUID());
+            String segmentationId = neutronNetwork.getProviderSegmentationID();
+            OvsdbTerminationPointAugmentation intf = getInterface(node, port);
+            long localPort = southbound.getOFPort(intf);
+            String attachedMac = southbound.getInterfaceExternalIdsValue(intf, Constants.EXTERNAL_ID_VM_MAC);
+            if (attachedMac == null) {
+                LOG.debug("programVlanRules: No AttachedMac seen in {}", intf);
+                return;
+            }
+            long dpid = getDpidOfIntegrationBridge(node);
+            String neutronPortId = southbound.getInterfaceExternalIdsValue(intf,
+                                                                           Constants.EXTERNAL_ID_INTERFACE_ID);
+            for (NeutronSecurityGroup securityGroupInPort:securityGroupList) {
+                ingressAclProvider.programPortSecurityGroup(dpid, segmentationId, attachedMac, localPort,
+                                                          securityGroupInPort, neutronPortId, write);
+                egressAclProvider.programPortSecurityGroup(dpid, segmentationId, attachedMac, localPort,
+                                                         securityGroupInPort, neutronPortId, write);
+            }
+        }
+    }
+
+    @Override
+    public void syncSecurityRule(NeutronPort port, NeutronSecurityRule securityRule,Neutron_IPs vmIp, boolean write) {
+        LOG.trace("syncSecurityGroup:" + securityRule + " Write:" + Boolean.valueOf(write));
+        if (null != port && null != port.getSecurityGroups()) {
+            Node node = getNode(port);
+            NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(port.getNetworkUUID());
+            String segmentationId = neutronNetwork.getProviderSegmentationID();
+            OvsdbTerminationPointAugmentation intf = getInterface(node, port);
+            long localPort = southbound.getOFPort(intf);
+            String attachedMac = southbound.getInterfaceExternalIdsValue(intf, Constants.EXTERNAL_ID_VM_MAC);
+            if (attachedMac == null) {
+                LOG.debug("programVlanRules: No AttachedMac seen in {}", intf);
+                return;
+            }
+            long dpid = getDpidOfIntegrationBridge(node);
+            if ("IPv4".equals(securityRule.getSecurityRuleEthertype())
+                    && "ingress".equals(securityRule.getSecurityRuleDirection())) {
+
+                ingressAclProvider.programPortSecurityRule(dpid, segmentationId, attachedMac, localPort,
+                                                           securityRule, vmIp, write);
+            } else if (securityRule.getSecurityRuleEthertype().equals("IPv4")
+                    && securityRule.getSecurityRuleDirection().equals("egress")) {
+                egressAclProvider.programPortSecurityRule(dpid, segmentationId, attachedMac, localPort,
+                                                          securityRule, vmIp, write);
+            }
+        }
+    }
+
+    private long getDpidOfIntegrationBridge(Node node) {
+        LOG.trace("getDpidOfIntegrationBridge:" + node);
+        long dpid = 0L;
+        if (southbound.getBridgeName(node).equals(configurationService.getIntegrationBridgeName())) {
+            dpid = getDpid(node);
+        }
+        return dpid;
+    }
+
+    private long getDpid(Node node) {
+        LOG.trace("getDpid" + node);
+        long dpid = southbound.getDataPathId(node);
+        if (dpid == 0) {
+            LOG.warn("getDpid: dpid not found: {}", node);
+        }
+        return dpid;
+    }
+
+    private Node getNode(NeutronPort port) {
+        LOG.trace("getNode:Port" + port);
+        List<Node> toplogyNodes = southbound.readOvsdbTopologyNodes();
+
+        for (Node topologyNode : toplogyNodes) {
+            try {
+                Node node = southbound.getBridgeNode(topologyNode,Constants.INTEGRATION_BRIDGE);
+                List<OvsdbTerminationPointAugmentation> ovsdbPorts = southbound.getTerminationPointsOfBridge(node);
+                for (OvsdbTerminationPointAugmentation ovsdbPort : ovsdbPorts) {
+                    String uuid = southbound.getInterfaceExternalIdsValue(ovsdbPort,
+                                                            Constants.EXTERNAL_ID_INTERFACE_ID);
+                    if (null != uuid && uuid.equals(port.getID())) {
+                        return node;
+                    }
+                }
+            } catch (Exception e) {
+                LOG.error("Exception during handlingNeutron network delete", e);
+            }
+        }
+        return null;
+    }
+
+    private OvsdbTerminationPointAugmentation getInterface(Node node, NeutronPort port) {
+        LOG.trace("getInterface:Node:" + node + " Port:" + port);
+        try {
+            List<OvsdbTerminationPointAugmentation> ovsdbPorts = southbound.getTerminationPointsOfBridge(node);
+            for (OvsdbTerminationPointAugmentation ovsdbPort : ovsdbPorts) {
+                String uuid = southbound.getInterfaceExternalIdsValue(ovsdbPort,
+                                                                      Constants.EXTERNAL_ID_INTERFACE_ID);
+                if (null != uuid && uuid.equals(port.getID())) {
+                    return ovsdbPort;
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Exception during handlingNeutron network delete", e);
+        }
+        return null;
     }
 
     @Override
-    public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
+    public void setDependencies(ServiceReference serviceReference) {
         southbound =
                 (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
+        neutronNetworkCache =
+                (INeutronNetworkCRUD) ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, this);
+        configurationService =
+                (ConfigurationService) ServiceHelper.getGlobalInstance(ConfigurationService.class, this);
     }
 
     @Override
     public void setDependencies(Object impl) {
         if (impl instanceof INeutronPortCRUD) {
             neutronPortCache = (INeutronPortCRUD)impl;
-        }
-        else if (impl instanceof INeutronSubnetCRUD) {
+        } else if (impl instanceof INeutronSubnetCRUD) {
             neutronSubnetCache = (INeutronSubnetCRUD) impl;
+        } else if (impl instanceof IngressAclProvider) {
+            ingressAclProvider = (IngressAclProvider) impl;
+        } else if (impl instanceof EgressAclProvider) {
+            egressAclProvider = (EgressAclProvider) impl;
         }
     }
-}
+}
\ No newline at end of file