use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class AbstractBmpMessageParser method parseMessage.
@Override
public final Notification parseMessage(final ByteBuf bytes) throws BmpDeserializationException {
Preconditions.checkArgument(bytes != null && bytes.isReadable());
final Notification parsedMessage = parseMessageBody(bytes);
LOG.trace("Parsed BMP message: {}", parsedMessage);
return parsedMessage;
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class BmpMockTest method testMain.
@Test
public void testMain() throws Exception {
final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
final ChannelFuture futureServer = this.bmpDispatcher.createServer(serverAddr, bmpSessionListenerFactory, KeyMapping.getKeyMapping());
waitFutureSuccess(futureServer);
final Channel serverChannel;
final int sessionUpWait;
if (futureServer.isSuccess()) {
serverChannel = futureServer.channel();
sessionUpWait = 10;
} else {
serverChannel = null;
// wait longer for the reconnection attempt
sessionUpWait = 40;
}
BmpMock.main(new String[] { "--remote_address", InetSocketAddressUtil.toHostAndPort(serverAddr).toString(), "--peers_count", "3", "--pre_policy_routes", "3" });
verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(sessionUpWait))).onSessionUp(Mockito.any(BmpSession.class));
// 1 * Initiate message + 3 * PeerUp Notification + 9 * Route Monitoring message
verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10)).times(13)).onMessage(Mockito.any(Notification.class));
if (serverChannel != null) {
serverChannel.close().sync();
}
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class PeerDownHandler method parseBgpNotificationMessage.
private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.Notification parseBgpNotificationMessage(final ByteBuf bytes) throws BmpDeserializationException {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder notificationCBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder notificationBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder();
try {
final Notification not = this.msgRegistry.parseMessage(bytes, null);
requireNonNull(not, "Notify message may not be null.");
Preconditions.checkArgument(not instanceof NotifyMessage, "An instance of NotifyMessage is required");
notificationBuilder.fieldsFrom((NotifyMessage) not);
notificationCBuilder.setNotification(notificationBuilder.build());
} catch (final BGPDocumentedException | BGPParsingException e) {
throw new BmpDeserializationException("Error while parsing BGP Notification message.", e);
}
return notificationCBuilder.build();
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class MockedNotificationServiceWrapper method getMockedNotificationService.
NotificationPublishService getMockedNotificationService() throws InterruptedException {
final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
doAnswer(invocation -> {
final Object notif = invocation.getArguments()[0];
assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
MockedNotificationServiceWrapper.this.publishedNotifications.add((Notification) notif);
return null;
}).when(mockedNotificationService).putNotification(any(Notification.class));
return mockedNotificationService;
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class AbstractPCEPSessionTest method setUp.
@Before
public final void setUp() {
MockitoAnnotations.initMocks(this);
final ChannelFuture future = new DefaultChannelPromise(this.channel);
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
AbstractPCEPSessionTest.this.msgsSend.add((Notification) args[0]);
return future;
}).when(this.channel).writeAndFlush(any(Notification.class));
doReturn(this.channelFuture).when(this.channel).closeFuture();
doReturn(this.channelFuture).when(this.channelFuture).addListener(any(GenericFutureListener.class));
doReturn("TestingChannel").when(this.channel).toString();
doReturn(this.pipeline).when(this.channel).pipeline();
doReturn(this.address).when(this.channel).localAddress();
doReturn(this.address).when(this.channel).remoteAddress();
doReturn(this.eventLoop).when(this.channel).eventLoop();
doReturn(true).when(this.future).cancel(false);
doReturn(this.future).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(this.pipeline).when(this.pipeline).addFirst(any(ChannelHandler.class));
doReturn(true).when(this.channel).isActive();
doReturn(mock(ChannelFuture.class)).when(this.channel).close();
doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).remoteAddress();
doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).localAddress();
this.openMsg = new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setDeadTimer(DEADTIMER).setKeepalive(KEEP_ALIVE).setSessionId((short) 0).build()).build()).build();
this.kaMsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
this.startTlsMsg = new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build();
this.closeMsg = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason((short) 6).build()).build()).build();
this.listener = new SimpleSessionListener();
}
Aggregations