use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class BmpMockSession method channelActive.
@Override
public void channelActive(final ChannelHandlerContext ctx) {
this.channel = ctx.channel();
this.channel.closeFuture().addListener((ChannelFutureListener) future -> LOG.info("BMP session {} close.", BmpMockSession.this.channel));
LOG.info("BMP session {} successfully established.", this.channel);
final InetSocketAddress localAddress = (InetSocketAddress) this.channel.localAddress();
this.remoteAddress = (InetSocketAddress) this.channel.remoteAddress();
advertizePeers(localAddress);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class BmpMonitoringStationImpl method closeServiceInstance.
@Override
public synchronized ListenableFuture<Void> closeServiceInstance() {
LOG.info("BMP Monitor Singleton Service {} instance closed, Monitor Id {}", getIdentifier().getValue(), this.monitorId.getValue());
if (this.channel != null) {
this.channel.close().addListener((ChannelFutureListener) future -> {
Preconditions.checkArgument(future.isSuccess(), "Channel failed to close: %s", future.cause());
BmpMonitoringStationImpl.this.sessionManager.close();
});
}
final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, this.yangMonitorId);
LOG.info("BMP monitoring station {} closed.", this.monitorId.getValue());
return wTx.submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class BGPSessionImplTest method setUp.
@Before
public void setUp() throws UnknownHostException {
new EmbeddedChannel();
MockitoAnnotations.initMocks(this);
final List<BgpParameters> tlvs = Lists.newArrayList();
this.classicOpen = new OpenBuilder().setMyAsNumber(AS_NUMBER.getValue().intValue()).setHoldTimer(HOLD_TIMER).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(tlvs).setBgpIdentifier(BGP_ID).build();
final List<OptionalCapabilities> capa = Lists.newArrayList();
capa.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, 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());
tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capa).build());
final ChannelFuture f = mock(ChannelFuture.class);
doReturn(null).when(f).addListener(Mockito.any());
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
BGPSessionImplTest.this.receivedMsgs.add((Notification) args[0]);
return f;
}).when(this.speakerListener).writeAndFlush(Mockito.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(Mockito.any(Runnable.class), Mockito.any(long.class), Mockito.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(Mockito.any(ChannelHandler.class), Mockito.any(String.class), Mockito.any(ChannelHandler.class));
doReturn(null).when(this.pipeline).replace(Matchers.<Class<ChannelHandler>>any(), Mockito.any(String.class), Mockito.any(ChannelHandler.class));
doReturn(this.pipeline).when(this.pipeline).addLast(Mockito.any(ChannelHandler.class));
final ChannelFuture futureChannel = mock(ChannelFuture.class);
doReturn(null).when(futureChannel).addListener(Mockito.any());
doReturn(futureChannel).when(this.speakerListener).close();
this.listener = new SimpleSessionListener();
this.bgpSession = new BGPSessionImpl(this.listener, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null);
this.bgpSession.setChannelExtMsgCoder(this.classicOpen);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class BGPSessionImplTest method testHoldTimerExpire.
@Test
public void testHoldTimerExpire() throws InterruptedException {
this.bgpSession.sessionUp();
checkIdleState(this.listener);
Assert.assertEquals(3, this.receivedMsgs.size());
Assert.assertTrue(this.receivedMsgs.get(2) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(2);
Assert.assertEquals(BGPError.HOLD_TIMER_EXPIRED.getCode(), error.getErrorCode().shortValue());
Assert.assertEquals(BGPError.HOLD_TIMER_EXPIRED.getSubcode(), error.getErrorSubcode().shortValue());
Mockito.verify(this.speakerListener).close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.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());
Assert.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().shortValue());
assertEquals(BGPError.CEASE.getSubcode(), error.getErrorSubcode().shortValue());
Mockito.verify(this.speakerListener).close();
}
Aggregations