use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex in project bgpcep by opendaylight.
the class SrLinkAttributesParser method parseAdjacencySegmentIdentifier.
public static SrAdjIds parseAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) {
final Flags adjFlags;
final Weight weight;
final SidLabelIndex sidValue;
if (buffer.isReadable()) {
final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
adjFlags = parseFlags(flags, protocolId);
weight = new Weight(readUint8(buffer));
buffer.skipBytes(RESERVED);
final boolean isValue;
final boolean isLocal;
switch(protocolId) {
case IsisLevel1:
case IsisLevel2:
isValue = flags.get(VALUE_ISIS);
isLocal = flags.get(LOCAL_ISIS);
break;
case Ospf:
case OspfV3:
isValue = flags.get(VALUE_OSPF);
isLocal = flags.get(LOCAL_OSPF);
break;
default:
return null;
}
sidValue = SidLabelIndexParser.parseSidLabelIndexByFlags(Size.forValue(buffer.readableBytes()), buffer, isValue, isLocal);
} else {
adjFlags = null;
weight = null;
sidValue = null;
}
return new SrAdjIdsBuilder().setFlags(adjFlags).setSidLabelIndex(sidValue).setWeight(weight).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex in project bgpcep by opendaylight.
the class SrLinkAttributesParser method serializeAdjFlags.
private static BitArray serializeAdjFlags(final Flags flags, final SidLabelIndex sidLabelIndex) {
final BitArray bitFlags = new BitArray(FLAGS_BITS_SIZE);
if (flags instanceof OspfAdjFlagsCase) {
final OspfAdjFlags ospfFlags = ((OspfAdjFlagsCase) flags).getOspfAdjFlags();
bitFlags.set(BACKUP_OSPF, ospfFlags.getBackup());
bitFlags.set(SET_OSPF, ospfFlags.getSet());
SidLabelIndexParser.setFlags(sidLabelIndex, bitFlags, VALUE_OSPF, LOCAL_OSPF);
} else if (flags instanceof IsisAdjFlagsCase) {
final IsisAdjFlags isisFlags = ((IsisAdjFlagsCase) flags).getIsisAdjFlags();
bitFlags.set(ADDRESS_FAMILY_FLAG, isisFlags.getAddressFamily());
bitFlags.set(BACKUP_ISIS, isisFlags.getBackup());
bitFlags.set(SET_ISIS, isisFlags.getSet());
SidLabelIndexParser.setFlags(sidLabelIndex, bitFlags, VALUE_ISIS, LOCAL_ISIS);
} else if (flags == null) {
SidLabelIndexParser.setFlags(sidLabelIndex, bitFlags, VALUE_EPE, LOCAL_EPE);
}
return bitFlags;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex 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.SidLabelIndex 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.SidLabelIndex in project bgpcep by opendaylight.
the class SrPrefixAttributesParser method serializePrefixFlags.
private static BitArray serializePrefixFlags(final Flags flags, final SidLabelIndex sidLabelIndex) {
final BitArray bitFlags = new BitArray(FLAGS_SIZE);
SidLabelIndexParser.setFlags(sidLabelIndex, bitFlags, VALUE, LOCAL);
if (flags instanceof OspfPrefixFlagsCase) {
final OspfPrefixFlags ospfFlags = ((OspfPrefixFlagsCase) flags).getOspfPrefixFlags();
bitFlags.set(NO_PHP_OSPF, ospfFlags.getNoPhp());
bitFlags.set(MAPPING_SERVER, ospfFlags.getMappingServer());
bitFlags.set(EXPLICIT_NULL, ospfFlags.getExplicitNull());
} else if (flags instanceof IsisPrefixFlagsCase) {
final IsisPrefixFlags isisFlags = ((IsisPrefixFlagsCase) flags).getIsisPrefixFlags();
bitFlags.set(RE_ADVERTISEMENT, isisFlags.getReadvertisement());
bitFlags.set(NODE_SID, isisFlags.getNodeSid());
bitFlags.set(NO_PHP, isisFlags.getNoPhp());
bitFlags.set(EXPLICIT_NULL, isisFlags.getExplicitNull());
}
return bitFlags;
}
Aggregations