use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class L3vpnMcastIpv4NlriHandler method parseNlri.
@Override
public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder, final PeerSpecificParserConstraint constraint) throws BGPParsingException {
if (!nlri.isReadable()) {
return;
}
final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationL3vpnMcastIpv4AdvertizedCaseBuilder().setDestinationIpv4L3vpnMcast(new DestinationIpv4L3vpnMcastBuilder().setL3vpnMcastDestination(L3vpnMcastNlriSerializer.extractDest(nlri, mPathSupported)).build()).build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class L3vpnMcastNlriSerializer method extractDest.
static List<L3vpnMcastDestination> extractDest(final ByteBuf nlri, final boolean addPath) {
List<L3vpnMcastDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final L3vpnMcastDestinationBuilder builder = new L3vpnMcastDestinationBuilder();
if (addPath) {
builder.setPathId(PathIdUtil.readPathId(nlri));
}
final int length = nlri.readUnsignedByte();
final int initialLength = nlri.readableBytes();
builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
if (length == Ipv6Util.IPV6_BITS_LENGTH) {
builder.setPrefix(new IpPrefix(Ipv6Util.prefixForByteBuf(nlri)));
} else {
builder.setPrefix(new IpPrefix(Ipv4Util.prefixForByteBuf(nlri)));
}
dests.add(builder.build());
int readed = initialLength - nlri.readableBytes();
while (readed % 8 != 0) {
nlri.readByte();
readed = initialLength - nlri.readableBytes();
}
}
return dests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class AbstractVpnNlriParser method serializeNlri.
private static void serializeNlri(final List<VpnDestination> dests, final boolean isWithdrawnRoute, final ByteBuf buffer) {
final ByteBuf nlriByteBuf = Unpooled.buffer();
for (final VpnDestination dest : dests) {
final List<LabelStack> labelStack = dest.getLabelStack();
final IpPrefix prefix = dest.getPrefix();
LOG.debug("Serializing Nlri: VpnDestination={}, IpPrefix={}", dest, prefix);
AbstractVpnNlriParser.serializeLengtField(prefix, labelStack, nlriByteBuf);
LUNlriParser.serializeLabelStackEntries(labelStack, isWithdrawnRoute, nlriByteBuf);
RouteDistinguisherUtil.serializeRouteDistinquisher(dest.getRouteDistinguisher(), nlriByteBuf);
Preconditions.checkArgument(prefix.getIpv6Prefix() != null || prefix.getIpv4Prefix() != null, "Ipv6 or Ipv4 prefix is missing.");
LUNlriParser.serializePrefixField(prefix, nlriByteBuf);
}
buffer.writeBytes(nlriByteBuf);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class RouteTargetConstrainNlriHandler method parseNlriDestinations.
private static List<RouteTargetConstrainDestination> parseNlriDestinations(final ByteBuf nlri, final boolean addPathSupported) {
final List<RouteTargetConstrainDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final RouteTargetConstrainDestinationBuilder builder = new RouteTargetConstrainDestinationBuilder();
if (addPathSupported) {
builder.setPathId(PathIdUtil.readPathId(nlri));
}
final int length = nlri.readUnsignedByte() / 8;
final ByteBuf nlriBuf = nlri.readSlice(length);
Integer type = null;
if (length != 0) {
builder.setOriginAs(new AsNumber(ByteBufUtils.readUint32(nlriBuf)));
type = (int) nlriBuf.readUnsignedByte();
// Skip Subtype
nlriBuf.skipBytes(1);
}
builder.setRouteTargetConstrainChoice(ImmutableRouteTargetConstrainNlriRegistry.getInstance().parseRouteTargetConstrain(type, nlriBuf));
dests.add(builder.build());
}
return dests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class RouteTargetConstrainNlriHandler method serializeNlriDestinations.
public static ByteBuf serializeNlriDestinations(final List<RouteTargetConstrainDestination> destinationList) {
final ByteBuf nlri = Unpooled.buffer();
for (final RouteTargetConstrainDestination dest : destinationList) {
final RouteTargetConstrainChoice rtcChoice = dest.getRouteTargetConstrainChoice();
if (rtcChoice instanceof RouteTargetConstrainDefaultCase) {
nlri.writeByte(0);
} else {
nlri.writeByte(RT_BITS_LENGTH);
final AsNumber originAs = dest.getOriginAs();
if (originAs != null) {
ByteBufUtils.write(nlri, originAs.getValue());
}
nlri.writeBytes(ImmutableRouteTargetConstrainNlriRegistry.getInstance().serializeRouteTargetConstrain(rtcChoice));
}
}
return nlri;
}
Aggregations