* [peer://127.0.0.4; p1, lp50] --(iBGP)--> | | --(RR-client, add-path) --> [Peer://127.0.0.6; (p1, path-id1, lp100), (p1, path-id2, pl50), (p1, path-id3, pl200), (p1, path-id4, pl20)]
* [peer://127.0.0.2; p1, lp20] --(iBGP)--> |___________________|
* p1 = 1.1.1.1/32
+ *
+ *
+ *
*/
@Test
public void testUseCase1() throws Exception {
final BgpParameters nonAddPathParams = createParameter(false);
final BgpParameters addPathParams = createParameter(true);
- final BGPPeer peer1 = configurePeer(this.tableRegistry, PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
+ final BGPPeer peer1 = configurePeer(this.tableRegistry, PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp,
+ this.serverRegistry);
final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
configurePeer(this.tableRegistry, PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
final SimpleSessionListener listener4 = new SimpleSessionListener();
- final BGPPeer peer4 = configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
+ final BGPPeer peer4 = configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams,
+ PeerRole.RrClient, this.serverRegistry);
BGPPeerState peer4State = peer4.getPeerState();
assertNull(peer4State.getGroupId());
assertEquals(new IpAddress(PEER1), transportStatePeer1.getRemoteAddress());
assertEquals(State.UP, peer1State.getBGPSessionState().getSessionState());
- checkEquals(()-> assertEquals(1L, peer1State.getBGPPeerMessagesState().getUpdateMessagesReceivedCount()));
- checkEquals(()-> assertEquals(0L, peer1State.getBGPPeerMessagesState().getUpdateMessagesSentCount()));
+ checkEquals(()-> assertEquals(1L,
+ peer1State.getBGPPeerMessagesState().getUpdateMessagesReceivedCount()));
+ checkEquals(()-> assertEquals(0L,
+ peer1State.getBGPPeerMessagesState().getUpdateMessagesSentCount()));
final BGPSessionState sessionStatePeer1 = peer1State.getBGPSessionState();
assertFalse(sessionStatePeer1.isAddPathCapabilitySupported());
assertEquals(1L, ribState.getTotalPrefixesCount());
final SimpleSessionListener listener6 = new SimpleSessionListener();
- final BGPPeer peer6 = configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
+ final BGPPeer peer6 = configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams,
+ PeerRole.RrClient, this.serverRegistry);
final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
checkPeersPresentOnDataStore(6);
checkReceivedMessages(listener6, 1);
assertEquals(UPD_NA_100, listener6.getListMsg().get(0));
causeBGPError(session6);
- checkEquals(()-> assertEquals(1L, peer6.getPeerState().getBGPPeerMessagesState().getNotificationMessagesSentCount()));
+ checkEquals(()-> assertEquals(1L,
+ peer6.getPeerState().getBGPPeerMessagesState().getNotificationMessagesSentCount()));
checkPeersPresentOnDataStore(5);
sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 20, 3);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 4);
- assertEquals(UPD_200.getAttributes().getLocalPref(), ((Update) listener4.getListMsg().get(1)).getAttributes().getLocalPref());
+ assertEquals(UPD_200.getAttributes().getLocalPref(),
+ ((Update) listener4.getListMsg().get(1)).getAttributes().getLocalPref());
assertEquals(UPD_20, listener5.getListMsg().get(3));
//withdraw second best route, 1 advertisement(1 withdrawal) for add-path supported, none for non add path
checkReceivedMessages(listener5, 7);
sendNotification(session1);
- checkEquals(()-> assertEquals(1L, peer1.getPeerState().getBGPPeerMessagesState().getNotificationMessagesReceivedCount()));
+ checkEquals(()-> assertEquals(1L,
+ peer1.getPeerState().getBGPPeerMessagesState().getNotificationMessagesReceivedCount()));
session1.close();
session2.close();
session3.close();
final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
final SimpleSessionListener listener4 = new SimpleSessionListener();
- configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
+ configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
+ this.serverRegistry);
final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
final SimpleSessionListener listener5 = new SimpleSessionListener();
assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(1));
final SimpleSessionListener listener6 = new SimpleSessionListener();
- configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
+ configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
+ this.serverRegistry);
final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
checkPeersPresentOnDataStore(6);
final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
final SimpleSessionListener listener4 = new SimpleSessionListener();
- configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
+ configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
+ this.serverRegistry);
final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
final SimpleSessionListener listener5 = new SimpleSessionListener();
assertEquals(UPD_100, listener5.getListMsg().get(0));
final SimpleSessionListener listener6 = new SimpleSessionListener();
- configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
+ configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
+ this.serverRegistry);
final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
checkPeersPresentOnDataStore(6);
checkReceivedMessages(listener6, 1);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 6);
- //withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, 1 withdrawal for non add path
+ //withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported,
+ // 1 withdrawal for non add path
sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
checkReceivedMessages(listener4, 3);
checkReceivedMessages(listener5, 8);
public class AdjRibsInWriterTest {
private static final TablesKey K4 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- private static final Map<TablesKey, SendReceive> ADD_PATH_TABLE_MAPS = Collections.singletonMap(K4, SendReceive.Both);
+ private static final Map<TablesKey, SendReceive> ADD_PATH_TABLE_MAPS
+ = Collections.singletonMap(K4, SendReceive.Both);
private final Set<TablesKey> tableTypes = Sets.newHashSet(K4);
private final String peerIp = "12.34.56.78";
@Mock
final YangInstanceIdentifier path = peerPath.node(AdjRibIn.QNAME)
.node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(K4))
.node(Attributes.QNAME).node(AdjRibInWriter.ATTRIBUTES_UPTODATE_FALSE.getNodeType());
- verify(this.tx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(path)
- , eq(AdjRibInWriter.ATTRIBUTES_UPTODATE_FALSE));
+ verify(this.tx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(path),
+ eq(AdjRibInWriter.ATTRIBUTES_UPTODATE_FALSE));
}
private void verifyPeerSkeletonInsertedCorrectly(final YangInstanceIdentifier peerPath) {
import org.opendaylight.protocol.bgp.rib.spi.State;
public final class CheckUtil {
+ private CheckUtil() {
+ throw new UnsupportedOperationException();
+ }
+
public static void checkIdleState(final SimpleSessionListener listener) {
final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
this.classic.toString());
final Nlri n1 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
- final Nlri n2 = new NlriBuilder().setPrefix( new Ipv4Prefix("127.0.0.1/32")).build();
- final Nlri n3 = new NlriBuilder().setPrefix( new Ipv4Prefix("2.2.2.2/24")).build();
+ final Nlri n2 = new NlriBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
+ final Nlri n3 = new NlriBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<Nlri> nlris = Lists.newArrayList(n1, n2, n3);
final UpdateBuilder ub = new UpdateBuilder();
ub.setNlri(nlris);
assertEquals(3, this.routes.size());
final Nlri n11 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
- final Nlri n22 = new NlriBuilder().setPrefix( new Ipv4Prefix("8.0.1.16/28")).build();
+ final Nlri n22 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.16/28")).build();
final List<Nlri> nlris2 = Lists.newArrayList(n11, n22);
ub.setNlri(nlris2);
- final WithdrawnRoutes w1 =new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
- final WithdrawnRoutes w2 =new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
+ final WithdrawnRoutes w1 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
+ final WithdrawnRoutes w2 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
final WithdrawnRoutes w3 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<WithdrawnRoutes> wrs = Lists.newArrayList(w1, w2, w3);
ub.setWithdrawnRoutes(wrs);
*/
package org.opendaylight.protocol.bgp.rib.impl;
+import static org.junit.Assert.assertTrue;
+
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.GuardedBy;
-import org.junit.Assert;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
@GuardedBy("this")
private final List<Notification> listMsg = Lists.newArrayList();
- private BGPSession session;
+ private BGPSession bgpSession;
private final CountDownLatch sessionLatch = new CountDownLatch(1);
public SimpleSessionListener() {
@Override
public void onSessionUp(final BGPSession session) {
LOG.info("Session Up");
- this.session = session;
+ this.bgpSession = session;
this.sessionLatch.countDown();
}
@Override
- public void onSessionDown(final BGPSession session, final Exception e) {
- LOG.debug("Session Down", e);
+ public void onSessionDown(final BGPSession session, final Exception exception) {
+ LOG.debug("Session Down", exception);
}
@Override
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<Void> releaseConnection() {
LOG.debug("Releasing connection");
- if (this.session != null) {
+ if (this.bgpSession != null) {
try {
- this.session.close();
+ this.bgpSession.close();
} catch (final Exception e) {
LOG.warn("Error closing session", e);
}
}
BGPSessionImpl getSession() {
- Assert.assertTrue("Session up", Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
- return (BGPSessionImpl) this.session;
+ assertTrue("Session up",
+ Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
+ return (BGPSessionImpl) this.bgpSession;
}
@Override
class AbstractConfig extends DefaultRibPoliciesMockTest {
protected static final AsNumber AS = new AsNumber(72L);
- protected static final AsNumber lOCAL_AS = new AsNumber(73L);
+ protected static final AsNumber LOCAL_AS = new AsNumber(73L);
protected static final RibId RIB_ID = new RibId("test");
static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
@Mock
deployer.close();
}
- /**
- * Test create Rib
- */
@Test
public void testDeployerCreateNeighbor() throws Exception {
deployer.init();
}
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)
+ 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(NeighborTransportConfig.class,
new NeighborTransportConfigBuilder().setRemotePort(PORT).build()).build()).build();
}
}
static Config createConfig() {
- return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.
- ConfigBuilder()
+ return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
+ .ConfigBuilder()
.setPeerAs(AS)
- .setLocalAs(lOCAL_AS)
+ .setLocalAs(LOCAL_AS)
.setPeerType(PeerType.INTERNAL)
.setAuthPassword(MD5_PASSWORD)
.setRouteFlapDamping(false)
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.MockitoAnnotations.initMocks;
import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.AFI_SAFI;
import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.AFI_SAFI_IPV4;
import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.MD5_PASSWORD;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- Mockito.doReturn(java.util.Optional.of(BGP_TABLE_TYPE_IPV4))
+ initMocks(this);
+ doReturn(java.util.Optional.of(BGP_TABLE_TYPE_IPV4))
.when(this.tableTypeRegistry).getTableType(IPV4UNICAST.class);
- Mockito.doReturn(java.util.Optional.of(BGP_TABLE_TYPE_IPV6))
+ doReturn(java.util.Optional.of(BGP_TABLE_TYPE_IPV6))
.when(this.tableTypeRegistry).getTableType(IPV6UNICAST.class);
- Mockito.doReturn(java.util.Optional.of(new BgpTableTypeImpl(Ipv6AddressFamily.class,
+ doReturn(java.util.Optional.of(new BgpTableTypeImpl(Ipv6AddressFamily.class,
MplsLabeledVpnSubsequentAddressFamily.class)))
.when(this.tableTypeRegistry).getTableType(IPV6LABELLEDUNICAST.class);
- Mockito.doReturn(java.util.Optional.of(IPV4UNICAST.class))
+ doReturn(java.util.Optional.of(IPV4UNICAST.class))
.when(this.tableTypeRegistry).getAfiSafiType(BGP_TABLE_TYPE_IPV4);
- Mockito.doReturn(java.util.Optional.of(IPV6UNICAST.class))
+ doReturn(java.util.Optional.of(IPV6UNICAST.class))
.when(this.tableTypeRegistry).getAfiSafiType(BGP_TABLE_TYPE_IPV6);
- Mockito.doReturn(AS).when(this.rib).getLocalAs();
+ doReturn(AS).when(this.rib).getLocalAs();
}
@Test
@Test
public void testGetHoldTimer() {
- TimersBuilder builder = new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net
- .yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder().setHoldTime(BigDecimal.TEN).build());
-
assertEquals(DEFAULT_TIMERS.toBigInteger().intValue(),
OpenConfigMappingUtil.getHoldTimer(NEIGHBOR, null));
assertEquals(HOLDTIMER,
assertEquals(DEFAULT_TIMERS.toBigInteger().intValue(),
OpenConfigMappingUtil.getHoldTimer(NEIGHBOR, new PeerGroupBuilder().build()));
+ TimersBuilder builder = new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net
+ .yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder().setHoldTime(BigDecimal.TEN).build());
assertEquals(BigDecimal.TEN.intValue(), OpenConfigMappingUtil.getHoldTimer(NEIGHBOR, new PeerGroupBuilder()
.setTimers(builder.build()).build()));
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.osgi.framework.ServiceRegistration;
public void setUp() throws Exception {
super.setUp();
- Mockito.doReturn(mock(GeneratedClassLoadingStrategy.class)).when(this.extension).getClassLoadingStrategy();
- Mockito.doReturn(this.ribSupport).when(this.extension).getRIBSupport(any(TablesKey.class));
+ doReturn(mock(GeneratedClassLoadingStrategy.class)).when(this.extension).getClassLoadingStrategy();
+ doReturn(this.ribSupport).when(this.extension).getRIBSupport(any(TablesKey.class));
final NodeIdentifier nii = new NodeIdentifier(QName.create("", "test").intern());
- Mockito.doReturn(nii).when(this.ribSupport).routeAttributesIdentifier();
- Mockito.doReturn(ImmutableSet.of()).when(this.ribSupport).cacheableAttributeObjects();
+ doReturn(nii).when(this.ribSupport).routeAttributesIdentifier();
+ doReturn(ImmutableSet.of()).when(this.ribSupport).cacheableAttributeObjects();
final MapEntryNode emptyTable = mock(MapEntryNode.class);
- Mockito.doReturn(emptyTable).when(this.ribSupport).emptyTable();
+ doReturn(emptyTable).when(this.ribSupport).emptyTable();
final NodeIdentifierWithPredicates niie = new NodeIdentifierWithPredicates(Rib.QNAME,
ImmutableMap.of(QName.create("", "test").intern(), "t"));
- Mockito.doReturn(niie).when(emptyTable).getIdentifier();
- Mockito.doReturn(QName.create("", "test").intern()).when(emptyTable).getNodeType();
- Mockito.doReturn(this.domTx).when(this.domDataBroker).createTransactionChain(any());
+ doReturn(niie).when(emptyTable).getIdentifier();
+ doReturn(QName.create("", "test").intern()).when(emptyTable).getNodeType();
+ doReturn(this.domTx).when(this.domDataBroker).createTransactionChain(any());
final DOMDataTreeChangeService dOMDataTreeChangeService = mock(DOMDataTreeChangeService.class);
- Mockito.doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, dOMDataTreeChangeService))
+ doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, dOMDataTreeChangeService))
.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)
+ doReturn(this.dataTreeRegistration).when(this.domSchemaService).registerSchemaContextListener(any());
+ doNothing().when(this.dataTreeRegistration).close();
+ doReturn(mock(ListenerRegistration.class)).when(dOMDataTreeChangeService)
.registerDataTreeChangeListener(any(), any());
- Mockito.doNothing().when(this.serviceRegistration).unregister();
+ doNothing().when(this.serviceRegistration).unregister();
}
@Test