use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class SynchronizationAndExceptionTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
final List<OptionalCapabilities> capa = new ArrayList<>();
capa.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().setRestartTime(Uint16.ZERO).build()).build()).setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(AS_NUMBER).build()).build()).build());
capa.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
this.classicOpen = new OpenBuilder().setMyAsNumber(Uint16.valueOf(AS_NUMBER.getValue())).setHoldTimer(Uint16.valueOf(HOLD_TIMER)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(capa).build())).setBgpIdentifier(BGP_ID).build();
doReturn(null).when(mock(ChannelFuture.class)).addListener(any());
doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
doReturn(true).when(this.speakerListener).isActive();
doAnswer(invocation -> {
final Runnable command = invocation.getArgument(0);
final long delay = (long) invocation.getArgument(1);
final TimeUnit unit = invocation.getArgument(2);
GlobalEventExecutor.INSTANCE.schedule(command, delay, unit);
return null;
}).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn("TestingChannel").when(this.speakerListener).toString();
doReturn(true).when(this.speakerListener).isWritable();
doReturn(new InetSocketAddress(InetAddress.getByName(BGP_ID.getValue()), 179)).when(this.speakerListener).remoteAddress();
doReturn(new InetSocketAddress(InetAddress.getByName(LOCAL_IP), LOCAL_PORT)).when(this.speakerListener).localAddress();
doReturn(this.pipeline).when(this.speakerListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(null).when(this.pipeline).replace(ArgumentMatchers.<Class<ChannelHandler>>any(), any(String.class), any(ChannelHandler.class));
doReturn(this.pipeline).when(this.pipeline).addLast(any(ChannelHandler.class));
final ChannelFuture futureChannel = mock(ChannelFuture.class);
doReturn(null).when(futureChannel).addListener(any());
doReturn(futureChannel).when(this.speakerListener).close();
doReturn(futureChannel).when(this.speakerListener).writeAndFlush(any(Notify.class));
doReturn(this.domChain).when(this.domBroker).createMergingTransactionChain(any());
doReturn(this.tx).when(this.domChain).newWriteOnlyTransaction();
final DOMDataTreeChangeService dOMDataTreeChangeService = mock(DOMDataTreeChangeService.class);
final ListenerRegistration<?> listener = mock(ListenerRegistration.class);
doReturn(listener).when(dOMDataTreeChangeService).registerDataTreeChangeListener(any(), any());
doNothing().when(listener).close();
doNothing().when(this.domChain).close();
doReturn(ImmutableClassToInstanceMap.of(DOMDataTreeChangeService.class, dOMDataTreeChangeService)).when(this.domBroker).getExtensions();
doNothing().when(this.tx).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doNothing().when(this.tx).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doNothing().when(this.tx).delete(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
doReturn(CommitInfo.emptyFluentFuture()).when(this.tx).commit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class BGPSessionImplTest method testBGPSession.
@Test
public void testBGPSession() throws BGPDocumentedException {
this.bgpSession.sessionUp();
assertEquals(State.UP, this.bgpSession.getState());
assertEquals(AS_NUMBER, this.bgpSession.getAsNumber());
assertEquals(BGP_ID, this.bgpSession.getBgpId());
assertEquals(1, this.bgpSession.getAdvertisedTableTypes().size());
assertEquals(State.UP, this.listener.getState());
this.bgpSession.handleMessage(new UpdateBuilder().build());
assertEquals(1, this.listener.getListMsg().size());
assertTrue(this.listener.getListMsg().get(0) instanceof Update);
this.bgpSession.close();
assertEquals(State.IDLE, this.bgpSession.getState());
assertEquals(1, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(0) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(0);
assertEquals(BGPError.CEASE.getCode(), error.getErrorCode());
assertEquals(BGPError.CEASE.getSubcode(), error.getErrorSubcode());
verify(this.speakerListener).close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class BGPSessionImplTest method testHoldTimerExpire.
@Test
public void testHoldTimerExpire() throws InterruptedException {
this.bgpSession.sessionUp();
checkIdleState(this.listener);
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(2);
assertEquals(BGPError.HOLD_TIMER_EXPIRED.getCode(), error.getErrorCode());
assertEquals(BGPError.HOLD_TIMER_EXPIRED.getSubcode(), error.getErrorSubcode());
verify(this.speakerListener).close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class BGPSessionImplTest method setUp.
@Before
public void setUp() throws UnknownHostException {
MockitoAnnotations.initMocks(this);
final List<OptionalCapabilities> capa = new ArrayList<>();
capa.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().build()).build()).setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(AS_NUMBER).build()).build()).build());
capa.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
this.classicOpen = new OpenBuilder().setMyAsNumber(Uint16.valueOf(AS_NUMBER.getValue())).setHoldTimer(HOLD_TIMER).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(capa).build())).setBgpIdentifier(BGP_ID).build();
final ChannelFuture f = mock(ChannelFuture.class);
doReturn(null).when(f).addListener(any());
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
BGPSessionImplTest.this.receivedMsgs.add((Notification) args[0]);
return f;
}).when(this.speakerListener).writeAndFlush(any(Notification.class));
doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
doReturn(true).when(this.speakerListener).isActive();
doAnswer(invocation -> {
final Runnable command = (Runnable) invocation.getArguments()[0];
final long delay = (long) invocation.getArguments()[1];
final TimeUnit unit = (TimeUnit) invocation.getArguments()[2];
GlobalEventExecutor.INSTANCE.schedule(command, delay, unit);
return null;
}).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn("TestingChannel").when(this.speakerListener).toString();
doReturn(true).when(this.speakerListener).isWritable();
doReturn(new InetSocketAddress(InetAddress.getByName(BGP_ID.getValue()), 179)).when(this.speakerListener).remoteAddress();
doReturn(new InetSocketAddress(InetAddress.getByName(LOCAL_IP), LOCAL_PORT)).when(this.speakerListener).localAddress();
doReturn(this.pipeline).when(this.speakerListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(null).when(this.pipeline).replace(ArgumentMatchers.<Class<ChannelHandler>>any(), any(String.class), any(ChannelHandler.class));
doReturn(this.pipeline).when(this.pipeline).addLast(any(ChannelHandler.class));
final ChannelFuture futureChannel = mock(ChannelFuture.class);
doReturn(null).when(futureChannel).addListener(any());
doReturn(futureChannel).when(this.speakerListener).close();
this.listener = new SimpleSessionListener();
this.bgpSession = new BGPSessionImpl(this.listener, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer().toJava(), null);
this.bgpSession.setChannelExtMsgCoder(this.classicOpen);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class AddPathBasePathsTest method testUseCase1.
/*
* Base-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)--> | | --(eBgp, non 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);
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, nonAddPathParams, PeerRole.Ebgp, this.serverRegistry);
final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
checkPeersPresentOnDataStore(5);
// new best route so far
sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 2);
assertEquals(UPD_NA_100, listener4.getListMsg().get(1));
assertEquals(UPD_NA_100_EBGP, listener5.getListMsg().get(1));
// the second best route
sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 100, 1);
checkReceivedMessages(listener4, 2);
checkReceivedMessages(listener5, 2);
// new best route
sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 1);
checkReceivedMessages(listener4, 3);
checkReceivedMessages(listener5, 3);
assertEquals(UPD_NA_200, listener4.getListMsg().get(2));
assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(2));
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_200, listener6.getListMsg().get(1));
session6.close();
checkPeersPresentOnDataStore(5);
// best route updated to be the worse one
sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 1);
checkReceivedMessages(listener4, 4);
checkReceivedMessages(listener5, 4);
assertEquals(UPD_NA_100, listener4.getListMsg().get(3));
assertEquals(UPD_NA_100_EBGP, listener5.getListMsg().get(3));
// Remove second best, no advertisement should be done
sendWithdrawalRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 1);
checkReceivedMessages(listener4, 4);
checkReceivedMessages(listener5, 4);
// Remove best, 1 advertisement
sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
checkReceivedMessages(listener4, 5);
checkReceivedMessages(listener5, 5);
// Remove best, 1 withdrawal
sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 0);
checkReceivedMessages(listener4, 6);
checkReceivedMessages(listener5, 6);
session1.close();
session2.close();
session3.close();
session4.close();
session5.close();
}
Aggregations