import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.protocol.bgp.rib.impl.ApplicationPeer.RegisterAppPeerListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Writer of Adjacency-RIB-In for a single peer. An instance of this object
* is attached to each {@link BGPPeer} and {@link ApplicationPeer}.
private static final NodeIdentifier PEER_TABLES = new NodeIdentifier(SupportedTables.QNAME);
private static final NodeIdentifier TABLES = new NodeIdentifier(Tables.QNAME);
private static final QName SEND_RECEIVE = QName.create(SupportedTables.QNAME, "send-receive").intern();
- static final NodeIdentifier SIMPLE_ROUTING_POLICY_NID = new NodeIdentifier(QName.create(Peer.QNAME, "simple-routing-policy").intern());
+ private static final NodeIdentifier SIMPLE_ROUTING_POLICY_NID = new NodeIdentifier(QName.create(Peer.QNAME, "simple-routing-policy").intern());
// FIXME: is there a utility method to construct this?
private static final ContainerNode EMPTY_ADJRIBIN = Builders.containerBuilder().withNodeIdentifier(ADJRIBIN).addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build()).build();
* @param simpleRoutingPolicy simple Routing Policy {@link SimpleRoutingPolicy}
*@param chain transaction chain @return A fresh writer instance
*/
- static AdjRibInWriter create(@Nonnull final YangInstanceIdentifier ribId, @Nonnull final PeerRole role, final Optional<SimpleRoutingPolicy> simpleRoutingPolicy,
- @Nonnull final DOMTransactionChain chain) {
+ static AdjRibInWriter create(@Nonnull final YangInstanceIdentifier ribId, @Nonnull final PeerRole role,
+ final Optional<SimpleRoutingPolicy> simpleRoutingPolicy, @Nonnull final DOMTransactionChain chain) {
return new AdjRibInWriter(ribId, chain, role, simpleRoutingPolicy, null, Collections.emptyMap());
}
* @param addPathTablesType
* @return New writer
*/
+ AdjRibInWriter transform(final PeerId newPeerId, final RIBSupportContextRegistry registry,
+ final Set<TablesKey> tableTypes, final Map<TablesKey, SendReceive> addPathTablesType) {
+ return transform(newPeerId, registry, tableTypes, addPathTablesType, null);
+ }
+
AdjRibInWriter transform(final PeerId newPeerId, final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes,
- final Map<TablesKey, SendReceive> addPathTablesType) {
+ final Map<TablesKey, SendReceive> addPathTablesType, @Nullable final RegisterAppPeerListener registerAppPeerListener) {
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
final YangInstanceIdentifier newPeerPath;
newPeerPath = createEmptyPeerStructure(newPeerId, tx);
- final ImmutableMap<TablesKey, TableContext> tb = createNewTableInstances(newPeerPath, registry, tableTypes, addPathTablesType, tx);
- tx.submit();
+ final ImmutableMap<TablesKey, TableContext> tb = createNewTableInstances(newPeerPath, registry, tableTypes,
+ addPathTablesType, tx);
+ Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ if(registerAppPeerListener != null) {
+ LOG.trace("Application Peer Listener registered");
+ registerAppPeerListener.register();
+ }
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.error("Failed to register Application Peer Listener", throwable);
+ }
+ });
return new AdjRibInWriter(this.ribPath, this.chain, this.role, this.simpleRoutingPolicy, newPeerPath, tb);
}
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPConfigModuleTracker;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPPeerStatsImpl;
import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
+import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.AdjRibIn;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
private EffectiveRibInWriter effectiveRibInWriter;
private AdjRibInWriter adjRibInWriter;
private BGPPeerStats peerStats;
+ private ListenerRegistration<ApplicationPeer> registration;
+ private final Set<NodeIdentifierWithPredicates> supportedTables = new HashSet<>();
+
+
+ @FunctionalInterface
+ interface RegisterAppPeerListener {
+ /**
+ * Register Application Peer Change Listener once AdjRibIn has been successfully initialized.
+ */
+ void register();
+ }
public ApplicationPeer(final ApplicationRibId applicationRibId, final Ipv4Address ipAddress, final RIB rib,
final BGPConfigModuleTracker moduleTracker) {
this(applicationRibId, bgpPeerId, targetRibDependency, null);
}
- public void instantiateServiceInstance() {
+ public synchronized void instantiateServiceInstance(final DOMDataTreeChangeService dataTreeChangeService,
+ final DOMDataTreeIdentifier appPeerDOMId) {
this.chain = this.rib.createPeerChain(this);
this.writerChain = this.rib.createPeerChain(this);
if (exportTracker != null) {
exportTracker.registerPeer(peerId, null, this.peerIId, PeerRole.Internal, simpleRoutingPolicy);
}
+ this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey));
});
this.adjRibInWriter = AdjRibInWriter.create(this.rib.getYangRibId(), PeerRole.Internal, simpleRoutingPolicy, this.writerChain);
final RIBSupportContextRegistry context = this.rib.getRibSupportContext();
- this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap());
+ final RegisterAppPeerListener registerAppPeerListener = () -> {
+ synchronized (this) {
+ if(this.chain != null) {
+ this.registration = dataTreeChangeService.registerDataTreeChangeListener(appPeerDOMId, this);
+ }
+ }
+ };
+ this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap(),
+ registerAppPeerListener);
this.peerStats = new BGPPeerStatsImpl(this.name, localTables);
this.effectiveRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
this.rib.getImportPolicyPeerTracker(), context, PeerRole.Internal, this.peerStats.getEffectiveRibInRouteCounters(),
* be determined in LocRib.
*/
@Override
- public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
+ public synchronized void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
+ if(this.chain == null) {
+ LOG.trace("Skipping data changed called to Application Peer. Change : {}", changes);
+ return;
+ }
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
LOG.debug("Received data change to ApplicationRib {}", changes);
for (final DataTreeCandidate tc : changes) {
final PathArgument lastArg = path.getLastPathArgument();
Verify.verify(lastArg instanceof NodeIdentifierWithPredicates, "Unexpected type %s in path %s", lastArg.getClass(), path);
final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) lastArg;
+ if (!this.supportedTables.contains(tableKey)) {
+ LOG.trace("Skipping received data change for non supported family {}.", tableKey);
+ continue;
+ }
for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) {
final PathArgument childIdentifier = child.getIdentifier();
final YangInstanceIdentifier tableId = this.adjRibsInId.node(tableKey).node(childIdentifier);
* @param tx
* @param routeTableIdentifier
*/
- private void processRoutesTable(final DataTreeCandidateNode node, final YangInstanceIdentifier identifier,
+ private synchronized void processRoutesTable(final DataTreeCandidateNode node, final YangInstanceIdentifier identifier,
final DOMDataWriteTransaction tx, final YangInstanceIdentifier routeTableIdentifier) {
for (final DataTreeCandidateNode child : node.getChildNodes()) {
final YangInstanceIdentifier childIdentifier = identifier.node(child.getIdentifier());
}
@Override
- public void close() {
- if(this.effectiveRibInWriter != null) {
+ public synchronized void close() {
+ if (this.registration != null) {
+ this.registration.close();
+ this.registration = null;
+ }
+ if (this.effectiveRibInWriter != null) {
this.effectiveRibInWriter.close();
}
- if(this.adjRibInWriter != null) {
+ if (this.adjRibInWriter != null) {
this.adjRibInWriter.removePeer();
}
- if(this.chain != null) {
+ if (this.chain != null) {
this.chain.close();
+ this.chain = null;
}
- if(this.writerChain != null) {
+ if (this.writerChain != null) {
this.writerChain.close();
+ this.writerChain = null;
}
if (this.moduleTracker != null) {
this.moduleTracker.onInstanceClose();
}
@Override
- public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction,
- final Throwable cause) {
- LOG.error("Transaction chain failed.", cause);
+ public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+ final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+ LOG.error("Transaction chain {} failed.", transaction != null ? transaction.getIdentifier() : null, cause);
}
@Override
public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
- LOG.debug("Transaction chain {} successfull.", chain);
+ LOG.debug("Transaction chain {} successful.", chain);
}
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.slf4j.Logger;
private BGPOpenConfigMappingService mappingService;
@Override
- public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService, final WriteConfiguration configurationWriter) {
+ public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService,
+ final WriteConfiguration configurationWriter) {
+ Preconditions.checkState(this.bgpAppPeerSingletonService == null, "Previous peer instance was not closed.");
this.currentConfiguration = neighbor;
this.mappingService = mappingService;
- this.bgpAppPeerSingletonService = new BgpAppPeerSingletonService(rib, createAppRibId(neighbor), neighbor.getNeighborAddress().getIpv4Address(),
- configurationWriter);
+ this.bgpAppPeerSingletonService = new BgpAppPeerSingletonService(rib, createAppRibId(neighbor),
+ neighbor.getNeighborAddress().getIpv4Address(), configurationWriter);
}
@Override
public void close() {
try {
this.bgpAppPeerSingletonService.close();
+ this.bgpAppPeerSingletonService = null;
} catch (final Exception e) {
LOG.warn("Failed to close application peer instance", e);
}
private final DOMDataTreeChangeService dataTreeChangeService;
private final ApplicationRibId appRibId;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
- private ListenerRegistration<ApplicationPeer> registration;
private final ServiceGroupIdentifier serviceGroupIdentifier;
private final WriteConfiguration configurationWriter;
- BgpAppPeerSingletonService(final RIB rib, final ApplicationRibId appRibId, final Ipv4Address neighborAddress, final WriteConfiguration configurationWriter) {
+ BgpAppPeerSingletonService(final RIB rib, final ApplicationRibId appRibId, final Ipv4Address neighborAddress,
+ final WriteConfiguration configurationWriter) {
this.applicationPeer = new ApplicationPeer(appRibId, neighborAddress, rib);
this.appRibId = appRibId;
this.dataTreeChangeService = rib.getService();
LOG.info("Application Peer Singleton Service {} instantiated", getIdentifier());
final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME)
.nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue()).node(Tables.QNAME).node(Tables.QNAME).build();
- this.applicationPeer.instantiateServiceInstance();
- this.registration = this.dataTreeChangeService
- .registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId), this.applicationPeer);
+ this.applicationPeer.instantiateServiceInstance(this.dataTreeChangeService,
+ new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId));
}
@Override
public ListenableFuture<Void> closeServiceInstance() {
LOG.info("Application Peer Singleton Service {} instance closed", getIdentifier());
- if(this.registration != null) {
- this.registration.close();
- }
this.applicationPeer.close();
return Futures.immediateFuture(null);
}
@Override
public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService,
final WriteConfiguration configurationWriter) {
- Preconditions.checkState(this.bgpPeerSingletonService == null, "Previous peer instance {} was not closed.");
+ Preconditions.checkState(this.bgpPeerSingletonService == null, "Previous peer instance was not closed.");
this.bgpPeerSingletonService = new BgpPeerSingletonService(rib, neighbor, mappingService, configurationWriter);
this.currentConfiguration = neighbor;
}
package org.opendaylight.protocol.bgp.rib.impl;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.CheckedFuture;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Rib;
private static final TablesKey K4 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
private final Set<TablesKey> tableTypes = Sets.newHashSet(K4);
-
- private static final AddressFamilies ADDRESS_FAMILIES = new AddressFamiliesBuilder().setAfi(Ipv4AddressFamily.class)
- .setSafi(UnicastSubsequentAddressFamily.class).setSendReceive(SendReceive.Both).build();
- private final List<AddressFamilies> addPathTablesType = Collections.singletonList(ADDRESS_FAMILIES);
private static final Map<TablesKey, SendReceive> ADD_PATH_TABLE_MAPS = Collections.singletonMap(K4, SendReceive.Both);
private final String peerIp = "12.34.56.78";
MockitoAnnotations.initMocks(this);
Mockito.doReturn("MockedTrans").when(this.tx).toString();
Mockito.doReturn(this.tx).when(this.chain).newWriteOnlyTransaction();
- Mockito.doReturn(Mockito.mock(CheckedFuture.class)).when(this.tx).submit();
+ final CheckedFuture checkedFuture = Mockito.mock(CheckedFuture.class);
+ Mockito.doNothing().when(checkedFuture).addListener(any(), any());
+ Mockito.doReturn(checkedFuture).when(this.tx).submit();
Mockito.doNothing().when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
Mockito.doNothing().when(this.tx).merge(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
Mockito.doReturn(this.context).when(this.registry).getRIBSupportContext(Mockito.any(TablesKey.class));
final Ipv4Prefix second = new Ipv4Prefix("127.0.0.1/32");
final Ipv4Prefix third = new Ipv4Prefix("127.0.0.3/32");
this.peer = new ApplicationPeer(new ApplicationRibId("t"), new Ipv4Address("127.0.0.1"), getRib());
- this.peer.instantiateServiceInstance();
+ this.peer.instantiateServiceInstance(null, null);
final YangInstanceIdentifier base = getRib().getYangRibId().node(LocRib.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(KEY));
this.peer.onDataTreeChanged(ipv4Input(base, ModificationType.WRITE, first, second, third));
assertEquals(3, this.routes.size());
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
any(YangInstanceIdentifier.class), any(NormalizedNode.class));
Mockito.doNothing().when(this.tx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class));
final CheckedFuture future = mock(CheckedFuture.class);
+ Mockito.doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(final InvocationOnMock invocation) throws Throwable {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
+ }
+ }).when(future).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
Mockito.doReturn(future).when(this.tx).submit();
Mockito.doReturn(mock(Optional.class)).when(future).checkedGet();
}
import io.netty.util.concurrent.Future;
import java.net.InetSocketAddress;
import java.util.Collections;
+import java.util.concurrent.Executor;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.osgi.framework.ServiceRegistration;
class AbstractConfig {
- protected static final AsNumber AS = new AsNumber(123456L);
+ protected static final AsNumber AS = new AsNumber(72L);
@Mock
protected RIB rib;
@Mock
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- Mockito.doAnswer(new Answer<ClusterSingletonServiceRegistration>() {
- @Override
- public ClusterSingletonServiceRegistration answer(final InvocationOnMock invocationOnMock) throws Throwable {
- singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
- return singletonServiceRegistration;
- }
+ Mockito.doAnswer(invocationOnMock->{
+ this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
+ return this.singletonServiceRegistration;
}).when(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
-
Mockito.doReturn(new UnsignedInt32Counter("counter")).when(this.render).getConfiguredPeerCounter();
Mockito.doReturn(this.render).when(this.rib).getRenderStats();
Mockito.doReturn(this.domTx).when(this.rib).createPeerChain(any(TransactionChainListener.class));
Mockito.doNothing().when(this.domDW).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
Mockito.doNothing().when(this.domDW).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
final CheckedFuture checkedFuture = mock(CheckedFuture.class);
+ Mockito.doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(final InvocationOnMock invocation) throws Throwable {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
+ }
+ }).when(checkedFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
Mockito.doReturn(checkedFuture).when(this.domDW).submit();
Mockito.doReturn(null).when(checkedFuture).checkedGet();
+ Mockito.doReturn(null).when(checkedFuture).get();
+ Mockito.doReturn("checkedFuture").when(checkedFuture).toString();
Mockito.doNothing().when(this.singletonServiceRegistration).close();
Mockito.doReturn(YangInstanceIdentifier.of(Rib.QNAME)).when(this.rib).getYangRibId();
Mockito.doReturn(this.listener).when(this.dataTreeChangeService).registerDataTreeChangeListener(any(), any());
Mockito.doReturn(mock(ServiceGroupIdentifier.class)).when(this.rib).getRibIServiceGroupIdentifier();
Mockito.doReturn(new BgpId("127.0.0.1")).when(this.rib).getBgpIdentifier();
- Mockito.doReturn(true).when(future).cancel(true);
- Mockito.doReturn(future).when(this.dispatcher)
+ Mockito.doReturn(true).when(this.future).cancel(true);
+ Mockito.doReturn(this.future).when(this.dispatcher)
.createReconnectingClient(any(InetSocketAddress.class), any(BGPPeerRegistry.class), anyInt(), any(Optional.class));
Mockito.doReturn(this.dispatcher).when(this.rib).getDispatcher();
public class AppPeerTest extends AbstractConfig {
private static final AppPeer APP_PEER = new AppPeer();
+ private final Neighbor neighbor = new NeighborBuilder()
+ .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
-
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
@Test
public void testAppPeer() throws Exception {
- final Neighbor neighbor = new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
- APP_PEER.start(this.rib, neighbor, this.mappingService, this.configurationWriter);
+ APP_PEER.start(this.rib, this.neighbor, this.mappingService, this.configurationWriter);
Mockito.verify(this.rib).getYangRibId();
Mockito.verify(this.rib).getService();
Mockito.verify(this.rib).getRibIServiceGroupIdentifier();
Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
this.singletonService.instantiateServiceInstance();
+ Mockito.verify(this.rib, times(2)).getYangRibId();
Mockito.verify(this.configurationWriter).apply();
Mockito.verify(this.rib).getRibSupportContext();
Mockito.verify(this.rib).getLocalTablesKeys();
Mockito.verify(this.domTx).newWriteOnlyTransaction();
+ APP_PEER.close();
+ Mockito.verify(this.singletonServiceRegistration).close();
+
APP_PEER.restart(this.rib, this.mappingService);
this.singletonService.instantiateServiceInstance();
Mockito.verify(this.rib, times(4)).getYangRibId();
this.singletonService.closeServiceInstance();
Mockito.verify(this.listener, times(2)).close();
- assertTrue(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build()));
- assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
+ assertTrue(APP_PEER.containsEqualConfiguration(this.neighbor));
+ assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder()
+ .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
APP_PEER.close();
- Mockito.verify(this.singletonServiceRegistration).close();
+ Mockito.verify(this.singletonServiceRegistration, times(2)).close();
}
}
\ No newline at end of file
this.bgpPeer.start(this.rib, neighbor, this.mappingService, this.configurationWriter);
fail("Expected Exception");
} catch (final IllegalStateException expected) {
- assertEquals("Previous peer instance {} was not closed.", expected.getMessage());
+ assertEquals("Previous peer instance was not closed.", expected.getMessage());
}
this.bgpPeer.setServiceRegistration(this.serviceRegistration);
this.bgpPeer.close();