use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix in project bgpcep by opendaylight.
the class SrPrefixAttributesParser method parseSrPrefix.
public static SrPrefix parseSrPrefix(final ByteBuf buffer, final ProtocolId protocol) {
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
final SrPrefixBuilder builder = new SrPrefixBuilder().setFlags(parsePrefixFlags(flags, protocol)).setAlgorithm(Algorithm.forValue(buffer.readUnsignedByte()));
buffer.skipBytes(RESERVED_PREFIX);
return builder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndexByFlags(Size.forValue(buffer.readableBytes()), buffer, flags.get(VALUE), flags.get(LOCAL))).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix in project bgpcep by opendaylight.
the class PrefixAttributesParser method parseAttribute.
private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId, final PrefixAttributesBuilder builder, final List<RouteTag> routeTags, final List<ExtendedRouteTag> exRouteTags) {
switch(key) {
case IGP_FLAGS:
parseIgpFags(builder, value);
break;
case ROUTE_TAG:
parseRouteTags(routeTags, value);
break;
case EXTENDED_ROUTE_TAG:
parseExtendedRouteTags(exRouteTags, value);
break;
case PREFIX_METRIC:
final IgpMetric metric = new IgpMetric(ByteBufUtils.readUint32(value));
builder.setPrefixMetric(metric);
LOG.debug("Parsed Metric: {}", metric);
break;
case FORWARDING_ADDRESS:
final IpAddressNoZone fwdAddress = parseForwardingAddress(value);
builder.setOspfForwardingAddress(fwdAddress);
LOG.debug("Parsed FWD Address: {}", fwdAddress);
break;
case PREFIX_OPAQUE:
if (LOG.isDebugEnabled()) {
LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
}
break;
case PREFIX_SID:
final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId);
builder.setSrPrefix(prefix);
LOG.debug("Parsed SR Prefix: {}", prefix);
break;
case IPV6_PREFIX_SID:
final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(value);
builder.setIpv6SrPrefix(ipv6Prefix);
LOG.debug("Parsed Ipv6 SR Prefix: {}", ipv6Prefix);
break;
case RANGE:
final SrRange range = RangeTlvParser.parseSrRange(value, protocolId);
builder.setSrRange(range);
LOG.debug("Parsed SR Range: {}", range);
break;
case BINDING_SID:
parseBindingSid(builder, value, protocolId);
break;
default:
LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createPrefix.
private void createPrefix(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
if (ippfx == null) {
LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
return;
}
final PrefixBuilder pb = new PrefixBuilder();
final PrefixKey pk = new PrefixKey(ippfx);
pb.withKey(pk);
pb.setPrefix(ippfx);
final PrefixAttributes pa;
// Very defensive lookup
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
} else {
LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
} else {
LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
SrPrefix srPrefix = null;
if (pa != null) {
if (pa.getPrefixMetric() != null) {
pb.setMetric(pa.getPrefixMetric().getValue());
}
if (pa.getSrPrefix() != null) {
srPrefix = pa.getSrPrefix();
}
}
ProtocolUtil.augmentProtocolId(value, pa, pb);
final Prefix pfx = pb.build();
LOG.debug("Created prefix {} for {}", pfx, prefixCase);
/*
* All set, but... the hosting node may not exist, we may need to fake it.
*/
final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
NodeHolder nh = this.nodes.get(node);
if (nh == null) {
nh = getNode(node);
nh.addPrefix(pfx);
if (srPrefix != null) {
nh.createSrHolderIfRequired().addSrPrefix(trans, false, ippfx, srPrefix);
}
putNode(trans, nh);
} else {
nh.addPrefix(pfx);
if (srPrefix != null) {
nh.createSrHolderIfRequired().addSrPrefix(trans, true, ippfx, srPrefix);
}
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix in project bgpcep by opendaylight.
the class SrAttributeParserTest method testSrPrefix.
// tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-00#section-2.3.1
@Test
public void testSrPrefix() {
final byte[] bytes = { (byte) 0xA0, 0, 0, 0, 1, 2, 3, 4 };
final byte[] bytesOspf = { (byte) 0x20, 0, 0, 0, 1, 2, 3, 4 };
final SrPrefix prefixIsis = new SrPrefixBuilder().setFlags(ISIS_PREFIX_FLAGS).setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(Uint32.valueOf(16909060L)).build()).build();
final SrPrefix prefixOspf = new SrPrefixBuilder().setFlags(OSPF_PREFIX_FLAGS).setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(Uint32.valueOf(16909060L)).build()).build();
assertEquals(prefixIsis, SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.IsisLevel1));
assertEquals(prefixOspf, SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.Ospf));
final ByteBuf serializedPrefix = Unpooled.buffer();
final ByteBuf serializedPrefixOspf = Unpooled.buffer();
SrPrefixAttributesParser.serializeSrPrefix(prefixIsis, serializedPrefix);
SrPrefixAttributesParser.serializeSrPrefix(prefixOspf, serializedPrefixOspf);
assertArrayEquals(bytes, ByteArray.readAllBytes(serializedPrefix));
assertArrayEquals(bytesOspf, ByteArray.readAllBytes(serializedPrefixOspf));
}
Aggregations