use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily 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.types.rev200120.AddressFamily in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandler method serializeCapability.
private ByteBuf serializeCapability(final LlGracefulRestartCapability cap) {
final Map<TablesKey, Tables> tables = cap.getTables();
if (tables == null || tables.isEmpty()) {
return Unpooled.EMPTY_BUFFER;
}
final ByteBuf buffer = Unpooled.buffer(PER_TABLE_SIZE * tables.size());
for (Tables table : tables.values()) {
final Class<? extends AddressFamily> afi = table.getAfi();
final Class<? extends SubsequentAddressFamily> safi = table.getSafi();
final Integer afival = this.afiReg.numberForClass(afi);
checkArgument(afival != null, "Unhandled address family %s", afi);
buffer.writeShort(afival);
final Integer safival = this.safiReg.numberForClass(safi);
checkArgument(safival != null, "Unhandled subsequent address family %s", safi);
buffer.writeByte(safival);
if (table.getAfiFlags() != null && table.getAfiFlags().getForwardingState()) {
buffer.writeByte(AFI_FLAG_FORWARDING_STATE);
} else {
buffer.writeByte(0);
}
final Uint24 staleTime = table.getLongLivedStaleTime();
final int timeval = staleTime != null ? staleTime.getValue().intValue() : 0;
checkArgument(timeval >= 0 && timeval <= MAX_STALE_TIME, "Restart time is %s", staleTime);
buffer.writeMedium(timeval);
}
return buffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily in project bgpcep by opendaylight.
the class BGPParserTest method testEORIpv6.
/*
* End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 1d <- length (29) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 06 <- total path attribute length
* 80 <- attribute flags
* 0f <- attribute type (15 - MP_UNREACH_NLRI)
* 03 <- attribute length
* 00 02 <- value (AFI 2: IPv6)
* 01 <- value (SAFI 1)
*/
@Test
public void testEORIpv6() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(6), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final Class<? extends AddressFamily> afi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getAfi();
final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getSafi();
assertEquals(Ipv6AddressFamily.class, afi);
assertEquals(UnicastSubsequentAddressFamily.class, safi);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(6), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily in project bgpcep by opendaylight.
the class SimpleRIBExtensionProviderContext method registerRIBSupport.
@Override
public <T extends RIBSupport<?, ?>> RIBSupportRegistration<T> registerRIBSupport(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final T support) {
final TablesKey key = new TablesKey(afi, safi);
final RIBSupport<?, ?> prev = this.supports.putIfAbsent(key, support);
checkArgument(prev == null, "AFI %s SAFI %s is already registered with %s", afi, safi, prev);
this.domSupports.put(RibSupportUtils.toYangTablesKey(afi, safi), support);
return new AbstractRIBSupportRegistration<>(support) {
@Override
protected void removeRegistration() {
// FIXME: clean up registrations, too
SimpleRIBExtensionProviderContext.this.supports.remove(key);
}
};
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily in project bgpcep by opendaylight.
the class PCEPEndPointsObjectSerializer method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof EndpointsObj, "Wrong instance of PCEPObject. Passed %s. Needed EndpointsObject.", object.getClass());
final EndpointsObj ePObj = (EndpointsObj) object;
final AddressFamily afi = ePObj.getAddressFamily();
final Boolean processing = object.getProcessingRule();
final Boolean ignore = object.getIgnore();
if (afi instanceof Ipv6Case) {
final Ipv6 ipv6 = ((Ipv6Case) afi).getIpv6();
PCEPEndPointsIpv6ObjectParser.serializeObject(processing, ignore, ipv6, buffer);
} else if (afi instanceof Ipv4Case) {
final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
PCEPEndPointsIpv4ObjectParser.serializeObject(processing, ignore, ipv4, buffer);
} else if (afi instanceof P2mpIpv4Case) {
final P2mpIpv4 ipv4 = ((P2mpIpv4Case) afi).getP2mpIpv4();
PCEPP2MPEndPointsIpv4ObjectParser.serializeObject(processing, ignore, ipv4, buffer);
} else if (afi instanceof P2mpIpv6Case) {
final P2mpIpv6 ipv6 = ((P2mpIpv6Case) afi).getP2mpIpv6();
PCEPP2MPEndPointsIpv6ObjectParser.serializeObject(processing, ignore, ipv6, buffer);
}
}
Aggregations