use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class AbstractRIBSupport method buildReach.
/**
* Build MpReachNlri object from DOM representation.
*
* @param routes Collection of MapEntryNode DOM representation of routes
* @param hop CNextHop as it was parsed from Attributes, to be included in MpReach object
* @return MpReachNlri
*/
private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
final MpReachNlriBuilder mb = new MpReachNlriBuilder();
mb.setAfi(this.getAfi());
mb.setSafi(this.getSafi());
mb.setCNextHop(hop);
mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(buildDestination(routes)).build());
return mb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class BGPPeer method prefixesToMpReach.
/**
* Creates MPReach for the prefixes to be handled in the same way as linkstate routes.
*
* @param message Update message containing prefixes in NLRI
* @return MpReachNlri with prefixes from the nlri field
*/
private static MpReachNlri prefixesToMpReach(final Update message) {
final List<Ipv4Prefixes> prefixes = message.getNlri().stream().map(n -> new Ipv4PrefixesBuilder().setPrefix(n.getPrefix()).setPathId(n.getPathId()).build()).collect(Collectors.toList());
final MpReachNlriBuilder b = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build()).build()).build());
if (message.getAttributes() != null) {
b.setCNextHop(message.getAttributes().getCNextHop());
}
return b.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class BGPPeer method onUpdateMessage.
/**
* Process Update message received.
* Calls {@link #checkMandatoryAttributesPresence(Update)} to check for presence of mandatory attributes.
*
* @param message Update message
*/
private synchronized void onUpdateMessage(final Update message) throws BGPDocumentedException {
checkMandatoryAttributesPresence(message);
// update AdjRibs
final Attributes attrs = message.getAttributes();
MpReachNlri mpReach;
final boolean isAnyNlriAnnounced = message.getNlri() != null;
if (isAnyNlriAnnounced) {
mpReach = prefixesToMpReach(message);
} else {
mpReach = MessageUtil.getMpReachNlri(attrs);
}
if (mpReach != null) {
this.ribWriter.updateRoutes(mpReach, nextHopToAttribute(attrs, mpReach));
}
MpUnreachNlri mpUnreach;
if (message.getWithdrawnRoutes() != null) {
mpUnreach = prefixesToMpUnreach(message, isAnyNlriAnnounced);
} else {
mpUnreach = MessageUtil.getMpUnreachNlri(attrs);
}
if (mpUnreach != null) {
this.ribWriter.removeRoutes(mpUnreach);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri 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.getImplementedInterface(), 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.writeZero(NEXT_HOP_LENGHT);
}
byteAggregator.writeZero(RESERVED);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri 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();
}
Aggregations