use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.
the class SimpleNlriRegistry method parseMpReach.
@Override
public MpReachNlri parseMpReach(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) throws BGPParsingException {
final MpReachNlriBuilder builder = new MpReachNlriBuilder();
final Class<? extends AddressFamily> afi = getAfi(buffer);
final Class<? extends SubsequentAddressFamily> safi = getSafi(buffer);
builder.setAfi(afi);
builder.setSafi(safi);
final BgpTableType key = createKey(builder.getAfi(), builder.getSafi());
final int nextHopLength = buffer.readUnsignedByte();
if (nextHopLength != 0) {
final NextHopParserSerializer nextHopParser = this.nextHopParsers.get(key);
if (nextHopParser != null) {
builder.setCNextHop(nextHopParser.parseNextHop(buffer.readSlice(nextHopLength)));
} else {
builder.setCNextHop(NextHopUtil.parseNextHop(buffer.readSlice(nextHopLength)));
LOG.warn("NexHop Parser/Serializer for AFI/SAFI ({},{}) not bound", afi, safi);
}
}
buffer.skipBytes(RESERVED);
final ByteBuf nlri = buffer.slice();
final NlriParser parser = this.handlers.get(key);
if (parser == null) {
LOG.warn(PARSER_NOT_FOUND, key);
} else {
parser.parseNlri(nlri, builder, constraint);
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.
the class SimpleNlriRegistry method registerNlriParser.
synchronized Registration registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser, final NextHopParserSerializer nextHopSerializer, final Class<? extends CNextHop> cnextHopClass, final Class<? extends CNextHop>... cnextHopClassList) {
final BgpTableType key = createKey(afi, safi);
final NlriParser prev = this.handlers.get(key);
checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
this.handlers.put(key, parser);
this.nextHopParsers.put(key, nextHopSerializer);
if (cnextHopClass != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cnextHopClass, key);
this.nextHopSerializers.put(nhKey, nextHopSerializer);
for (final Class<? extends CNextHop> cnextHop : cnextHopClassList) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cnextHop, key);
this.nextHopSerializers.put(nhKeys, nextHopSerializer);
}
}
final Object lock = this;
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (lock) {
SimpleNlriRegistry.this.handlers.remove(key);
SimpleNlriRegistry.this.nextHopParsers.remove(key);
if (cnextHopClass != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cnextHopClass, key);
SimpleNlriRegistry.this.nextHopSerializers.remove(nhKey);
for (final Class<? extends CNextHop> cnextHop : cnextHopClassList) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cnextHop, key);
SimpleNlriRegistry.this.nextHopSerializers.remove(nhKeys);
}
}
}
}
};
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.
the class SimpleNlriRegistry method serializeMpReach.
@Override
public void serializeMpReach(final MpReachNlri mpReachNlri, final ByteBuf byteAggregator) {
final Class<? extends AddressFamily> afi = mpReachNlri.getAfi();
final Class<? extends SubsequentAddressFamily> safi = mpReachNlri.getSafi();
byteAggregator.writeShort(this.afiReg.numberForClass(afi));
byteAggregator.writeByte(this.safiReg.numberForClass(safi));
final CNextHop cNextHop = mpReachNlri.getCNextHop();
if (cNextHop != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> key = new SimpleEntry(cNextHop.implementedInterface(), new BgpTableTypeImpl(afi, safi));
final NextHopParserSerializer nextHopSerializer = this.nextHopSerializers.get(key);
final ByteBuf nextHopBuffer = Unpooled.buffer();
nextHopSerializer.serializeNextHop(cNextHop, nextHopBuffer);
byteAggregator.writeByte(nextHopBuffer.writerIndex());
byteAggregator.writeBytes(nextHopBuffer);
} else {
byteAggregator.writeByte(0);
}
byteAggregator.writeZero(RESERVED);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.
the class BGPPeer method onRouteRefreshMessage.
private void onRouteRefreshMessage(final RouteRefresh message) {
final Class<? extends AddressFamily> rrAfi = message.getAfi();
final Class<? extends SubsequentAddressFamily> rrSafi = message.getSafi();
final TablesKey key = new TablesKey(rrAfi, rrSafi);
synchronized (this) {
final AdjRibOutListener listener = this.adjRibOutListenerSet.remove(key);
if (listener != null) {
listener.close();
createAdjRibOutListener(key, listener.isMpSupported());
} else {
LOG.info("Ignoring RouteRefresh message. Afi/Safi is not supported: {}, {}.", rrAfi, rrSafi);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.
the class Ipv6NlriParser method prefixes.
private static DestinationIpv6 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraint, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
final List<Ipv6Prefixes> prefixes = new ArrayList<>();
final boolean supported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi));
while (nlri.isReadable()) {
final Ipv6PrefixesBuilder prefixesBuilder = new Ipv6PrefixesBuilder();
if (supported) {
prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri));
}
prefixesBuilder.setPrefix(Ipv6Util.prefixForByteBuf(nlri));
prefixes.add(prefixesBuilder.build());
}
return new DestinationIpv6Builder().setIpv6Prefixes(prefixes).build();
}
Aggregations