use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes in project bgpcep by opendaylight.
the class LinkstateAttributeParserTest method testPositiveV4Prefixes.
@Test
public void testPositiveV4Prefixes() throws BGPParsingException, BGPDocumentedException {
final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder, null);
final Attributes1 attrs = builder.augmentation(Attributes1.class);
final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
assertNotNull(ls);
assertNotNull(ls.getSrRange());
assertFalse(ls.getSrRange().getInterArea());
assertEquals(1, ls.getSrRange().getSubTlvs().size());
assertNotNull(ls.getSrBindingSidLabels());
final IgpBits ispBits = ls.getIgpBits();
assertTrue(ispBits.getUpDown().getUpDown());
assertTrue(ispBits.getIsIsUpDown());
assertTrue(ispBits.getOspfNoUnicast());
assertTrue(ispBits.getOspfLocalAddress());
assertTrue(ispBits.getOspfPropagateNssa());
assertEquals(2, ls.getRouteTags().size());
assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0).getValue());
assertEquals(1, ls.getExtendedTags().size());
assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70 }, ls.getExtendedTags().get(0).getValue());
assertEquals(10, ls.getPrefixMetric().getValue().intValue());
assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4AddressNoZone().getValue());
// serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
buff.skipBytes(3);
// there is unresolved TLV at the end, that needs to be cut off
assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes 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.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes in project bgpcep by opendaylight.
the class PrefixAttributesParser method serializePrefixAttributes.
static void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
if (prefixAtrributes.getIgpBits() != null) {
final BitArray igpBit = new BitArray(FLAGS_SIZE);
final IgpBits igpBits = prefixAtrributes.getIgpBits();
igpBit.set(UP_DOWN_BIT, igpBits.getUpDown().getUpDown() || igpBits.getIsIsUpDown());
igpBit.set(OSPF_NO_UNICAST, igpBits.getOspfNoUnicast());
igpBit.set(OSPF_LOCAL_ADDRESS, igpBits.getOspfLocalAddress());
igpBit.set(OSPF_PROPAGATE_ADDRESS, igpBits.getOspfPropagateNssa());
TlvUtil.writeTLV(IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.array()), byteAggregator);
}
serializeRouteTags(prefixAtrributes.getRouteTags(), byteAggregator);
serializeExtendedRouteTags(prefixAtrributes.getExtendedTags(), byteAggregator);
serializePrefixMetric(prefixAtrributes.getPrefixMetric(), byteAggregator);
serializeForwardingAddress(prefixAtrributes.getOspfForwardingAddress(), byteAggregator);
serializeSrPrefix(prefixAtrributes.getSrPrefix(), byteAggregator);
serializeIpv6SrPrefix(prefixAtrributes.getIpv6SrPrefix(), byteAggregator);
serializeSrRange(prefixAtrributes.getSrRange(), byteAggregator);
serializeSrBindingLabel(prefixAtrributes.getSrBindingSidLabels(), byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes in project bgpcep by opendaylight.
the class LinkstateGraphBuilder method createPrefix.
/**
* Create new Prefix in the Connected Graph.
*
* @param value The complete Linkstate route information
* @param prefixCase The Prefix part of the Linkstate route
* @param attributes The Prefix attributes
*/
private void createPrefix(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;
}
/* Verify that all mandatory information are present */
final PrefixAttributes pa;
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType instanceof PrefixAttributesCase) {
pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
} else {
LOG.warn("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
return;
}
} else {
LOG.warn("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
return;
}
/*
* Get Connected Vertex from Connected Graph corresponding to the
* Advertising Node Descriptor
*/
Uint64 vertexId = getVertexId(prefixCase.getAdvertisingNodeDescriptors().getCRouterIdentifier());
if (vertexId == Uint64.ZERO) {
LOG.warn("Unable to get the Vertex Identifier from descriptor {}, skipping it", prefixCase.getAdvertisingNodeDescriptors());
return;
}
/* Create Prefix */
PrefixBuilder builder = new PrefixBuilder().setVertexId(vertexId).setPrefix(ippfx);
if (pa.getSrPrefix() != null && pa.getSrPrefix().getSidLabelIndex() instanceof SidCase) {
builder.setPrefixSid(((SidCase) pa.getSrPrefix().getSidLabelIndex()).getSid());
if (pa.getSrPrefix().getFlags() instanceof IsisPrefixFlagsCase) {
builder.setNodeSid(((IsisPrefixFlagsCase) pa.getSrPrefix().getFlags()).getIsisPrefixFlags().getNodeSid());
} else {
/*
* Seems that OSPF Flags are not accessible. Assuming that the
* Prefix is a Node SID
*/
builder.setNodeSid(true);
}
}
Prefix prefix = builder.build();
/* Add the Prefix to the Connected Vertex within the Connected Graph */
LOG.info("Add prefix {} in TED[{}]", builder.getPrefix(), cgraph);
cgraph.addPrefix(prefix);
}
Aggregations