use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase in project bgpcep by opendaylight.
the class LinkstateAttributeParserTest method testPositiveLinks.
@Test
public void testPositiveLinks() throws BGPParsingException, BGPDocumentedException {
final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
final Attributes1 attrs = builder.augmentation(Attributes1.class);
final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
assertNotNull(ls);
assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
assertEquals(Uint32.ZERO, ls.getAdminGroup().getValue());
assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
assertNotNull(ls.getUnreservedBandwidth());
assertEquals(8, ls.getUnreservedBandwidth().size());
assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
assertTrue(ls.getMplsProtocol().getLdp());
assertTrue(ls.getMplsProtocol().getRsvpte());
assertEquals(Uint32.TEN, ls.getMetric().getValue());
assertEquals(2, ls.getSharedRiskLinkGroups().size());
assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
assertEquals("12K-2", ls.getLinkName());
final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setIsisAdjFlags(new IsisAdjFlagsBuilder().setAddressFamily(Boolean.TRUE).setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build()).build();
assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
assertEquals(Uint32.valueOf(1048575L), ((LocalLabelCase) ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
assertEquals(Uint32.valueOf(1048559L), ((LocalLabelCase) ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
assertEquals(Uint32.valueOf(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
assertEquals(Uint8.valueOf(5), ls.getPeerNodeSid().getWeight().getValue());
assertEquals(Uint32.valueOf(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
assertEquals(Uint8.valueOf(5), ls.getPeerSetSids().get(0).getWeight().getValue());
assertEquals(Uint32.valueOf(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
assertEquals(Uint8.valueOf(5), ls.getPeerAdjSid().getWeight().getValue());
// Performance Metrics
assertEquals(Uint32.valueOf(10000L), ls.getLinkDelay().getValue());
assertEquals(Uint32.valueOf(5000L), ls.getLinkMinMaxDelay().getMinDelay().getValue());
assertEquals(Uint32.valueOf(20000L), ls.getLinkMinMaxDelay().getMaxDelay().getValue());
assertEquals(Uint32.valueOf(10000L), ls.getDelayVariation().getValue());
assertEquals(Uint32.ZERO, ls.getLinkLoss().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getResidualBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getAvailableBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, ls.getUtilizedBandwidth().getValue());
// serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
// The LINK_ATTR buffer is now greater than 255 bytes. Need to skip one more byte
buff.skipBytes(4);
// there is unresolved TLV at the end, that needs to be cut off
assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createLink.
private void createLink(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
// defensive lookup
final LinkAttributes la;
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
la = ((LinkAttributesCase) attrType).getLinkAttributes();
} else {
LOG.debug("Missing attribute type in link {} route {}, skipping it", linkCase, value);
la = null;
}
} else {
LOG.debug("Missing attributes in link {} route {}, skipping it", linkCase, value);
la = null;
}
final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
Long adjSid = null;
if (la != null) {
if (la.getMetric() != null) {
ilab.setMetric(la.getMetric().getValue());
}
ilab.setName(la.getLinkName());
if (la.getSrAdjIds() != null && !la.getSrAdjIds().isEmpty()) {
final SrAdjIds srAdjIds = la.getSrAdjIds().get(0);
if (srAdjIds != null) {
final SidLabelIndex sidLabelIndex = srAdjIds.getSidLabelIndex();
if (sidLabelIndex instanceof LocalLabelCase) {
adjSid = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
}
}
}
}
ProtocolUtil.augmentProtocolId(value, ilab, la, linkCase.getLinkDescriptors());
final LinkBuilder lb = new LinkBuilder().setLinkId(buildLinkId(base, linkCase)).addAugmentation(new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
final NodeId srcNode = buildNodeId(base, linkCase.getLocalNodeDescriptors());
LOG.trace("Link {} implies source node {}", linkCase, srcNode);
final NodeId dstNode = buildNodeId(base, linkCase.getRemoteNodeDescriptors());
LOG.trace("Link {} implies destination node {}", linkCase, dstNode);
final TerminationPoint srcTp = buildLocalTp(base, linkCase.getLinkDescriptors());
LOG.trace("Link {} implies source TP {}", linkCase, srcTp);
final TerminationPoint dstTp = buildRemoteTp(base, linkCase.getLinkDescriptors());
LOG.trace("Link {} implies destination TP {}", linkCase, dstTp);
lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
LOG.trace("Created TP {} as link source", srcTp);
NodeHolder snh = this.nodes.get(srcNode);
if (snh == null) {
snh = getNode(srcNode);
snh.addTp(srcTp, lb.getLinkId(), false);
if (adjSid != null) {
snh.createSrHolderIfRequired().addAdjacencySid(trans, false, lb.getLinkId(), adjSid);
}
putNode(trans, snh);
} else {
snh.addTp(srcTp, lb.getLinkId(), false);
if (adjSid != null) {
snh.createSrHolderIfRequired().addAdjacencySid(trans, true, lb.getLinkId(), adjSid);
}
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.key()), srcTp);
}
if (adjSid != null) {
lb.addAugmentation(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Link1Builder().setSegment(new SegmentId(Uint32.valueOf(adjSid))).build());
}
LOG.debug("Created TP {} as link destination", dstTp);
NodeHolder dnh = this.nodes.get(dstNode);
if (dnh == null) {
dnh = getNode(dstNode);
dnh.addTp(dstTp, lb.getLinkId(), true);
putNode(trans, dnh);
} else {
dnh.addTp(dstTp, lb.getLinkId(), true);
final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, new NodeKey(dnh.getNodeId()));
trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.key()), dstTp);
}
final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
final Link link = lb.build();
trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
LOG.debug("Created link {} at {} for {}", link, lid, linkCase);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase in project bgpcep by opendaylight.
the class LinkstateGraphBuilder method createEdgeAttributes.
/**
* Create Edge Attributes from Link attributes.
*
* @param la Linkstate Attributes
* @param linkDesc Linkstate Descriptors
*
* @return EdgeAttributes
*/
private static EdgeAttributes createEdgeAttributes(final LinkAttributes la, final LinkDescriptors linkDesc) {
EdgeAttributesBuilder builder = new EdgeAttributesBuilder();
if (linkDesc.getIpv4InterfaceAddress() != null) {
builder.setLocalAddress(new IpAddress(linkDesc.getIpv4InterfaceAddress()));
}
if (linkDesc.getIpv6InterfaceAddress() != null) {
builder.setLocalAddress(new IpAddress(linkDesc.getIpv6InterfaceAddress()));
}
if (linkDesc.getIpv4NeighborAddress() != null) {
builder.setRemoteAddress(new IpAddress(linkDesc.getIpv4NeighborAddress()));
}
if (linkDesc.getIpv6NeighborAddress() != null) {
builder.setRemoteAddress(new IpAddress(linkDesc.getIpv6NeighborAddress()));
}
if (linkDesc.getLinkLocalIdentifier() != null) {
builder.setLocalIdentifier(linkDesc.getLinkLocalIdentifier());
}
if (linkDesc.getLinkRemoteIdentifier() != null) {
builder.setRemoteIdentifier(linkDesc.getLinkRemoteIdentifier());
}
if (la.getMetric() != null) {
builder.setMetric(la.getMetric().getValue());
}
if (la.getTeMetric() != null) {
builder.setTeMetric(la.getTeMetric().getValue());
}
if (la.getMaxLinkBandwidth() != null) {
builder.setMaxLinkBandwidth(bandwithToDecimalBandwidth(la.getMaxLinkBandwidth()));
}
if (la.getMaxReservableBandwidth() != null) {
builder.setMaxResvLinkBandwidth(bandwithToDecimalBandwidth(la.getMaxReservableBandwidth()));
}
if (la.getUnreservedBandwidth() != null) {
int upperBound = Math.min(la.getUnreservedBandwidth().size(), MAX_PRIORITY);
final List<UnreservedBandwidth> unRsvBw = new ArrayList<>(upperBound);
for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.UnreservedBandwidth bandwidth : la.nonnullUnreservedBandwidth().values()) {
unRsvBw.add(new UnreservedBandwidthBuilder().setBandwidth(bandwithToDecimalBandwidth(bandwidth.getBandwidth())).withKey(new UnreservedBandwidthKey(bandwidth.getPriority())).build());
}
builder.setUnreservedBandwidth(unRsvBw);
}
if (la.getAdminGroup() != null) {
builder.setAdminGroup(la.getAdminGroup().getValue());
}
if (la.getLinkDelay() != null) {
builder.setDelay(new Delay(la.getLinkDelay().getValue()));
}
if (la.getLinkMinMaxDelay() != null && la.getLinkMinMaxDelay() != null) {
MinMaxDelay mmDelay = new MinMaxDelayBuilder().setMaxDelay(new Delay(la.getLinkMinMaxDelay().getMaxDelay().getValue())).setMinDelay(new Delay(la.getLinkMinMaxDelay().getMinDelay().getValue())).build();
builder.setMinMaxDelay(mmDelay);
}
if (la.getDelayVariation() != null) {
builder.setJitter(new Delay(la.getDelayVariation().getValue()));
}
if (la.getLinkLoss() != null) {
builder.setLoss(new Loss(la.getLinkLoss().getValue()));
}
if (la.getAvailableBandwidth() != null) {
builder.setAvailableBandwidth(bandwithToDecimalBandwidth(la.getAvailableBandwidth()));
}
if (la.getResidualBandwidth() != null) {
builder.setResidualBandwidth(bandwithToDecimalBandwidth(la.getResidualBandwidth()));
}
if (la.getUtilizedBandwidth() != null) {
builder.setUtilizedBandwidth(bandwithToDecimalBandwidth(la.getUtilizedBandwidth()));
}
if (la.getSharedRiskLinkGroups() != null) {
List<Uint32> srlgs = new ArrayList<>();
for (SrlgId srlg : la.getSharedRiskLinkGroups()) {
srlgs.add(srlg.getValue());
}
builder.setSrlgs(srlgs);
}
for (SrAdjIds adj : la.nonnullSrAdjIds()) {
if (adj.getSidLabelIndex() instanceof LocalLabelCase) {
boolean backup = false;
if (adj.getFlags() instanceof OspfAdjFlags) {
backup = ((OspfAdjFlags) adj.getFlags()).getBackup();
}
if (adj.getFlags() instanceof IsisAdjFlags) {
backup = ((IsisAdjFlags) adj.getFlags()).getBackup();
}
if (!backup) {
builder.setAdjSid(((LocalLabelCase) adj.getSidLabelIndex()).getLocalLabel().getValue());
} else {
builder.setBackupAdjSid(((LocalLabelCase) adj.getSidLabelIndex()).getLocalLabel().getValue());
}
}
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createNode.
private void createNode(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final NodeCase nodeCase, final Attributes attributes) {
final NodeAttributes na;
// defensive lookup
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
na = ((NodeAttributesCase) attrType).getNodeAttributes();
} else {
LOG.debug("Missing attribute type in node {} route {}, skipping it", nodeCase, value);
na = null;
}
} else {
LOG.debug("Missing attributes in node {} route {}, skipping it", nodeCase, value);
na = null;
}
final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
final List<IpAddress> ids = new ArrayList<>();
Long srgbFirstValue = null;
Integer srgbRangeSize = null;
if (na != null) {
if (na.getIpv4RouterId() != null) {
ids.add(new IpAddress(na.getIpv4RouterId()));
}
if (na.getIpv6RouterId() != null) {
ids.add(new IpAddress(na.getIpv6RouterId()));
}
if (na.getDynamicHostname() != null) {
inab.setName(new DomainName(na.getDynamicHostname()));
}
if (na.getSrCapabilities() != null) {
final SidLabelIndex sidLabelIndex = na.getSrCapabilities().getSidLabelIndex();
if (sidLabelIndex instanceof LocalLabelCase) {
srgbFirstValue = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
}
srgbRangeSize = na.getSrCapabilities().getRangeSize() != null ? na.getSrCapabilities().getRangeSize().getValue().intValue() : null;
}
}
if (!ids.isEmpty()) {
inab.setRouterId(ids);
}
ProtocolUtil.augmentProtocolId(value, inab, na, nodeCase.getNodeDescriptors());
final NodeId nid = buildNodeId(base, nodeCase.getNodeDescriptors());
final NodeHolder nh = getNode(nid);
/*
* Eventhough the the holder creates a dummy structure, we need to duplicate it here,
* as that is the API requirement. The reason for it is the possible presence of supporting
* node -- something which the holder does not track.
*/
final NodeBuilder nb = new NodeBuilder();
nb.setNodeId(nid);
nb.withKey(new NodeKey(nb.getNodeId()));
nh.advertized(nb, inab);
if (srgbFirstValue != null && srgbRangeSize != null) {
nh.createSrHolderIfRequired().addSrgb(trans, false, srgbFirstValue, srgbRangeSize);
}
putNode(trans, nh);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase in project bgpcep by opendaylight.
the class LinkstateGraphBuilder method getVertex.
/**
* Create Vertex from the Node Attributes.
*
* @param na Node Attributes
* @param cvertex Connected Vertex associated to this Vertex
* @param as As number
*
* @return New Vertex
*/
private static Vertex getVertex(final NodeAttributes na, final Uint64 id, final Uint32 as) {
VertexBuilder builder = new VertexBuilder().setVertexId(id).setAsn(as);
if (na.getIpv4RouterId() != null) {
builder.setRouterId(new IpAddress(na.getIpv4RouterId()));
}
if (na.getIpv6RouterId() != null) {
builder.setRouterId(new IpAddress(na.getIpv6RouterId()));
}
/*
* Set Router Name with dynamic hostname (IS-IS) or IPv4 address in dot decimal format (OSPF)
*/
if (na.getDynamicHostname() != null) {
builder.setName(na.getDynamicHostname());
} else {
int key = id.intValue();
builder.setName((key << 24 & 0xFF) + "." + (key << 16 & 0xFF) + "." + (key << 8 & 0xFF) + "." + (key & 0xFF));
}
if (na.getSrCapabilities() != null) {
final SidLabelIndex labelIndex = na.getSrCapabilities().getSidLabelIndex();
if (labelIndex instanceof LocalLabelCase) {
builder.setSrgb(new SrgbBuilder().setLowerBound(((LocalLabelCase) labelIndex).getLocalLabel().getValue()).setRangeSize(na.getSrCapabilities().getRangeSize().getValue()).build());
} else if (labelIndex instanceof SidCase) {
builder.setSrgb(new SrgbBuilder().setLowerBound(((SidCase) labelIndex).getSid()).setRangeSize(na.getSrCapabilities().getRangeSize().getValue()).build());
}
}
if (na.getNodeFlags() != null) {
if (na.getNodeFlags().getAbr()) {
builder.setVertexType(VertexType.Abr);
}
if (na.getNodeFlags().getExternal()) {
builder.setVertexType(VertexType.AsbrOut);
}
} else {
builder.setVertexType(VertexType.Standard);
}
return builder.build();
}
Aggregations