--- /dev/null
+package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router._interface.ports.EndpointByRouterInterfacePort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router._interface.ports.EndpointByRouterInterfacePortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router.gateway.ports.EndpointByRouterGatewayPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router.gateway.ports.EndpointByRouterGatewayPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ports.by.endpoints.PortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ports.by.endpoints.PortByEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router._interface.ports.by.endpoints.RouterInterfacePortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router._interface.ports.by.endpoints.RouterInterfacePortByEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router.gateway.ports.by.endpoints.RouterGatewayPortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router.gateway.ports.by.endpoints.RouterGatewayPortByEndpointBuilder;
+
+public class MappingFactory {
+
+ private MappingFactory() {
+ throw new UnsupportedOperationException("cannot create an instance");
+ }
+
+ public static EndpointByPort createEndpointByPort(EndpointKey epKey, UniqueId portId) {
+ return new EndpointByPortBuilder().setPortId(portId)
+ .setL2Context(epKey.getL2Context())
+ .setMacAddress(epKey.getMacAddress())
+ .build();
+ }
+
+ public static PortByEndpoint createPortByEndpoint(UniqueId portId, EndpointKey epKey) {
+ return new PortByEndpointBuilder().setPortId(portId)
+ .setL2Context(epKey.getL2Context())
+ .setMacAddress(epKey.getMacAddress())
+ .build();
+ }
+
+ public static EndpointByRouterGatewayPort createEndpointByRouterGatewayPort(EndpointKey epKey, UniqueId portId) {
+ return new EndpointByRouterGatewayPortBuilder().setPortId(portId)
+ .setL2Context(epKey.getL2Context())
+ .setMacAddress(epKey.getMacAddress())
+ .build();
+ }
+
+ public static RouterGatewayPortByEndpoint createRouterGatewayPortByEndpoint(UniqueId portId, EndpointKey epKey) {
+ return new RouterGatewayPortByEndpointBuilder().setPortId(portId)
+ .setL2Context(epKey.getL2Context())
+ .setMacAddress(epKey.getMacAddress())
+ .build();
+ }
+
+ public static EndpointByRouterInterfacePort createEndpointByRouterInterfacePort(EndpointKey epKey, UniqueId portId) {
+ return new EndpointByRouterInterfacePortBuilder().setPortId(portId)
+ .setL2Context(epKey.getL2Context())
+ .setMacAddress(epKey.getMacAddress())
+ .build();
+ }
+
+ public static RouterInterfacePortByEndpoint createRouterInterfacePortByEndpoint(UniqueId portId, EndpointKey epKey) {
+ return new RouterInterfacePortByEndpointBuilder().setPortId(portId)
+ .setL2Context(epKey.getL2Context())
+ .setMacAddress(epKey.getMacAddress())
+ .build();
+ }
+
+}
import org.opendaylight.neutron.spi.NeutronSecurityGroup;
import org.opendaylight.neutron.spi.NeutronSecurityRule;
import org.opendaylight.neutron.spi.Neutron_IPs;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.l3.prefix.fields.EndpointL3Gateways;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.l3.prefix.fields.EndpointL3GatewaysBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPort;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router._interface.ports.EndpointByRouterInterfacePort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router.gateway.ports.EndpointByRouterGatewayPort;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ports.by.endpoints.PortByEndpoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ports.by.endpoints.PortByEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router._interface.ports.by.endpoints.RouterInterfacePortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router.gateway.ports.by.endpoints.RouterGatewayPortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.EndpointLocation.LocationType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup;
return;
}
if (isRouterGatewayPort(port)) {
- LOG.trace("Port is router gateway - {}", port.getID());
+ LOG.trace("Port is router gateway - {} does nothing. {} handles router iface.",
+ NeutronPortAware.class.getSimpleName(), NeutronRouterAware.class.getSimpleName());
return;
}
if (isFloatingIp(port)) {
LOG.trace("Port is floating ip - {}", port.getID());
return;
}
- if (Strings.isNullOrEmpty(port.getTenantID())) {
- LOG.trace("REMOVE ME: Tenant is null - {}", port.getID());
- return;
- }
ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
TenantId tenantId = new TenantId(Utils.normalizeUuid(port.getTenantID()));
if (isDhcpPort(port)) {
}
}
}
-
boolean isNeutronPortCreated = addNeutronPort(port, rwTx, epService);
if (!isNeutronPortCreated) {
rwTx.cancel();
return false;
}
EndpointKey epKey = new EndpointKey(fwCtx.getL2BridgeDomain().getId(), new MacAddress(port.getMacAddress()));
- UniqueId portId = new UniqueId(port.getID());
- EndpointByPort endpointByPort = createEndpointByPort(epKey, portId);
- rwTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.endpointByPortIid(portId), endpointByPort, true);
- PortByEndpoint portByEndpoint = createPortByEndpoint(portId, epKey);
- rwTx.put(LogicalDatastoreType.OPERATIONAL,
- IidFactory.portByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), portByEndpoint, true);
+ addNeutronGbpMapping(port, epKey, rwTx);
try {
RegisterEndpointInput registerEpRpcInput = createRegisterEndpointInput(port, fwCtx);
return true;
}
+ private static void addNeutronGbpMapping(NeutronPort port, EndpointKey epKey, ReadWriteTransaction rwTx) {
+ if (isRouterInterfacePort(port)) {
+ LOG.trace("Adding RouterInterfacePort-Endpoint mapping for port {} and endpoint {}", port.getID(), epKey);
+ UniqueId portId = new UniqueId(port.getID());
+ EndpointByRouterInterfacePort endpointByPort = MappingFactory.createEndpointByRouterInterfacePort(epKey,
+ portId);
+ rwTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.endpointByRouterInterfacePortIid(portId),
+ endpointByPort, true);
+ RouterInterfacePortByEndpoint portByEndpoint = MappingFactory.createRouterInterfacePortByEndpoint(portId,
+ epKey);
+ rwTx.put(LogicalDatastoreType.OPERATIONAL,
+ IidFactory.routerInterfacePortByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()),
+ portByEndpoint, true);
+ } else if (isRouterGatewayPort(port)) {
+ LOG.trace("Adding RouterGatewayPort-Endpoint mapping for port {} and endpoint {}", port.getID(), epKey);
+ UniqueId portId = new UniqueId(port.getID());
+ EndpointByRouterGatewayPort endpointByPort = MappingFactory.createEndpointByRouterGatewayPort(epKey, portId);
+ rwTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.endpointByRouterGatewayPortIid(portId),
+ endpointByPort, true);
+ RouterGatewayPortByEndpoint portByEndpoint = MappingFactory.createRouterGatewayPortByEndpoint(portId, epKey);
+ rwTx.put(LogicalDatastoreType.OPERATIONAL,
+ IidFactory.routerGatewayPortByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()),
+ portByEndpoint, true);
+ } else {
+ LOG.trace("Adding Port-Endpoint mapping for port {} (device owner {}) and endpoint {}", port.getID(),
+ port.getDeviceOwner(), epKey);
+ UniqueId portId = new UniqueId(port.getID());
+ EndpointByPort endpointByPort = MappingFactory.createEndpointByPort(epKey, portId);
+ rwTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.endpointByPortIid(portId), endpointByPort, true);
+ PortByEndpoint portByEndpoint = MappingFactory.createPortByEndpoint(portId, epKey);
+ rwTx.put(LogicalDatastoreType.OPERATIONAL,
+ IidFactory.portByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), portByEndpoint, true);
+ }
+ }
+
+ public static boolean addL3PrefixEndpoint(L3ContextId l3ContextId, IpPrefix ipPrefix, IpAddress ipAddress, TenantId tenantId,
+ ReadWriteTransaction rwTx, EndpointService epService) {
+
+ EndpointL3PrefixKey epL3PrefixKey = new EndpointL3PrefixKey( ipPrefix, l3ContextId);
+
+ EndpointL3Key epL3Key = null;
+ List<EndpointL3Key> l3Gateways = new ArrayList<>();
+ if (ipAddress != null) {
+ epL3Key = new EndpointL3Key(ipAddress, l3ContextId);
+ l3Gateways.add(epL3Key);
+ }
+
+
+ try {
+ RegisterL3PrefixEndpointInput registerL3PrefixEpRpcInput = createRegisterL3PrefixEndpointInput(epL3PrefixKey, l3Gateways,tenantId);
+
+ RpcResult<Void> rpcResult = epService.registerL3PrefixEndpoint(registerL3PrefixEpRpcInput).get();
+ if (!rpcResult.isSuccessful()) {
+ LOG.warn("Illegal state - RPC registerEndpoint failed. Input of RPC: {}", registerL3PrefixEpRpcInput);
+ return false;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("addPort - RPC invocation failed.", e);
+ return false;
+ }
+ return true;
+
+ }
+
private static boolean validateForwardingCtx(ForwardingCtx fwCtx) {
if (fwCtx.getL2FloodDomain() == null) {
LOG.warn("Illegal state - l2-flood-domain does not exist.");
return true;
}
- private static EndpointByPort createEndpointByPort(EndpointKey epKey, UniqueId portId) {
- return new EndpointByPortBuilder().setPortId(portId)
- .setL2Context(epKey.getL2Context())
- .setMacAddress(epKey.getMacAddress())
- .build();
- }
-
- private static PortByEndpoint createPortByEndpoint(UniqueId portId, EndpointKey epKey) {
- return new PortByEndpointBuilder().setPortId(portId)
- .setL2Context(epKey.getL2Context())
- .setMacAddress(epKey.getMacAddress())
- .build();
- }
-
private List<NeutronSecurityRule> createDhcpSecRules(NeutronPort port, EndpointGroupId consumerEpgId, ReadTransaction rTx) {
TenantId tenantId = new TenantId(Utils.normalizeUuid(port.getTenantID()));
Neutron_IPs firstIp = MappingUtils.getFirstIp(port.getFixedIPs());
}
}
+ 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();
+ }
+
private static RegisterEndpointInput createRegisterEndpointInput(NeutronPort port, ForwardingCtx fwCtx) {
List<EndpointGroupId> epgIds = new ArrayList<>();
// each EP has to be in EPG ANY, except dhcp and router
epgIds.add(new EndpointGroupId(secGrp.getSecurityGroupUUID()));
}
}
+ LocationType locationType = LocationType.Internal;
+ if(isRouterGatewayPort(port)) {
+ locationType = LocationType.External;
+ }
RegisterEndpointInputBuilder inputBuilder = new RegisterEndpointInputBuilder().setL2Context(
fwCtx.getL2BridgeDomain().getId())
.setMacAddress(new MacAddress(port.getMacAddress()))
.setTenant(new TenantId(Utils.normalizeUuid(port.getTenantID())))
.setEndpointGroups(epgIds)
.addAugmentation(OfOverlayContextInput.class,
- new OfOverlayContextInputBuilder().setPortName(createTapPortName(port)).build())
+ new OfOverlayContextInputBuilder()
+ .setPortName(createTapPortName(port))
+ .setLocationType(locationType)
+ .build())
.setTimestamp(System.currentTimeMillis());
List<Neutron_IPs> fixedIPs = port.getFixedIPs();
// TODO Li msunal this getting of just first IP has to be rewrite when OFOverlay renderer
return l3s;
}
+
+
}
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.neutron.spi.NeutronSecurityRule;
import org.opendaylight.neutron.spi.NeutronSubnet;
import org.opendaylight.neutron.spi.Neutron_IPs;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
@Override
public void neutronRouterUpdated(NeutronRouter router) {
LOG.trace("neutronRouterUpdated - {}", router);
- // TODO Li msunal external gateway
+ if (router.getExternalGatewayInfo() == null || router.getExternalGatewayInfo().getExternalFixedIPs() == null) {
+ LOG.trace("neutronRouterUpdated - not an external Gateway");
+ return;
+ }
+
+ INeutronPortCRUD portInterface = NeutronCRUDInterfaces.getINeutronPortCRUD(this);
+ if (portInterface == null) {
+ LOG.warn("Illegal state - No provider for {}", INeutronPortCRUD.class.getName());
+ return;
+ }
+
+ ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
+ TenantId tenantId = new TenantId(Utils.normalizeUuid(router.getTenantID()));
+ L3ContextId l3ContextIdFromRouterId = new L3ContextId(router.getID());
+ InstanceIdentifier<L3Context> l3ContextIidForRouterId = IidFactory.l3ContextIid(tenantId,
+ l3ContextIdFromRouterId);
+ Optional<L3Context> potentialL3ContextForRouter = DataStoreHelper.readFromDs(
+ LogicalDatastoreType.CONFIGURATION, l3ContextIidForRouterId, rwTx);
+ L3Context l3Context = null;
+ if (potentialL3ContextForRouter.isPresent()) {
+ l3Context = potentialL3ContextForRouter.get();
+ } else { // add L3 context if missing
+ l3Context = createL3ContextFromRouter(router);
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, l3ContextIidForRouterId, l3Context);
+ }
+
+ INeutronSubnetCRUD subnetInterface = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ if (subnetInterface == null) {
+ LOG.warn("Illegal state - No provider for {}", INeutronSubnetCRUD.class.getName());
+ return;
+ }
+ NeutronSubnet defaultSubnet = subnetInterface.getSubnet(router.getExternalGatewayInfo()
+ .getExternalFixedIPs()
+ .get(0)
+ .getSubnetUUID());;
+ IpAddress defaultGateway = null;
+ if (defaultSubnet != null) {
+ defaultGateway = Utils.createIpAddress(defaultSubnet.getGatewayIP());
+ }
+ // Create L3Prefix Endpoints for all routes
+ if (router.getRoutes().isEmpty()) {
+ List<String> defaultRoute = ImmutableList.of("0.0.0.0/0");
+ router.setRoutes(defaultRoute);
+
+ }
+ if (l3ContextIdFromRouterId != null) {
+ for (String route : router.getRoutes()) {
+ IpPrefix ipPrefix = Utils.createIpPrefix(route);
+ boolean addedL3Prefix = NeutronPortAware.addL3PrefixEndpoint(l3ContextIdFromRouterId, ipPrefix,
+ defaultGateway, tenantId, rwTx, epService);
+ if (!addedL3Prefix) {
+ LOG.warn("Could not add EndpointL3Prefix for Neutron route {} for router {}", route, router.getID());
+ rwTx.cancel();
+ return;
+ }
+ }
+ }
+ for (Neutron_IPs externalFixedIp : router.getExternalGatewayInfo().getExternalFixedIPs()) {
+ NeutronPort routerPort = portInterface.getPort(router.getGatewayPortId());
+ IpAddress ipAddress = Utils.createIpAddress(routerPort.getFixedIPs().get(0).getIpAddress());
+ // External subnet associated with gateway port should use the gateway IP not router IP.
+ NeutronSubnet neutronSubnet = subnetInterface.getSubnet(externalFixedIp.getSubnetUUID());
+ ipAddress = Utils.createIpAddress(neutronSubnet.getGatewayIP());
+ SubnetId subnetId = new SubnetId(externalFixedIp.getSubnetUUID());
+ Subnet subnet = resolveSubnetWithVirtualRouterIp(tenantId, subnetId, ipAddress, rwTx);
+ if (subnet == null) {
+ rwTx.cancel();
+ return;
+ }
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnet.getId()), subnet);
+
+ if (Strings.isNullOrEmpty(routerPort.getTenantID())) {
+ routerPort.setTenantID(router.getTenantID());
+ }
+ // create security rules for router
+ List<NeutronSecurityRule> routerSecRules = createRouterSecRules(routerPort, null, rwTx);
+ if (routerSecRules == null) {
+ rwTx.cancel();
+ return;
+ }
+ for (NeutronSecurityRule routerSecRule : routerSecRules) {
+ boolean isRouterSecRuleAdded = NeutronSecurityRuleAware.addNeutronSecurityRule(routerSecRule, rwTx);
+ if (!isRouterSecRuleAdded) {
+ rwTx.cancel();
+ return;
+ }
+ }
+
+ boolean isSuccessful = setNewL3ContextToEpsFromSubnet(tenantId, l3Context, subnet, rwTx);
+ if (!isSuccessful) {
+ rwTx.cancel();
+ return;
+ }
+ }
+
+ DataStoreHelper.submitToDs(rwTx);
}
@Override
Subnet subnet = potentialSubnet.get();
L2FloodDomainId l2FdId = new L2FloodDomainId(subnet.getParent().getValue());
ForwardingCtx fwCtx = MappingUtils.createForwardingContext(tenantId, l2FdId, rTx);
- if (fwCtx.getL3Context() != null && fwCtx.getL3Context().equals(l3ContextIdFromRouterId)) {
+ if (fwCtx.getL3Context() != null && fwCtx.getL3Context().getId().equals(l3ContextIdFromRouterId)) {
// TODO Be msunal
LOG.warn("Illegal state - Neutron mapper does not support multiple router interfaces in the same subnet yet.");
return StatusCode.FORBIDDEN;
return;
}
- INeutronSubnetCRUD subnetInterface = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
- if (subnetInterface == null) {
- LOG.warn("Illegal state - No provider for {}", INeutronSubnetCRUD.class.getName());
- return;
- }
-
ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
TenantId tenantId = new TenantId(Utils.normalizeUuid(router.getTenantID()));
L3ContextId l3ContextIdFromRouterId = new L3ContextId(router.getID());
l3ContextIdFromRouterId);
Optional<L3Context> potentialL3ContextForRouter = DataStoreHelper.readFromDs(
LogicalDatastoreType.CONFIGURATION, l3ContextIidForRouterId, rwTx);
- // add L3 context if missing
- if (!potentialL3ContextForRouter.isPresent()) {
- Name l3ContextName = null;
- if (!Strings.isNullOrEmpty(router.getName())) {
- l3ContextName = new Name(router.getName());
- }
- L3Context l3Context = new L3ContextBuilder().setId(l3ContextIdFromRouterId)
- .setName(l3ContextName)
- .setDescription(new Description(MappingUtils.NEUTRON_ROUTER__ + router.getID()))
- .build();
+ L3Context l3Context = null;
+ if (potentialL3ContextForRouter.isPresent()) {
+ l3Context = potentialL3ContextForRouter.get();
+ } else { // add L3 context if missing
+ l3Context = createL3ContextFromRouter(router);
rwTx.put(LogicalDatastoreType.CONFIGURATION, l3ContextIidForRouterId, l3Context);
}
+ // Based on Neutron Northbound - Port representing router interface
+ // contains exactly on fixed IP
+ NeutronPort routerPort = portInterface.getPort(routerInterface.getPortUUID());
SubnetId subnetId = new SubnetId(routerInterface.getSubnetUUID());
+ IpAddress ipAddress = Utils.createIpAddress(routerPort.getFixedIPs().get(0).getIpAddress());
+ Subnet subnet = resolveSubnetWithVirtualRouterIp(tenantId, subnetId, ipAddress, rwTx);
+ if (subnet == null) {
+ rwTx.cancel();
+ return;
+ }
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnet.getId()), subnet);
+
+ // create security rules for router
+ List<NeutronSecurityRule> routerSecRules = createRouterSecRules(routerPort, null, rwTx);
+ if (routerSecRules == null) {
+ rwTx.cancel();
+ return;
+ }
+ for (NeutronSecurityRule routerSecRule : routerSecRules) {
+ boolean isRouterSecRuleAdded = NeutronSecurityRuleAware.addNeutronSecurityRule(routerSecRule, rwTx);
+ if (!isRouterSecRuleAdded) {
+ rwTx.cancel();
+ return;
+ }
+ }
+
+ boolean isSuccessful = setNewL3ContextToEpsFromSubnet(tenantId, l3Context, subnet, rwTx);
+ if (!isSuccessful) {
+ rwTx.cancel();
+ return;
+ }
+
+ DataStoreHelper.submitToDs(rwTx);
+ }
+
+ private static @Nonnull L3Context createL3ContextFromRouter(NeutronRouter router) {
+ Name l3ContextName = null;
+ if (!Strings.isNullOrEmpty(router.getName())) {
+ l3ContextName = new Name(router.getName());
+ }
+ return new L3ContextBuilder().setId(new L3ContextId(router.getID()))
+ .setName(l3ContextName)
+ .setDescription(new Description(MappingUtils.NEUTRON_ROUTER__ + router.getID()))
+ .build();
+ }
+
+ private @Nullable Subnet resolveSubnetWithVirtualRouterIp(TenantId tenantId, SubnetId subnetId,
+ IpAddress ipAddress, ReadTransaction rTx) {
Optional<Subnet> potentialSubnet = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
- IidFactory.subnetIid(tenantId, subnetId), rwTx);
+ IidFactory.subnetIid(tenantId, subnetId), rTx);
if (!potentialSubnet.isPresent()) {
LOG.warn("Illegal state - subnet {} does not exist.", subnetId.getValue());
- rwTx.cancel();
- return;
+ return null;
}
- // Based on Neutron Northbound - Port representing router interface
- // contains exactly on
- // fixed IP
- NeutronPort routerPort = portInterface.getPort(routerInterface.getPortUUID());
// TODO: Li alagalah: Add gateways and prefixes instead of
// VirtualRouterID
- Subnet subnet = new SubnetBuilder(potentialSubnet.get()).setVirtualRouterIp(
- Utils.createIpAddress(routerPort.getFixedIPs().get(0).getIpAddress())).build();
- rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetId), subnet);
+ return new SubnetBuilder(potentialSubnet.get()).setVirtualRouterIp(ipAddress).build();
+ }
+
+ /**
+ * @return {@code false} if illegal state occurred; {@code true} otherwise
+ */
+ public boolean setNewL3ContextToEpsFromSubnet(TenantId tenantId, L3Context l3Context, Subnet subnet,
+ ReadWriteTransaction rwTx) {
if (subnet.getParent() == null) {
- LOG.warn("Illegal state - subnet {} does not have a parent.", subnetId.getValue());
- rwTx.cancel();
- return;
+ LOG.warn("Illegal state - subnet {} does not have a parent.", subnet.getId().getValue());
+ return false;
}
L2FloodDomainId l2FdId = new L2FloodDomainId(subnet.getParent().getValue());
ForwardingCtx fwCtx = MappingUtils.createForwardingContext(tenantId, l2FdId, rwTx);
if (fwCtx.getL2BridgeDomain() == null) {
LOG.warn("Illegal state - l2-flood-domain {} does not have a parent.", l2FdId.getValue());
- rwTx.cancel();
- return;
+ return false;
}
L2BridgeDomain l2BridgeDomain = new L2BridgeDomainBuilder(fwCtx.getL2BridgeDomain()).setParent(
- l3ContextIdFromRouterId).build();
+ l3Context.getId()).build();
rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BridgeDomain.getId()),
l2BridgeDomain);
- // create security rules for router
- List<NeutronSecurityRule> routerSecRules = createRouterSecRules(routerPort, null, rwTx);
- if (routerSecRules == null) {
- rwTx.cancel();
- return;
- }
- for (NeutronSecurityRule routerSecRule : routerSecRules) {
- boolean isRouterSecRuleAdded = NeutronSecurityRuleAware.addNeutronSecurityRule(routerSecRule, rwTx);
- if (!isRouterSecRuleAdded) {
- rwTx.cancel();
- return;
- }
+ INeutronSubnetCRUD subnetInterface = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ if (subnetInterface == null) {
+ LOG.warn("Illegal state - No provider for {}", INeutronSubnetCRUD.class.getName());
+ return false;
}
List<L3> l3Eps = new ArrayList<>();
L3ContextId oldL3ContextId = fwCtx.getL3Context().getId();
- NeutronSubnet neutronSubnet = subnetInterface.getSubnet(subnetId.getValue());
+ NeutronSubnet neutronSubnet = subnetInterface.getSubnet(subnet.getId().getValue());
List<NeutronPort> portsInNeutronSubnet = neutronSubnet.getPortsInSubnet();
for (NeutronPort port : portsInNeutronSubnet) {
boolean isPortAdded = NeutronPortAware.addNeutronPort(port, rwTx, epService);
if (!isPortAdded) {
- rwTx.cancel();
- return;
+ return false;
}
// TODO Li msunal this has to be rewrite when OFOverlay renderer
// will support l3-endpoints.
Neutron_IPs firstIp = MappingUtils.getFirstIp(port.getFixedIPs());
if (firstIp != null) {
l3Eps.add(new L3Builder().setL3Context(oldL3ContextId)
- .setIpAddress(Utils.createIpAddress(firstIp.getIpAddress()))
- .build());
+ .setIpAddress(Utils.createIpAddress(firstIp.getIpAddress()))
+ .build());
}
}
if (!l3Eps.isEmpty()) {
epService.unregisterEndpoint(new UnregisterEndpointInputBuilder().setL3(l3Eps).build());
}
-
- DataStoreHelper.submitToDs(rwTx);
+ return true;
}
public static List<NeutronSecurityRule> createRouterSecRules(NeutronPort port, EndpointGroupId consumerEpgId,
TenantId tenantId = new TenantId(Utils.normalizeUuid(neutronSubnet.getTenantID()));
Subnet subnet = createSubnet(neutronSubnet);
rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetId), subnet, true);
-
DataStoreHelper.submitToDs(rwTx);
}
rwTx.cancel();
return;
}
-
DataStoreHelper.submitToDs(rwTx);
}
-
}
package org.opendaylight.groupbasedpolicy.neutron.mapper.util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.NeutronByGbpMappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.EndpointsByPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.EndpointsByRouterGatewayPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.EndpointsByRouterInterfacePorts;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPort;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router._interface.ports.EndpointByRouterInterfacePort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router._interface.ports.EndpointByRouterInterfacePortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router.gateway.ports.EndpointByRouterGatewayPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.router.gateway.ports.EndpointByRouterGatewayPortKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.PortsByEndpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.RouterGatewayPortsByEndpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.RouterInterfacePortsByEndpoints;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ports.by.endpoints.PortByEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ports.by.endpoints.PortByEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router._interface.ports.by.endpoints.RouterInterfacePortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router._interface.ports.by.endpoints.RouterInterfacePortByEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router.gateway.ports.by.endpoints.RouterGatewayPortByEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.router.gateway.ports.by.endpoints.RouterGatewayPortByEndpointKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.mapper.rev150223.Mappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.mapper.rev150223.mappings.EndpointGroupPairToContractMappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.mapper.rev150223.mappings.NetworkMappings;
.build();
}
+ public static InstanceIdentifier<EndpointL3Prefix> endpointL3PrefixIid(L3ContextId l3Context, IpPrefix ipPrefix) {
+ return InstanceIdentifier.builder(Endpoints.class)
+ .child(EndpointL3Prefix.class, new EndpointL3PrefixKey(ipPrefix, l3Context))
+ .build();
+ }
+
public static InstanceIdentifier<Subnet> subnetIid(TenantId tenantId, SubnetId subnetId) {
return InstanceIdentifier.builder(Tenants.class)
.child(Tenant.class, new TenantKey(tenantId))
.child(PortByEndpoint.class, new PortByEndpointKey(l2BdId, mac))
.build();
}
+
+ public static InstanceIdentifier<EndpointByRouterGatewayPort> endpointByRouterGatewayPortIid(UniqueId portId) {
+ return InstanceIdentifier.builder(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class)
+ .child(GbpByNeutronMappings.class)
+ .child(EndpointsByRouterGatewayPorts.class)
+ .child(EndpointByRouterGatewayPort.class, new EndpointByRouterGatewayPortKey(portId))
+ .build();
+ }
+
+ public static InstanceIdentifier<RouterGatewayPortByEndpoint> routerGatewayPortByEndpointIid(L2BridgeDomainId l2BdId, MacAddress mac) {
+ return InstanceIdentifier.builder(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class)
+ .child(NeutronByGbpMappings.class)
+ .child(RouterGatewayPortsByEndpoints.class)
+ .child(RouterGatewayPortByEndpoint.class, new RouterGatewayPortByEndpointKey(l2BdId, mac))
+ .build();
+ }
+
+ public static InstanceIdentifier<EndpointByRouterInterfacePort> endpointByRouterInterfacePortIid(UniqueId portId) {
+ return InstanceIdentifier.builder(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class)
+ .child(GbpByNeutronMappings.class)
+ .child(EndpointsByRouterInterfacePorts.class)
+ .child(EndpointByRouterInterfacePort.class, new EndpointByRouterInterfacePortKey(portId))
+ .build();
+ }
+
+ public static InstanceIdentifier<RouterInterfacePortByEndpoint> routerInterfacePortByEndpointIid(L2BridgeDomainId l2BdId, MacAddress mac) {
+ return InstanceIdentifier.builder(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class)
+ .child(NeutronByGbpMappings.class)
+ .child(RouterInterfacePortsByEndpoints.class)
+ .child(RouterInterfacePortByEndpoint.class, new RouterInterfacePortByEndpointKey(l2BdId, mac))
+ .build();
+ }
}
uses neutron-port-key;
}
}
+ container router-gateway-ports-by-endpoints {
+ description "Neutron router gateway ports by groupbasedpolicy endpoint";
+ list router-gateway-port-by-endpoint {
+ description "Neutron router gateway port key by groupbasedpolicy endpoint key";
+ key "l2-context mac-address";
+ uses gbp-endpoint:l2-key;
+ uses neutron-port-key;
+ }
+ }
+ container router-interface-ports-by-endpoints {
+ description "Neutron router interface ports by groupbasedpolicy endpoint";
+ list router-interface-port-by-endpoint {
+ description "Neutron router interface port key by groupbasedpolicy endpoint key";
+ key "l2-context mac-address";
+ uses gbp-endpoint:l2-key;
+ uses neutron-port-key;
+ }
+ }
}
container gbp-by-neutron-mappings {
uses gbp-endpoint:l2-key;
}
}
+ container endpoints-by-router-gateway-ports {
+ description "Groupbasedpolicy endpoints by neutron router gateway ports";
+ list endpoint-by-router-gateway-port {
+ description "Groupbasedpolicy endpoint key by neutron router gateway port key";
+ key port-id;
+ uses neutron-port-key;
+ uses gbp-endpoint:l2-key;
+ }
+ }
+ container endpoints-by-router-interface-ports {
+ description "Groupbasedpolicy endpoints by neutron router interface ports";
+ list endpoint-by-router-interface-port {
+ description "Groupbasedpolicy endpoint key by neutron router interface port key";
+ key port-id;
+ uses neutron-port-key;
+ uses gbp-endpoint:l2-key;
+ }
+ }
}
}