use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class FSMTest method testBgpExtendedMessageCapability.
@Test
public void testBgpExtendedMessageCapability() {
this.clientSession.channelActive(null);
assertEquals(1, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(0) instanceof Open);
final List<BgpParameters> tlvs = new ArrayList<>();
final List<OptionalCapabilities> capas = new ArrayList<>();
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(30))).build()).build()).build());
tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.ONE).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(tlvs).setBgpIdentifier(new Ipv4AddressNoZone("1.1.1.2")).build());
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof Keepalive);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion 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.types.rev181109.ProtocolVersion 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.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class OpenTest method testSerializeOpen.
@Test
public void testSerializeOpen() throws BGPDocumentedException {
final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("127.0.0.1")).setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(List.of(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(1000))).build()).addAugmentation(new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().setRestartFlags(new GracefulRestartCapability.RestartFlags(false)).setRestartTime(Uint16.ZERO).setTables(Map.of()).build()).build()).build()).build())).build())).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(registry).serializeMessage(open, msg);
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(registry).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
assertEquals(open.getBgpIdentifier(), openResult.getBgpIdentifier());
assertEquals(open.getHoldTimer(), openResult.getHoldTimer());
assertEquals(open.getMyAsNumber(), openResult.getMyAsNumber());
boolean grace = false;
if (openResult.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability() != null) {
grace = true;
}
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 0 : 1).getCParameters().getAs4BytesCapability());
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().augmentation(CParameters1.class).getGracefulRestartCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 1 : 0).getCParameters().augmentation(CParameters1.class).getGracefulRestartCapability());
}
Aggregations