use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class BmpRouterPeerImpl method setPeerTables.
private static Set<TablesKey> setPeerTables(final ReceivedOpen open) {
final Set<TablesKey> tables = Sets.newHashSet(DEFAULT_TABLE);
for (final BgpParameters param : open.getBgpParameters()) {
for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
final CParameters cParam = optCapa.getCParameters();
if (cParam.getAugmentation(CParameters1.class) == null || cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() == null) {
continue;
}
final MultiprotocolCapability multi = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
final TablesKey tt = new TablesKey(multi.getAfi(), multi.getSafi());
tables.add(tt);
}
}
return tables;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class AddPathCapabilityHandler method serializeCapability.
@Override
public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
final CParameters1 aug = capability.augmentation(CParameters1.class);
if (aug == null) {
return;
}
final AddPathCapability addPathCap = aug.getAddPathCapability();
if (addPathCap == null) {
return;
}
final List<AddressFamilies> families = addPathCap.getAddressFamilies();
if (families != null) {
final ByteBuf capBuffer = Unpooled.buffer(families.size() * TRIPLET_BYTE_SIZE);
for (final AddressFamilies addressFamily : families) {
final Class<? extends AddressFamily> afi = addressFamily.getAfi();
final Integer afival = this.afiReg.numberForClass(afi);
checkArgument(afival != null, "Unhandled address family " + afi);
final Class<? extends SubsequentAddressFamily> safi = addressFamily.getSafi();
final Integer safival = this.safiReg.numberForClass(safi);
checkArgument(safival != null, "Unhandled subsequent address family " + safi);
final SendReceive sendReceive = addressFamily.getSendReceive();
checkArgument(sendReceive != null, "Unhandled Send/Receive value");
capBuffer.writeShort(afival).writeByte(safival).writeByte(sendReceive.getIntValue());
}
CapabilityUtil.formatCapability(CODE, capBuffer, byteAggregator);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class AddPathCapabilityHandler method parseCapability.
@Override
public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
final List<AddressFamilies> families = new ArrayList<>();
while (buffer.isReadable()) {
final int afiVal = buffer.readUnsignedShort();
final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
if (afi == null) {
throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
}
final int safiVal = buffer.readUnsignedByte();
final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
if (safi == null) {
throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
}
final SendReceive sendReceive = SendReceive.forValue(buffer.readUnsignedByte());
if (sendReceive != null) {
families.add(new AddressFamiliesBuilder().setAfi(afi).setSafi(safi).setSendReceive(sendReceive).build());
}
}
return new CParametersBuilder().addAugmentation(new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(families).build()).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class MultiProtocolCapabilityHandler method serializeCapability.
@Override
public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
final CParameters1 aug = capability.augmentation(CParameters1.class);
if (aug == null) {
return;
}
final MultiprotocolCapability mp = aug.getMultiprotocolCapability();
if (mp == null) {
return;
}
final ByteBuf capBuffer = Unpooled.buffer();
MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, mp.getAfi(), mp.getSafi(), capBuffer);
CapabilityUtil.formatCapability(CODE, capBuffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters 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);
}
Aggregations