use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder 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(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(35L)).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(10).build();
assertEquals(10, AsNumberUtil.advertizedAsNumber(open2).getValue().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method testGetOpenMessage.
@Test
public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Map<ByteBuf, Notification> openMap = Maps.newHashMap();
final Set<BgpTableType> type = Sets.newHashSet();
type.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
final List<BgpParameters> params = Lists.newArrayList();
final CParameters par = new CParametersBuilder().addAugmentation(CParameters1.class, 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(30).setHoldTimer(30).setBgpParameters(params).setVersion(new ProtocolVersion((short) 4)).build());
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
final Set<BgpTableType> result = Sets.newHashSet();
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.getAugmentation(CParameters1.class) != null && cp.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final BgpTableType t = new BgpTableTypeImpl(cp.getAugmentation(CParameters1.class).getMultiprotocolCapability().getAfi(), cp.getAugmentation(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.rev131007.OpenBuilder in project bgpcep by opendaylight.
the class ParserTest method testOpenMessage.
@Test
public void testOpenMessage() throws UnknownHostException, BGPParsingException, BGPDocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(new ProtocolVersion((short) 4)).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, bytes);
assertArrayEquals(openBMsg, ByteArray.getAllBytes(bytes));
final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
assertTrue(m instanceof Open);
assertEquals(100, ((Open) m).getMyAsNumber().intValue());
assertEquals(180, ((Open) m).getHoldTimer().intValue());
assertEquals(new Ipv4Address("20.20.20.20"), ((Open) m).getBgpIdentifier());
assertTrue(((Open) m).getBgpParameters().isEmpty());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder in project bgpcep by opendaylight.
the class PCEPOpenObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final int versionValue = ByteArray.copyBitsRange(bytes.readByte(), VERSION_SF_OFFSET, VERSION_SF_LENGTH);
final OpenBuilder builder = new OpenBuilder();
builder.setVersion(new ProtocolVersion((short) versionValue));
builder.setProcessingRule(header.isProcessingRule());
builder.setIgnore(header.isIgnore());
final short keepalive = bytes.readUnsignedByte();
builder.setKeepalive(keepalive);
final short deadTimer = bytes.readUnsignedByte();
if (keepalive == 0) {
builder.setDeadTimer((short) 0);
} else {
builder.setDeadTimer(deadTimer);
}
builder.setSessionId(bytes.readUnsignedByte());
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, bytes.slice());
builder.setTlvs(tbuilder.build());
final Open obj = builder.build();
if (versionValue != PCEP_VERSION) {
// TODO: Should we move this check into the negotiator
LOG.debug("Unsupported PCEP version {}", versionValue);
return new UnknownObject(PCEPErrors.PCEP_VERSION_NOT_SUPPORTED, obj);
}
return obj;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder in project bgpcep by opendaylight.
the class PeerUpHandler method serializeMessageBody.
@Override
public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
super.serializeMessageBody(message, buffer);
Preconditions.checkArgument(message instanceof PeerUpNotification, "An instance of Peer Up notification is required");
final PeerUpNotification peerUp = (PeerUpNotification) message;
if (peerUp.getLocalAddress().getIpv4Address() != null) {
buffer.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
ByteBufWriteUtil.writeIpv4Address(peerUp.getLocalAddress().getIpv4Address(), buffer);
} else {
ByteBufWriteUtil.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer);
}
ByteBufWriteUtil.writeUnsignedShort(peerUp.getLocalPort().getValue(), buffer);
ByteBufWriteUtil.writeUnsignedShort(peerUp.getRemotePort().getValue(), buffer);
this.msgRegistry.serializeMessage(new OpenBuilder(peerUp.getSentOpen()).build(), buffer);
this.msgRegistry.serializeMessage(new OpenBuilder(peerUp.getReceivedOpen()).build(), buffer);
serializeTlvs(peerUp.getInformation(), buffer);
}
Aggregations