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 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); } }
public static <T extends ContextType> Parent createParent(NetworkDomainId id, Class<T> domainType) { return new ParentBuilder().setContextId(new ContextId(id.getValue())).setContextType(domainType).build(); }
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 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(); }
@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); }
@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(); }
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(); }
@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); }
ContextId routerL3CtxId = new ContextId(newRouter.getUuid().getValue()); rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain); ContextId l2BdId = new ContextId(potentialSubnet.get().getNetworkId().getValue()); Optional<ForwardingContext> optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx);
Subnet routerPortSubnet = potentialRouterPortSubnet.get(); modifyForwardingOnDelete(routerPortSubnet, l3Context, tenantId, rwTx); ContextId l2BdId = new ContextId(routerPortSubnet.getNetworkId().getValue()); ForwardingContext fwdCtx = new ForwardingContextBuilder().setContextId(l2BdId) .setContextType(MappingUtils.L2_BRDIGE_DOMAIN) 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);
AddressEndpointUnreg addrEpUnreg = new AddressEndpointUnregBuilder().setAddress(l3BaseEp.getAddress()) .setAddressType(l3BaseEp.getAddressType()) .setContextId(new ContextId(portInSameSubnet.getNetworkId().getValue())) .setContextType(l3BaseEp.getContextType()) .build();
ContextId routerL3Context = new ContextId(port.getDeviceId()); ContextId l2BdId = new ContextId(routerPortSubnet.getNetworkId().getValue()); ForwardingContext l2Bd = new ForwardingContextBuilder().setContextId(l2BdId) .setContextType(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);
private AddressEndpointRegBuilder createBasicMacAddrEpInputBuilder(Port port, NetworkDomainId networkContainment, @Nullable List<EndpointGroupId> endpointGroupsToAdd) { AddressEndpointRegBuilder addrEpbuilder = new AddressEndpointRegBuilder().setAddressType(MacAddressType.class) .setAddress(port.getMacAddress().getValue()) .setAddressType(MacAddressType.class) .setContextType(MappingUtils.L2_BRDIGE_DOMAIN) .setContextId(new ContextId(port.getNetworkId().getValue())) .setTenant(new TenantId(port.getTenantId().getValue())) .setTimestamp(System.currentTimeMillis()); List<EndpointGroupId> epgs = concatEndpointGroups(port.getSecurityGroups(), endpointGroupsToAdd); addrEpbuilder.setEndpointGroup(epgs); if (networkContainment != null) { addrEpbuilder.setNetworkContainment(new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(networkContainment) .setNetworkDomainType(MappingUtils.SUBNET) .build()).build()); } return addrEpbuilder; }
TenantId tenantId = new TenantId(network.getTenantId().getValue()); Name name; ContextId ctxId = new ContextId(network.getUuid().getValue()); ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder() .setContextId(ctxId)