L3Context getL3ContextForSubnet(IndexedTenant indexedTenant, Subnet subnet) { if (indexedTenant == null || subnet == null || subnet.getParent() == null) { return null; } return indexedTenant.resolveL3Context(new L2FloodDomainId(subnet.getParent().getValue())); }
@Override public void onDeleted(Network network, Neutron oldNeutron, Neutron newNeutron) { LOG.trace("deleted network - {}", network); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); TenantId tenantId = new TenantId(network.getTenantId().getValue()); ContextId id = new ContextId(network.getUuid().getValue()); Optional<ForwardingContext> potentialL2Fd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2FloodDomainIid(tenantId, id), rwTx); if (!potentialL2Fd.isPresent()) { LOG.warn("Illegal state - l2-flood-domain {} does not exist.", id.getValue()); return; } Optional<ForwardingContext> potentialL2Bd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, id), rwTx); if (!potentialL2Bd.isPresent()) { LOG.warn("Illegal state - l2-bridge-domain {} does not exist.", id.getValue()); return; } Optional<ForwardingContext> potentialL3Ctx = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l3ContextIid(tenantId, id), rwTx); if (!potentialL3Ctx.isPresent()) { LOG.warn("Illegal state - l3-context {} does not exist.", id.getValue()); return; } removeTenantNetworkDomains(network, tenantId, rwTx); DataStoreHelper.submitToDs(rwTx); }
} else if (!contextId.equals(consSubnet.getParent())) { LOG.error("Flood domain is not the same for all Network domains in the Consumer EPG "); return null; } else if (!contextId.equals(provSubnet.getParent())) { LOG.error("Flood domain is not the same for all Network domains in the Provider EPG "); return null; L2FloodDomainId consL2FldId = new L2FloodDomainId(consSubnet.getParent().getValue()); L2FloodDomain consFloodDomain = readL2FloodDomain(consL2FldId, tenantId); if (consFloodDomain == null) { return null; L2FloodDomainId provL2FldId = new L2FloodDomainId(provSubnet.getParent().getValue()); L2FloodDomain provFloodDomain = readL2FloodDomain(provL2FldId, tenantId); if (provFloodDomain == null) {
private static ContextId resolveL3ContextForPort(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)) { LOG.trace("Router interface port was found in the same subnet as port have {}", port); return new ContextId(routerIfacePort.getDeviceId()); } } return new ContextId(port.getNetworkId().getValue()); } }
private void processDeletedEN(EndpointNetwork en, WriteTransaction wtx) { for (AddressEndpoint endpoint : endpoints) { if (endpoint.getContextType().isAssignableFrom(L3Context.class) && endpoint.getContextId().equals(en.getL3ContextId()) && endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils.samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) { InstanceIdentifier<AbsoluteLocation> iid = IidFactory .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class, endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId()) .child(AbsoluteLocation.class); wtx.delete(LogicalDatastoreType.CONFIGURATION, iid); LOG.debug("Location deleted for endpoint {}", endpoint); } } return; }
private void unregisterEndpointAndRemoveMapping(UnregisterEndpointInput baseEpUnreg, Port port, ReadWriteTransaction rwTx) { boolean isUnregisteredBaseEndpoint = epRegistrator.unregisterEndpoint(baseEpUnreg); if (isUnregisteredBaseEndpoint) { 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); LOG.trace("Removing Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}", port.getUuid().getValue(), port.getDeviceOwner(), portByBaseEndpointKey); removeBaseEndpointMappings(portByBaseEndpointKey, portId, rwTx); } }
private void processCreatedEN(EndpointNetwork en, InstanceIdentifier<?> nodeIID, String connectorIID, WriteTransaction wtx) { for (AddressEndpoint endpoint : endpoints) { if (endpoint.getContextType().isAssignableFrom(L3Context.class) && endpoint.getContextId().equals(en.getL3ContextId()) && endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils.samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) { InstanceIdentifier<AbsoluteLocation> iid = IidFactory .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class, endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId()) .child(AbsoluteLocation.class); wtx.put(LogicalDatastoreType.CONFIGURATION, iid, createRealLocation(nodeIID, connectorIID), true); LOG.debug("New location created for endpoint {}", endpoint); } } return; }
if (L2FloodDomain.class.equals(fwCtxCont.getContextType())) { return fwCtxCont.getContextId() == null ? java.util.Optional.empty() : java.util.Optional .of(fwCtxCont.getContextId().getValue());
TenantId tenantId = new TenantId(network.getTenantId().getValue()); Name name; ContextId ctxId = new ContextId(network.getUuid().getValue()); ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder() .setContextId(ctxId) addProviderPhysicalNetworkMapping(tenantId, new L2FloodDomainId(ctxId.getValue()), NetworkUtils.getSegmentationId(network), rwTx);
public static <T extends ContextType> Parent createParent(NetworkDomainId id, Class<T> domainType) { return new ParentBuilder().setContextId(new ContextId(id.getValue())).setContextType(domainType).build(); }
private void removeLocationForEndpoint(AddressEndpoint endpoint, WriteTransaction wtx) { for (NetworkElement ne : nullToEmpty(networkElements.getNetworkElement())) { for (Interface iface : nullToEmpty(ne.getInterface())) { for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) { if (endpoint.getContextType().isAssignableFrom(L3Context.class) && endpoint.getContextId().equals(en.getL3ContextId()) && endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils .samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) { InstanceIdentifier<AbsoluteLocation> iid = IidFactory .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class, endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId()) .child(AbsoluteLocation.class); wtx.delete(LogicalDatastoreType.CONFIGURATION, iid); LOG.debug("Location deleted for endpoint {}", endpoint); return; } } } } }
Subnet subnet = ctx.getTenant(extEp.getTenant()).resolveSubnet(new SubnetId(extEp.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(extEp.getTenant()) .resolveL2FloodDomain(new L2FloodDomainId(subnet.getParent().getValue())); if (l2Fd != null) { Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class);
private static @Nonnull ForwardingContext createL3ContextFromRouter( Router router) { Name l3ContextName = null; if (!Strings.isNullOrEmpty(router.getName())) { l3ContextName = new Name(router.getName()); } return new ForwardingContextBuilder().setContextId(new ContextId(router.getUuid().getValue())) .setContextType(MappingUtils.L3_CONTEXT) .setName(new Name(l3ContextName.getValue())) .build(); }
private void createLocationForEndpoint(AddressEndpoint endpoint, WriteTransaction wtx) { for (NetworkElement ne : nullToEmpty(networkElements.getNetworkElement())) { for (Interface iface : nullToEmpty(ne.getInterface())) { for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) { if (endpoint.getContextType().isAssignableFrom(L3Context.class) && endpoint.getContextId().equals(en.getL3ContextId()) && endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils .samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) { InstanceIdentifier<AbsoluteLocation> iid = IidFactory .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class, endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId()) .child(AbsoluteLocation.class); wtx.put(LogicalDatastoreType.CONFIGURATION, iid, createRealLocation(ne.getIid(), iface.getIid()), true); LOG.debug("New location created for endpoint {}", endpoint); return; } } } } }
if (natIpSubnet != null && natIpSubnet.getParent() != null) { L2FloodDomain natEpl2Fd = ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(natIpSubnet.getParent().getValue())); if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) { Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId(); L2FloodDomain l2Fd = ctx.getTenant(endpoint.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(sub.getParent().getValue())); if (l2Fd == null) { return;
private Subnet createSubnet(List<L3Address> endPoints, NetworkDomainId networkDomainId , L2FloodDomainId floodDomainId) { L3Address endPoint = endPoints.get(0); String ip = endPoint.getIpAddress().getIpv4Address().getValue(); ip = ip.substring(0, ip.lastIndexOf('.')) + ".1"; return new SubnetBuilder() .setId(new SubnetId(networkDomainId.getValue())) .setParent(new ContextId(floodDomainId.getValue())) .setVirtualRouterIp( GBPRendererHelper.createIpAddress(ip)) .setIpPrefix(GBPRendererHelper.createIpPrefix(ip + "/24")) .build(); }
L2FloodDomain l2Fd = null; if (extSubnet != null && extSubnet.getParent() != null) { l2Fd = tenant.resolveL2FloodDomain(new L2FloodDomainId(extSubnet.getParent().getValue()));
@Deprecated public static Subnet createTenantSubnet( org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet subnet, IpAddress virtualRouterIp) { org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder subnetBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder(); subnetBuilder.setId(new SubnetId(subnet.getUuid().getValue())); subnetBuilder.setParent(new ContextId(subnet.getNetworkId().getValue())); if (!Strings.isNullOrEmpty(subnet.getName())) { try { subnetBuilder.setName(new Name(subnet.getName())); } catch (Exception e) { LOG.info("Name '{}' of Neutron Subnet '{}' is ignored.", subnet.getName(), subnet.getUuid().getValue()); LOG.debug("Name exception", e); } } subnetBuilder.setIpPrefix(subnet.getCidr()); subnetBuilder.setVirtualRouterIp(virtualRouterIp); return subnetBuilder.build(); }
L2FloodDomainId l2fdId = new L2FloodDomainId(s.getParent().getValue()); L2BridgeDomain bd = tenant.resolveL2BridgeDomain(l2fdId); L2FloodDomain fd = tenant.resolveL2FloodDomain(l2fdId);
private org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput createUnregisterBaseEndpointInput( Port port, Neutron neutron) { UnregisterEndpointInputBuilder inputBuilder = new UnregisterEndpointInputBuilder(); List<AddressEndpointUnreg> list = new ArrayList<>(); AddressEndpointUnregBuilder addrL2EpUnregBuilder = new AddressEndpointUnregBuilder(); addrL2EpUnregBuilder.setAddress(port.getMacAddress().getValue()) .setAddressType(MacAddressType.class) .setContextId(new ContextId(port.getNetworkId().getValue())) .setContextType(MappingUtils.L2_BRDIGE_DOMAIN); list.add(addrL2EpUnregBuilder.build()); Optional<FixedIps> potentialFirstIp = PortUtils.resolveFirstFixedIps(port); if (potentialFirstIp.isPresent()) { ContextId l3ContextId = resolveL3ContextForPort(port, potentialFirstIp.get(), neutron); AddressEndpointUnregBuilder addrL3EpUnregBuilder = new AddressEndpointUnregBuilder(); addrL3EpUnregBuilder.setAddress(MappingUtils.ipAddressToStringIpPrefix(potentialFirstIp.get().getIpAddress())) .setAddressType(IpPrefixType.class) .setContextId(l3ContextId) .setContextType(L3Context.class); list.add(addrL3EpUnregBuilder.build()); } inputBuilder.setAddressEndpointUnreg(list); return inputBuilder.build(); }