use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class APITest method testAsNumberUtil.
@Test
public void testAsNumberUtil() {
final List<BgpParameters> params = new ArrayList<>();
final List<OptionalCapabilities> capas = new ArrayList<>();
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(35))).build()).build()).build());
params.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
final Open open1 = new OpenBuilder().setBgpParameters(params).build();
assertEquals(35L, AsNumberUtil.advertizedAsNumber(open1).getValue().longValue());
final Open open2 = new OpenBuilder().setMyAsNumber(Uint16.valueOf(10)).build();
assertEquals(10, AsNumberUtil.advertizedAsNumber(open2).getValue().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method testGetOpenMessage.
@Test
public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Map<ByteBuf, Notification> openMap = new HashMap<>();
final Set<BgpTableType> type = new HashSet<>();
type.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
final List<BgpParameters> params = new ArrayList<>();
final CParameters par = new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build()).build();
params.add(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(par).build())).build());
final byte[] input = new byte[] { 5, 8, 13, 21 };
openMap.put(Unpooled.copiedBuffer(input), new OpenBuilder().setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(30)).setBgpParameters(params).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build());
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
final Set<BgpTableType> result = new HashSet<>();
for (final BgpParameters p : ((Open) mockParser.parseMessage(Unpooled.copiedBuffer(input), null)).getBgpParameters()) {
for (final OptionalCapabilities capa : p.getOptionalCapabilities()) {
final CParameters cp = capa.getCParameters();
if (cp.augmentation(CParameters1.class) != null && cp.augmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final BgpTableType t = new BgpTableTypeImpl(cp.augmentation(CParameters1.class).getMultiprotocolCapability().getAfi(), cp.augmentation(CParameters1.class).getMultiprotocolCapability().getSafi());
result.add(t);
}
}
}
assertEquals(type, result);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class ParserTest method testOpenMessage.
@Test
public void testOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(Uint16.valueOf(100)).setHoldTimer(Uint16.valueOf(180)).setBgpIdentifier(new Ipv4AddressNoZone("20.20.20.20")).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, bytes);
assertArrayEquals(OPEN_BMSG, ByteArray.getAllBytes(bytes));
final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
assertThat(m, instanceOf(Open.class));
final Open mo = (Open) m;
assertEquals(100, mo.getMyAsNumber().intValue());
assertEquals(180, mo.getHoldTimer().intValue());
assertEquals(new Ipv4Address("20.20.20.20"), mo.getBgpIdentifier());
assertNull(mo.getBgpParameters());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class OpenTest method testSerializeLongOpen.
@Test
public void testSerializeLongOpen() throws BGPDocumentedException {
final List<OptionalCapabilities> capabilities = new ArrayList<>();
for (int i = 0; i < 200; ++i) {
capabilities.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(1000))).build()).build()).build());
}
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(capabilities).build())).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(registry).serializeMessage(open, msg);
assertEquals(1235, msg.readableBytes());
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(registry).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
assertEquals(200, openResult.getBgpParameters().get(0).getOptionalCapabilities().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class AbstractBGPSessionNegotiator method handleOpen.
@SuppressWarnings("checkstyle:illegalCatch")
private synchronized void handleOpen(final Open openObj) {
final IpAddressNoZone remoteIp = getRemoteIp();
final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
try {
final BGPSessionListener peer = this.registry.getPeer(remoteIp, getSourceId(openObj, preferences), getDestinationId(openObj, preferences), openObj);
sendMessage(new KeepaliveBuilder().build());
this.state = State.OPEN_CONFIRM;
this.session = new BGPSessionImpl(peer, this.channel, openObj, preferences, this.registry);
this.session.setChannelExtMsgCoder(openObj);
LOG.debug("Channel {} moved to OPEN_CONFIRM state with remote proposal {}", this.channel, openObj);
} catch (final BGPDocumentedException | RuntimeException e) {
LOG.warn("Channel {} negotiation failed", this.channel, e);
negotiationFailed(e);
}
}
Aggregations