use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class AbstractAddPathTest method sendNotification.
void sendNotification(final BGPSessionImpl session) {
final Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
waitFutureSuccess(session.writeAndFlush(notMsg));
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class FSMTest method sendNotification.
@Test
public void sendNotification() {
this.clientSession.channelActive(null);
this.clientSession.handleMessage(this.classicOpen);
this.clientSession.handleMessage(new KeepaliveBuilder().build());
assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.FINISHED);
this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).build());
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Notify);
final Notification m = this.receivedMsgs.get(2);
assertEquals(BGPError.FSM_ERROR.getCode(), ((Notify) m).getErrorCode().shortValue());
assertEquals(BGPError.FSM_ERROR.getSubcode(), ((Notify) m).getErrorSubcode().shortValue());
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class AbstractPCEPSessionTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
this.receivedMsgs = new ArrayList<>();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
return this.channelFuture;
}).when(this.clientListener).writeAndFlush(any(Notification.class));
doReturn(null).when(this.channelFuture).addListener(Mockito.any());
doReturn("TestingChannel").when(this.clientListener).toString();
doReturn(this.pipeline).when(this.clientListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(this.eventLoop).when(this.clientListener).eventLoop();
doNothing().when(this.statsRegistry).bind(any(), any());
doNothing().when(this.statsRegistry).unbind(any());
doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(true).when(this.clientListener).isActive();
final InetSocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
doReturn(ra).when(this.clientListener).remoteAddress();
final InetSocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
doReturn(la).when(this.clientListener).localAddress();
doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
doReturn(getDataBroker()).when(this.topologyDependencies).getDataBroker();
doReturn(this.statsRegistry).when(this.topologyDependencies).getStateRegistry();
@SuppressWarnings("unchecked") final T listenerFactory = (T) ((Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
doReturn(new IpAddress(new Ipv4Address(this.testAddress))).when(this.sessionConfig).getListenAddress();
doReturn(new PortNumber(4189)).when(this.sessionConfig).getListenPort();
doReturn(RPC_TIMEOUT).when(this.sessionConfig).getRpcTimeout();
doReturn(TEST_TOPOLOGY_ID).when(this.topology).getTopologyId();
doReturn(Collections.emptyList()).when(this.topology).getNode();
final PCEPTopologyConfiguration configDep = new PCEPTopologyConfiguration(this.sessionConfig, this.topology);
this.manager = new ServerSessionManager(this.topologyDependencies, listenerFactory, configDep);
startSessionManager();
this.neg = new DefaultPCEPSessionNegotiator(this.promise, this.clientListener, this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
this.topologyRpcs = new TopologyRPCs(this.manager);
}
use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.
the class FiniteStateMachineTest method testErrorOneTwo.
/**
* OpenWait timer expired.
*
* @throws InterruptedException exception
*/
@Test
public void testErrorOneTwo() throws Exception {
this.serverSession.channelActive(null);
assertEquals(1, this.msgsSend.size());
assertTrue(this.msgsSend.get(0) instanceof OpenMessage);
checkEquals(() -> {
for (final Notification m : this.msgsSend) {
if (m instanceof Pcerr) {
final Errors obj = ((Pcerr) m).getPcerrMessage().getErrors().get(0);
assertEquals(new Short((short) 1), obj.getErrorObject().getType());
assertEquals(new Short((short) 2), obj.getErrorObject().getValue());
}
}
});
}
use of org.opendaylight.yangtools.yang.binding.Notification 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);
}
Aggregations