RouterEp registration and L3 Endpoints update 25/47025/2
authorMichal Cmarada <mcmarada@cisco.com>
Wed, 28 Sep 2016 14:41:23 +0000 (16:41 +0200)
committerMichal Cmarada <mcmarada@cisco.com>
Wed, 19 Oct 2016 08:01:38 +0000 (08:01 +0000)
Change-Id: I3129dcb31b4ff0b990c00315d61b6ff5bc3840cc
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java

index a22a655ce60fd7162a5f6f8df17dda0c815b7d58..4e8886357b217ab07c7c34dd47531dd374510898 100644 (file)
@@ -114,37 +114,13 @@ public class NeutronPortAware implements NeutronAware<Port> {
             }
             FixedIps portIpWithSubnet = potentialPortIpWithSubnet.get();
             ContextId routerL3Context = new ContextId(port.getDeviceId());
-            // change L3Context for all EPs with same subnet as router port
-            changeL3ContextForEpsInSubnet(portIpWithSubnet.getSubnetId(), neutron);
-            // set L3Context as parent for bridge domain which is parent of subnet
-            TenantId tenantId = new TenantId(port.getTenantId().getValue());
-            Optional<Subnet> potentialRouterPortSubnet = SubnetUtils.findSubnet(portIpWithSubnet.getSubnetId(), neutron.getSubnets());
-            if (!potentialRouterPortSubnet.isPresent()) {
-                LOG.warn("Illegal state - router interface port is in subnet which does not exist. {}",
-                        port);
-                return;
-            }
-            Subnet routerPortSubnet = potentialRouterPortSubnet.get();
             ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
-            ContextId l2BdId = new ContextId(routerPortSubnet.getNetworkId().getValue());
-            ForwardingContext l2Bd = new ForwardingContextBuilder().setContextId(l2BdId)
-                .setContextType(MappingUtils.L2_BRDIGE_DOMAIN)
-                .setParent(MappingUtils.createParent(routerL3Context, MappingUtils.L3_CONTEXT))
-                .build();
-            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2Bd, true);
-            // set virtual router IP for subnet
-            NetworkDomain subnetDomain = NeutronSubnetAware.createSubnet(
-                    routerPortSubnet, portIpWithSubnet.getIpAddress());
-            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain);
 
             AddressEndpointKey addrEpKey = new AddressEndpointKey(port.getMacAddress().getValue(),
-                    MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN);
+                MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN);
             UniqueId portId = new UniqueId(port.getUuid().getValue());
             addBaseEndpointMappings(addrEpKey, portId, rwTx);
 
-            // does the same for tenant forwarding domains
-            processTenantForwarding(routerPortSubnet, routerL3Context, portIpWithSubnet, tenantId, rwTx);
-
             // Add Qrouter port as Endpoint
             if (port.getAugmentation(PortBindingExtension.class) != null &&
                 PortUtils.DEVICE_VIF_TYPE.equals(port.getAugmentation(PortBindingExtension.class).getVifType())) {
@@ -172,12 +148,36 @@ public class NeutronPortAware implements NeutronAware<Port> {
                     epInBuilder =
                     createEndpointRegFromPort(
                         port, ipWithSubnet, networkContainment, epgsFromSecGroups, neutron);
-
                 registerBaseEndpointAndStoreMapping(
                     ImmutableList.of(l2BaseEp.build(), l3BaseEp.build()), port, rwTx);
                 registerEndpointAndStoreMapping(epInBuilder.build(), port, rwTx);
             }
 
+            // change L3Context for all EPs with same subnet as router port
+            changeL3ContextForEpsInSubnet(portIpWithSubnet.getSubnetId(), neutron);
+            // set L3Context as parent for bridge domain which is parent of subnet
+            TenantId tenantId = new TenantId(port.getTenantId().getValue());
+            Optional<Subnet> potentialRouterPortSubnet = SubnetUtils.findSubnet(portIpWithSubnet.getSubnetId(), neutron.getSubnets());
+            if (!potentialRouterPortSubnet.isPresent()) {
+                LOG.warn("Illegal state - router interface port is in subnet which does not exist. {}",
+                        port);
+                return;
+            }
+            Subnet routerPortSubnet = potentialRouterPortSubnet.get();
+            ContextId l2BdId = new ContextId(routerPortSubnet.getNetworkId().getValue());
+            ForwardingContext l2Bd = new ForwardingContextBuilder().setContextId(l2BdId)
+                .setContextType(MappingUtils.L2_BRDIGE_DOMAIN)
+                .setParent(MappingUtils.createParent(routerL3Context, MappingUtils.L3_CONTEXT))
+                .build();
+            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2Bd, true);
+            // set virtual router IP for subnet
+            NetworkDomain subnetDomain = NeutronSubnetAware.createSubnet(
+                    routerPortSubnet, portIpWithSubnet.getIpAddress());
+            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain);
+
+            // does the same for tenant forwarding domains
+            processTenantForwarding(routerPortSubnet, routerL3Context, portIpWithSubnet, tenantId, rwTx);
+
             DataStoreHelper.submitToDs(rwTx);
         } else if (PortUtils.isDhcpPort(port)) {
             // process as normal port but put it to DHCP group
@@ -298,7 +298,7 @@ public class NeutronPortAware implements NeutronAware<Port> {
                     // endpoint has only one network containment therefore only first IP is used
                     FixedIps ipWithSubnet = firstFixedIps.get();
                     List<EndpointGroupId> endpointGroupIds = new ArrayList<>();
-                    if (PortUtils.isDhcpPort(portInSameSubnet)) {
+                    if (PortUtils.isDhcpPort(portInSameSubnet) || PortUtils.isQrouterPort(portInSameSubnet)) {
                         endpointGroupIds.add(NetworkService.EPG_ID);
                     } else if (PortUtils.isNormalPort(portInSameSubnet)) {
                         endpointGroupIds.add(NetworkClient.EPG_ID);
@@ -315,7 +315,9 @@ public class NeutronPortAware implements NeutronAware<Port> {
                         .setContextType(l3BaseEp.getContextType())
                         .build();
                     epRegistrator.unregisterEndpoint(addrEpUnreg);
-                    epRegistrator.registerEndpoint(l3BaseEp.build());
+                    RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder()
+                        .setAddressEndpointReg(ImmutableList.of(l2BaseEp.build(), l3BaseEp.build())).build();
+                    epRegistrator.registerEndpoint(regBaseEpInput);
 
                     modifyL3ContextForEndpoints(portInSameSubnet, ipWithSubnet, l3BaseEp.getContextId());
                 }