@GuardedBy("this")
private boolean closed;
- public BgpDeployerImpl(final String networkInstanceName, final BlueprintContainer container, final BundleContext bundleContext, final DataBroker dataBroker,
+ public BgpDeployerImpl(final String networkInstanceName, final BlueprintContainer container,
+ final BundleContext bundleContext, final DataBroker dataBroker,
final BGPTableTypeRegistryConsumer mappingService) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.container = Preconditions.checkNotNull(container);
LOG.error("Failed to initialize Network Instance {}.", networkInstanceName, t);
}
});
- this.registration = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
- this.networkInstanceIId.child(Protocols.class).child(Protocol.class).augmentation(Protocol1.class).child(Bgp.class)), this);
+ this.registration = dataBroker.registerDataTreeChangeListener(
+ 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);
}
@Override
public synchronized void close() throws Exception {
+ LOG.info("Closing BGP Deployer.");
this.registration.close();
this.peers.values().forEach(PeerBean::close);
this.peers.clear();
this.closed = true;
}
- private static CheckedFuture<Void, TransactionCommitFailedException> initializeNetworkInstance(final DataBroker dataBroker,
- final InstanceIdentifier<NetworkInstance> networkInstance) {
+ private static CheckedFuture<Void, TransactionCommitFailedException> 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());
+ new NetworkInstanceBuilder().setName(networkInstance.firstKeyOf(NetworkInstance.class).getName())
+ .setProtocols(new ProtocolsBuilder().build()).build());
return wTx.submit();
}
- private void onGlobalChanged(final DataObjectModification<Global> dataObjectModification,
+ private synchronized void onGlobalChanged(final DataObjectModification<Global> dataObjectModification,
final InstanceIdentifier<Bgp> rootIdentifier) {
switch (dataObjectModification.getModificationType()) {
case DELETE:
}
}
- private List<PeerBean> closeAllBindedPeers(final InstanceIdentifier<Bgp> rootIdentifier) {
+ 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 -> {
- final PeerBean peer = entry.getValue();
+ this.peers.entrySet().stream().filter(entry -> entry.getKey().firstIdentifierOf(Bgp.class)
+ .contains(rootIdentifier)).forEach(entry -> {final PeerBean peer = entry.getValue();
peer.close();
filtered.add(peer);
});
LOG.debug("RIB instance created: {}", ribImpl);
}
- private void onGlobalUpdated(final InstanceIdentifier<Bgp> rootIdentifier, final Global global, final RibImpl ribImpl,
- final WriteConfiguration configurationWriter) {
+ private synchronized void onGlobalUpdated(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
+ final RibImpl ribImpl, final WriteConfiguration configurationWriter) {
LOG.debug("Modifying RIB instance with configuration: {}", global);
final List<PeerBean> closedPeers = closeAllBindedPeers(rootIdentifier);
ribImpl.close();
}
}
- private void registerRibInstance(final RibImpl ribImpl, final String ribInstanceName) {
+ private synchronized void registerRibInstance(final RibImpl ribImpl, final String ribInstanceName) {
final Dictionary<String, String> properties = new Hashtable<>();
properties.put(InstanceType.RIB.getBeanName(), ribInstanceName);
- final ServiceRegistration<?> serviceRegistration = this.bundleContext.registerService(InstanceType.RIB.getServices(), ribImpl, properties);
+ final ServiceRegistration<?> serviceRegistration = this.bundleContext.registerService(
+ InstanceType.RIB.getServices(), ribImpl, properties);
ribImpl.setServiceRegistration(serviceRegistration);
}
- private void initiateRibInstance(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
+ private synchronized void initiateRibInstance(final InstanceIdentifier<Bgp> rootIdentifier, final Global global,
final RibImpl ribImpl, final WriteConfiguration configurationWriter) {
final String ribInstanceName = getRibInstanceName(rootIdentifier);
ribImpl.start(global, ribInstanceName, this.tableTypeRegistry, configurationWriter);
registerRibInstance(ribImpl, ribInstanceName);
}
- private void onNeighborsChanged(final DataObjectModification<Neighbors> dataObjectModification,
+ private synchronized void onNeighborsChanged(final DataObjectModification<Neighbors> dataObjectModification,
final InstanceIdentifier<Bgp> rootIdentifier) {
for (final DataObjectModification<? extends DataObject> neighborModification : dataObjectModification.getModifiedChildren()) {
switch (neighborModification.getModificationType()) {
LOG.debug("Peer instance created {}", bgpPeer);
}
- private void onNeighborUpdated(final PeerBean bgpPeer, final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor,
+ private synchronized void onNeighborUpdated(final PeerBean bgpPeer, final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor,
final WriteConfiguration configurationWriter) {
LOG.debug("Updating Peer instance with configuration: {}", neighbor);
bgpPeer.close();
}
}
- private void registerPeerInstance(final BgpPeer bgpPeer, final String peerInstanceName) {
+ private synchronized void registerPeerInstance(final BgpPeer bgpPeer, final String peerInstanceName) {
final Dictionary<String, String> properties = new Hashtable<>();
properties.put(InstanceType.PEER.getBeanName(), peerInstanceName);
- final ServiceRegistration<?> serviceRegistration = this.bundleContext.registerService(InstanceType.PEER.getServices(), bgpPeer, properties);
+ final ServiceRegistration<?> serviceRegistration = this.bundleContext
+ .registerService(InstanceType.PEER.getServices(), bgpPeer, properties);
bgpPeer.setServiceRegistration(serviceRegistration);
}
- private void initiatePeerInstance(final InstanceIdentifier<Bgp> rootIdentifier, final InstanceIdentifier<Neighbor> neighborIdentifier, final Neighbor neighbor,
+ private synchronized void registerAppPeerInstance(final AppPeer appPeer, final String peerInstanceName) {
+ 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);
+ 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 String peerInstanceName = getNeighborInstanceName(neighborIdentifier);
final RibImpl rib = this.ribs.get(rootIdentifier);
bgpPeer.start(rib, neighbor, this.tableTypeRegistry, configurationWriter);
if (bgpPeer instanceof BgpPeer) {
registerPeerInstance((BgpPeer) bgpPeer, peerInstanceName);
+ } else if(bgpPeer instanceof AppPeer) {
+ registerAppPeerInstance((AppPeer) bgpPeer, peerInstanceName);
}
}
}
}
@Override
- public <T extends DataObject> ListenableFuture<Void> writeConfiguration(final T data, final InstanceIdentifier<T> identifier) {
- final ReadWriteTransaction wTx = this.dataBroker.newReadWriteTransaction();
+ 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();
}