+ private boolean registerExternalGateway(TenantId tenantId, IpPrefix ipPrefix, ContextId routerl3ContextId,
+ NetworkDomainId networkDomainId) {
+ AddressEndpointRegBuilder addrEpBuilder = new AddressEndpointRegBuilder();
+ addrEpBuilder.setAddressType(IpPrefixType.class);
+ addrEpBuilder.setAddress(MappingUtils.ipPrefixToStringIpAddress(ipPrefix));
+ addrEpBuilder.setContextId(routerl3ContextId);
+ addrEpBuilder.setContextType(MappingUtils.L3_CONTEXT);
+ addrEpBuilder.setTenant(tenantId);
+ addrEpBuilder.setNetworkContainment(new NetworkContainmentBuilder().setContainment(
+ new NetworkDomainContainmentBuilder().setNetworkDomainId(networkDomainId).build()).build());
+ addrEpBuilder.setEndpointGroup(ImmutableList.of(MappingUtils.EPG_EXTERNAL_ID));
+ addrEpBuilder.setTimestamp(System.currentTimeMillis());
+ return epRegistrator.registerEndpoint(addrEpBuilder.build());
+ }
+
+ private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, NetworkDomainId subnetId) {
+ Subnet subnet = new SubnetBuilder().setVirtualRouterIp(MappingUtils.ipPrefixToIpAddress(gatewayIp.getValue())).build();
+ return new NetworkDomainBuilder().setKey(new NetworkDomainKey(subnetId, MappingUtils.SUBNET))
+ .addAugmentation(SubnetAugmentForwarding.class,
+ new SubnetAugmentForwardingBuilder().setSubnet(subnet).build())
+ .build();
+ }
+
+ @Deprecated
+ private void updateTenantForwarding(Neutron newNeutron, Router oldRouter, Router newRouter, L3ContextId l3ContextId, TenantId tenantId, ReadWriteTransaction rwTx) {
+ InstanceIdentifier<L3Context> l3ContextIid =
+ IidFactory.l3ContextIid(tenantId, l3ContextId);
+ Optional<L3Context> optL3Context = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rwTx);
+ L3Context l3Context = null;
+ if (optL3Context.isPresent()) {
+ l3Context = optL3Context.get();
+ } else { // add L3 context if missing
+ l3Context = createL3CtxFromRouter(newRouter);
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, l3ContextIid, l3Context);
+ }
+
+ if (newRouter.getGatewayPortId() != null && oldRouter.getGatewayPortId() == null) {
+ // external network is attached to router
+ Uuid gatewayPortId = newRouter.getGatewayPortId();
+ Optional<Port> potentialGwPort = PortUtils.findPort(gatewayPortId, newNeutron.getPorts());
+ if (!potentialGwPort.isPresent()) {
+ LOG.warn("Illegal state - router gateway port {} does not exist for router {}.",
+ gatewayPortId.getValue(), newRouter);
+ rwTx.cancel();
+ return;
+ }
+
+ Port gwPort = potentialGwPort.get();
+ List<FixedIps> fixedIpsFromGwPort = gwPort.getFixedIps();
+ if (fixedIpsFromGwPort == null || fixedIpsFromGwPort.isEmpty()) {
+ LOG.warn("Illegal state - router gateway port {} does not contain fixed IPs {}",
+ gatewayPortId.getValue(), gwPort);
+ rwTx.cancel();
+ return;
+ }
+
+ // router can have only one external network
+ FixedIps ipWithSubnetFromGwPort = fixedIpsFromGwPort.get(0);
+ Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet> potentialSubnet = SubnetUtils.findSubnet(ipWithSubnetFromGwPort.getSubnetId(), newNeutron.getSubnets());
+ if (!potentialSubnet.isPresent()) {
+ LOG.warn("Illegal state - Subnet {} does not exist for router {}.",
+ ipWithSubnetFromGwPort.getSubnetId(), newRouter);
+ rwTx.cancel();
+ return;
+ }
+ IpAddress gatewayIp = potentialSubnet.get().getGatewayIp();
+ boolean registeredExternalGateway = epRegistrator.registerL3EpAsExternalGateway(tenantId, gatewayIp,
+ l3ContextId, new NetworkDomainId(ipWithSubnetFromGwPort.getSubnetId().getValue()));
+ if (!registeredExternalGateway) {
+ LOG.warn("Could not add L3Prefix as gateway of default route. Gateway port {}", gwPort);
+ rwTx.cancel();
+ return;
+ }
+ EndpointL3Key epL3Key = new EndpointL3Key(gatewayIp, l3ContextId);
+ addNeutronExtGwMapping(epL3Key, rwTx);
+
+ boolean registeredDefaultRoute = epRegistrator.registerExternalL3PrefixEndpoint(MappingUtils.DEFAULT_ROUTE,
+ l3ContextId, gatewayIp, tenantId);
+ if (!registeredDefaultRoute) {
+ LOG.warn("Could not add EndpointL3Prefix as default route. Gateway port {}", gwPort);
+ rwTx.cancel();
+ return;
+ }
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet subnetWithGw =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder().setId(new SubnetId(ipWithSubnetFromGwPort.getSubnetId().getValue()))
+ .setVirtualRouterIp(gatewayIp)
+ .build();
+ rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetWithGw.getId()),
+ subnetWithGw);
+ L2BridgeDomainId l2BdId = new L2BridgeDomainId(potentialSubnet.get().getNetworkId().getValue());
+ Optional<L2BridgeDomain> optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+ IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx);
+ if (!optBd.isPresent()) {
+ LOG.warn(
+ "Could not read L2-Bridge-Domain {} Modifiaction of it's parent to L3-Context of router {} aborted.",
+ l2BdId, newRouter.getUuid());
+ rwTx.cancel();
+ return;
+ }
+ L2BridgeDomain l2BdWithGw = new L2BridgeDomainBuilder(optBd.get())
+ .setParent(new L3ContextId(l3ContextId.getValue()))
+ .build();
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
+ l2BdWithGw);
+ }
+ }
+
+ 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();
+ }
+
+ @Deprecated
+ private static @Nonnull L3Context createL3CtxFromRouter(Router router) {