import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
private final CodecsRegistryImpl codecsRegistry;
private final ServiceGroupIdentifier serviceGroupIdentifier;
private final ClusterSingletonServiceProvider provider;
- private final BgpDeployer.WriteConfiguration configurationWriter;
- private ClusterSingletonServiceRegistration registration;
private final DOMDataBrokerExtension service;
private final Map<TransactionChain<?, ?>, LocRibWriter> txChainToLocRibWriter = new HashMap<>();
private final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies;
private final ImportPolicyPeerTracker importPolicyPeerTracker;
private final RibId ribId;
private final Map<TablesKey, ExportPolicyPeerTracker> exportPolicyPeerTrackerMap;
-
+ private ClusterSingletonServiceRegistration registration;
private DOMTransactionChain domChain;
@GuardedBy("this")
private boolean isServiceInstantiated;
public RIBImpl(final ClusterSingletonServiceProvider provider, final RibId ribId, final AsNumber localAs, final BgpId localBgpId,
final ClusterIdentifier clusterId, final RIBExtensionConsumerContext extensions, final BGPDispatcher dispatcher,
final BindingCodecTreeFactory codecFactory, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables,
- @Nonnull final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies, final GeneratedClassLoadingStrategy classStrategy,
- final BgpDeployer.WriteConfiguration configurationWriter) {
+ @Nonnull final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies,
+ final GeneratedClassLoadingStrategy classStrategy) {
super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(requireNonNull(ribId))),
localBgpId, localAs);
this.localAs = requireNonNull(localAs);
this.serviceGroupIdentifier = ServiceGroupIdentifier.create(this.ribId.getValue() + "-service-group");
requireNonNull(provider, "ClusterSingletonServiceProvider is null");
this.provider = provider;
- this.configurationWriter = configurationWriter;
final ImmutableMap.Builder<TablesKey, ExportPolicyPeerTracker> exportPolicies = new ImmutableMap.Builder<>();
for (final BgpTableType t : this.localTables) {
this.isServiceInstantiated = true;
setActive(true);
this.domChain = this.domDataBroker.createTransactionChain(this);
- if (this.configurationWriter != null) {
- this.configurationWriter.apply();
- }
LOG.info("RIB Singleton Service {} instantiated, RIB {}", getIdentifier().getValue(), this.ribId.getValue());
LOG.debug("Instantiating RIB table {} at {}", this.ribId, this.yangRibId);
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
import org.opendaylight.protocol.bgp.rib.impl.ApplicationPeer;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer.WriteConfiguration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
@GuardedBy("this")
private ServiceRegistration<?> serviceRegistration;
+ private static ApplicationRibId createAppRibId(final Neighbor neighbor) {
+ final Config config = neighbor.getConfig();
+ if (config != null && !Strings.isNullOrEmpty(config.getDescription())) {
+ return new ApplicationRibId(config.getDescription());
+ }
+ return new ApplicationRibId(neighbor.getNeighborAddress().getIpv4Address().getValue());
+ }
+
@Override
- public synchronized void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final WriteConfiguration configurationWriter) {
+ public synchronized void start(final RIB rib, final Neighbor neighbor,
+ final BGPTableTypeRegistryConsumer tableTypeRegistry) {
Preconditions.checkState(this.bgpAppPeerSingletonService == null, "Previous peer instance was not closed.");
this.currentConfiguration = neighbor;
this.bgpAppPeerSingletonService = new BgpAppPeerSingletonService(rib, createAppRibId(neighbor),
- neighbor.getNeighborAddress().getIpv4Address(), configurationWriter);
+ neighbor.getNeighborAddress().getIpv4Address());
}
@Override
public synchronized void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
Preconditions.checkState(this.currentConfiguration != null);
- start(rib, this.currentConfiguration, tableTypeRegistry, null);
+ start(rib, this.currentConfiguration, tableTypeRegistry);
}
@Override
&& OpenConfigMappingUtil.isApplicationPeer(neighbor);
}
- private static ApplicationRibId createAppRibId(final Neighbor neighbor) {
- final Config config = neighbor.getConfig();
- if (config != null && !Strings.isNullOrEmpty(config.getDescription())) {
- return new ApplicationRibId(config.getDescription());
- }
- return new ApplicationRibId(neighbor.getNeighborAddress().getIpv4Address().getValue());
- }
-
@Override
public BGPPeerState getPeerState() {
return this.bgpAppPeerSingletonService.getPeerState();
}
private final class BgpAppPeerSingletonService implements ClusterSingletonService, BGPPeerStateConsumer,
- AutoCloseable {
+ AutoCloseable {
private final ApplicationPeer applicationPeer;
private final DOMDataTreeChangeService dataTreeChangeService;
private final ApplicationRibId appRibId;
- private ClusterSingletonServiceRegistration singletonServiceRegistration;
private final ServiceGroupIdentifier serviceGroupIdentifier;
- private final WriteConfiguration configurationWriter;
+ private ClusterSingletonServiceRegistration singletonServiceRegistration;
@GuardedBy("this")
private boolean isServiceInstantiated;
- BgpAppPeerSingletonService(final RIB rib, final ApplicationRibId appRibId, final Ipv4Address neighborAddress,
- final WriteConfiguration configurationWriter) {
+ BgpAppPeerSingletonService(final RIB rib, final ApplicationRibId appRibId, final Ipv4Address neighborAddress) {
this.applicationPeer = new ApplicationPeer(appRibId, neighborAddress, rib);
this.appRibId = appRibId;
this.dataTreeChangeService = rib.getService();
this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
- this.configurationWriter = configurationWriter;
LOG.info("Application Peer Singleton Service {} registered, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
+ getIdentifier().getValue(), this.appRibId.getValue());
//this need to be always the last step
this.singletonServiceRegistration = rib.registerClusterSingletonService(this);
}
@Override
public synchronized void instantiateServiceInstance() {
this.isServiceInstantiated = true;
- if(this.configurationWriter != null) {
- this.configurationWriter.apply();
- }
LOG.info("Application Peer Singleton Service {} instantiated, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
+ getIdentifier().getValue(), this.appRibId.getValue());
final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME)
- .nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue()).node(Tables.QNAME).node(Tables.QNAME).build();
+ .nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue())
+ .node(Tables.QNAME).node(Tables.QNAME).build();
this.applicationPeer.instantiateServiceInstance(this.dataTreeChangeService,
- new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId));
+ new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId));
}
@Override
public synchronized ListenableFuture<Void> closeServiceInstance() {
- if(!this.isServiceInstantiated) {
+ if (!this.isServiceInstantiated) {
LOG.trace("Application Peer Singleton Service {} instance already closed, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
+ getIdentifier().getValue(), this.appRibId.getValue());
return Futures.immediateFuture(null);
}
LOG.info("Application Peer Singleton Service {} instance closed, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
+ getIdentifier().getValue(), this.appRibId.getValue());
this.isServiceInstantiated = false;
return this.applicationPeer.close();
}
import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getNeighborInstanceName;
import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getRibInstanceName;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class BgpDeployerImpl implements BgpDeployer, ClusteredDataTreeChangeListener<Bgp>, AutoCloseable {
+public final class BgpDeployerImpl implements ClusteredDataTreeChangeListener<Bgp>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(BgpDeployerImpl.class);
private final InstanceIdentifier<NetworkInstance> networkInstanceIId;
private final BlueprintContainer container;
private boolean closed;
public BgpDeployerImpl(final String networkInstanceName, final BlueprintContainer container,
- final BundleContext bundleContext, final DataBroker dataBroker,
- final BGPTableTypeRegistryConsumer mappingService) {
+ final BundleContext bundleContext, final DataBroker dataBroker,
+ final BGPTableTypeRegistryConsumer mappingService) {
this.dataBroker = requireNonNull(dataBroker);
this.container = requireNonNull(container);
this.bundleContext = requireNonNull(bundleContext);
this.tableTypeRegistry = requireNonNull(mappingService);
this.networkInstanceIId = InstanceIdentifier.create(NetworkInstances.class)
- .child(NetworkInstance.class, new NetworkInstanceKey(networkInstanceName));
+ .child(NetworkInstance.class, new NetworkInstanceKey(networkInstanceName));
Futures.addCallback(initializeNetworkInstance(dataBroker, this.networkInstanceIId), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
}
}, MoreExecutors.directExecutor());
this.registration = dataBroker.registerDataTreeChangeListener(
- new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, this.networkInstanceIId.child(Protocols.class)
- .child(Protocol.class).augmentation(Protocol1.class).child(Bgp.class)), this);
+ new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, this.networkInstanceIId.child(Protocols.class)
+ .child(Protocol.class).augmentation(Protocol1.class).child(Bgp.class)), this);
LOG.info("BGP Deployer {} started.", networkInstanceName);
}
+ private static ListenableFuture<Void> initializeNetworkInstance(
+ final DataBroker dataBroker, final InstanceIdentifier<NetworkInstance> networkInstance) {
+ final WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+ wTx.merge(LogicalDatastoreType.CONFIGURATION, networkInstance,
+ new NetworkInstanceBuilder().setName(networkInstance.firstKeyOf(NetworkInstance.class).getName())
+ .setProtocols(new ProtocolsBuilder().build()).build());
+ return wTx.submit();
+ }
+
@Override
public synchronized void onDataTreeChanged(final Collection<DataTreeModification<Bgp>> changes) {
if (this.closed) {
}
}
- @Override
+ @VisibleForTesting
public InstanceIdentifier<NetworkInstance> getInstanceIdentifier() {
return this.networkInstanceIId;
}
this.closed = true;
final List<ListenableFuture<Void>> futurePeerCloseList = this.peers.values().stream()
- .map(PeerBean::closeServiceInstance).collect(Collectors.toList());
+ .map(PeerBean::closeServiceInstance).collect(Collectors.toList());
final ListenableFuture<List<Void>> futureOfRelevance = Futures.allAsList(futurePeerCloseList);
final ListenableFuture<ListenableFuture<List<Void>>> maxRelevanceFuture = transform(futureOfRelevance,
- futurePeersClose -> {
- this.peers.values().forEach(PeerBean::close);
- BgpDeployerImpl.this.peers.clear();
+ futurePeersClose -> {
+ this.peers.values().forEach(PeerBean::close);
+ BgpDeployerImpl.this.peers.clear();
- final List<ListenableFuture<Void>> futureRIBCloseList = BgpDeployerImpl.this.ribs.values().stream()
- .map(RibImpl::closeServiceInstance).collect(Collectors.toList());
- return Futures.allAsList(futureRIBCloseList);
- }, MoreExecutors.directExecutor());
+ final List<ListenableFuture<Void>> futureRIBCloseList = BgpDeployerImpl.this.ribs.values().stream()
+ .map(RibImpl::closeServiceInstance).collect(Collectors.toList());
+ return Futures.allAsList(futureRIBCloseList);
+ }, MoreExecutors.directExecutor());
final ListenableFuture<Void> ribFutureClose = transform(maxRelevanceFuture, futurePeersClose -> {
BgpDeployerImpl.this.ribs.values().forEach(RibImpl::close);
ribFutureClose.get();
}
- private static ListenableFuture<Void> initializeNetworkInstance(
- final DataBroker dataBroker, final InstanceIdentifier<NetworkInstance> networkInstance) {
- final WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
- wTx.merge(LogicalDatastoreType.CONFIGURATION, networkInstance,
- new NetworkInstanceBuilder().setName(networkInstance.firstKeyOf(NetworkInstance.class).getName())
- .setProtocols(new ProtocolsBuilder().build()).build());
- return wTx.submit();
- }
-
private synchronized void onGlobalChanged(final DataObjectModification<Global> dataObjectModification,
- final InstanceIdentifier<Bgp> rootIdentifier) {
+ final InstanceIdentifier<Bgp> rootIdentifier) {
switch (dataObjectModification.getModificationType()) {
- case DELETE:
- onGlobalRemoved(rootIdentifier);
- break;
- case SUBTREE_MODIFIED:
- case WRITE:
- onGlobalModified(rootIdentifier, dataObjectModification.getDataAfter(), null);
- break;
- default:
- break;
+ case DELETE:
+ onGlobalRemoved(rootIdentifier);
+ break;
+ case SUBTREE_MODIFIED:
+ case WRITE:
+ onGlobalModified(rootIdentifier, dataObjectModification.getDataAfter());
+ break;
+ default:
+ break;
}
}
- @Override
- public synchronized void onGlobalModified(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
- final WriteConfiguration configurationWriter) {
+ @VisibleForTesting
+ synchronized void onGlobalModified(final InstanceIdentifier<Bgp> rootIdentifier, final Global global) {
final RibImpl ribImpl = this.ribs.get(rootIdentifier);
- if(ribImpl == null ) {
- onGlobalCreated(rootIdentifier, global, configurationWriter);
+ if (ribImpl == null) {
+ onGlobalCreated(rootIdentifier, global);
} else if (!ribImpl.isGlobalEqual(global)) {
- onGlobalUpdated(rootIdentifier, global, ribImpl, configurationWriter);
+ onGlobalUpdated(rootIdentifier, global, ribImpl);
}
}
private synchronized List<PeerBean> closeAllBindedPeers(final InstanceIdentifier<Bgp> rootIdentifier) {
final List<PeerBean> filtered = new ArrayList<>();
this.peers.entrySet().stream().filter(entry -> entry.getKey().firstIdentifierOf(Bgp.class)
- .contains(rootIdentifier)).forEach(entry -> {
+ .contains(rootIdentifier)).forEach(entry -> {
final PeerBean peer = entry.getValue();
try {
peer.closeServiceInstance().get();
return filtered;
}
- private synchronized void onGlobalCreated(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
- final WriteConfiguration configurationWriter) {
+ private synchronized void onGlobalCreated(final InstanceIdentifier<Bgp> rootIdentifier, final Global global) {
LOG.debug("Creating RIB instance with configuration: {}", global);
final RibImpl ribImpl = (RibImpl) this.container.getComponentInstance(InstanceType.RIB.getBeanName());
- initiateRibInstance(rootIdentifier, global, ribImpl, configurationWriter);
+ initiateRibInstance(rootIdentifier, global, ribImpl);
this.ribs.put(rootIdentifier, ribImpl);
LOG.debug("RIB instance created: {}", ribImpl);
}
private synchronized void onGlobalUpdated(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
- final RibImpl ribImpl, final WriteConfiguration configurationWriter) {
+ final RibImpl ribImpl) {
LOG.debug("Modifying RIB instance with configuration: {}", global);
final List<PeerBean> closedPeers = closeAllBindedPeers(rootIdentifier);
try {
LOG.error("RIB instance failed to close service instance", e);
}
ribImpl.close();
- initiateRibInstance(rootIdentifier, global, ribImpl, configurationWriter);
+ initiateRibInstance(rootIdentifier, global, ribImpl);
closedPeers.forEach(peer -> peer.restart(ribImpl, this.tableTypeRegistry));
LOG.debug("RIB instance created: {}", ribImpl);
}
- @Override
- public synchronized void onGlobalRemoved(final InstanceIdentifier<Bgp> rootIdentifier) {
+ @VisibleForTesting
+ synchronized void onGlobalRemoved(final InstanceIdentifier<Bgp> rootIdentifier) {
LOG.debug("Removing RIB instance: {}", rootIdentifier);
final RibImpl ribImpl = this.ribs.remove(rootIdentifier);
if (ribImpl != null) {
final Dictionary<String, String> properties = new Hashtable<>();
properties.put(InstanceType.RIB.getBeanName(), ribInstanceName);
final ServiceRegistration<?> serviceRegistration = this.bundleContext.registerService(
- InstanceType.RIB.getServices(), ribImpl, properties);
+ InstanceType.RIB.getServices(), ribImpl, properties);
ribImpl.setServiceRegistration(serviceRegistration);
}
private synchronized void initiateRibInstance(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
- final RibImpl ribImpl, final WriteConfiguration configurationWriter) {
+ final RibImpl ribImpl) {
final String ribInstanceName = getRibInstanceName(rootIdentifier);
- ribImpl.start(global, ribInstanceName, this.tableTypeRegistry, configurationWriter);
+ ribImpl.start(global, ribInstanceName, this.tableTypeRegistry);
registerRibInstance(ribImpl, ribInstanceName);
}
private synchronized void onNeighborsChanged(final DataObjectModification<Neighbors> dataObjectModification,
- final InstanceIdentifier<Bgp> rootIdentifier) {
+ final InstanceIdentifier<Bgp> rootIdentifier) {
for (final DataObjectModification<? extends DataObject> neighborModification : dataObjectModification.getModifiedChildren()) {
switch (neighborModification.getModificationType()) {
- case DELETE:
- onNeighborRemoved(rootIdentifier, (Neighbor) neighborModification.getDataBefore());
- break;
- case SUBTREE_MODIFIED:
- case WRITE:
- onNeighborModified(rootIdentifier, (Neighbor) neighborModification.getDataAfter(), null);
- break;
- default:
- break;
+ case DELETE:
+ onNeighborRemoved(rootIdentifier, (Neighbor) neighborModification.getDataBefore());
+ break;
+ case SUBTREE_MODIFIED:
+ case WRITE:
+ onNeighborModified(rootIdentifier, (Neighbor) neighborModification.getDataAfter());
+ break;
+ default:
+ break;
}
}
}
- @Override
- public synchronized void onNeighborModified(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor,
- final WriteConfiguration configurationWriter) {
+ @VisibleForTesting
+ synchronized void onNeighborModified(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
//restart peer instance with a new configuration
final PeerBean bgpPeer = this.peers.get(getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey()));
if (bgpPeer == null) {
- onNeighborCreated(rootIdentifier, neighbor, configurationWriter);
- } else if(!bgpPeer.containsEqualConfiguration(neighbor)){
- onNeighborUpdated(bgpPeer, rootIdentifier, neighbor, configurationWriter);
+ onNeighborCreated(rootIdentifier, neighbor);
+ } else if (!bgpPeer.containsEqualConfiguration(neighbor)) {
+ onNeighborUpdated(bgpPeer, rootIdentifier, neighbor);
}
}
- private synchronized void onNeighborCreated(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor,
- final WriteConfiguration configurationWriter) {
+ private synchronized void onNeighborCreated(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
LOG.debug("Creating Peer instance with configuration: {}", neighbor);
final PeerBean bgpPeer;
if (OpenConfigMappingUtil.isApplicationPeer(neighbor)) {
} else {
bgpPeer = (PeerBean) this.container.getComponentInstance(InstanceType.PEER.getBeanName());
}
- final InstanceIdentifier<Neighbor> neighborInstanceIdentifier = getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey());
- initiatePeerInstance(rootIdentifier, neighborInstanceIdentifier, neighbor, bgpPeer, configurationWriter);
+ final InstanceIdentifier<Neighbor> neighborInstanceIdentifier =
+ getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey());
+ initiatePeerInstance(rootIdentifier, neighborInstanceIdentifier, neighbor, bgpPeer);
this.peers.put(neighborInstanceIdentifier, bgpPeer);
LOG.debug("Peer instance created {}", bgpPeer);
}
- private synchronized void onNeighborUpdated(final PeerBean bgpPeer, final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor,
- final WriteConfiguration configurationWriter) {
+ private synchronized void onNeighborUpdated(final PeerBean bgpPeer, final InstanceIdentifier<Bgp> rootIdentifier,
+ final Neighbor neighbor) {
LOG.debug("Updating Peer instance with configuration: {}", neighbor);
bgpPeer.close();
- final InstanceIdentifier<Neighbor> neighborInstanceIdentifier = getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey());
- initiatePeerInstance(rootIdentifier, neighborInstanceIdentifier, neighbor, bgpPeer, configurationWriter);
+ final InstanceIdentifier<Neighbor> neighborInstanceIdentifier =
+ getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey());
+ initiatePeerInstance(rootIdentifier, neighborInstanceIdentifier, neighbor, bgpPeer);
LOG.debug("Peer instance updated {}", bgpPeer);
}
- @Override
- public synchronized void onNeighborRemoved(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
+ @VisibleForTesting
+ synchronized void onNeighborRemoved(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
LOG.debug("Removing Peer instance: {}", rootIdentifier);
final PeerBean bgpPeer = this.peers.remove(getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey()));
if (bgpPeer != null) {
final Dictionary<String, String> properties = new Hashtable<>();
properties.put(InstanceType.PEER.getBeanName(), peerInstanceName);
final ServiceRegistration<?> serviceRegistration = this.bundleContext
- .registerService(InstanceType.PEER.getServices(), bgpPeer, properties);
+ .registerService(InstanceType.PEER.getServices(), bgpPeer, properties);
bgpPeer.setServiceRegistration(serviceRegistration);
}
final Dictionary<String, String> properties = new Hashtable<>();
properties.put(InstanceType.PEER.getBeanName(), peerInstanceName);
final ServiceRegistration<?> serviceRegistration = this.bundleContext
- .registerService(InstanceType.APP_PEER.getServices(), appPeer, properties);
+ .registerService(InstanceType.APP_PEER.getServices(), appPeer, properties);
appPeer.setServiceRegistration(serviceRegistration);
}
private synchronized void initiatePeerInstance(final InstanceIdentifier<Bgp> rootIdentifier,
- final InstanceIdentifier<Neighbor> neighborIdentifier, final Neighbor neighbor,
- final PeerBean bgpPeer, final WriteConfiguration configurationWriter) {
+ final InstanceIdentifier<Neighbor> neighborIdentifier, final Neighbor neighbor,
+ final PeerBean bgpPeer) {
final String peerInstanceName = getNeighborInstanceName(neighborIdentifier);
final RibImpl rib = this.ribs.get(rootIdentifier);
if (rib != null) {
- bgpPeer.start(rib, neighbor, this.tableTypeRegistry, configurationWriter);
+ bgpPeer.start(rib, neighbor, this.tableTypeRegistry);
if (bgpPeer instanceof BgpPeer) {
registerPeerInstance((BgpPeer) bgpPeer, peerInstanceName);
- } else if(bgpPeer instanceof AppPeer) {
+ } else if (bgpPeer instanceof AppPeer) {
registerAppPeerInstance((AppPeer) bgpPeer, peerInstanceName);
}
}
}
- @Override
- public BGPTableTypeRegistryConsumer getTableTypeRegistry() {
+ @VisibleForTesting
+ BGPTableTypeRegistryConsumer getTableTypeRegistry() {
return this.tableTypeRegistry;
}
-
- @Override
- public <T extends DataObject> ListenableFuture<Void> writeConfiguration(final T data,
- final InstanceIdentifier<T> identifier) {
- final WriteTransaction wTx = this.dataBroker.newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.CONFIGURATION, identifier, data, true);
- return wTx.submit();
- }
-
- @Override
- public <T extends DataObject> ListenableFuture<Void> removeConfiguration(
- final InstanceIdentifier<T> identifier) {
- final WriteTransaction wTx = this.dataBroker.newWriteOnlyTransaction();
- wTx.delete(LogicalDatastoreType.CONFIGURATION, identifier);
- return wTx.submit();
- }
}
import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer.WriteConfiguration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
this.rpcRegistry = rpcRegistry;
}
+ private static List<BgpParameters> getBgpParameters(final Neighbor neighbor, final RIB rib,
+ final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ final List<BgpParameters> tlvs = new ArrayList<>();
+ final List<OptionalCapabilities> caps = new ArrayList<>();
+ caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(
+ new As4BytesCapabilityBuilder().setAsNumber(rib.getLocalAs()).build()).build()).build());
+
+ caps.add(new OptionalCapabilitiesBuilder()
+ .setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
+ caps.add(new OptionalCapabilitiesBuilder()
+ .setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
+
+ final List<AfiSafi> afiSafi = OpenConfigMappingUtil
+ .getAfiSafiWithDefault(neighbor.getAfiSafis(), false);
+ final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil
+ .toAddPathCapability(afiSafi, tableTypeRegistry);
+ if (!addPathCapability.isEmpty()) {
+ caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder()
+ .addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder().setAddressFamilies(addPathCapability)
+ .build()).build()).build()).build());
+ }
+
+ final List<BgpTableType> tableTypes = OpenConfigMappingUtil.toTableTypes(afiSafi, tableTypeRegistry);
+ for (final BgpTableType tableType : tableTypes) {
+ if (!rib.getLocalTables().contains(tableType)) {
+ LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.",
+ tableType);
+ }
+
+ caps.add(new OptionalCapabilitiesBuilder().setCParameters(
+ new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder(tableType).build()).build()).build()).build());
+ }
+ tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(caps).build());
+ return tlvs;
+ }
+
+ private static Optional<byte[]> getPassword(final KeyMapping key) {
+ if (key != null) {
+ return Optional.of(Iterables.getOnlyElement(key.values()));
+ }
+ return Optional.absent();
+ }
+
@Override
- public synchronized void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final WriteConfiguration configurationWriter) {
- Preconditions.checkState(this.bgpPeerSingletonService == null, "Previous peer instance was not closed.");
- this.bgpPeerSingletonService = new BgpPeerSingletonService(rib, neighbor, tableTypeRegistry, configurationWriter);
+ public synchronized void start(final RIB rib, final Neighbor neighbor,
+ final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ Preconditions.checkState(this.bgpPeerSingletonService == null,
+ "Previous peer instance was not closed.");
+ this.bgpPeerSingletonService = new BgpPeerSingletonService(rib, neighbor, tableTypeRegistry);
this.currentConfiguration = neighbor;
}
@Override
public synchronized void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
Preconditions.checkState(this.currentConfiguration != null);
- start(rib, this.currentConfiguration, tableTypeRegistry, null);
+ start(rib, this.currentConfiguration, tableTypeRegistry);
}
@Override
&& Objects.equals(this.currentConfiguration.getTransport(), neighbor.getTransport());
}
- private static List<BgpParameters> getBgpParameters(final Neighbor neighbor, final RIB rib,
- final BGPTableTypeRegistryConsumer tableTypeRegistry) {
- final List<BgpParameters> tlvs = new ArrayList<>();
- final List<OptionalCapabilities> caps = new ArrayList<>();
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(
- new As4BytesCapabilityBuilder().setAsNumber(rib.getLocalAs()).build()).build()).build());
-
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
-
- final List<AfiSafi> afiSafi = OpenConfigMappingUtil.getAfiSafiWithDefault(neighbor.getAfiSafis(), false);
- final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil.toAddPathCapability(afiSafi, tableTypeRegistry);
- if (!addPathCapability.isEmpty()) {
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class,
- new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(addPathCapability).build()).build()).build()).build());
- }
-
- final List<BgpTableType> tableTypes = OpenConfigMappingUtil.toTableTypes(afiSafi, tableTypeRegistry);
- for (final BgpTableType tableType : tableTypes) {
- if (!rib.getLocalTables().contains(tableType)) {
- LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", tableType);
- }
-
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(
- new CParametersBuilder().addAugmentation(CParameters1.class,
- new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder(tableType).build()).build()).build()).build());
- }
- tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(caps).build());
- return tlvs;
- }
-
- private static Optional<byte[]> getPassword(final KeyMapping key) {
- if (key != null) {
- return Optional.of(Iterables.getOnlyElement(key.values()));
- }
- return Optional.absent();
- }
-
@Override
public BGPPeerState getPeerState() {
if (this.bgpPeerSingletonService == null) {
private final InetSocketAddress inetAddress;
private final int retryTimer;
private final KeyMapping keys;
- private final WriteConfiguration configurationWriter;
- private ClusterSingletonServiceRegistration registration;
private final BGPPeer bgpPeer;
private final IpAddress neighborAddress;
private final BGPSessionPreferences prefs;
+ private ClusterSingletonServiceRegistration registration;
private Future<Void> connection;
@GuardedBy("this")
private boolean isServiceInstantiated;
private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor,
- final BGPTableTypeRegistryConsumer tableTypeRegistry, final WriteConfiguration configurationWriter) {
+ final BGPTableTypeRegistryConsumer tableTypeRegistry) {
this.neighborAddress = neighbor.getNeighborAddress();
final AfiSafis afisSAfis = requireNonNull(neighbor.getAfiSafis());
final Set<TablesKey> afiSafisAdvertized = OpenConfigMappingUtil
.toTableKey(afisSAfis.getAfiSafi(), tableTypeRegistry);
this.bgpPeer = new BGPPeer(Ipv4Util.toStringIP(this.neighborAddress), rib,
- OpenConfigMappingUtil.toPeerRole(neighbor), getSimpleRoutingPolicy(neighbor), BgpPeer.this.rpcRegistry,
- afiSafisAdvertized, Collections.emptySet());
+ OpenConfigMappingUtil.toPeerRole(neighbor), getSimpleRoutingPolicy(neighbor),
+ BgpPeer.this.rpcRegistry, afiSafisAdvertized, Collections.emptySet());
final List<BgpParameters> bgpParameters = getBgpParameters(neighbor, rib, tableTypeRegistry);
final KeyMapping keyMapping = OpenConfigMappingUtil.getNeighborKey(neighbor);
this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(),
this.inetAddress = Ipv4Util.toInetSocketAddress(this.neighborAddress, OpenConfigMappingUtil.getPort(neighbor));
this.retryTimer = OpenConfigMappingUtil.getRetryTimer(neighbor);
this.keys = keyMapping;
- this.configurationWriter = configurationWriter;
this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier.getValue());
//this need to be always the last step
@Override
public synchronized void instantiateServiceInstance() {
this.isServiceInstantiated = true;
- if (this.configurationWriter != null) {
- this.configurationWriter.apply();
- }
- LOG.info("Peer Singleton Service {} instantiated, Peer {}", getIdentifier().getValue(), this.neighborAddress);
+ LOG.info("Peer Singleton Service {} instantiated, Peer {}", getIdentifier().getValue(),
+ this.neighborAddress);
this.bgpPeer.instantiateServiceInstance();
this.dispatcher.getBGPPeerRegistry().addPeer(this.neighborAddress, this.bgpPeer, this.prefs);
if (this.activeConnection) {
- this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, this.retryTimer, this.keys);
+ this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, this.retryTimer,
+ this.keys);
}
}
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer.WriteConfiguration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
/**
* Common interface for BgpPeer and AppPeer beans
- *
*/
public interface PeerBean extends AutoCloseable {
- void start(RIB rib, Neighbor neighbor, BGPTableTypeRegistryConsumer tableTypeRegistry, WriteConfiguration configurationWriter);
+ void start(RIB rib, Neighbor neighbor, BGPTableTypeRegistryConsumer tableTypeRegistry);
void restart(RIB rib, BGPTableTypeRegistryConsumer tableTypeRegistry);
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
this.domSchemaService = domSchemaService;
}
- void start(final Global global, final String instanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final BgpDeployer.WriteConfiguration configurationWriter) {
+ void start(final Global global, final String instanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
Preconditions.checkState(this.ribImpl == null,
"Previous instance %s was not closed.", this);
- this.ribImpl = createRib(global, instanceName, tableTypeRegistry, configurationWriter);
+ this.ribImpl = createRib(global, instanceName, tableTypeRegistry);
this.schemaContextRegistration = this.domSchemaService.registerSchemaContextListener(this.ribImpl);
}
private RIBImpl createRib(
final Global global,
final String bgpInstanceName,
- final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final BgpDeployer.WriteConfiguration configurationWriter) {
+ final BGPTableTypeRegistryConsumer tableTypeRegistry) {
this.afiSafi = getAfiSafiWithDefault(global.getAfiSafis(), true);
final Config globalConfig = global.getConfig();
this.asNumber = globalConfig.getAs();
this.domBroker,
toTableTypes(this.afiSafi, tableTypeRegistry),
pathSelectionModes,
- this.extensions.getClassLoadingStrategy(),
- configurationWriter);
+ this.extensions.getClassLoadingStrategy());
}
@Override
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.rib.impl.spi;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * The BgpDeployer service is managing RIB, Peer, Application Peer instances based on the OpenConfig BGP
- * configuration status.
- * BGP configuration is held under the specific OpenConfig's NetworkInstance subtree.
- */
-public interface BgpDeployer {
-
- interface WriteConfiguration {
- void apply();
- }
-
- /**
- * Get pointer to NetworkInstance instance where this particular BGP deployer is binded.
- *
- * @return InstanceIdentifier
- */
- InstanceIdentifier<NetworkInstance> getInstanceIdentifier();
-
- BGPTableTypeRegistryConsumer getTableTypeRegistry();
-
- <T extends DataObject> ListenableFuture<Void> writeConfiguration(T data, InstanceIdentifier<T> identifier);
-
- <T extends DataObject> ListenableFuture<Void> removeConfiguration(InstanceIdentifier<T> identifier);
-
- /**
- * Create, start and register rib instance
- * @param rootIdentifier
- * @param global
- * @param configurationWriter
- */
- void onGlobalModified(InstanceIdentifier<Bgp> rootIdentifier, Global global, WriteConfiguration configurationWriter);
-
- /**
- * Destroy rib instance
- * @param rootIdentifier
- */
- void onGlobalRemoved(InstanceIdentifier<Bgp> rootIdentifier);
-
- /**
- * Create, start and register peer instance
- * @param rootIdentifier
- * @param neighbor
- */
- void onNeighborModified(InstanceIdentifier<Bgp> rootIdentifier, Neighbor neighbor, WriteConfiguration configurationWriter);
-
- /**
- * Destroy peer instance
- * @param rootIdentifier
- * @param neighbor
- */
- void onNeighborRemoved(InstanceIdentifier<Bgp> rootIdentifier, Neighbor neighbor);
-}
<argument ref="bgpTableTypeRegistry"/>
</bean>
- <service ref="bgpDeployer" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer"/>
-
<bean id="ribImpl" class="org.opendaylight.protocol.bgp.rib.impl.config.RibImpl" scope="prototype">
<argument ref="clusterSingletonServiceProvider"/>
<argument ref="globalBgpExtensions"/>
public class AbstractRIBTestSetup {
- private RIBImpl rib;
- private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("128.0.0.1");
- private static final BgpId RIB_ID = new BgpId("127.0.0.1");
protected static final Class<? extends AddressFamily> AFI = Ipv4AddressFamily.class;
protected static final Class<? extends SubsequentAddressFamily> SAFI = UnicastSubsequentAddressFamily.class;
- protected static final QName AFI_QNAME = BindingReflections.findQName(AFI).intern();
- protected static final QName SAFI_QNAME = BindingReflections.findQName(SAFI).intern();
protected static final TablesKey KEY = new TablesKey(AFI, SAFI);
+ protected static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, "prefix").intern();
+ private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("128.0.0.1");
+ private static final BgpId RIB_ID = new BgpId("127.0.0.1");
+ private RIBImpl rib;
private BindingCodecTreeFactory codecFactory;
private RIBActivator a1;
private RIBSupport ribSupport;
- protected static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, "prefix").intern();
-
@Mock
private BGPDispatcher dispatcher;
private DOMDataWriteTransaction domTransWrite;
@Mock
- private CheckedFuture<?,?> future;
+ private CheckedFuture<?, ?> future;
@Mock
private Optional<Rib> o;
@Mock
private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
+ private static ModuleInfoBackedContext createClassLoadingStrategy() {
+ final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
+ try {
+ ctx.registerModuleInfo(BindingReflections.getModuleInfo(Ipv4Route.class));
+ } catch (final RuntimeException e) {
+ throw e;
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ return ctx;
+ }
+
+ private static BindingCodecTreeFactory createCodecFactory(final ClassLoadingStrategy str, final SchemaContext ctx) {
+ final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()));
+ final BindingNormalizedNodeCodecRegistry codec = new BindingNormalizedNodeCodecRegistry(generator);
+ codec.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(str, ctx));
+ return codec;
+ }
+
@Before
public void setUp() throws Exception {
mockRib();
final RIBExtensionProviderContext context = new SimpleRIBExtensionProviderContext();
final ModuleInfoBackedContext strategy = createClassLoadingStrategy();
final SchemaContext schemaContext = strategy.tryToCreateSchemaContext().get();
- this.codecFactory = createCodecFactory(strategy,schemaContext);
+ this.codecFactory = createCodecFactory(strategy, schemaContext);
final List<BgpTableType> localTables = new ArrayList<>();
localTables.add(new BgpTableTypeImpl(AFI, SAFI));
this.a1.startRIBExtensionProvider(context);
mockedMethods();
doReturn(Mockito.mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
- .registerClusterSingletonService(any(ClusterSingletonService.class));
- this.rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test"), new AsNumber(5L), RIB_ID, CLUSTER_ID, context,
- this.dispatcher, this.codecFactory, this.dom, localTables, Collections.singletonMap(new TablesKey(AFI, SAFI),
- BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+ .registerClusterSingletonService(any(ClusterSingletonService.class));
+ this.rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test"),
+ new AsNumber(5L), RIB_ID, CLUSTER_ID, context,
+ this.dispatcher, this.codecFactory, this.dom, localTables,
+ Collections.singletonMap(new TablesKey(AFI, SAFI),
+ BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
this.rib.onGlobalContextUpdated(schemaContext);
this.ribSupport = getRib().getRibSupportContext().getRIBSupportContext(KEY).getRibSupport();
}
- private static ModuleInfoBackedContext createClassLoadingStrategy() {
- final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
- try {
- ctx.registerModuleInfo(BindingReflections.getModuleInfo(Ipv4Route.class));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
- return ctx;
- }
-
- private static BindingCodecTreeFactory createCodecFactory(final ClassLoadingStrategy str, final SchemaContext ctx) {
- final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()));
- final BindingNormalizedNodeCodecRegistry codec = new BindingNormalizedNodeCodecRegistry(generator);
- codec.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(str, ctx));
- return codec;
- }
-
@SuppressWarnings("unchecked")
private void mockedMethods() throws Exception {
MockitoAnnotations.initMocks(this);
return this.rib;
}
- public DOMDataBroker getDOMBroker() {
- return this.dom;
- }
-
public DOMDataWriteTransaction getTransaction() {
return this.domTransWrite;
}
this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
AS_NUMBER, BGP_ID, null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
- getDomBroker(), TABLES_TYPE, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
+ getDomBroker(), TABLES_TYPE, pathTables, this.ribExtension.getClassLoadingStrategy());
this.ribImpl.instantiateServiceInstance();
this.ribImpl.onGlobalContextUpdated(this.schemaContext);
this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
- this.ribExtension.getClassLoadingStrategy(), null);
+ this.ribExtension.getClassLoadingStrategy());
this.ribImpl.instantiateServiceInstance();
this.ribImpl.onGlobalContextUpdated(this.schemaContext);
final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
- this.ribExtension.getClassLoadingStrategy(), null);
+ this.ribExtension.getClassLoadingStrategy());
this.ribImpl.instantiateServiceInstance();
this.ribImpl.onGlobalContextUpdated(this.schemaContext);
AS_NUMBER, new BgpId("127.0.0.1"), null, this.ext2, this.dispatcher,
this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
- GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
rib.instantiateServiceInstance();
assertTablesExists(tables);
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID,
null, this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables,
Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
- GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
rib.instantiateServiceInstance();
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
assertTablesExists(tables);
BasePathSelectionModeFactory.createBestPathSelectionStrategy());
final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER,
new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
- this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy(),
- null);
+ this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy());
ribImpl.instantiateServiceInstance();
ribImpl.onGlobalContextUpdated(this.schemaContext);
BasePathSelectionModeFactory.createBestPathSelectionStrategy());
final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER,
new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
- this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy(),
- null);
+ this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy());
ribImpl.instantiateServiceInstance();
ribImpl.onGlobalContextUpdated(this.schemaContext);
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.LongAdder;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.osgi.framework.ServiceRegistration;
class AbstractConfig {
- static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
protected static final AsNumber AS = new AsNumber(72L);
+ protected static final RibId RIB_ID = new RibId("test");
+ static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
protected ClusterSingletonService singletonService;
@Mock
protected RIB rib;
@Mock
protected BGPTableTypeRegistryConsumer tableTypeRegistry;
@Mock
- protected BgpDeployer.WriteConfiguration configurationWriter;
- @Mock
protected DOMTransactionChain domTx;
@Mock
protected BGPDispatcher dispatcher;
private ImportPolicyPeerTracker importPolicyPeerTracker;
@Mock
private DOMDataTreeChangeService dataTreeChangeService;
- protected static final RibId RIB_ID = new RibId("test");
@Before
public void setUp() throws Exception {
Mockito.doReturn(java.util.Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
Mockito.doReturn(Collections.singleton(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)))
.when(this.rib).getLocalTables();
- Mockito.doNothing().when(this.configurationWriter).apply();
Mockito.doNothing().when(this.bgpPeerRegistry).addPeer(any(IpAddress.class), any(BGPSessionListener.class), any(BGPSessionPreferences.class));
Mockito.doNothing().when(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
public class AppPeerTest extends AbstractConfig {
private static final AppPeer APP_PEER = new AppPeer();
private final Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().addAugmentation(Config2.class,
- new Config2Builder().setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME).build()).build())
- .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
+ new Config2Builder().setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME).build()).build())
+ .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
@Override
@Before
@Test
public void testAppPeer() throws Exception {
- APP_PEER.start(this.rib, this.neighbor, this.tableTypeRegistry, this.configurationWriter);
+ APP_PEER.start(this.rib, this.neighbor, this.tableTypeRegistry);
Mockito.verify(this.rib).getYangRibId();
Mockito.verify(this.rib).getService();
Mockito.verify(this.rib).getRibIServiceGroupIdentifier();
this.singletonService.instantiateServiceInstance();
Mockito.verify(this.rib, times(2)).getYangRibId();
- Mockito.verify(this.configurationWriter).apply();
Mockito.verify(this.rib).getRibSupportContext();
Mockito.verify(this.rib, times(2)).getLocalTablesKeys();
Mockito.verify(this.domTx).newWriteOnlyTransaction();
Mockito.verify(this.rib, times(4)).getYangRibId();
Mockito.verify(this.rib, times(4)).getService();
Mockito.verify(this.rib, times(2)).getRibIServiceGroupIdentifier();
- Mockito.verify(this.rib, times(2)).registerClusterSingletonService(any(ClusterSingletonService.class));
+ Mockito.verify(this.rib, times(2))
+ .registerClusterSingletonService(any(ClusterSingletonService.class));
Mockito.verify(this.listener, times(2)).close();
assertTrue(APP_PEER.containsEqualConfiguration(this.neighbor));
assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder()
- .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
+ .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
APP_PEER.close();
Mockito.verify(this.singletonServiceRegistration, times(2)).close();
}
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
verify(spyDeployer).onDataTreeChanged(any(Collection.class));
- verify(spyDeployer).onGlobalModified(any(InstanceIdentifier.class), any(), any());
- verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class), any(BgpDeployer.WriteConfiguration.class));
- verifyPrivate(spyDeployer).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any(BgpDeployer
- .WriteConfiguration.class));
+ verify(spyDeployer).onGlobalModified(any(InstanceIdentifier.class), any());
+ verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class));
+ verifyPrivate(spyDeployer).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verifyPrivate(spyDeployer).invoke("registerRibInstance", any(RibImpl.class), anyString());
verify(spyDeployer).onDataTreeChanged(any(Collection.class));
verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
- verify(spyDeployer, times(2)).onGlobalModified(any(InstanceIdentifier.class), any(), any());
- verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class), any(BgpDeployer
- .WriteConfiguration.class));
- verifyPrivate(spyDeployer).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any(BgpDeployer
- .WriteConfiguration.class));
+ verify(spyDeployer, times(2)).onGlobalModified(any(InstanceIdentifier.class), any());
+ verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class));
+ verifyPrivate(spyDeployer).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verifyPrivate(spyDeployer).invoke("registerRibInstance", any(RibImpl.class), anyString());
verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
verify(this.bundleContext, times(2)).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
- verify(spyDeployer, times(3)).onGlobalModified(any(InstanceIdentifier.class), any(), any());
- verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class),
- any(BgpDeployer.WriteConfiguration.class));
- verifyPrivate(spyDeployer).invoke("onGlobalUpdated", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any(BgpDeployer.WriteConfiguration.class));
+ verify(spyDeployer, times(3)).onGlobalModified(any(InstanceIdentifier.class), any());
+ verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class));
+ verifyPrivate(spyDeployer).invoke("onGlobalUpdated", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verify(this.dataTreeRegistration).close();
verify(this.registration).unregister();
verifyPrivate(spyDeployer).invoke("closeAllBindedPeers", any(InstanceIdentifier.class));
- verifyPrivate(spyDeployer, times(2)).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any
- (BgpDeployer.WriteConfiguration.class));
+ verifyPrivate(spyDeployer, times(2)).invoke("initiateRibInstance",
+ any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verifyPrivate(spyDeployer, times(2)).invoke("registerRibInstance", any(RibImpl.class), anyString());
verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
verify(this.bundleContext, times(2)).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
- verify(spyDeployer, times(3)).onGlobalModified(any(InstanceIdentifier.class), any(), any());
+ verify(spyDeployer, times(3)).onGlobalModified(any(InstanceIdentifier.class), any());
verify(spyDeployer).onGlobalRemoved(any(InstanceIdentifier.class));
verify(this.dataTreeRegistration, times(2)).close();
verify(this.registration, times(2)).unregister();
- verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class),
- any(BgpDeployer.WriteConfiguration.class));
- verifyPrivate(spyDeployer).invoke("onGlobalUpdated", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any(BgpDeployer.WriteConfiguration.class));
+ verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class));
+ verifyPrivate(spyDeployer).invoke("onGlobalUpdated", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verifyPrivate(spyDeployer, times(2)).invoke("closeAllBindedPeers", any(InstanceIdentifier.class));
- verifyPrivate(spyDeployer, times(2)).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any
- (BgpDeployer.WriteConfiguration.class));
+ verifyPrivate(spyDeployer, times(2)).invoke("initiateRibInstance",
+ any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verifyPrivate(spyDeployer, times(2)).invoke("registerRibInstance", any(RibImpl.class), anyString());
verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
verify(spyDeployer).onDataTreeChanged(any(Collection.class));
- verify(spyDeployer).onGlobalModified(any(InstanceIdentifier.class), any(), any());
- verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class), any(BgpDeployer.WriteConfiguration.class));
- verifyPrivate(spyDeployer).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class), any(BgpDeployer
- .WriteConfiguration.class));
+ verify(spyDeployer).onGlobalModified(any(InstanceIdentifier.class), any());
+ verifyPrivate(spyDeployer).invoke("onGlobalCreated", any(InstanceIdentifier.class), any(Global.class));
+ verifyPrivate(spyDeployer).invoke("initiateRibInstance", any(InstanceIdentifier.class), any(Global.class), any(RibImpl.class));
verifyPrivate(spyDeployer).invoke("registerRibInstance", any(RibImpl.class), anyString());
verify(spyDeployer).onDataTreeChanged(any(Collection.class));
spyDeployer.onDataTreeChanged(this.collection);
verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
verifyPrivate(spyDeployer).invoke("onNeighborsChanged", any(DataObjectModification.class), any(InstanceIdentifier.class));
- verify(spyDeployer).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class), any());
- verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class), any(BgpDeployer.WriteConfiguration.class));
+ verify(spyDeployer).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class));
+ verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class));
verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
verifyPrivate(spyDeployer).invoke("initiatePeerInstance", any(InstanceIdentifier.class), any(InstanceIdentifier.class), any(Neighbor.class),
- any(PeerBean.class), any(BgpDeployer.WriteConfiguration.class));
+ any(PeerBean.class));
verifyPrivate(spyDeployer).invoke("registerPeerInstance", any(BgpPeer.class), anyString());
verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
spyDeployer.onDataTreeChanged(this.collection);
verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
verifyPrivate(spyDeployer, times(2)).invoke("onNeighborsChanged", any(DataObjectModification.class), any(InstanceIdentifier.class));
- verify(spyDeployer, times(2)).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class), any());
- verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class), any(BgpDeployer.WriteConfiguration.class));
+ verify(spyDeployer, times(2)).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class));
+ verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class));
verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
verifyPrivate(spyDeployer).invoke("initiatePeerInstance", any(InstanceIdentifier.class), any(InstanceIdentifier.class), any(Neighbor.class),
- any(PeerBean.class), any(BgpDeployer.WriteConfiguration.class));
+ any(PeerBean.class));
verifyPrivate(spyDeployer).invoke("registerPeerInstance", any(Neighbor.class), anyString());
verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
spyDeployer.onDataTreeChanged(this.collection);
verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
verifyPrivate(spyDeployer, times(3)).invoke("onNeighborsChanged", any(DataObjectModification.class), any(InstanceIdentifier.class));
- verify(spyDeployer, times(3)).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class), any());
- verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class), any(BgpDeployer.WriteConfiguration.class));
+ verify(spyDeployer, times(3)).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class));
+ verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class));
verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
verifyPrivate(spyDeployer, times(2)).invoke("initiatePeerInstance", any(InstanceIdentifier.class), any(InstanceIdentifier.class), any(Neighbor.class),
- any(PeerBean.class), any(BgpDeployer.WriteConfiguration.class));
+ any(PeerBean.class));
verifyPrivate(spyDeployer, times(2)).invoke("registerPeerInstance", any(Neighbor.class), anyString());
verify(this.bundleContext, times(2)).registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
verify(spyDeployer, times(5)).onDataTreeChanged(any(Collection.class));
verify( this.dObject).getDataBefore();
verifyPrivate(spyDeployer, times(4)).invoke("onNeighborsChanged", any(DataObjectModification.class), any(InstanceIdentifier.class));
- verify(spyDeployer, times(3)).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class), any());
+ verify(spyDeployer, times(3)).onNeighborModified(any(InstanceIdentifier.class), any(Neighbor.class));
verify(spyDeployer, times(1)).onNeighborRemoved(any(InstanceIdentifier.class), any(Neighbor.class));
- verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class), any(BgpDeployer.WriteConfiguration.class));
+ verifyPrivate(spyDeployer).invoke("onNeighborCreated", any(InstanceIdentifier.class), any(Neighbor.class));
verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
verifyPrivate(spyDeployer, times(2)).invoke("initiatePeerInstance", any(InstanceIdentifier.class), any(InstanceIdentifier.class), any(Neighbor.class),
- any(PeerBean.class), any(BgpDeployer.WriteConfiguration.class));
+ any(PeerBean.class));
verifyPrivate(spyDeployer, times(2)).invoke("registerPeerInstance", any(Neighbor.class), anyString());
verify(this.bundleContext, times(2)).registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
static final String MD5_PASSWORD = "123";
static final PortNumber PORT = new PortNumber(179);
static final AfiSafi AFI_SAFI_IPV4 = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
- .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(SHORT).build()).build();
+ .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(SHORT).build()).build();
static final List<AfiSafi> AFI_SAFI = Collections.singletonList(AFI_SAFI_IPV4);
private BgpPeer bgpPeer;
+ static Neighbor createNeighborExpected(final IpAddress neighborAddress) {
+ return new NeighborBuilder()
+ .setAfiSafis(createAfiSafi())
+ .setConfig(createConfig())
+ .setNeighborAddress(neighborAddress)
+ .setRouteReflector(createRR())
+ .setTimers(createTimers())
+ .setTransport(createTransport())
+ .setAddPaths(createAddPath())
+ .build();
+ }
+
+ static Transport createTransport() {
+ return new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+ .rev151009.bgp.neighbor.group.transport.ConfigBuilder().setMtuDiscovery(false).setPassiveMode(false)
+ .addAugmentation(Config1.class, new Config1Builder().setRemotePort(PORT).build()).build()).build();
+ }
+
+ static Timers createTimers() {
+ return new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009
+ .bgp.neighbor.group.timers.ConfigBuilder().setHoldTime(DEFAULT_TIMERS)
+ .setMinimumAdvertisementInterval(DEFAULT_TIMERS)
+ .setKeepaliveInterval(DEFAULT_TIMERS).setConnectRetry(DEFAULT_TIMERS).build()).build();
+ }
+
+ static RouteReflector createRR() {
+ return new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+ .rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder()
+ .setRouteReflectorClusterId(RrClusterIdTypeBuilder.getDefaultInstance("127.0.0.1"))
+ .setRouteReflectorClient(false).build()).build();
+ }
+
+ static Config createConfig() {
+ return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
+ .ConfigBuilder().setPeerAs(AS).setPeerType(PeerType.INTERNAL).setAuthPassword(MD5_PASSWORD)
+ .setRouteFlapDamping(false).setSendCommunity(CommunityType.NONE).build();
+ }
+
+ static AfiSafis createAfiSafi() {
+ return new AfiSafisBuilder().setAfiSafi(AFI_SAFI).build();
+ }
+
+ static AddPaths createAddPath() {
+ return new AddPathsBuilder().setConfig(new ConfigBuilder().setReceive(true).setSendMax(SHORT).build()).build();
+ }
+
@Override
@Before
public void setUp() throws Exception {
@Test
public void testBgpPeer() throws Exception {
final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig())
- .setNeighborAddress(NEIGHBOR_ADDRESS).setRouteReflector(createRR()).setTimers(createTimers())
- .setTransport(createTransport()).setAddPaths(createAddPath()).build();
+ .setNeighborAddress(NEIGHBOR_ADDRESS).setRouteReflector(createRR()).setTimers(createTimers())
+ .setTransport(createTransport()).setAddPaths(createAddPath()).build();
- this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry, this.configurationWriter);
+ this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry);
Mockito.verify(this.rib).createPeerChain(any());
Mockito.verify(this.rib, times(2)).getLocalAs();
Mockito.verify(this.rib).getLocalTables();
Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
this.singletonService.instantiateServiceInstance();
- Mockito.verify(this.configurationWriter).apply();
Mockito.verify(this.bgpPeerRegistry).addPeer(any(), any(), any());
Mockito.verify(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class),
- anyInt(), any(KeyMapping.class));
+ anyInt(), any(KeyMapping.class));
try {
- this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry, this.configurationWriter);
+ this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry);
fail("Expected Exception");
} catch (final IllegalStateException expected) {
assertEquals("Previous peer instance was not closed.", expected.getMessage());
Mockito.verify(this.future, times(2)).cancel(true);
final Neighbor neighborDiffConfig = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS)
- .setAfiSafis(createAfiSafi()).build();
- this.bgpPeer.start(this.rib, neighborDiffConfig, this.tableTypeRegistry, this.configurationWriter);
+ .setAfiSafis(createAfiSafi()).build();
+ this.bgpPeer.start(this.rib, neighborDiffConfig, this.tableTypeRegistry);
assertTrue(this.bgpPeer.containsEqualConfiguration(neighborDiffConfig));
this.bgpPeer.close();
}
-
- static Neighbor createNeighborExpected(final IpAddress neighborAddress) {
- return new NeighborBuilder()
- .setAfiSafis(createAfiSafi())
- .setConfig(createConfig())
- .setNeighborAddress(neighborAddress)
- .setRouteReflector(createRR())
- .setTimers(createTimers())
- .setTransport(createTransport())
- .setAddPaths(createAddPath())
- .build();
- }
-
- static Transport createTransport() {
- return new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor
- .group.transport.ConfigBuilder().setMtuDiscovery(false).setPassiveMode(false).addAugmentation(Config1.class, new Config1Builder()
- .setRemotePort(PORT).build()).build()).build();
- }
-
- static Timers createTimers() {
- return new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
- .timers.ConfigBuilder().setHoldTime(DEFAULT_TIMERS).setMinimumAdvertisementInterval(DEFAULT_TIMERS)
- .setKeepaliveInterval(DEFAULT_TIMERS).setConnectRetry(DEFAULT_TIMERS).build()).build();
- }
-
- static RouteReflector createRR() {
- return new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
- .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClusterId(RrClusterIdTypeBuilder.getDefaultInstance("127.0.0.1"))
- .setRouteReflectorClient(false).build()).build();
- }
-
- static Config createConfig() {
- return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder().setPeerAs(AS)
- .setPeerType(PeerType.INTERNAL).setAuthPassword(MD5_PASSWORD).setRouteFlapDamping(false).setSendCommunity(CommunityType.NONE).build();
- }
-
- static AfiSafis createAfiSafi() {
- return new AfiSafisBuilder().setAfiSafi(AFI_SAFI).build();
- }
-
- static AddPaths createAddPath() {
- return new AddPathsBuilder().setConfig(new ConfigBuilder().setReceive(true).setSendMax(SHORT).build()).build();
- }
}
\ No newline at end of file
public class RibImplTest extends AbstractConfig {
private static final List<AfiSafi> AFISAFIS = new ArrayList<>();
private static final Long ALL_PATHS = 0L;
- private static final BgpTableType TABLE_TYPE = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ private static final BgpTableType TABLE_TYPE =
+ new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
private static final Ipv4Address BGP_ID = new BgpId(new Ipv4Address("127.0.0.1"));
static {
AFISAFIS.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
- .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+ .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true)
+ .setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
}
@Mock
@Mock
private ServiceRegistration<?> serviceRegistration;
+ private static Global createGlobal() {
+ return new GlobalBuilder()
+ .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS).build())
+ .setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base
+ .ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build()).build();
+ }
+
@Override
@Before
public void setUp() throws Exception {
Mockito.doAnswer(invocationOnMock -> {
RibImplTest.this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
return RibImplTest.this.singletonServiceRegistration;
- }).when(this.clusterSingletonServiceProvider).registerClusterSingletonService(any(ClusterSingletonService.class));
+ }).when(this.clusterSingletonServiceProvider)
+ .registerClusterSingletonService(any(ClusterSingletonService.class));
Mockito.doReturn(mock(GeneratedClassLoadingStrategy.class)).when(this.extension).getClassLoadingStrategy();
Mockito.doReturn(this.ribSupport).when(this.extension).getRIBSupport(any(TablesKey.class));
Mockito.doReturn(this.domTx).when(this.domDataBroker).createTransactionChain(any());
final DOMDataTreeChangeService dOMDataTreeChangeService = mock(DOMDataTreeChangeService.class);
Mockito.doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, dOMDataTreeChangeService))
- .when(this.domDataBroker).getSupportedExtensions();
+ .when(this.domDataBroker).getSupportedExtensions();
Mockito.doReturn(this.dataTreeRegistration).when(this.domSchemaService).registerSchemaContextListener(any());
Mockito.doNothing().when(this.dataTreeRegistration).close();
- Mockito.doReturn(mock(ListenerRegistration.class)).when(dOMDataTreeChangeService).registerDataTreeChangeListener(any(), any());
+ Mockito.doReturn(mock(ListenerRegistration.class)).when(dOMDataTreeChangeService)
+ .registerDataTreeChangeListener(any(), any());
Mockito.doNothing().when(this.serviceRegistration).unregister();
}
@Test
public void testRibImpl() throws Exception {
final RibImpl ribImpl = new RibImpl(this.clusterSingletonServiceProvider, this.extension, this.dispatcher,
- this.bindingCodecTreeFactory, this.domDataBroker, this.domSchemaService);
+ this.bindingCodecTreeFactory, this.domDataBroker, this.domSchemaService);
ribImpl.setServiceRegistration(this.serviceRegistration);
- ribImpl.start(createGlobal(), "rib-test", this.tableTypeRegistry, this.configurationWriter);
+ ribImpl.start(createGlobal(), "rib-test", this.tableTypeRegistry);
verify(this.extension).getClassLoadingStrategy();
verify(this.domDataBroker).getSupportedExtensions();
verify(this.clusterSingletonServiceProvider).registerClusterSingletonService(any());
verify(this.domSchemaService).registerSchemaContextListener(any(RIBImpl.class));
this.singletonService.instantiateServiceInstance();
- Mockito.verify(this.configurationWriter).apply();
assertEquals("RIBImpl{}", ribImpl.toString());
assertEquals(ServiceGroupIdentifier.create("rib-test-service-group"), ribImpl.getRibIServiceGroupIdentifier());
- assertEquals(Collections.singleton(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)), ribImpl.getLocalTablesKeys());
+ assertEquals(Collections.singleton(new TablesKey(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class)), ribImpl.getLocalTablesKeys());
assertNotNull(ribImpl.getImportPolicyPeerTracker());
assertNotNull(ribImpl.getService());
assertNotNull(ribImpl.getInstanceIdentifier());
verify(this.dataTreeRegistration).close();
verify(this.serviceRegistration).unregister();
}
-
- private static Global createGlobal() {
- return new GlobalBuilder()
- .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS).build())
- .setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base
- .ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build()).build();
- }
}
\ No newline at end of file
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Function;
import org.opendaylight.bgpcep.bgp.topology.provider.AbstractTopologyBuilder;
import org.opendaylight.bgpcep.bgp.topology.provider.spi.BgpTopologyDeployer;
import org.opendaylight.bgpcep.bgp.topology.provider.spi.BgpTopologyProvider;
}
@Override
- public final void onTopologyBuilderCreated(final Topology topology, final Function<Topology, Void> writeFunction) {
+ public final void onTopologyBuilderCreated(final Topology topology) {
LOG.debug("Cretaing topology builder instance {}", topology);
final TopologyReferenceSingletonService currentInstance = this.topologyBuilders.get(topology.getTopologyId());
if (currentInstance == null || !currentInstance.getConfiguration().equals(topology)) {
- final TopologyReferenceSingletonService topologyBuilder = createInstance(topology, writeFunction);
+ final TopologyReferenceSingletonService topologyBuilder = createInstance(topology);
this.topologyBuilders.put(topology.getTopologyId(), topologyBuilder);
LOG.debug("Topology builder instance created {}", topologyBuilder);
}
return aug != null && topologyTypeFilter(aug);
}
- private TopologyReferenceSingletonService createInstance(final Topology topology, final Function<Topology, Void> writeFunction) {
- final RibReference ribReference = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(topology.getAugmentation(Topology1.class).getRibId())));
- final AbstractTopologyBuilder<?> topologyBuilder = createTopologyBuilder(this.dataBroker, ribReference, topology.getTopologyId());
- return new TopologyReferenceSingletonServiceImpl(topologyBuilder, this.deployer, topology, writeFunction);
+ private TopologyReferenceSingletonService createInstance(final Topology topology) {
+ final RibReference ribReference = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class)
+ .child(Rib.class, new RibKey(topology.getAugmentation(Topology1.class).getRibId())));
+ final AbstractTopologyBuilder<?> topologyBuilder = createTopologyBuilder(this.dataBroker,
+ ribReference, topology.getTopologyId());
+ return new TopologyReferenceSingletonServiceImpl(topologyBuilder, this.deployer, topology);
}
- abstract AbstractTopologyBuilder<?> createTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
- final TopologyId topologyId);
+ abstract AbstractTopologyBuilder<?> createTopologyBuilder(final DataBroker dataProvider,
+ final RibReference locRibReference, final TopologyId topologyId);
abstract boolean topologyTypeFilter(TopologyTypes1 topology);
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.bgpcep.bgp.topology.provider.config;
-
-import com.google.common.reflect.AbstractInvocationHandler;
-import com.google.common.reflect.Reflection;
-import java.lang.reflect.Method;
-import org.opendaylight.bgpcep.bgp.topology.provider.spi.BgpTopologyDeployer;
-import org.opendaylight.bgpcep.bgp.topology.provider.spi.TopologyReferenceSingletonService;
-import org.opendaylight.bgpcep.topology.TopologyReference;
-import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.config.rev160726.Topology1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.config.rev160726.Topology1Builder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.osgi.framework.BundleContext;
-
-public final class BackwardsCssTopologyProvider {
-
- private BackwardsCssTopologyProvider() {
- throw new UnsupportedOperationException();
- }
-
- public static TopologyReferenceSingletonService createBackwardsCssInstance(final TopologyTypes topologyTypes, final TopologyId topologyId, final BundleContext bundleContext,
- final KeyedInstanceIdentifier<Rib, RibKey> ribIId) {
- //map configuration to topology
- final Topology topology = createConfiguration(topologyTypes, topologyId, ribIId.getKey().getId());
- //create instance
- final WaitingServiceTracker<BgpTopologyDeployer> deployerTracker = WaitingServiceTracker.create(BgpTopologyDeployer.class, bundleContext);
- final BgpTopologyDeployer topologyDeployer = deployerTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
- topologyDeployer.createInstance(topology);
- //get topology service, use filter
- final WaitingServiceTracker<TopologyReference> topologyTracker = WaitingServiceTracker.create(TopologyReference.class,
- bundleContext, "(" + "topology-id" + "=" + topology.getTopologyId().getValue() + ")");
- final TopologyReference topologyService = topologyTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
- return Reflection.newProxy(TopologyReferenceSingletonService.class, new AbstractInvocationHandler() {
- @Override
- protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
- if (method.getName().equals("close")) {
- topologyDeployer.removeInstance(topology);
- deployerTracker.close();
- topologyTracker.close();
- return null;
- }
-
- return method.invoke(topologyService, args);
- }
- });
- }
-
- private static Topology createConfiguration(final TopologyTypes topologyTypes, final TopologyId topologyId, final RibId ribId) {
- final TopologyBuilder topologyBuilder = new TopologyBuilder();
- topologyBuilder.setTopologyId(topologyId);
- topologyBuilder.setKey(new TopologyKey(topologyBuilder.getTopologyId()));
- topologyBuilder.setTopologyTypes(topologyTypes);
- topologyBuilder.addAugmentation(Topology1.class, new Topology1Builder().setRibId(ribId).build());
- return topologyBuilder.build();
- }
-
-}
\ No newline at end of file
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
-import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.bgpcep.bgp.topology.provider.spi.BgpTopologyDeployer;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.protocol.bgp.rib.spi.util.ClusterSingletonServiceRegistrationHelper;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yangtools.concepts.AbstractRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class BgpTopologyDeployerImpl implements AutoCloseable, ClusteredDataTreeChangeListener<Topology>, BgpTopologyDeployer {
+public final class BgpTopologyDeployerImpl implements BgpTopologyDeployer, AutoCloseable,
+ ClusteredDataTreeChangeListener<Topology> {
private static final Logger LOG = LoggerFactory.getLogger(BgpTopologyDeployerImpl.class);
- private static final InstanceIdentifier<Topology> TOPOLOGY_IID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class);
+ private static final InstanceIdentifier<Topology> TOPOLOGY_IID =
+ InstanceIdentifier.create(NetworkTopology.class).child(Topology.class);
@GuardedBy("this")
private final Set<BgpTopologyProvider> topologyProviders = new HashSet<>();
private final DataBroker dataBroker;
- private final ListenerRegistration<BgpTopologyDeployerImpl> registration;
private final BundleContext context;
private final ClusterSingletonServiceProvider singletonProvider;
+ private ListenerRegistration<BgpTopologyDeployerImpl> registration;
@GuardedBy("this")
private boolean closed;
- public BgpTopologyDeployerImpl(final BundleContext context, final DataBroker dataBroker, final ClusterSingletonServiceProvider singletonProvider) {
+ public BgpTopologyDeployerImpl(final BundleContext context, final DataBroker dataBroker,
+ final ClusterSingletonServiceProvider singletonProvider) {
this.context = requireNonNull(context);
this.dataBroker = requireNonNull(dataBroker);
this.singletonProvider = requireNonNull(singletonProvider);
- this.registration =
- this.dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(NetworkTopology.class).child(Topology.class)), this);
+ }
+
+ public void init() {
+ this.registration = this.dataBroker.registerDataTreeChangeListener(
+ new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, TOPOLOGY_IID), this);
LOG.info("BGP topology deployer started.");
}
final DataObjectModification<Topology> rootNode = change.getRootNode();
final Topology dataBefore = rootNode.getDataBefore();
final Topology dataAfter = rootNode.getDataAfter();
- LOG.trace("BGP topology deployer configuration changed: modification type: [{}], data before:[{}], data after: [{}]", rootNode.getModificationType(), dataBefore, dataAfter);
+ LOG.trace("BGP topology deployer configuration changed: modification type: [{}]," +
+ " data before:[{}], data after: [{}]", rootNode.getModificationType(), dataBefore, dataAfter);
switch (rootNode.getModificationType()) {
- case DELETE:
- filterTopologyBuilders(dataBefore).forEach(provider -> provider.onTopologyBuilderRemoved(dataBefore));
- break;
- case SUBTREE_MODIFIED:
- filterTopologyBuilders(dataBefore).forEach(provider -> provider.onTopologyBuilderRemoved(dataBefore));
- filterTopologyBuilders(dataAfter).forEach(provider -> provider.onTopologyBuilderCreated(dataAfter, null));
- break;
- case WRITE:
- filterTopologyBuilders(dataAfter).forEach(provider -> provider.onTopologyBuilderCreated(dataAfter, null));
- break;
- default:
- break;
+ case DELETE:
+ filterTopologyBuilders(dataBefore)
+ .forEach(provider -> provider.onTopologyBuilderRemoved(dataBefore));
+ break;
+ case SUBTREE_MODIFIED:
+ filterTopologyBuilders(dataBefore).forEach(provider
+ -> provider.onTopologyBuilderRemoved(dataBefore));
+ filterTopologyBuilders(dataAfter).forEach(provider
+ -> provider.onTopologyBuilderCreated(dataAfter));
+ break;
+ case WRITE:
+ filterTopologyBuilders(dataAfter).forEach(provider
+ -> provider.onTopologyBuilderCreated(dataAfter));
+ break;
+ default:
+ break;
}
}
}
@Override
public AbstractRegistration registerService(final TopologyReferenceSingletonService topologyProviderService) {
final Dictionary<String, String> properties = new Hashtable<>();
- properties.put("topology-id", topologyProviderService.getInstanceIdentifier().firstKeyOf(Topology.class).getTopologyId().getValue());
- final ServiceRegistration<?> registerService = this.context.registerService(new String[]{TopologyReference.class.getName()}, topologyProviderService, properties);
- final ClusterSingletonServiceRegistration registerClusterSingletonService = registerSingletonService(topologyProviderService);
+ properties.put("topology-id", topologyProviderService.getInstanceIdentifier()
+ .firstKeyOf(Topology.class).getTopologyId().getValue());
+ final ServiceRegistration<?> registerService = this.context
+ .registerService(new String[]{TopologyReference.class.getName()},
+ topologyProviderService, properties);
+ final ClusterSingletonServiceRegistration registerClusterSingletonService =
+ registerSingletonService(topologyProviderService);
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
registerClusterSingletonService.close();
} catch (final Exception e) {
LOG.warn("Failed to close ClusterSingletonServiceRegistration {} for TopologyBuilder {}",
- registerClusterSingletonService, topologyProviderService.getInstanceIdentifier(), e);
+ registerClusterSingletonService, topologyProviderService.getInstanceIdentifier(), e);
}
registerService.unregister();
}
};
}
- @Override
- public void createInstance(final Topology topology) {
- final Function<Topology, Void> writeFunction = topology1 -> {
- final WriteTransaction wTx = this.dataBroker.newWriteOnlyTransaction();
- final KeyedInstanceIdentifier<Topology, TopologyKey> topologyIIdKeyed =
- InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, topology1.getKey());
- wTx.put(LogicalDatastoreType.CONFIGURATION, topologyIIdKeyed, topology1, true);
- wTx.submit();
- return null;
- };
-
- filterTopologyBuilders(topology).forEach(provider -> provider.onTopologyBuilderCreated(topology, writeFunction));
- }
-
- @Override
- public void removeInstance(final Topology topology) {
- filterTopologyBuilders(topology).forEach(provider -> provider.onTopologyBuilderRemoved(topology));
- }
-
- @Override
- public InstanceIdentifier<Topology> getInstanceIdentifier() {
- return TOPOLOGY_IID;
- }
-
@Override
public synchronized void close() {
- this.registration.close();
+ if (this.registration != null) {
+ this.registration.close();
+ this.registration = null;
+ }
+
LOG.info("BGP topology deployer stopped.");
this.closed = true;
}
private Iterable<BgpTopologyProvider> filterTopologyBuilders(final Topology topology) {
return this.topologyProviders.stream().filter(input -> input.topologyTypeFilter(topology))
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
}
private ClusterSingletonServiceRegistration registerSingletonService(
- final ClusterSingletonService clusterSingletonService) {
+ final ClusterSingletonService clusterSingletonService) {
return ClusterSingletonServiceRegistrationHelper
- .registerSingletonService(this.singletonProvider, clusterSingletonService);
+ .registerSingletonService(this.singletonProvider, clusterSingletonService);
}
}
import static java.util.Objects.requireNonNull;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.function.Function;
import org.opendaylight.bgpcep.bgp.topology.provider.AbstractTopologyBuilder;
import org.opendaylight.bgpcep.bgp.topology.provider.spi.BgpTopologyDeployer;
import org.opendaylight.bgpcep.bgp.topology.provider.spi.TopologyReferenceSingletonService;
private final AbstractTopologyBuilder<?> topologyBuilder;
private final AbstractRegistration serviceRegistration;
private final Topology configuration;
- private final Function<Topology, Void> writeFunction;
TopologyReferenceSingletonServiceImpl(final AbstractTopologyBuilder<?> topologyBuilder, final BgpTopologyDeployer deployer,
- final Topology configuration, final Function<Topology, Void> writeFunction) {
- this.writeFunction = writeFunction;
+ final Topology configuration) {
this.configuration = requireNonNull(configuration);
this.topologyBuilder = requireNonNull(topologyBuilder);
this.serviceRegistration = deployer.registerService(this);
public void instantiateServiceInstance() {
LOG.info("Topology Singleton Service {} instantiated", getIdentifier());
this.topologyBuilder.start();
- if (this.writeFunction != null) {
- this.writeFunction.apply(this.configuration);
- }
}
@Override
package org.opendaylight.bgpcep.bgp.topology.provider.spi;
+import com.google.common.annotations.Beta;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yangtools.concepts.AbstractRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+@Beta
public interface BgpTopologyDeployer {
AbstractRegistration registerTopologyProvider(BgpTopologyProvider topologyBuilder);
DataBroker getDataBroker();
AbstractRegistration registerService(TopologyReferenceSingletonService topologyProviderService);
-
- void createInstance(Topology topology);
-
- void removeInstance(Topology topology);
-
- InstanceIdentifier<Topology> getInstanceIdentifier();
}
package org.opendaylight.bgpcep.bgp.topology.provider.spi;
-import java.util.function.Function;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
void onTopologyBuilderRemoved(Topology topology);
- void onTopologyBuilderCreated(Topology topology, Function<Topology, Void> writeFunction);
+ void onTopologyBuilderCreated(Topology topology);
}
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" odl:type="pingpong"/>
<reference id="clusterSingletonServiceProvider" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
- <bean id="bgpTopologyDeployer" class="org.opendaylight.bgpcep.bgp.topology.provider.config.BgpTopologyDeployerImpl" destroy-method="close">
+ <bean id="bgpTopologyDeployer" class="org.opendaylight.bgpcep.bgp.topology.provider.config.BgpTopologyDeployerImpl"
+ init-method="init"
+ destroy-method="close">
<argument ref="blueprintBundleContext"/>
<argument ref="dataBroker"/>
<argument ref="clusterSingletonServiceProvider"/>
public synchronized void close() {
if (this.registration != null) {
this.registration.close();
+ this.registration = null;
}
}
}