package org.opendaylight.controller.config.yang.config.groupbasedpolicy;
-import java.util.concurrent.Future;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.groupbasedpolicy.api.DomainSpecificRegistry;
import org.opendaylight.groupbasedpolicy.api.EndpointAugmentorRegistry;
import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentorRegistry;
ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
private final DataBroker dataBroker;
private ClusterSingletonServiceProvider clusterSingletonService;
+ private final RpcProviderRegistry rpcProviderRegistry;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
private EndpointAugmentorRegistryImpl endpointAugmentorRegistryImpl;
private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistryImpl;
private BaseEndpointServiceImpl baseEndpointServiceImpl;
private RendererManager rendererManager;
+ private BindingAwareBroker.RpcRegistration<BaseEndpointService> baseEndpointServiceRpcRegistration;
public DomainSpecificRegistryInstance(final DataBroker dataBroker,
- final ClusterSingletonServiceProvider clusterSingletonService) {
+ final ClusterSingletonServiceProvider clusterSingletonService,
+ final RpcProviderRegistry rpcProviderRegistry) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
+ this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
}
@Override
netDomainAugmentorRegistryImpl = new NetworkDomainAugmentorRegistryImpl();
baseEndpointServiceImpl = new BaseEndpointServiceImpl(dataBroker, endpointAugmentorRegistryImpl);
rendererManager = new RendererManager(dataBroker, netDomainAugmentorRegistryImpl, endpointAugmentorRegistryImpl);
+
+ baseEndpointServiceRpcRegistration = rpcProviderRegistry.addRpcImplementation(BaseEndpointService.class, this);
}
@Override
public ListenableFuture<Void> closeServiceInstance() {
LOG.info("Instance {} closed", this.getClass().getSimpleName());
baseEndpointServiceImpl.close();
+ baseEndpointServiceRpcRegistration.close();
rendererManager.close();
+
return Futures.immediateFuture(null);
}
package org.opendaylight.controller.config.yang.config.groupbasedpolicy;
-import java.util.concurrent.Future;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentation;
import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
import org.opendaylight.groupbasedpolicy.endpoint.EndpointRpcRegistry;
ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
private final DataBroker dataBroker;
private ClusterSingletonServiceProvider clusterSingletonService;
+ private final RpcProviderRegistry rpcProviderRegistry;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
private EndpointRpcRegistry endpointRpcRegistry;
+ private BindingAwareBroker.RpcRegistration<EndpointService> serviceRpcRegistration;
public EpRendererAugmentationRegistryImplInstance(final DataBroker dataBroker,
- final ClusterSingletonServiceProvider clusterSingletonService) {
+ final ClusterSingletonServiceProvider clusterSingletonService,
+ final RpcProviderRegistry rpcProviderRegistry) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
+ this.rpcProviderRegistry = rpcProviderRegistry;
}
@Override
public void instantiateServiceInstance() {
LOG.info("Instantiating {}", this.getClass().getSimpleName());
endpointRpcRegistry = new EndpointRpcRegistry(dataBroker);
+
+ serviceRpcRegistration = rpcProviderRegistry.addRpcImplementation(EndpointService.class, this);
}
@Override
public ListenableFuture<Void> closeServiceInstance() {
LOG.info("Instance {} closed", this.getClass().getSimpleName());
endpointRpcRegistry.close();
+ serviceRpcRegistration.close();
return Futures.immediateFuture(null);
}
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
<reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
+ <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
<!-- Modules /-->
<bean id="groupbasedpolicy" class="org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance"
- init-method="initialize" destroy-method="close">
+ init-method="initialize" destroy-method="close">
<argument ref="dataBroker"/>
<argument ref="policyValidatorRegistry"/>
<argument ref="clusterSingletonService"/>
</bean>
<bean id="domainSpecificRegistry" class="org.opendaylight.controller.config.yang.config.groupbasedpolicy.DomainSpecificRegistryInstance"
- init-method="initialize" destroy-method="close">
+ init-method="initialize" destroy-method="close">
<argument ref="dataBroker"/>
<argument ref="clusterSingletonService"/>
+ <argument ref="rpcRegistry"/>
</bean>
<bean id="epRendererAugmentationRegistry" class="org.opendaylight.controller.config.yang.config.groupbasedpolicy.EpRendererAugmentationRegistryImplInstance"
- init-method="initialize" destroy-method="close">
+ init-method="initialize" destroy-method="close">
<argument ref="dataBroker"/>
<argument ref="clusterSingletonService"/>
+ <argument ref="rpcRegistry"/>
</bean>
<bean id="statisticsManagerImpl" class="org.opendaylight.controller.config.yang.config.groupbasedpolicy.StatisticsManagerImplInstance"
- init-method="initialize" destroy-method="close">
+ init-method="initialize" destroy-method="close">
<argument ref="dataBroker"/>
<argument ref="clusterSingletonService"/>
</bean>
<bean id="policyValidatorRegistry" class="org.opendaylight.controller.config.yang.config.groupbasedpolicy.PolicyValidatorRegistryInstance"
- init-method="initialize" destroy-method="close">
+ init-method="initialize" destroy-method="close">
<argument ref="dataBroker"/>
<argument ref="clusterSingletonService"/>
</bean>
<service ref="policyValidatorRegistry" interface="org.opendaylight.groupbasedpolicy.api.PolicyValidatorRegistry" odl:type="default"/>
<service ref="statisticsManagerImpl" interface="org.opendaylight.groupbasedpolicy.api.StatisticsManager" odl:type="default"/>
- <!-- RPC implementations -->
- <odl:rpc-implementation ref="domainSpecificRegistry"/>
- <odl:rpc-implementation ref="epRendererAugmentationRegistry"/>
</blueprint>
\ No newline at end of file
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.groupbasedpolicy.neutron.mapper.NeutronMapper;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
private static final ServiceGroupIdentifier IDENTIFIER =
ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
private final DataBroker dataBroker;
- private final EndpointService epService;
- private final BaseEndpointService baseEndpointService;
private final ClusterSingletonServiceProvider clusterSingletonService;
+ private final RpcProviderRegistry rpcBroker;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
private NeutronMapper mapper;
public NeutronMapperInstance(final DataBroker dataBroker,
- final EndpointService epService,
- final BaseEndpointService baseEndpointService,
+ final RpcProviderRegistry rpcBroker,
final ClusterSingletonServiceProvider clusterSingletonService) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- this.epService = Preconditions.checkNotNull(epService);
- this.baseEndpointService = Preconditions.checkNotNull(baseEndpointService);
+ this.rpcBroker = Preconditions.checkNotNull(rpcBroker);
this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
}
@Override
public void instantiateServiceInstance() {
LOG.info("Instantiating {}", this.getClass().getSimpleName());
+ final EndpointService epService = rpcBroker.getRpcService(EndpointService.class);
+ final BaseEndpointService baseEndpointService = rpcBroker.getRpcService(BaseEndpointService.class);
mapper = new NeutronMapper(dataBroker, epService, baseEndpointService);
}
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.unregister.endpoint.input.L3Builder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return true;
}
+ @Deprecated
+ public boolean unregisterL3EpAsExternalGateway(IpAddress ipAddress, L3ContextId l3Context) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput unregisterEndpointInput =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder()
+ .setL3(ImmutableList.of(new L3Builder().setL3Context(l3Context)
+ .setIpAddress(ipAddress)
+ .build()))
+ .build();
+
+ try {
+ RpcResult<Void> rpcResult = epService.unregisterEndpoint(unregisterEndpointInput).get();
+ if (!rpcResult.isSuccessful()) {
+ LOG.warn("Illegal state - unregisterL3EndpointAsExternalGateway was not successful. Input of RPC: {}",
+ unregisterEndpointInput);
+ return false;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("unregisterL3EndpointAsExternalGateway failed. {}", unregisterEndpointInput, e);
+ return false;
+ }
+ return true;
+ }
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainmentBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.network.containment.containment.NetworkDomainContainmentBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointRegBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.AddressEndpointUnregBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
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.forwarding.l2_l3.rev160427.IpPrefixType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentForwarding;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentForwardingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.has.subnet.Subnet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.has.subnet.SubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.fields.Parent;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContextBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
return epRegistrator.registerEndpoint(addrEpBuilder.build());
}
+ private boolean unregisterExternalGateway(IpPrefix ipPrefix, ContextId routerl3ContextId) {
+ AddressEndpointUnregBuilder addrEpBuilder = new AddressEndpointUnregBuilder();
+ addrEpBuilder.setAddressType(IpPrefixType.class);
+ addrEpBuilder.setAddress(MappingUtils.ipPrefixToStringIpAddress(ipPrefix));
+ addrEpBuilder.setContextId(routerl3ContextId);
+ addrEpBuilder.setContextType(MappingUtils.L3_CONTEXT);
+ return epRegistrator.unregisterEndpoint(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))
.build();
rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
l2BdWithGw);
- }
+ }
+ }
+
+ private void deleteTenantForwarding(Neutron newNeutron, Router oldRouter, L3ContextId l3ContextId, TenantId tenantId, ReadWriteTransaction rwTx) {
+ InstanceIdentifier<L3Context> l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId);
+
+ LOG.trace("Deleting router from TenantForwarding {}", l3ContextIid);
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rwTx);
+
+ if (oldRouter.getGatewayPortId() != null) {
+ // external network is attached to router
+ Uuid gatewayPortId = oldRouter.getGatewayPortId();
+ Optional<Port> potentialGwPort = PortUtils.findPort(gatewayPortId, newNeutron.getPorts());
+ if (!potentialGwPort.isPresent()) {
+ LOG.trace("Gateway port {} is not present. Skipping delete of extGW from TenantForwarding",
+ gatewayPortId);
+ return;
+ }
+
+ Port gwPort = potentialGwPort.get();
+ List<FixedIps> fixedIpsFromGwPort = gwPort.getFixedIps();
+ if (fixedIpsFromGwPort == null || fixedIpsFromGwPort.isEmpty()) {
+ LOG.trace("Gateway port {} does not contain fixed IPs. Skipping delete of extGW from TenantForwarding",
+ gatewayPortId);
+ 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.trace("Gateway port {} does not contain fixed IPs. Skipping delete of extGW from TenantForwarding",
+ gatewayPortId);
+ return;
+ }
+ IpAddress gatewayIp = potentialSubnet.get().getGatewayIp();
+ boolean registeredExternalGateway = epRegistrator.unregisterL3EpAsExternalGateway(gatewayIp, l3ContextId);
+ if (!registeredExternalGateway) {
+ LOG.trace("L3 Gateway endpoint {} with IP {} was not unregistered.", l3ContextId, gatewayIp);
+ return;
+ } else {
+ LOG.trace("L3 Gateway endpoint {} with IP {} was unregistered successfully.", l3ContextId, gatewayIp);
+ }
+ EndpointL3Key epL3Key = new EndpointL3Key(gatewayIp, l3ContextId);
+
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
+ NeutronGbpIidFactory.externalGatewayAsL3Endpoint(epL3Key.getL3Context(), epL3Key.getIpAddress()), rwTx);
+
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(Endpoints.class)
+ .child(EndpointL3Prefix.class, new EndpointL3PrefixKey(MappingUtils.DEFAULT_ROUTE, l3ContextId))
+ .build(), rwTx);
+
+ Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet>
+ subnetOptional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+ IidFactory.subnetIid(tenantId, new SubnetId(ipWithSubnetFromGwPort.getSubnetId().getValue())),
+ dataProvider.newReadOnlyTransaction());
+
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet
+ subnet =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder(
+ subnetOptional.get()).setVirtualRouterIp(null).build();
+ LOG.trace("Removing VirtualRouterIp from subnet {}.", subnetOptional.get());
+ rwTx.put(LogicalDatastoreType.CONFIGURATION,
+ IidFactory.subnetIid(tenantId, new SubnetId(ipWithSubnetFromGwPort.getSubnetId().getValue())), subnet);
+
+ L2BridgeDomainId l2BdId = new L2BridgeDomainId(potentialSubnet.get().getNetworkId().getValue());
+ L3ContextId l3Context = new L3ContextId( potentialSubnet.get().getNetworkId().getValue());
+ Optional<L2BridgeDomain> optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+ IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx);
+ if (optBd.isPresent()) {
+ L2BridgeDomain l2BdWithGw = new L2BridgeDomainBuilder(optBd.get()).setParent(l3Context).build();
+ LOG.trace("Setting parent for L2BridgeDomain {} back to network {}.", l2BdWithGw, l3Context);
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
+ l2BdWithGw);
+ }
+ }
}
private static @Nonnull ForwardingContext createL3ContextFromRouter(
@Override
public void onDeleted(Router router, Neutron oldNeutron, Neutron newNeutron) {
- LOG.trace("deleted router - {}", router);
+ LOG.debug("deleted router - {}", router);
+ ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
+ ContextId routerl3ContextId = new ContextId(router.getUuid().getValue());
+ TenantId tenantId = new TenantId(router.getTenantId().getValue());
+ deleteExtGw(router, tenantId, newNeutron, rwTx);
+ InstanceIdentifier<ForwardingContext> routerL3CtxIid = L2L3IidFactory.l3ContextIid(tenantId, routerl3ContextId);
+
+ LOG.trace("Removing router from forwardingByTenant. Router: {} Path: {}", router, routerL3CtxIid);
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, routerL3CtxIid, rwTx);
+
+ InstanceIdentifier<L3Context> l3ContextInstanceIdentifier =
+ IidFactory.l3ContextIid(tenantId, new L3ContextId(routerl3ContextId));
+ LOG.trace("Removing router from Tenant`s forwarding context. Router: {} Path: {}", router,
+ l3ContextInstanceIdentifier);
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, l3ContextInstanceIdentifier, rwTx);
+
+ DataStoreHelper.submitToDs(rwTx);
+ }
+
+ private void deleteExtGw(Router router, TenantId tenantId, Neutron newNeutron, ReadWriteTransaction rwTx) {
+ ContextId routerL3CtxId = new ContextId(router.getUuid().getValue());
+ if (router.getGatewayPortId() != null) {
+ // external network is attached to router
+ Uuid gatewayPortId = router.getGatewayPortId();
+ Optional<Port> potentialGwPort = PortUtils.findPort(gatewayPortId, newNeutron.getPorts());
+ if (!potentialGwPort.isPresent()) {
+ LOG.trace("Gateway port {} is not present. Skipping delete for external gateway", gatewayPortId);
+ return;
+ }
+
+ Port gwPort = potentialGwPort.get();
+ List<FixedIps> fixedIpsFromGwPort = gwPort.getFixedIps();
+ if (fixedIpsFromGwPort == null || fixedIpsFromGwPort.isEmpty()) {
+ LOG.trace("Gateway port {} with does not contain fixed IPs. Skipping delete for external gateway",
+ gatewayPortId);
+ return;
+ }
+
+ 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.trace("Subnet for GW port {} is not present. Skipping delete for external gateway",
+ gatewayPortId);
+ return;
+ }
+ IpPrefix gatewayIp = MappingUtils.ipAddressToIpPrefix(potentialSubnet.get().getGatewayIp());
+
+ if (!unregisterExternalGateway(gatewayIp, routerL3CtxId)) {
+ LOG.warn("Could not unregister routerL3Prefix as gateway of default route. Gateway port {}", gwPort);
+ return;
+ }
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
+ NeutronGbpIidFactory.externalGatewayAsEndpoint(routerL3CtxId, gatewayIp, MappingUtils.L3_CONTEXT),
+ rwTx);
+ NetworkDomainId domainId = new NetworkDomainId(ipWithSubnetFromGwPort.getSubnetId().getValue());
+ Optional<NetworkDomain> domainOptional =
+ DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+ L2L3IidFactory.subnetIid(tenantId, domainId), dataProvider.newReadWriteTransaction());
+
+ if (domainOptional.isPresent()) {
+ Subnet originalSubnet = domainOptional.get().getAugmentation(SubnetAugmentForwarding.class).getSubnet();
+ if (originalSubnet != null) {
+ LOG.trace("Deleting virtual router IP from Subnet {} in gateway {}", originalSubnet, gatewayPortId);
+ SubnetBuilder subnetBuilder = new SubnetBuilder(originalSubnet).setVirtualRouterIp(null);
+ rwTx.put(LogicalDatastoreType.CONFIGURATION,
+ L2L3IidFactory.subnetIid(tenantId, domainId)
+ .augmentation(SubnetAugmentForwarding.class)
+ .child(Subnet.class),
+ subnetBuilder.build());
+ }
+ }
+ ContextId l2BdId = new ContextId(potentialSubnet.get().getNetworkId().getValue());
+ Optional<ForwardingContext> optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+ L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx);
+ Parent parent = MappingUtils.createParent(l2BdId, MappingUtils.L3_CONTEXT);
+ if (optBd.isPresent()) {
+ ForwardingContext bridgeDomain = new ForwardingContextBuilder(optBd.get()).setParent(parent).build();
+ LOG.trace("Setting parent for L2BridgeDomain {} back to network {}.", bridgeDomain, parent);
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
+ bridgeDomain);
+ }
+ }
+ deleteTenantForwarding(newNeutron, router, new L3ContextId(routerL3CtxId), tenantId, rwTx);
}
}
odl:use-default-for-reference-types="true">
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
- <odl:rpc-service id="epService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService"/>
- <odl:rpc-service id="baseEpService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService"/>
+ <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
<reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
<bean id="neutronMapper" class="org.opendaylight.controller.config.yang.config.neutron_mapper.impl.NeutronMapperInstance"
- init-method="instantiate" destroy-method="close">
+ init-method="instantiate" destroy-method="close">
<argument ref="dataBroker"/>
- <argument ref="epService"/>
- <argument ref="baseEpService"/>
- <argument ref="clusterSingletonService" />
+ <argument ref="rpcRegistry"/>
+ <argument ref="clusterSingletonService"/>
</bean>
</blueprint>
\ No newline at end of file
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.groupbasedpolicy.neutron.ovsdb.NeutronOvsdb;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
private static final ServiceGroupIdentifier IDENTIFIER =
ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
private final DataBroker dataBroker;
- private final EndpointService epService;
private final IntegrationBridgeSetting settings;
private final ClusterSingletonServiceProvider clusterSingletonService;
+ private final RpcProviderRegistry rpcBroker;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
private NeutronOvsdb neutronOvsdb;
public NeutronOvsdbInstance(final DataBroker dataBroker,
- final EndpointService epService,
+ final RpcProviderRegistry rpcBroker,
final IntegrationBridgeSetting settings,
final ClusterSingletonServiceProvider clusterSingletonService) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- this.epService = Preconditions.checkNotNull(epService);
+ this.rpcBroker = Preconditions.checkNotNull(rpcBroker);
this.settings = Preconditions.checkNotNull(settings);
this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
}
@Override
public void instantiateServiceInstance() {
LOG.info("Instantiating {}", this.getClass().getSimpleName());
+ final EndpointService epService = rpcBroker.getRpcService(EndpointService.class);
neutronOvsdb = new NeutronOvsdb(dataBroker, epService, settings);
}
odl:use-default-for-reference-types="true">
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
- <odl:rpc-service id="epService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService"/>
+ <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
<reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
<odl:clustered-app-config id="moduleConfig"
- binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.ovsdb.params.rev160812.IntegrationBridgeSetting">
+ binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.ovsdb.params.rev160812.IntegrationBridgeSetting">
<odl:default-config><![CDATA[
<integration-bridge-setting xmlns="urn:opendaylight:groupbasedpolicy:neutron:ovsdb:params">
<name>br-int</name>
</odl:clustered-app-config>
<bean id="neutronOvsdb" class="org.opendaylight.controller.config.yang.config.neutron_ovsdb.impl.NeutronOvsdbInstance"
- init-method="initialize" destroy-method="close">
+ init-method="initialize" destroy-method="close">
<argument ref="dataBroker"/>
- <argument ref="epService"/>
+ <argument ref="rpcRegistry"/>
<argument ref="moduleConfig"/>
- <argument ref="clusterSingletonService" />
+ <argument ref="clusterSingletonService"/>
</bean>
</blueprint>
\ No newline at end of file
public NeutronVppMapper(String socketPath, String socketPrefix, DataBroker dataBroker) {\r
SocketInfo socketInfo = new SocketInfo(socketPath, socketPrefix);\r
vppNodeListener = new VppNodeListener(dataBroker, socketInfo);\r
- neutronListener = new NeutronListener(dataBroker, socketInfo);\r
+ neutronListener = new NeutronListener(dataBroker);\r
LOG.info("Neutron VPP started!");\r
}\r
\r
@Override\r
protected void onSubtreeModified(DataObjectModification<RendererNode> rootNode,\r
InstanceIdentifier<RendererNode> rootIdentifier) {\r
- deleteData(rootNode.getDataAfter());\r
- writeData(rootNode.getDataBefore());\r
+ deleteData(rootNode.getDataBefore());\r
+ writeData(rootNode.getDataAfter());\r
}\r
\r
private void writeData(RendererNode rendererNode) {\r
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
import org.opendaylight.yangtools.concepts.ListenerRegistration;\r
import org.opendaylight.yangtools.yang.binding.DataObject;\r
private final Set<MappingProvider<? extends DataObject>> dataChangeProviders = new LinkedHashSet<>();\r
protected ListenerRegistration<NeutronListener> registeredListener;\r
\r
- public NeutronListener(DataBroker dataBroker, SocketInfo socketInfo) {\r
- registerHandlersAndListeners(dataBroker, socketInfo);\r
+ public NeutronListener(DataBroker dataBroker) {\r
+ registerHandlersAndListeners(dataBroker);\r
registeredListener = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(\r
LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).build()), this);\r
}\r
\r
- private void registerHandlersAndListeners(DataBroker dataBroker, SocketInfo socketInfo) {\r
- PortHandler portHandler = new PortHandler(dataBroker, socketInfo);\r
+ private void registerHandlersAndListeners(DataBroker dataBroker) {\r
+ PortHandler portHandler = new PortHandler(dataBroker);\r
dataChangeProviders.add(new PortAware(portHandler, dataBroker));\r
dataChangeProviders.add(new NetworkAware(dataBroker));\r
}\r
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;\r
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
import com.google.common.annotations.VisibleForTesting;\r
import com.google.common.base.Optional;\r
\r
+import javax.annotation.Nonnull;\r
public class PortHandler implements TransactionChainListener {\r
\r
private static final Logger LOG = LoggerFactory.getLogger(PortHandler.class);\r
private static final String VPP_INTERFACE_NAME_PREFIX = "neutron_port_";\r
private static final String TAP_PORT_NAME_PREFIX = "tap";\r
private static final String RT_PORT_NAME_PREFIX = "qr-";\r
+ private static final String VHOST_SOCKET_KEY = "vhostuser_socket";\r
\r
private BindingTransactionChain transactionChain;\r
private DataBroker dataBroker;\r
- private SocketInfo socketInfo;\r
\r
- PortHandler(DataBroker dataBroker, SocketInfo socketInfo) {\r
+ PortHandler(DataBroker dataBroker) {\r
this.dataBroker = dataBroker;\r
- this.socketInfo = socketInfo;\r
transactionChain = this.dataBroker.createTransactionChain(this);\r
}\r
\r
.setAddressType(bebp.getAddressType())\r
.setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue())\r
.setVppNodeId(new NodeId(portBinding.getHostId()));\r
+\r
if (port.getDeviceOwner().contains(COMPUTE_OWNER)) {\r
- String socket = socketInfo.getSocketPath() + socketInfo.getSocketPrefix() + bebp.getPortId().getValue();\r
- vppEpBuilder.setInterfaceTypeChoice(new VhostUserCaseBuilder().setSocket(socket).build());\r
+ vppEpBuilder.setInterfaceTypeChoice(\r
+ new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build());\r
} else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) {\r
TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue()))\r
.setName(createPortName(port.getUuid()))\r
return vppEpBuilder.build();\r
}\r
\r
+ private String getSocketFromPortBinding(@Nonnull PortBindingExtension portBindingExtension) {\r
+ List<VifDetails> vifDetails = nullToEmpty(portBindingExtension.getVifDetails());\r
+\r
+ for (VifDetails detail : vifDetails) {\r
+ if (VHOST_SOCKET_KEY.equalsIgnoreCase(detail.getDetailsKey())) {\r
+ return detail.getValue();\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
private LoopbackCase getLoopbackCase(Port port) {\r
LoopbackCaseBuilder loopbackCase = new LoopbackCaseBuilder()\r
.setPhysAddress(new PhysAddress(port.getMacAddress().getValue()));\r
public void init() {\r
port = TestUtils.createValidVppPort();\r
bebp = TestUtils.createBaseEndpointByPortForPort();\r
- socketInfo = new SocketInfo("/tmp/", "_socket");\r
dataBroker = getDataBroker();\r
- neutronListener = new NeutronListener(dataBroker, socketInfo);\r
+ neutronListener = new NeutronListener(dataBroker);\r
neutronListener.clearDataChangeProviders();\r
baseEpByPortListener = Mockito.spy(new PortAware(new PortHandler(\r
- dataBroker, socketInfo), dataBroker));\r
+ dataBroker), dataBroker));\r
neutronListener.addDataChangeProvider(baseEpByPortListener);\r
}\r
\r
@Test\r
public void constructorTest() {\r
dataBroker = Mockito.spy(dataBroker);\r
- NeutronListener neutronListener = new NeutronListener(dataBroker, socketInfo);\r
+ NeutronListener neutronListener = new NeutronListener(dataBroker);\r
verify(dataBroker).registerDataTreeChangeListener(\r
eq(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,\r
InstanceIdentifier.builder(Neutron.class)\r
private BindingTransactionChain transactionChain;
private Port port;
- private SocketInfo socketInfo;
private BaseEndpointByPort bebp;
@Rule
public void init() {
port = TestUtils.createValidVppPort();
bebp = TestUtils.createBaseEndpointByPortForPort();
- socketInfo = new SocketInfo("/tmp/", "_socket");
dataBroker = Mockito.spy(getDataBroker());
transactionChain = mock(BindingTransactionChain.class);
when(dataBroker.createTransactionChain(any(PortHandler.class))).thenReturn(transactionChain);
- portHandler = new PortHandler(dataBroker, socketInfo);
+ portHandler = new PortHandler(dataBroker);
when(transactionChain.newReadOnlyTransaction()).thenAnswer(new Answer<ReadTransaction>() {
@Override
assertTrue(vppEp.getInterfaceTypeChoice() instanceof VhostUserCase);
VhostUserCase vhostUserCase = (VhostUserCase) vppEp.getInterfaceTypeChoice();
assertNotNull(vhostUserCase);
- assertEquals(vhostUserCase.getSocket(), socketInfo.getSocketPath() + socketInfo.getSocketPrefix()
- + bebp.getPortId().getValue());
+ assertEquals(TestUtils.TEST_SOCKET, vhostUserCase.getSocket());
}
@Test
import static org.junit.Assert.assertNotNull;\r
import static org.junit.Assert.assertTrue;\r
\r
+import java.util.Collections;\r
import java.util.Iterator;\r
\r
import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtensionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetailsBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetailsKey;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;\r
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;\r
\r
public class TestUtils {\r
+ public static String TEST_SOCKET = "/tmp/socket_testsocket";\r
\r
public static Port createValidVppPort() {\r
PortBindingExtension portBindingExt = new PortBindingExtensionBuilder().setHostId("devstack-control")\r
.setVifType("vhostuser")\r
+ .setVifDetails(Collections.singletonList(\r
+ new VifDetailsBuilder().setKey(new VifDetailsKey("vhostuser_socket"))\r
+ .setValue(TEST_SOCKET)\r
+ .build()))\r
.build();\r
return new PortBuilder().setUuid(new Uuid("00000000-1111-2222-3333-444444444444"))\r
.setDeviceOwner("compute")\r