Merge "Bug 5008 - QoS and Queue fixes for ovsdb southbound"
authorSam Hague <shague@redhat.com>
Mon, 25 Jan 2016 15:00:04 +0000 (15:00 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 25 Jan 2016 15:00:04 +0000 (15:00 +0000)
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/AbstractServiceInstance.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/NeutronL3Adapter.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImpl.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImplTest.java

index 3835bed28d42acacf7bc3c3e3710c05363276491..2153a689a833dee0a2fa5144432b84e63a0d45f2 100644 (file)
@@ -157,8 +157,8 @@ public abstract class AbstractServiceInstance {
             LOG.debug("writeFlow: flowBuilder: {}, nodeBuilder: {}",
                     flowBuilder.build(), nodeBuilder.build());
             WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
-            modification.put(LogicalDatastoreType.CONFIGURATION, createNodePath(nodeBuilder),
-                    nodeBuilder.build(), true /*createMissingParents*/);
+            //modification.put(LogicalDatastoreType.CONFIGURATION, createNodePath(nodeBuilder),
+            //        nodeBuilder.build(), true /*createMissingParents*/);
             modification.put(LogicalDatastoreType.CONFIGURATION, createFlowPath(flowBuilder, nodeBuilder),
                     flowBuilder.build(), true /*createMissingParents*/);
             CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
index 39efd4bc46e6788f64b3e0acdf9b9c7cb26591da..e467f9c8a8286d3ee37782c09dec791b147fc0e9 100644 (file)
@@ -1553,15 +1553,19 @@ public class NeutronL3Adapter extends AbstractHandler implements GatewayMacResol
         this.portCleanupCache.remove(port);
     }
 
+    public Set<NeutronPort> getPortCleanupCache() {
+        return this.portCleanupCache;
+    }
+
     public NeutronPort getPortFromCleanupCache(String portid) {
         for (NeutronPort neutronPort : this.portCleanupCache) {
             if (neutronPort.getPortUUID() != null ) {
                 if (neutronPort.getPortUUID().equals(portid)) {
                     LOG.info("getPortFromCleanupCache: Matching NeutronPort found {}", portid);
                     return neutronPort;
-                    }
                 }
             }
+        }
         return null;
     }
 
index e77eca2844a5e0b8c5ca945c9195d435754d4cb5..889e9c52b3c83b78053fd1ca363a30240200780f 100644 (file)
@@ -34,20 +34,24 @@ import java.util.concurrent.ConcurrentHashMap;
  * @author Aswin Suryanarayanan.
  */
 
-public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityGroupCacheManger{
+public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityGroupCacheManger {
 
     private final Map<String, Set<String>> securityGroupCache = new ConcurrentHashMap<>();
     private static final Logger LOG = LoggerFactory.getLogger(SecurityGroupCacheManagerImpl.class);
     private volatile SecurityServicesManager securityServicesManager;
     private volatile INeutronPortCRUD neutronPortCache;
+    private volatile NeutronL3Adapter neutronL3Adapter;
 
     @Override
     public void portAdded(String securityGroupUuid, String portUuid) {
         LOG.debug("In portAdded securityGroupUuid:" + securityGroupUuid + " portUuid:" + portUuid);
         NeutronPort port = neutronPortCache.getPort(portUuid);
         if (port == null) {
-            LOG.debug("In portAdded no neutron port found:" + " portUuid:" + portUuid);
-            return;
+            port = neutronL3Adapter.getPortFromCleanupCache(portUuid);
+            if (port == null) {
+                LOG.error("In portAdded no neutron port found:" + " portUuid:" + portUuid);
+                return;
+            }
         }
         processPortAdded(securityGroupUuid,port);
     }
@@ -56,9 +60,13 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
     public void portRemoved(String securityGroupUuid, String portUuid) {
         LOG.debug("In portRemoved securityGroupUuid:" + securityGroupUuid + " portUuid:" + portUuid);
         NeutronPort port = neutronPortCache.getPort(portUuid);
+
         if (port == null) {
-            LOG.debug("In portRemoved no neutron port found:" + " portUuid:" + portUuid);
-            return;
+            port = neutronL3Adapter.getPortFromCleanupCache(portUuid);
+            if (port == null) {
+                LOG.error("In portRemoved no neutron port found:" + " portUuid:" + portUuid);
+                return;
+            }
         }
         processPortRemoved(securityGroupUuid,port);
     }
@@ -109,6 +117,8 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
             }
             NeutronPort cachedport = neutronPortCache.getPort(cachedportUuid);
             if (null == cachedport) {
+                LOG.error("In processPortAdded cachedport port not found in neuton cache:"
+                            + " cachedportUuid:" + cachedportUuid);
                 return;
             }
             List<NeutronSecurityRule> remoteSecurityRules = retrieveSecurityRules(securityGroupUuid, cachedportUuid);
@@ -138,8 +148,13 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
                 continue;
             }
             NeutronPort cachedport = neutronPortCache.getPort(cachedportUuid);
-            if (null == cachedport) {
-                return;
+            if (cachedport == null) {
+                cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid);
+                if (null == cachedport) {
+                    LOG.error("In processPortRemoved cachedport port not found in neuton cache:"
+                                + " cachedportUuid:" + cachedportUuid);
+                    return;
+                }
             }
             List<NeutronSecurityRule> remoteSecurityRules = retrieveSecurityRules(securityGroupUuid, cachedportUuid);
             for (NeutronSecurityRule securityRule : remoteSecurityRules) {
@@ -160,8 +175,12 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
          */
         LOG.debug("In retrieveSecurityRules securityGroupUuid:" + securityGroupUuid + " portUuid:" + portUuid);
         NeutronPort port = neutronPortCache.getPort(portUuid);
-        if (null == port) {
-            return null;
+        if (port == null) {
+            port = neutronL3Adapter.getPortFromCleanupCache(portUuid);
+            if (null == port) {
+                LOG.error("In retrieveSecurityRules no neutron port found:" + " portUuid:" + portUuid);
+                return null;
+            }
         }
         List<NeutronSecurityRule> remoteSecurityRules = new ArrayList<>();
         List<NeutronSecurityGroup> securityGroups = port.getSecurityGroups();
@@ -200,6 +219,8 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
 
     @Override
     public void setDependencies(ServiceReference serviceReference) {
+        neutronL3Adapter =
+                (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
         securityServicesManager =
                 (SecurityServicesManager) ServiceHelper.getGlobalInstance(SecurityServicesManager.class, this);
         neutronPortCache = (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
index c5f7f58691f429a4f5dc66ee956cf4a9db4487ed..fe878c3cc6eb032b46cac74f7de87921649ceb59 100644 (file)
@@ -71,7 +71,12 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            return false;
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("isPortSecurityReady for {}", terminationPointAugmentation.getName()
+                          + "not found");
+                return false;
+            }
         }
         String deviceOwner = neutronPort.getDeviceOwner();
         if (!deviceOwner.contains("compute")) {
@@ -96,7 +101,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
             LOG.error("neutron port is null");
             return neutronSecurityGroups;
         }
-        LOG.trace("isPortSecurityReady for {}", terminationPointAugmentation.getName());
+        LOG.trace("getSecurityGroupInPortList for {}", terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
                                                                        Constants.EXTERNAL_ID_INTERFACE_ID);
         if (neutronPortId == null) {
@@ -104,7 +109,12 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            return neutronSecurityGroups;
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("getSecurityGroupInPortList for {}", terminationPointAugmentation.getName()
+                          + "not found.");
+                return neutronSecurityGroups;
+            }
         }
         neutronSecurityGroups = neutronPort.getSecurityGroups();
         return neutronSecurityGroups;
@@ -129,11 +139,10 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                 neutronPort = neutronPortCache.getPort(neutronPortId);
 
             }
-            if (neutronPort == null ){
+            if (neutronPort == null{
                 neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
-                if (neutronPort == null)
-                {
-                    LOG.info("getDHCPServerPort: neutron port of {} is not found", neutronPortId);
+                if (neutronPort == null) {
+                    LOG.error("getDHCPServerPort: neutron port of {} is not found", neutronPortId);
                     return null;
                 }
                 LOG.info("getDHCPServerPort: neutron port of {} got from cleanupcache", neutronPortId);
@@ -189,8 +198,11 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            LOG.error("getNeutronPortFromDhcpIntf: neutron port of {} is not found", neutronPortId);
-            return null;
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("getNeutronPortFromDhcpIntf: neutron port of {} is not found", neutronPortId);
+                return null;
+            }
         }
         /* if the current port is a DHCP port, return true*/
         if (neutronPort.getDeviceOwner().contains("dhcp")) {
@@ -216,19 +228,18 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                 neutronPort = neutronPortCache.getPort(neutronPortId);
 
             }
-            if (neutronPort == null ){
+            if (neutronPort == null{
                 LOG.trace("getNeutronPortFromCache: neutron port of {} search in cleanupcache", neutronPortId);
 
                 neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
-                if (neutronPort == null)
-                {
-                    LOG.info("getNeutronPortFromCache: neutron port of {} is not found", neutronPortId);
+                if (neutronPort == null) {
+                    LOG.error("getNeutronPortFromCache: neutron port of {} is not found", neutronPortId);
                     return null;
                 }
                 LOG.trace("getNeutronPortFromCache: neutron port of {} got from cleanupcache", neutronPortId);
 
             }
-        }catch (Exception e) {
+        } catch (Exception e) {
             LOG.warn("getNeutronPortFromCache:getNeutronPortFromCache failed due to ", e);
             return null;
         }
@@ -240,7 +251,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
     @Override
     public boolean isComputePort(OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-           LOG.warn("isComputePort : neutronPortCache is null");
+            LOG.warn("isComputePort : neutronPortCache is null");
         }
         NeutronPort neutronPort = null;
         LOG.trace("isComputePort for {}", terminationPointAugmentation.getName());
@@ -254,8 +265,9 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         if (neutronPort == null) {
             neutronPort = getNeutronPortFromCache(terminationPointAugmentation);
-            if (neutronPort == null)
-            return false;
+            if (neutronPort == null) {
+                return false;
+            }
         }
         /*Check the device owner and if it contains compute to identify
          * whether it is a compute port.*/
@@ -385,7 +397,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         /*For every port check whether security grouplist contains the current
          * security group.*/
         try {
-            for (NeutronPort neutronPort:neutronPortCache.getAllPorts()) {
+            for (NeutronPort neutronPort:neutronL3Adapter.getPortCleanupCache()) {
                 if (!neutronPort.getDeviceOwner().contains("compute")) {
                     LOG.debug("getVMListForSecurityGroup : the port {} is not "
                             + "compute port belongs to {}", neutronPort.getID(), neutronPort.getDeviceOwner());
index 31439ed2e060e71eae6f24b66b628338b02045fe..c471b4c5592cc1be952ce0968433c322a52a02f0 100644 (file)
@@ -19,6 +19,7 @@ import static org.mockito.Mockito.when;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 
 import org.junit.Before;
@@ -78,6 +79,7 @@ public class SecurityServicesImplTest {
     @Mock OvsdbTerminationPointAugmentation tp;
     @Mock IngressAclProvider ingressAclService;
     @Mock EgressAclProvider egressAclService;
+    @Mock NeutronL3Adapter neutronL3Adapter;
 
     private static final String NEUTRON_PORT_ID_VM_1 = "neutronID_VM_1";
     private static final String NEUTRON_PORT_ID_VM_2 = "neutronID_VM_2";
@@ -366,7 +368,7 @@ public class SecurityServicesImplTest {
         portList.add(neutronPort_Vm2);
         portList.add(neutronPort_Vm3);
         portList.add(neutronPort_Dhcp);
-        when(neutronPortCache.getAllPorts()).thenReturn(portList);
+        when(neutronL3Adapter.getPortCleanupCache()).thenReturn(new HashSet<NeutronPort>(portList));
         List<Neutron_IPs> ipList = securityServicesImpl.getVmListForSecurityGroup(NEUTRON_PORT_ID_VM_1, SECURITY_GROUP_ID_2);
         assertEquals(ipList,neutron_IPs_2);
     }