- public void neutronPortDeleted(NeutronPort port) {
- LOG.trace("neutronPortDeleted - {}", port);
- if (isRouterInterfacePort(port)) {
- LOG.trace("Port is router interface - {} does nothing. {} handles router iface.",
- NeutronPortAware.class.getSimpleName(), NeutronRouterAware.class.getSimpleName());
- return;
- }
- if (isRouterGatewayPort(port)) {
- LOG.trace("Port is router gateway - {} does nothing. {} handles router iface.",
- NeutronPortAware.class.getSimpleName(), NeutronRouterAware.class.getSimpleName());
- return;
- }
- if (isFloatingIpPort(port)) {
- LOG.trace("Port is floating ip - {} device id - {}", port.getID(), port.getDeviceID());
- floatingIpPortByDeviceId.remove(port.getDeviceID());
- }
- ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
- TenantId tenantId = new TenantId(Utils.normalizeUuid(port.getTenantID()));
- L2FloodDomainId l2FdId = new L2FloodDomainId(port.getNetworkUUID());
- ForwardingCtx fwCtx = MappingUtils.createForwardingContext(tenantId, l2FdId, rwTx);
- boolean isFwCtxValid = validateForwardingCtx(fwCtx);
- if (!isFwCtxValid) {
- rwTx.cancel();
- return;
- }
-
- EndpointKey epKey = new EndpointKey(fwCtx.getL2BridgeDomain().getId(), new MacAddress(port.getMacAddress()));
- deleteNeutronGbpMapping(port, epKey, rwTx);
- UnregisterEndpointInput unregisterEpRpcInput = createUnregisterEndpointInput(port, fwCtx);
- try {
- RpcResult<Void> rpcResult = epService.unregisterEndpoint(unregisterEpRpcInput).get();
- if (!rpcResult.isSuccessful()) {
- LOG.warn("Illegal state - RPC unregisterEndpoint failed. Input of RPC: {}", unregisterEpRpcInput);
- }
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("addPort - RPC invocation failed.", e);
- rwTx.cancel();
- }
- }
-
- private static void deleteNeutronGbpMapping(NeutronPort port, EndpointKey epKey, ReadWriteTransaction rwTx) {
- UniqueId portId = new UniqueId(port.getID());
- if (isRouterInterfacePort(port)) {
- LOG.trace("Adding RouterInterfacePort-Endpoint mapping for port {} and endpoint {}", port.getID(), epKey);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.endpointByRouterInterfacePortIid(portId), rwTx);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.routerInterfacePortByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), rwTx);
- } else if (isRouterGatewayPort(port)) {
- LOG.trace("Adding RouterGatewayPort-Endpoint mapping for port {} and endpoint {}", port.getID(), epKey);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.endpointByRouterGatewayPortIid(portId), rwTx);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.routerGatewayPortByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), rwTx);
- } else if (isFloatingIpPort(port)) {
- LOG.trace("Adding FloatingIpPort-Endpoint mapping for port {} and endpoint {}", port.getID(), epKey);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.endpointByFloatingIpPortIid(portId), rwTx);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.floatingIpPortByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), rwTx);
- } else {
- LOG.trace("Adding Port-Endpoint mapping for port {} (device owner {}) and endpoint {}", port.getID(),
- port.getDeviceOwner(), epKey);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.endpointByPortIid(portId), rwTx);
- DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
- NeutronGbpIidFactory.portByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), rwTx);
- }
- }
-
- private static RegisterL3PrefixEndpointInput createRegisterL3PrefixEndpointInput(EndpointL3PrefixKey key, List<EndpointL3Key> endpointL3Keys, TenantId tenantId) {
- List<EndpointGroupId> epgIds = new ArrayList<>();
- // each EP has to be in EPG ANY, except dhcp and router
- epgIds.add(MappingUtils.EPG_ANY_ID);
-
- List<EndpointL3Gateways> l3Gateways = new ArrayList<EndpointL3Gateways>();
- for (EndpointL3Key epL3Key : endpointL3Keys) {
- EndpointL3Gateways l3Gateway = new EndpointL3GatewaysBuilder().setIpAddress(epL3Key.getIpAddress())
- .setL3Context(epL3Key.getL3Context())
- .build();
- l3Gateways.add(l3Gateway);
- }
- RegisterL3PrefixEndpointInputBuilder inputBuilder = new RegisterL3PrefixEndpointInputBuilder()
- .setL3Context(key.getL3Context())
- .setIpPrefix(key.getIpPrefix())
- .setEndpointGroups(epgIds)
- .setTenant(tenantId)
- .setEndpointL3Gateways(l3Gateways)
- .setTimestamp(System.currentTimeMillis());
- return inputBuilder.build();