Search in sources :

Example 26 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class StrictBGPPeerRegistryTest method testAsMismatch.

@Test
public void testAsMismatch() {
    final AsNumber as2 = new AsNumber(Uint32.valueOf(3));
    this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
    try {
        this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
    } catch (final BGPDocumentedException e) {
        assertEquals(BGPError.BAD_PEER_AS, e.getError());
        return;
    }
    fail("Peer AS number mismatch");
}
Also used : BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Test(org.junit.Test)

Example 27 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class BgpPeerTest method testBgpPeer.

@Test
public void testBgpPeer() throws ExecutionException, InterruptedException {
    final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig()).setNeighborAddress(NEIGHBOR_ADDRESS).setRouteReflector(createRR()).setTimers(createTimers()).setTransport(createTransport()).setAddPaths(createAddPath()).build();
    bgpPeer.start(rib, neighbor, null, peerGroupLoader, tableTypeRegistry);
    verify(rib).createPeerDOMChain(any());
    verify(rib, times(2)).getLocalAs();
    verify(rib).getLocalTables();
    bgpPeer.instantiateServiceInstance();
    verify(bgpPeerRegistry).addPeer(any(), any(), any());
    verify(dispatcher).createReconnectingClient(any(InetSocketAddress.class), any(), anyInt(), any(KeyMapping.class));
    final var ex = assertThrows(IllegalStateException.class, () -> bgpPeer.start(rib, neighbor, null, peerGroupLoader, tableTypeRegistry));
    assertEquals("Previous peer instance was not closed.", ex.getMessage());
    bgpPeer.closeServiceInstance();
    verify(bgpPeerRegistry).removePeer(any());
    verify(future).cancel(true);
    bgpPeer.stop().get();
    bgpPeer.start(rib, bgpPeer.getCurrentConfiguration(), null, peerGroupLoader, tableTypeRegistry);
    bgpPeer.instantiateServiceInstance();
    verify(rib, times(2)).createPeerDOMChain(any());
    verify(rib, times(4)).getLocalAs();
    verify(rib, times(2)).getLocalTables();
    verify(bgpPeerRegistry, times(2)).addPeer(any(), any(), any());
    verify(dispatcher, times(2)).createReconnectingClient(any(InetSocketAddress.class), any(), anyInt(), any(KeyMapping.class));
    final Neighbor neighborExpected = createNeighborExpected(NEIGHBOR_ADDRESS);
    assertTrue(bgpPeer.containsEqualConfiguration(neighborExpected));
    assertFalse(bgpPeer.containsEqualConfiguration(createNeighborExpected(new IpAddress(new Ipv4Address("127.0.0.2")))));
    bgpPeer.closeServiceInstance();
    verify(bgpPeerRegistry, times(2)).removePeer(any());
    verify(future, times(2)).cancel(true);
    bgpPeer.instantiateServiceInstance();
    verify(bgpPeerRegistry, times(3)).addPeer(any(), any(), any());
    verify(dispatcher, times(3)).createReconnectingClient(any(InetSocketAddress.class), any(), anyInt(), any(KeyMapping.class));
    bgpPeer.closeServiceInstance();
    verify(bgpPeerRegistry, times(3)).removePeer(any());
    verify(future, times(3)).cancel(true);
    verify(rib, times(3)).createPeerDOMChain(any());
    bgpPeer.stop().get();
    bgpPeer.start(rib, bgpPeer.getCurrentConfiguration(), null, peerGroupLoader, tableTypeRegistry);
    bgpPeer.instantiateServiceInstance();
    verify(rib, times(4)).createPeerDOMChain(any());
    verify(rib, times(6)).getLocalAs();
    verify(rib, times(3)).getLocalTables();
    verify(bgpPeerRegistry, times(4)).addPeer(any(), any(), any());
    verify(dispatcher, times(4)).createReconnectingClient(any(InetSocketAddress.class), any(), anyInt(), any(KeyMapping.class));
    bgpPeer.closeServiceInstance();
    verify(bgpPeerRegistry, times(4)).removePeer(any());
    verify(future, times(4)).cancel(true);
    bgpPeer.stop().get();
    final Neighbor neighborDiffConfig = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS).setAfiSafis(createAfiSafi()).build();
    bgpPeer.start(rib, neighborDiffConfig, null, peerGroupLoader, tableTypeRegistry);
    assertTrue(bgpPeer.containsEqualConfiguration(neighborDiffConfig));
    bgpPeer.stop().get();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Neighbor(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor) KeyMapping(org.opendaylight.protocol.concepts.KeyMapping) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NeighborBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 28 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class GracefulRestartTest method nonIpv4PeerGracefulRestart.

/**
 * Test graceful restart of a non-IPv4 peer.
 * {@link BGPPeer#releaseConnection(boolean)} should not throw NPE and binding chain should be closed
 * successfully.
 *
 * @throws InterruptedException on create peer session.
 */
@Test
public void nonIpv4PeerGracefulRestart() throws InterruptedException {
    BgpParameters parametersv6 = PeerUtil.createBgpParameters(Collections.singletonList(IPV6_TABLES_KEY), Collections.emptyList(), Collections.singletonMap(IPV6_TABLES_KEY, true), GRACEFUL_RESTART_TIME);
    gracefulAfiSafiAdvertised.add(IPV6_TABLES_KEY);
    this.nonIpv4 = configurePeer(this.tableRegistry, PEER2, this.ribImpl, parametersv6, PeerRole.Ibgp, this.serverRegistry, afiSafiAdvertised, gracefulAfiSafiAdvertised);
    this.sessionv6 = createPeerSession(PEER2, parametersv6, this.listener);
    final Open open = createClassicOpen(true);
    this.sessionv6.writeAndFlush(open);
    checkIdleState(this.nonIpv4);
    synchronized (this.nonIpv4) {
        assertNull(this.nonIpv4.ribOutChain);
    }
}
Also used : BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) Test(org.junit.Test)

Example 29 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class AddPathAllPathsTest method testUseCase1.

/*
     * All-Paths
     *                                            ___________________
     *                                           | ODL BGP 127.0.0.1 |
     * [peer://127.0.0.2; p1, lp100] --(iBGP)--> |                   | --(RR-client, non add-path) -->
     * [peer://127.0.0.3; p1, lp200] --(iBGP)--> |                   |     [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
     * [peer://127.0.0.4; p1, lp50] --(iBGP)-->  |                   | --(RR-client, add-path) -->
     * [peer://127.0.0.2; p1, lp20] --(iBGP)-->  |___________________|     [Peer://127.0.0.6; (p1, path-id1, lp100),
     * p1 = 1.1.1.1/32                                                      (p1, path-id2, pl50), (p1, path-id3, pl200),
     *                                                                      (p1, path-id4, pl20)]
     */
@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 BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
    configurePeer(this.tableRegistry, PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
    configurePeer(this.tableRegistry, PEER3, 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);
    BGPPeerState peer4State = peer4.getPeerState();
    assertNull(peer4State.getGroupId());
    assertEquals(new IpAddressNoZone(PEER4), peer4State.getNeighborAddress());
    assertEquals(0L, peer4State.getTotalPathsCount());
    assertEquals(0L, peer4State.getTotalPrefixes());
    assertNull(peer4State.getBGPTimersState());
    assertNull(peer4State.getBGPTransportState());
    assertNull(peer4State.getBGPSessionState());
    assertEquals(0L, peer4State.getBGPErrorHandlingState().getErroneousUpdateReceivedCount());
    BGPGracelfulRestartState gracefulRestart = peer4State.getBGPGracelfulRestart();
    assertFalse(gracefulRestart.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(gracefulRestart.isGracefulRestartReceived(TABLES_KEY));
    assertFalse(gracefulRestart.isLocalRestarting());
    assertFalse(gracefulRestart.isPeerRestarting());
    assertEquals(0L, gracefulRestart.getPeerRestartTime());
    BGPAfiSafiState afiSafiState = peer4State.getBGPAfiSafiState();
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiState.getAfiSafisAdvertized());
    assertEquals(Collections.emptySet(), afiSafiState.getAfiSafisReceived());
    assertEquals(0L, afiSafiState.getPrefixesSentCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesReceivedCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesInstalledCount(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isLocalRestarting());
    assertFalse(afiSafiState.isPeerRestarting());
    assertFalse(afiSafiState.isAfiSafiSupported(TABLES_KEY));
    final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
    final SimpleSessionListener listener5 = new SimpleSessionListener();
    configurePeer(this.tableRegistry, PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
    checkPeersPresentOnDataStore(5);
    // the best route
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 2);
    assertEquals(UPD_100, listener5.getListMsg().get(1));
    final BGPPeerState peer1State = peer1.getPeerState();
    assertNull(peer1State.getGroupId());
    assertEquals(new IpAddressNoZone(PEER1), peer1State.getNeighborAddress());
    assertEquals(1L, peer1State.getTotalPathsCount());
    assertEquals(1L, peer1State.getTotalPrefixes());
    final BGPTimersState timerStatePeer1 = peer1State.getBGPTimersState();
    assertEquals(HOLDTIMER, timerStatePeer1.getNegotiatedHoldTime());
    assertTrue(timerStatePeer1.getUpTime() > 0L);
    final BGPTransportState transportStatePeer1 = peer1State.getBGPTransportState();
    assertEquals(new PortNumber(PORT), transportStatePeer1.getLocalPort());
    assertEquals(new IpAddressNoZone(PEER1), transportStatePeer1.getRemoteAddress());
    assertEquals(State.UP, peer1State.getBGPSessionState().getSessionState());
    checkEquals(() -> assertEquals(1L, peer1State.getBGPPeerMessagesState().getUpdateMessagesReceivedCount()));
    checkEquals(() -> assertEquals(1L, peer1State.getBGPPeerMessagesState().getUpdateMessagesSentCount()));
    final BGPSessionState sessionStatePeer1 = peer1State.getBGPSessionState();
    assertFalse(sessionStatePeer1.isAddPathCapabilitySupported());
    assertFalse(sessionStatePeer1.isAsn32CapabilitySupported());
    assertFalse(sessionStatePeer1.isGracefulRestartCapabilitySupported());
    assertTrue(sessionStatePeer1.isMultiProtocolCapabilitySupported());
    assertFalse(sessionStatePeer1.isRouterRefreshCapabilitySupported());
    final BGPAfiSafiState afiSafiStatePeer1 = peer1State.getBGPAfiSafiState();
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiStatePeer1.getAfiSafisAdvertized());
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiStatePeer1.getAfiSafisReceived());
    assertEquals(0L, afiSafiStatePeer1.getPrefixesSentCount(TABLES_KEY));
    assertEquals(1L, afiSafiStatePeer1.getPrefixesReceivedCount(TABLES_KEY));
    assertEquals(1L, afiSafiStatePeer1.getPrefixesInstalledCount(TABLES_KEY));
    assertFalse(afiSafiStatePeer1.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiStatePeer1.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiStatePeer1.isLocalRestarting());
    assertFalse(afiSafiStatePeer1.isPeerRestarting());
    assertTrue(afiSafiStatePeer1.isAfiSafiSupported(TABLES_KEY));
    final BGPRibState ribState = this.ribImpl.getRIBState();
    assertEquals(1, ribState.getPathsCount().size());
    assertEquals(1L, ribState.getTablesPrefixesCount().size());
    assertEquals(BGP_ID, ribState.getRouteId());
    assertEquals(AS_NUMBER, ribState.getAs());
    assertEquals(1L, ribState.getPathCount(TABLES_KEY));
    assertEquals(1L, ribState.getPrefixesCount(TABLES_KEY));
    assertEquals(1L, ribState.getTotalPathsCount());
    assertEquals(1L, ribState.getTotalPrefixesCount());
    final SimpleSessionListener listener6 = new SimpleSessionListener();
    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, 2);
    assertEquals(UPD_NA_100, listener6.getListMsg().get(1));
    causeBGPError(session6);
    checkEquals(() -> assertEquals(1L, peer6.getPeerState().getBGPPeerMessagesState().getNotificationMessagesSentCount()));
    checkPeersPresentOnDataStore(5);
    // the second best route
    sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 3);
    assertEquals(UPD_50, listener5.getListMsg().get(2));
    // new best route
    sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 3);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 4);
    assertEquals(UPD_200, listener5.getListMsg().get(3));
    peer4State = peer4.getPeerState();
    assertNull(peer4State.getGroupId());
    assertEquals(new IpAddressNoZone(PEER4), peer4State.getNeighborAddress());
    assertEquals(0L, peer4State.getTotalPathsCount());
    assertEquals(0L, peer4State.getTotalPrefixes());
    final BGPTimersState timerState = peer4State.getBGPTimersState();
    assertEquals(HOLDTIMER, timerState.getNegotiatedHoldTime());
    assertTrue(timerState.getUpTime() > 0L);
    final BGPTransportState transportState = peer4State.getBGPTransportState();
    assertEquals(new PortNumber(PORT), transportState.getLocalPort());
    assertEquals(new IpAddressNoZone(PEER4), transportState.getRemoteAddress());
    final BGPPeerMessagesState peerMessagesState = peer4State.getBGPPeerMessagesState();
    assertEquals(0L, peerMessagesState.getNotificationMessagesReceivedCount());
    assertEquals(0L, peerMessagesState.getNotificationMessagesSentCount());
    assertEquals(0L, peerMessagesState.getUpdateMessagesReceivedCount());
    assertEquals(3L, peerMessagesState.getUpdateMessagesSentCount());
    final BGPSessionState bgpSessionState = peer4State.getBGPSessionState();
    assertEquals(State.UP, bgpSessionState.getSessionState());
    assertFalse(bgpSessionState.isAddPathCapabilitySupported());
    assertFalse(bgpSessionState.isAsn32CapabilitySupported());
    assertFalse(bgpSessionState.isGracefulRestartCapabilitySupported());
    assertTrue(bgpSessionState.isMultiProtocolCapabilitySupported());
    assertFalse(bgpSessionState.isRouterRefreshCapabilitySupported());
    final BGPErrorHandlingState errorHandling = peer4State.getBGPErrorHandlingState();
    assertEquals(0L, errorHandling.getErroneousUpdateReceivedCount());
    gracefulRestart = peer4State.getBGPGracelfulRestart();
    assertFalse(gracefulRestart.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(gracefulRestart.isGracefulRestartReceived(TABLES_KEY));
    assertFalse(gracefulRestart.isLocalRestarting());
    assertFalse(gracefulRestart.isPeerRestarting());
    assertEquals(0L, gracefulRestart.getPeerRestartTime());
    afiSafiState = peer4State.getBGPAfiSafiState();
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiState.getAfiSafisAdvertized());
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiState.getAfiSafisReceived());
    assertEquals(2L, afiSafiState.getPrefixesSentCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesReceivedCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesInstalledCount(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isLocalRestarting());
    assertFalse(afiSafiState.isPeerRestarting());
    assertTrue(afiSafiState.isAfiSafiSupported(TABLES_KEY));
    // the worst route
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 20, 3);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 5);
    assertEquals(UPD_200.getAttributes().getLocalPref(), ((Update) listener4.getListMsg().get(2)).getAttributes().getLocalPref());
    assertEquals(UPD_20, listener5.getListMsg().get(4));
    // withdraw second best route, 1 advertisement(1 withdrawal) for add-path supported, none for non add path
    sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 6);
    // we advertise again to try new test
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 3);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 7);
    assertEquals(UPD_200, listener5.getListMsg().get(3));
    // withdraw second best route, 1 advertisement(1 withdrawal) for add-path supported, 1 for non add path
    // (withdrawal)
    sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
    checkReceivedMessages(listener4, 4);
    checkReceivedMessages(listener5, 8);
    sendNotification(session1);
    checkEquals(() -> assertEquals(1L, peer1.getPeerState().getBGPPeerMessagesState().getNotificationMessagesReceivedCount()));
    session1.close();
    session2.close();
    session3.close();
    session4.close();
    session5.close();
}
Also used : BGPTimersState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState) BGPTransportState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState) BGPSessionState(org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState) BGPPeerState(org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) BGPAfiSafiState(org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState) BGPRibState(org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState) BGPPeerMessagesState(org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerMessagesState) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) BGPGracelfulRestartState(org.opendaylight.protocol.bgp.rib.spi.state.BGPGracelfulRestartState) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) BGPErrorHandlingState(org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState) Test(org.junit.Test)

Example 30 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class AddPathNPathsTest method testUseCase1.

/*
     * N-Paths
     *                                            ___________________
     *                                           | ODL BGP 127.0.0.1 |
     * [peer://127.0.0.2; p1, lp100] --(iBGP)--> |                   | --(RR-client, non add-path) -->
     * [peer://127.0.0.3; p1, lp200] --(iBGP)--> |                   |     [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
     * [peer://127.0.0.4; p1, lp50] --(iBGP)-->  |                   | --(RR-client, add-path) -->
     * [peer://127.0.0.2; p1, lp20] --(iBGP)-->  |___________________|     [Peer://127.0.0.6; (p1, path-id1, lp100),
     * p1 = 1.1.1.1/32                                                      (p1, path-id2, pl50), (p1, path-id3, pl200)]
     */
@Test
public void testUseCase1() throws Exception {
    final BgpParameters nonAddPathParams = createParameter(false);
    final BgpParameters addPathParams = createParameter(true);
    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 session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
    configurePeer(this.tableRegistry, PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
    final SimpleSessionListener listener4 = new SimpleSessionListener();
    configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
    final SimpleSessionListener listener5 = new SimpleSessionListener();
    configurePeer(this.tableRegistry, PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
    checkPeersPresentOnDataStore(5);
    // new best route so far
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 2);
    assertEquals(UPD_100, listener5.getListMsg().get(1));
    final SimpleSessionListener listener6 = new SimpleSessionListener();
    configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
    checkPeersPresentOnDataStore(6);
    checkReceivedMessages(listener6, 2);
    assertEquals(UPD_NA_100, listener6.getListMsg().get(1));
    session6.close();
    checkPeersPresentOnDataStore(5);
    // the second best route
    sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 3);
    assertEquals(UPD_50, listener5.getListMsg().get(2));
    // new best route
    sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 4);
    assertEquals(UPD_200, listener5.getListMsg().get(3));
    // the worst prefix, no changes
    sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 20, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 4);
    // withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, none for non add path
    sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 6);
    // we advertise again to try new test
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 7);
    // 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, 4);
    checkReceivedMessages(listener5, 9);
    session1.close();
    session2.close();
    session3.close();
    session4.close();
    session5.close();
}
Also used : BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 ByteBuf (io.netty.buffer.ByteBuf)13 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)11 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)9 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)8 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)8 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 ArrayList (java.util.ArrayList)6 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)5 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)5 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)5 PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)5 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)4 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)4 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)4