use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress in project bgpcep by opendaylight.
the class AbstractBGPDispatcherTest method setUp.
@Before
public void setUp() {
if (!Epoll.isAvailable()) {
this.boss = new NioEventLoopGroup();
this.worker = new NioEventLoopGroup();
}
this.registry = new StrictBGPPeerRegistry();
this.clientListener = new SimpleSessionListener();
this.serverListener = new SimpleSessionListener();
final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);
this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(this.clientAddress.getAddress().getHostAddress()));
this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(this.clientAddress));
this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress 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.5; (p1, lp100), (p1, lp1200)]
* [peer://127.0.0.3; p1, lp200] --(iBGP)--> | |
* [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(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
configurePeer(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(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
BGPPeerState peer4State = peer4.getPeerState();
assertNull(peer4State.getGroupId());
assertEquals(new IpAddress(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(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, 1);
checkReceivedMessages(listener5, 1);
assertEquals(UPD_100, listener5.getListMsg().get(0));
final BGPPeerState peer1State = peer1.getPeerState();
assertNull(peer1State.getGroupId());
assertEquals(new IpAddress(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 IpAddress(PEER1), transportStatePeer1.getRemoteAddress());
assertEquals(State.UP, peer1State.getBGPSessionState().getSessionState());
checkEquals(() -> assertEquals(1L, peer1State.getBGPPeerMessagesState().getUpdateMessagesReceivedCount()));
checkEquals(() -> assertEquals(0L, 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(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()));
checkPeersPresentOnDataStore(5);
// the second best route
sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
checkReceivedMessages(listener4, 1);
checkReceivedMessages(listener5, 2);
assertEquals(UPD_50, listener5.getListMsg().get(1));
// new best route
sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 3);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 3);
assertEquals(UPD_200, listener5.getListMsg().get(2));
peer4State = peer4.getPeerState();
assertNull(peer4State.getGroupId());
assertEquals(new IpAddress(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 IpAddress(PEER4), transportState.getRemoteAddress());
final BGPPeerMessagesState peerMessagesState = peer4State.getBGPPeerMessagesState();
assertEquals(0L, peerMessagesState.getNotificationMessagesReceivedCount());
assertEquals(0L, peerMessagesState.getNotificationMessagesSentCount());
assertEquals(0L, peerMessagesState.getUpdateMessagesReceivedCount());
assertEquals(2L, 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, 2);
checkReceivedMessages(listener5, 4);
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
sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 5);
// we advertise again to try new test
sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 3);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 6);
assertEquals(UPD_200, listener5.getListMsg().get(2));
// 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, 3);
checkReceivedMessages(listener5, 7);
sendNotification(session1);
checkEquals(() -> assertEquals(1L, peer1.getPeerState().getBGPPeerMessagesState().getNotificationMessagesReceivedCount()));
session1.close();
session2.close();
session3.close();
session4.close();
session5.close();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress in project bgpcep by opendaylight.
the class AppPeerTest method testAppPeer.
@Test
public void testAppPeer() {
APP_PEER.start(this.rib, this.neighbor, null, this.peerGroupLoader, this.tableTypeRegistry);
Mockito.verify(this.rib).getYangRibId();
Mockito.verify(this.rib).getService();
Mockito.verify(this.rib, times(1)).getLocalTablesKeys();
APP_PEER.instantiateServiceInstance();
Mockito.verify(this.rib, times(2)).getYangRibId();
Mockito.verify(this.rib, times(2)).getRibSupportContext();
Mockito.verify(this.rib, times(2)).getLocalTablesKeys();
Mockito.verify(this.domTx).newWriteOnlyTransaction();
APP_PEER.closeServiceInstance();
APP_PEER.close();
APP_PEER.restart(this.rib, null, this.peerGroupLoader, this.tableTypeRegistry);
APP_PEER.instantiateServiceInstance();
Mockito.verify(this.rib, times(4)).getYangRibId();
Mockito.verify(this.rib, times(2)).getService();
Mockito.verify(this.listener).close();
assertTrue(APP_PEER.containsEqualConfiguration(this.neighbor));
assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
APP_PEER.closeServiceInstance();
APP_PEER.close();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress in project bgpcep by opendaylight.
the class BgpPeerTest method testBgpPeer.
@Test
public void testBgpPeer() {
final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig()).setNeighborAddress(NEIGHBOR_ADDRESS).setRouteReflector(createRR()).setTimers(createTimers()).setTransport(createTransport()).setAddPaths(createAddPath()).build();
this.bgpPeer.start(this.rib, neighbor, null, this.peerGroupLoader, this.tableTypeRegistry);
Mockito.verify(this.rib).createPeerDOMChain(any());
Mockito.verify(this.rib, times(2)).getLocalAs();
Mockito.verify(this.rib).getLocalTables();
this.bgpPeer.instantiateServiceInstance();
Mockito.verify(this.bgpPeerRegistry).addPeer(any(), any(), any());
Mockito.verify(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class), anyInt(), any(KeyMapping.class));
try {
this.bgpPeer.start(this.rib, neighbor, null, this.peerGroupLoader, this.tableTypeRegistry);
fail("Expected Exception");
} catch (final IllegalStateException expected) {
assertEquals("Previous peer instance was not closed.", expected.getMessage());
}
this.bgpPeer.setServiceRegistration(this.serviceRegistration);
this.bgpPeer.closeServiceInstance();
this.bgpPeer.close();
Mockito.verify(this.future).cancel(true);
this.bgpPeer.restart(this.rib, null, this.peerGroupLoader, this.tableTypeRegistry);
this.bgpPeer.instantiateServiceInstance();
Mockito.verify(this.rib, times(2)).createPeerDOMChain(any());
Mockito.verify(this.rib, times(4)).getLocalAs();
Mockito.verify(this.rib, times(2)).getLocalTables();
final Neighbor neighborExpected = createNeighborExpected(NEIGHBOR_ADDRESS);
assertTrue(this.bgpPeer.containsEqualConfiguration(neighborExpected));
assertFalse(this.bgpPeer.containsEqualConfiguration(createNeighborExpected(new IpAddress(new Ipv4Address("127.0.0.2")))));
Mockito.verify(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
this.bgpPeer.closeServiceInstance();
this.bgpPeer.close();
Mockito.verify(this.serviceRegistration).unregister();
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, null, this.peerGroupLoader, this.tableTypeRegistry);
assertTrue(this.bgpPeer.containsEqualConfiguration(neighborDiffConfig));
this.bgpPeer.close();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testPeerConnectionSuccessfull.
@Test
public void testPeerConnectionSuccessfull() throws Exception {
final Ipv4Address to2 = new Ipv4Address("255.255.255.254");
final IpAddress remoteIp2 = new IpAddress(to2);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
final BGPSessionListener session2 = getMockSession();
this.peerRegistry.addPeer(remoteIp2, session2, this.mockPreferences);
final BGPSessionListener returnedSession1 = this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
assertSame(this.peer1, returnedSession1);
final BGPSessionListener returnedSession2 = this.peerRegistry.getPeer(remoteIp2, FROM, to2, this.classicOpen);
assertSame(session2, returnedSession2);
Mockito.verifyZeroInteractions(this.peer1);
Mockito.verifyZeroInteractions(session2);
}
Aggregations