@Deprecated private void removeTenantNetworkDomains(Network network, TenantId tenantId, ReadWriteTransaction rwTx) { L2FloodDomainId l2FdId = new L2FloodDomainId(network.getUuid().getValue()); Optional<L2FloodDomain> potentialL2Fd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, IidFactory.l2FloodDomainIid(tenantId, l2FdId), rwTx); if (!potentialL2Fd.isPresent()) { LOG.warn("Illegal state - l2-flood-domain {} does not exist.", l2FdId.getValue()); return; } L2BridgeDomainId l2BdId = new L2BridgeDomainId(l2FdId); Optional<L2BridgeDomain> potentialL2Bd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx); if (!potentialL2Bd.isPresent()) { LOG.warn("Illegal state - l2-bridge-domain {} does not exist.", l2BdId.getValue()); return; } L3ContextId l3CtxId = new L3ContextId(l2FdId); Optional<L3Context> potentialL3Ctx = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3CtxId), rwTx); if (!potentialL3Ctx.isPresent()) { LOG.warn("Illegal state - l3-context {} does not exist.", l3CtxId.getValue()); return; } } }
public static Boolean contains(List<L3ContextId> l3ContextIds, L3ContextId l3Context) { for (L3ContextId l3ContextId: l3ContextIds) { if (l3ContextId.getValue() != null && l3Context.getValue() != null && l3ContextId.getValue().equalsIgnoreCase(l3Context.getValue())) { return true; } } return false; }
@Deprecated private static @Nonnull L3Context createL3CtxFromRouter(Router router) { Name l3ContextName = null; if (!Strings.isNullOrEmpty(router.getName())) { l3ContextName = new Name(router.getName()); } return new L3ContextBuilder().setId(new L3ContextId(router.getUuid().getValue())) .setName(l3ContextName) .setDescription(new Description(MappingUtils.NEUTRON_ROUTER + router.getUuid().getValue())) .build(); }
@Deprecated private static L3Address resolveL3AddressFromPort(Port port, FixedIps portFixedIPs, Neutron neutron) { Set<Port> routerIfacePorts = PortUtils.findRouterInterfacePorts(neutron.getPorts()); for (Port routerIfacePort : routerIfacePorts) { Uuid routerIfacePortSubnet = routerIfacePort.getFixedIps().get(0).getSubnetId(); // if port is in the same subnet as router interface then we want to use L3Context of // router if (portFixedIPs.getSubnetId().equals(routerIfacePortSubnet)) { L3ContextId epL3ContextId = new L3ContextId(routerIfacePort.getDeviceId()); LOG.trace("Router interface port was found in the same subnet as port have {}", port); return new L3AddressBuilder().setL3Context(epL3ContextId) .setIpAddress(portFixedIPs.getIpAddress()) .build(); } } return new L3AddressBuilder().setL3Context(new L3ContextId(port.getNetworkId().getValue())) .setIpAddress(portFixedIPs.getIpAddress()) .build(); }
.setParent(new L3ContextId(l3ContextId.getValue())) .build(); rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
@Deprecated private void processTenantSubnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet neutronSubnet, Network networkOfSubnet, TenantId tenantId, ReadWriteTransaction rwTx) { Subnet subnet; if (NetworkUtils.isProviderPhysicalNetwork(networkOfSubnet)) { // add virtual router IP only in case it is provider physical network subnet = createTenantSubnet(neutronSubnet, neutronSubnet.getGatewayIp()); IpAddress gatewayIp = neutronSubnet.getGatewayIp(); boolean registeredDefaultRoute = epRegistrator.registerExternalL3PrefixEndpoint(MappingUtils.DEFAULT_ROUTE, new L3ContextId(neutronSubnet.getNetworkId().getValue()), gatewayIp, tenantId); if (!registeredDefaultRoute) { LOG.warn("Could not add EndpointL3Prefix as default route. Subnet within provider physical network {}", neutronSubnet); rwTx.cancel(); return; } } else { // virtual router IP is not set and it will be set when router gateway port is set // or when a router port is attached to a network subnet = createTenantSubnet(neutronSubnet, null); } rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnet.getId()), subnet, true); }
@Deprecated private void modifyL3ContextForEndpoints(Port port, FixedIps resolvedPortFixedIp, ContextId newContextId) { org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder epInBuilder = createBasicEndpointInputBuilder(port); epInBuilder.setNetworkContainment(new NetworkDomainId(resolvedPortFixedIp.getSubnetId().getValue())); L3Address l3Address = new L3AddressBuilder().setL3Context(new L3ContextId(newContextId)) .setIpAddress(resolvedPortFixedIp.getIpAddress()) .build(); epInBuilder.setL3Address(ImmutableList.of(l3Address)); List<EndpointGroupId> epgsFromSecGroups = resolveEpgIdsFromSecGroups(port.getSecurityGroups()); epgsFromSecGroups.add(NetworkClient.EPG_ID); epInBuilder.setEndpointGroups(epgsFromSecGroups); epRegistrator.registerEndpoint(epInBuilder.build()); // unregister L3EP L3ContextId oldL3Context = new L3ContextId(port.getNetworkId().getValue()); L3 l3 = new L3Builder().setL3Context(oldL3Context).setIpAddress(resolvedPortFixedIp.getIpAddress()).build(); org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput epUnreg = new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder().setL3( ImmutableList.of(l3)) .build(); epRegistrator.unregisterEndpoint(epUnreg); }
@Deprecated private void processTenantForwarding(Subnet routerPortSubnet, ContextId routerL3Context, FixedIps portIpWithSubnet, TenantId tenantId, ReadWriteTransaction rwTx) { L2BridgeDomainId l2BdId = new L2BridgeDomainId(routerPortSubnet.getNetworkId().getValue()); L2BridgeDomain l2Bd = new L2BridgeDomainBuilder().setId(l2BdId).setParent(new L3ContextId(routerL3Context)).build(); rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2Bd, true); // set virtual router IP for subnet org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet subnet = NeutronSubnetAware.createTenantSubnet( routerPortSubnet, portIpWithSubnet.getIpAddress()); rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnet.getId()), subnet); }
@Override public void onUpdated(Floatingip oldFloatingIp, Floatingip newFloatingIp, Neutron oldNeutron, Neutron newNeutron) { LOG.trace("updated floatingIP - OLD: {}\nNEW: {}", oldFloatingIp, newFloatingIp); IpAddress oldEpIp = oldFloatingIp.getFixedIpAddress(); IpAddress newEpIp = newFloatingIp.getFixedIpAddress(); if (Objects.equal(oldEpIp, newEpIp)) { // floating IP was not moved from one port to the other return; } ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); IpAddress epNatIp = newFloatingIp.getFloatingIpAddress(); L3ContextId routerL3ContextId = new L3ContextId(newFloatingIp.getRouterId().getValue()); if (epNatIp != null && newEpIp != null) { NatAddress nat = new NatAddressBuilder().setNatAddress(epNatIp).build(); rwTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.l3EndpointIid(routerL3ContextId, newEpIp).augmentation(NatAddress.class), nat, true); } if (oldEpIp != null) { DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, IidFactory.l3EndpointIid(routerL3ContextId, oldEpIp).augmentation(NatAddress.class), rwTx); } boolean isSubmitToDsSuccessful = DataStoreHelper.submitToDs(rwTx); if (!isSubmitToDsSuccessful) { LOG.warn("Nat address {} was not added to endpoint {}", epNatIp, newEpIp); } }
@Override public void onCreated(Router router, Neutron neutron) { LOG.trace("created router - {}", router); ContextId routerl3ContextId = new ContextId(router.getUuid().getValue()); TenantId tenantId = new TenantId(router.getTenantId().getValue()); InstanceIdentifier<ForwardingContext> routerL3CtxIid = L2L3IidFactory.l3ContextIid(tenantId, routerl3ContextId); ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder(); Name routerName = null; if (!Strings.isNullOrEmpty(router.getName())) { try { routerName = new Name(router.getName()); fwdCtxBuilder.setName(routerName); } catch (Exception e) { LOG.info("Name '{}' of Neutron Subnet '{}' is ignored.", router.getName(), router.getUuid().getValue()); LOG.debug("Name exception", e); } } ForwardingContext routerl3Context = fwdCtxBuilder.setContextId(routerl3ContextId) .setContextType(MappingUtils.L3_CONTEXT) .build(); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.CONFIGURATION, routerL3CtxIid, routerl3Context, true); createTenantL3Context(new L3ContextId(routerl3ContextId), tenantId, routerName, wTx); DataStoreHelper.submitToDs(wTx); }
IpAddress gatewayIp = neutronSubnet.getGatewayIp(); boolean registeredDefaultRoute = epRegistrator.registerExternalL3PrefixEndpoint(MappingUtils.DEFAULT_ROUTE, new L3ContextId(neutronSubnet.getNetworkId().getValue()), gatewayIp, tenantId); if (!registeredDefaultRoute) { LOG.warn("Could not add EndpointL3Prefix as default route. Subnet within provider physical network {}",
l2BdWithGw); updateTenantForwarding(newNeutron, oldRouter, newRouter, new L3ContextId(routerL3CtxId), tenantId, rwTx); DataStoreHelper.submitToDs(rwTx);
@Deprecated private void createTenantNetworkDomains(Network network, TenantId tenantId, ReadWriteTransaction rwTx) { Name name; L3ContextBuilder l3CtxBuilder = new L3ContextBuilder(); L2FloodDomainBuilder l2FdBuilder = new L2FloodDomainBuilder(); L2BridgeDomainBuilder l2BdBuilder = new L2BridgeDomainBuilder(); if (!Strings.isNullOrEmpty(network.getName())) { try { name = new Name(network.getName()); l3CtxBuilder.setName(name); l2FdBuilder.setName(name); l2BdBuilder.setName(name); } catch (Exception e) { name = null; LOG.info("Name of Neutron Network '{}' is ignored.", network.getName()); LOG.debug("Name exception", e); } } L2FloodDomainId l2FdId = new L2FloodDomainId(network.getUuid().getValue()); L3ContextId l3ContextId = new L3ContextId(l2FdId); L3Context l3Context = l3CtxBuilder.setId(l3ContextId).build(); rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3Context.getId()), l3Context, true); L2BridgeDomainId l2BdId = new L2BridgeDomainId(l2FdId); L2BridgeDomain l2Bd = l2BdBuilder.setId(l2BdId).setParent(l3Context.getId()).build(); rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2Bd, true); L2FloodDomain l2Fd = l2FdBuilder.setId(l2FdId).setParent(l2BdId).build(); rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2FloodDomainIid(tenantId, l2FdId), l2Fd, true); }
L3ContextId l3Context = new L3ContextId(port.getNetworkId().getValue());