Bug 6421 - Missing mappings for router port 54/43954/3
authorTomas Cechvala <tcechval@cisco.com>
Mon, 15 Aug 2016 09:58:50 +0000 (11:58 +0200)
committerTomas Cechvala <tcechval@cisco.com>
Mon, 15 Aug 2016 13:17:52 +0000 (13:17 +0000)
VPP renderer needs mapping info for a router port.

Change-Id: Ic8ab0ca5efb94fc511d8c4b3598c3255a3d563e6
Signed-off-by: Tomas Cechvala <tcechval@cisco.com>
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java

index 14bbf9f39e351ed3471a8f80a12b6344bc3fa2d5..da1ab83b6fae18b2b67b832926c589498abeae8d 100644 (file)
@@ -17,6 +17,7 @@ import javax.annotation.Nullable;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.util.L2L3IidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.gbp.util.NeutronGbpIidFactory;
@@ -135,6 +136,11 @@ public class NeutronPortAware implements NeutronAware<Port> {
                     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);
+            UniqueId portId = new UniqueId(port.getUuid().getValue());
+            addBaseEndpointMappings(addrEpKey, portId, rwTx);
+
             // does the same for tenant forwarding domains
             processTenantForwarding(routerPortSubnet, routerL3Context, portIpWithSubnet, tenantId, rwTx);
 
@@ -442,7 +448,7 @@ public class NeutronPortAware implements NeutronAware<Port> {
     }
 
     private void registerBaseEndpointAndStoreMapping(List<AddressEndpointReg> addrEpRegs, Port port,
-            ReadWriteTransaction rwTx) {
+            WriteTransaction wTx) {
         RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder().setAddressEndpointReg(addrEpRegs)
             .build();
 
@@ -458,35 +464,41 @@ public class NeutronPortAware implements NeutronAware<Port> {
                         port.getUuid());
                 AddressEndpointKey addrEpKey = new AddressEndpointKey(addrEpReg.getAddress(),
                         addrEpReg.getAddressType(), addrEpReg.getContextId(), addrEpReg.getContextType());
-                BaseEndpointByPort baseEndpointByPort = MappingFactory.createBaseEndpointByPort(addrEpKey, portId);
-                rwTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.baseEndpointByPortIid(portId),
-                        baseEndpointByPort, true);
-                PortByBaseEndpoint portByBaseEndpoint = MappingFactory.createPortByBaseEndpoint(portId, addrEpKey);
-                rwTx.put(LogicalDatastoreType.OPERATIONAL,
-                        NeutronGbpIidFactory.portByBaseEndpointIid(new PortByBaseEndpointKey(
-                                portByBaseEndpoint.getKey())), portByBaseEndpoint, true);
+                addBaseEndpointMappings(addrEpKey, portId, wTx);
             }
         }
     }
 
+    private void addBaseEndpointMappings(AddressEndpointKey addrEpKey, UniqueId portId, WriteTransaction wTx) {
+        BaseEndpointByPort baseEndpointByPort = MappingFactory.createBaseEndpointByPort(addrEpKey, portId);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.baseEndpointByPortIid(portId),
+                baseEndpointByPort, true);
+        PortByBaseEndpoint portByBaseEndpoint = MappingFactory.createPortByBaseEndpoint(portId, addrEpKey);
+        wTx.put(LogicalDatastoreType.OPERATIONAL,
+                NeutronGbpIidFactory.portByBaseEndpointIid(new PortByBaseEndpointKey(
+                        portByBaseEndpoint.getKey())), portByBaseEndpoint, true);
+    }
+
     private void unregisterEndpointAndRemoveMapping(UnregisterEndpointInput baseEpUnreg, Port port,
             ReadWriteTransaction rwTx) {
         boolean isUnregisteredBaseEndpoint = epRegistrator.unregisterEndpoint(baseEpUnreg);
         if (isUnregisteredBaseEndpoint) {
             UniqueId portId = new UniqueId(port.getUuid().getValue());
-            EndpointKey epKey = new EndpointKey(new L2BridgeDomainId(port.getNetworkId().getValue()), new MacAddress(
-                    port.getMacAddress().getValue()));
-            LOG.trace("Removing Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}",
-                    port.getUuid().getValue(), port.getDeviceOwner(), epKey);
             PortByBaseEndpointKey portByBaseEndpointKey = new PortByBaseEndpointKey(port.getMacAddress().getValue(),
                     MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN);
-            DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
-                    NeutronGbpIidFactory.baseEndpointByPortIid(portId), rwTx);
-            DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
-                    NeutronGbpIidFactory.portByBaseEndpointIid(portByBaseEndpointKey), rwTx);
+            LOG.trace("Removing Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}",
+                    port.getUuid().getValue(), port.getDeviceOwner(), portByBaseEndpointKey);
+            removeBaseEndpointMappings(portByBaseEndpointKey, portId, rwTx);
         }
     }
 
+    private void removeBaseEndpointMappings(PortByBaseEndpointKey portByBaseEndpointKey, UniqueId portId, ReadWriteTransaction rwTx) {
+        DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
+                NeutronGbpIidFactory.baseEndpointByPortIid(portId), rwTx);
+        DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
+                NeutronGbpIidFactory.portByBaseEndpointIid(portByBaseEndpointKey), rwTx);
+    }
+
     @Override
     public void onUpdated(Port oldPort, Port newPort, Neutron oldNeutron, Neutron newNeutron) {
         LOG.trace("updated port - OLD: {}\nNEW: {}", oldPort, newPort);
@@ -531,6 +543,10 @@ public class NeutronPortAware implements NeutronAware<Port> {
             NetworkDomain subnet = NeutronSubnetAware.createSubnet(routerPortSubnet, null);
             rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnet.getNetworkDomainId()),
                     subnet);
+            UniqueId portId = new UniqueId(port.getUuid().getValue());
+            PortByBaseEndpointKey portByBaseEndpointKey = new PortByBaseEndpointKey(port.getMacAddress().getValue(),
+                    MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN);
+            removeBaseEndpointMappings(portByBaseEndpointKey, portId, rwTx);
             DataStoreHelper.submitToDs(rwTx);
         } else if (PortUtils.isDhcpPort(port)) {
             LOG.trace("Port is DHCP port: {}", port.getUuid().getValue());