use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project bgpcep by opendaylight.
the class VpnDestinationUtil method parseNlri.
static List<VpnDestination> parseNlri(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
if (!nlri.isReadable()) {
return null;
}
final List<VpnDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final VpnDestinationBuilder builder = new VpnDestinationBuilder();
if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) {
builder.setPathId(PathIdUtil.readPathId(nlri));
}
final short length = nlri.readUnsignedByte();
final List<LabelStack> labels = LUNlriParser.parseLabel(nlri);
builder.setLabelStack(labels);
final int labelNum = labels != null ? labels.size() : 1;
final int prefixLen = length - (LUNlriParser.LABEL_LENGTH * Byte.SIZE * labelNum) - (RouteDistinguisherUtil.RD_LENGTH * Byte.SIZE);
builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
Preconditions.checkState(prefixLen > 0, "A valid VPN IP prefix is required.");
builder.setPrefix(LUNlriParser.parseIpPrefix(nlri, prefixLen, afi));
dests.add(builder.build());
}
return dests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project bgpcep by opendaylight.
the class CreateTunnelInstructionExecutor method buildAddressFamily.
private static AddressFamily buildAddressFamily(final TerminationPoint sp, final TerminationPoint dp) {
// We need the IGP augmentation -- it has IP addresses
final TerminationPoint1 sp1 = requireNonNull(sp.augmentation(TerminationPoint1.class));
final TerminationPoint1 dp1 = requireNonNull(dp.augmentation(TerminationPoint1.class));
// Get the types
final TerminationPointType spt = sp1.getIgpTerminationPointAttributes().getTerminationPointType();
final TerminationPointType dpt = dp1.getIgpTerminationPointAttributes().getTerminationPointType();
// The types have to match
Preconditions.checkArgument(spt.implementedInterface().equals(dpt.implementedInterface()));
// And they have to actually be Ip
final Ip sips = (Ip) spt;
final Ip dips = (Ip) dpt;
/*
* Now a bit of magic. We need to find 'like' addresses, e.g. both
* IPv4 or both IPv6. We are in IPv6-enabled world now, so let's
* prefer that.
*/
Optional<AddressFamily> ret = findIpv6(sips.getIpAddress(), dips.getIpAddress());
if (!ret.isPresent()) {
ret = findIpv4(sips.getIpAddress(), dips.getIpAddress());
}
// We need to have a ret now
Preconditions.checkArgument(ret != null, "Failed to find like Endpoint addresses");
return ret.get();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project bgpcep by opendaylight.
the class EvpnNlriParser method parseNlri.
@Nullable
private static List<EvpnDestination> parseNlri(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
if (!nlri.isReadable()) {
return null;
}
final List<EvpnDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final EvpnDestinationBuilder builder = new EvpnDestinationBuilder();
if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) {
builder.setPathId(PathIdUtil.readPathId(nlri));
}
final NlriType type = NlriType.forValue(nlri.readUnsignedByte());
final int length = nlri.readUnsignedByte();
final ByteBuf nlriBuf = nlri.readSlice(length);
builder.setRouteDistinguisher(parseRouteDistinguisher(nlriBuf));
builder.setEvpnChoice(SimpleEvpnNlriRegistry.getInstance().parseEvpn(type, nlriBuf));
dests.add(builder.build());
}
return dests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.AddressFamily 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.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.AddressFamily 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);
}
}
}
}
};
}
Aggregations