2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.bgpcep.bgp.topology.provider;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.VisibleForTesting;
13 import com.google.common.base.Preconditions;
14 import com.google.common.collect.Collections2;
15 import com.google.common.collect.Lists;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.List;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
24 import org.opendaylight.mdsal.binding.api.WriteTransaction;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.protocol.bgp.rib.RibReference;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4InterfaceIdentifier;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv6InterfaceIdentifier;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateAddressFamily;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateSubsequentAddressFamily;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.TopologyIdentifier;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.ObjectType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrAdjIds;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.LinkCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.PrefixCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LinkDescriptors;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.LinkstateRoutes;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.LinkstateRoute;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.prefix.sid.tlv.Flags;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.prefix.sid.tlv.flags.IsisPrefixFlagsCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.sr.node.attributes.Segments;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.sr.node.attributes.SegmentsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.sr.node.attributes.SegmentsKey;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.sr.node.attributes.segments.segment.specification.AdjacencyCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.sr.node.attributes.segments.segment.specification.PrefixCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.sr.node.attributes.segments.segment.specification.adjacency._case.AdjacencyBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.topology.sr.type.TopologySrBuilder;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixKey;
98 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
99 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.TerminationPointType;
100 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.IpBuilder;
101 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.UnnumberedBuilder;
102 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
103 import org.opendaylight.yangtools.yang.common.Uint32;
104 import org.slf4j.Logger;
105 import org.slf4j.LoggerFactory;
107 public class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
109 static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder()
110 .addAugmentation(new TopologyTypes1Builder()
111 .setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build()).build();
113 static final TopologyTypes SR_AWARE_LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder(LINKSTATE_TOPOLOGY_TYPE)
114 .addAugmentation(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819
115 .TopologyTypes1Builder().setTopologySr(new TopologySrBuilder().build()).build())
118 private static final String UNHANDLED_OBJECT_CLASS = "Unhandled object class {}";
120 private static final class TpHolder {
121 private final Set<LinkId> local = new HashSet<>();
122 private final Set<LinkId> remote = new HashSet<>();
124 private final TerminationPoint tp;
126 TpHolder(final TerminationPoint tp) {
127 this.tp = requireNonNull(tp);
130 synchronized void addLink(final LinkId id, final boolean isRemote) {
138 synchronized boolean removeLink(final LinkId id, final boolean isRemote) {
139 final boolean removed;
141 removed = this.remote.remove(id);
143 removed = this.local.remove(id);
146 LOG.warn("Removed non-reference link {} from TP {} isRemote {}", this.tp.getTpId().getValue(),
147 id.getValue(), isRemote);
150 return this.local.isEmpty() && this.remote.isEmpty();
153 TerminationPoint getTp() {
158 private final class NodeHolder {
159 private final Map<PrefixKey, Prefix> prefixes = new HashMap<>();
160 private final Map<TpId, TpHolder> tps = new HashMap<>();
161 private boolean advertized = false;
162 private IgpNodeAttributesBuilder inab;
163 private NodeBuilder nb;
164 private NodeSrHolder sr;
166 NodeHolder(final NodeId id) {
167 this.inab = new IgpNodeAttributesBuilder();
168 this.nb = new NodeBuilder().withKey(new NodeKey(id)).setNodeId(id);
172 * Synchronized in-core state of a node into the backing store using the transaction.
174 * @param trans data modification transaction which to use
175 * @return True if the node has been purged, false otherwise.
177 boolean syncState(final WriteTransaction trans) {
178 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.key());
181 * Transaction's putOperationalData() does a merge. Force it onto a replace
182 * by removing the data. If we decide to remove the node -- we just skip the put.
184 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
186 if (!this.advertized) {
187 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
188 LOG.trace("Removing unadvertized unused node {}", this.nb.getNodeId().getValue());
192 LOG.trace("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId().getValue(),
193 this.tps.size(), this.prefixes.size());
196 // Re-generate termination points
197 this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), TpHolder::getTp)));
199 // Re-generate prefixes
200 this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
202 // Write the node out
203 if (this.sr != null && this.sr.getSegmentCount() > 0) {
204 this.nb.addAugmentation(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr
205 .rev130819.Node1Builder().setSegments(this.sr.getSegments()).build());
207 final Node n = this.nb
208 .addAugmentation(new Node1Builder().setIgpNodeAttributes(this.inab.build()).build())
210 trans.put(LogicalDatastoreType.OPERATIONAL, nid, n);
211 LOG.trace("Created node {} at {}", n, nid);
215 boolean checkForRemoval(final WriteTransaction trans) {
216 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.key());
218 if (!this.advertized) {
219 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
220 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
221 LOG.trace("Removing unadvertized unused node {}", this.nb.getNodeId().getValue());
225 LOG.trace("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId().getValue(),
226 this.tps.size(), this.prefixes.size());
231 synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
232 final TpHolder h = this.tps.get(tp);
234 if (h.removeLink(link, isRemote)) {
236 LOG.trace("Removed TP {}", tp.getValue());
239 LOG.warn("Removed non-present TP {} by link {}", tp.getValue(), link.getValue());
243 void addTp(final TerminationPoint tp, final LinkId link, final boolean isRemote) {
244 final TpHolder h = this.tps.computeIfAbsent(tp.getTpId(), k -> new TpHolder(tp));
245 h.addLink(link, isRemote);
248 void addPrefix(final Prefix pfx) {
249 this.prefixes.put(pfx.key(), pfx);
252 void removePrefix(final PrefixCase prefixCase) {
253 this.prefixes.remove(new PrefixKey(prefixCase.getPrefixDescriptors().getIpReachabilityInformation()));
256 void unadvertized() {
257 this.inab = new IgpNodeAttributesBuilder();
258 this.nb = new NodeBuilder().withKey(this.nb.key()).setNodeId(this.nb.getNodeId());
259 this.advertized = false;
260 LOG.debug("Node {} is unadvertized", this.nb.getNodeId().getValue());
263 void advertized(final NodeBuilder nodeBuilder, final IgpNodeAttributesBuilder igpNodeAttBuilder) {
264 this.nb = requireNonNull(nodeBuilder);
265 this.inab = requireNonNull(igpNodeAttBuilder);
266 this.advertized = true;
267 LOG.debug("Node {} is advertized", nodeBuilder.getNodeId().getValue());
271 return this.nb.getNodeId();
274 NodeSrHolder getSrHolder() {
278 NodeSrHolder createSrHolderIfRequired() {
279 if (this.sr == null) {
280 this.sr = new NodeSrHolder(this.nb.getNodeId());
286 private final class NodeSrHolder {
287 private final NodeId nodeId;
288 private Long srgbFirstValue = null;
289 private Integer srgbRangeSize = null;
290 private final List<Segments> segments = new ArrayList<>();
291 private final Map<IpPrefix, SrPrefix> srPrefixes = new HashMap<>();
292 private final Map<IpPrefix, Segments> prefixSegments = new HashMap<>();
293 private final Map<LinkId, Segments> adjSegments = new HashMap<>();
295 NodeSrHolder(final NodeId nodeId) {
296 this.nodeId = nodeId;
299 void addSrgb(final WriteTransaction trans, final boolean updateNode, final Long srgbFirstVal,
300 final Integer srgbRangeSz) {
301 this.srgbFirstValue = srgbFirstVal;
302 this.srgbRangeSize = srgbRangeSz;
303 this.srPrefixes.entrySet().forEach(entry -> {
304 final IpPrefix ippfx = entry.getKey();
305 final SrPrefix srPrefix = entry.getValue();
306 final SidLabelIndex sidLabelIndex = srPrefix.getSidLabelIndex();
307 if (sidLabelIndex instanceof SidCase) {
308 final Long sidIndex = ((SidCase) sidLabelIndex).getSid().longValue();
309 if (sidIndex >= this.srgbRangeSize) {
310 LOG.warn("Prefix SID index {} is outside the SRGB range of {} for node {}", sidIndex,
311 this.srgbRangeSize, this.nodeId.getValue());
314 final Long prefixSid = this.srgbFirstValue + sidIndex;
315 final boolean isNodeSid = isAssociatedWithNodeSid(ippfx, srPrefix);
316 addPrefixSid(trans, updateNode, ippfx, prefixSid, isNodeSid);
321 void removeSrgb(final WriteTransaction trans) {
322 this.srgbFirstValue = null;
323 this.srgbRangeSize = null;
324 this.srPrefixes.entrySet().forEach(entry -> {
325 final IpPrefix ippfx = entry.getKey();
326 final SrPrefix srPrefix = entry.getValue();
327 final SidLabelIndex sidLabelIndex = srPrefix.getSidLabelIndex();
328 if (sidLabelIndex instanceof SidCase) {
329 removePrefixSid(trans, false, ippfx);
334 void addSrPrefix(final WriteTransaction trans, final boolean updateNode, final IpPrefix ippfx,
335 final SrPrefix srPrefix) {
336 this.srPrefixes.put(ippfx, srPrefix);
337 final SidLabelIndex sidLabelIndex = srPrefix.getSidLabelIndex();
338 Long prefixSid = null;
339 if (sidLabelIndex instanceof LocalLabelCase) {
340 prefixSid = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
341 } else if (sidLabelIndex instanceof SidCase) {
342 if (this.srgbFirstValue != null && this.srgbRangeSize != null) {
343 final Long sidIndex = ((SidCase) sidLabelIndex).getSid().longValue();
344 if (sidIndex >= this.srgbRangeSize) {
345 LOG.warn("Prefix SID index {} is outside the SRGB range of {} for node {}", sidIndex,
346 this.srgbRangeSize, this.nodeId.getValue());
349 prefixSid = this.srgbFirstValue + sidIndex;
352 if (prefixSid != null) {
353 final boolean isNodeSid = isAssociatedWithNodeSid(ippfx, srPrefix);
354 addPrefixSid(trans, updateNode, ippfx, prefixSid, isNodeSid);
358 void removeSrPrefix(final WriteTransaction trans, final IpPrefix ippfx) {
359 if (!this.srPrefixes.containsKey(ippfx)) {
362 removePrefixSid(trans, true, ippfx);
363 this.srPrefixes.remove(ippfx);
366 void addPrefixSid(final WriteTransaction trans, final boolean updateNode, final IpPrefix ippfx,
367 final Long prefixSid, final boolean isNodeSid) {
368 LOG.trace("Adding prefix SID {} for prefix {} on node {}", prefixSid, ippfx.stringValue(),
369 this.nodeId.getValue());
370 final SegmentId segmentId = new SegmentId(Uint32.valueOf(prefixSid));
371 final Segments prefixSegment = new SegmentsBuilder()
372 .setSegmentId(segmentId)
373 .withKey(new SegmentsKey(segmentId))
374 .setSegmentSpecification(new PrefixCaseBuilder()
375 .setPrefix(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr
376 .rev130819.sr.node.attributes.segments.segment.specification.prefix._case.PrefixBuilder()
377 .setPrefix(ippfx).setNodeSid(isNodeSid ? isNodeSid : null).build())
380 this.prefixSegments.put(ippfx, prefixSegment);
381 this.segments.add(prefixSegment);
382 addSegment(trans, updateNode, prefixSegment);
385 void removePrefixSid(final WriteTransaction trans, final boolean updateNode, final IpPrefix ippfx) {
386 if (!this.prefixSegments.containsKey(ippfx)) {
389 LOG.trace("Removing prefix SID for prefix {} on node {}", ippfx.stringValue(),
390 this.nodeId.getValue());
391 final Segments prefixSegment = this.prefixSegments.remove(ippfx);
392 this.segments.remove(prefixSegment);
393 removeSegment(trans, updateNode, prefixSegment);
396 void addAdjacencySid(final WriteTransaction trans, final boolean updateNode, final LinkId linkId,
398 LOG.trace("Adding adjacency SID {} for link {} on node {}", adjSid, linkId.getValue(),
399 this.nodeId.getValue());
400 final SegmentId segmentId = new SegmentId(Uint32.valueOf(adjSid));
401 final SegmentsBuilder sb = new SegmentsBuilder();
402 sb.setSegmentId(segmentId);
403 sb.withKey(new SegmentsKey(segmentId));
404 sb.setSegmentSpecification(new AdjacencyCaseBuilder()
405 .setAdjacency(new AdjacencyBuilder().setAdjacency(linkId).build()).build());
406 final Segments adjSegment = sb.build();
407 this.adjSegments.put(linkId, adjSegment);
408 this.segments.add(adjSegment);
409 addSegment(trans, updateNode, adjSegment);
412 void removeAdjacencySid(final WriteTransaction trans, final LinkId linkId) {
413 if (!this.adjSegments.containsKey(linkId)) {
416 LOG.trace("Removing adjacency SID for link {} on node {}", linkId.getValue(),
417 this.nodeId.getValue());
418 final Segments adjSegment = this.adjSegments.remove(linkId);
419 this.segments.remove(adjSegment);
420 removeSegment(trans, true, adjSegment);
423 void addSegment(final WriteTransaction trans, final boolean updateNode, final Segments segment) {
425 final InstanceIdentifier<Node> nodeIId = getNodeInstanceIdentifier(new NodeKey(this.nodeId));
426 final InstanceIdentifier<Segments> segmentIId = nodeIId.builder()
427 .augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr
428 .rev130819.Node1.class)
429 .child(Segments.class, segment.key()).build();
430 trans.put(LogicalDatastoreType.OPERATIONAL, segmentIId, segment);
432 addSrAwareTopologyType(trans);
435 void removeSegment(final WriteTransaction trans, final boolean updateNode, final Segments segment) {
437 final InstanceIdentifier<Node> nodeIId = getNodeInstanceIdentifier(new NodeKey(this.nodeId));
438 final InstanceIdentifier<Segments> segmentIId = nodeIId.builder()
439 .augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr
440 .rev130819.Node1.class)
441 .child(Segments.class, segment.key()).build();
442 trans.delete(LogicalDatastoreType.OPERATIONAL, segmentIId);
444 removeSrAwareTopologyTypeIfRequired(trans);
447 boolean isAssociatedWithNodeSid(final IpPrefix ippfx, final SrPrefix srPrefix) {
448 if (ippfx.getIpv4Prefix() != null && !ippfx.stringValue().endsWith("/32")
449 || ippfx.getIpv6Prefix() != null && !ippfx.stringValue().endsWith("/128")) {
452 final Flags prefixFlags = srPrefix.getFlags();
453 if (prefixFlags instanceof IsisPrefixFlagsCase) {
454 return !Boolean.FALSE.equals(((IsisPrefixFlagsCase) prefixFlags).getIsisPrefixFlags().isNodeSid());
459 List<Segments> getSegments() {
460 return this.segments;
463 int getSegmentCount() {
464 return this.segments.size();
468 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
469 private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
470 private boolean srAwareTopologyTypeAdded;
472 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
473 final TopologyId topologyId) {
474 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class,
475 LinkstateSubsequentAddressFamily.class);
479 LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
480 final TopologyId topologyId, final long listenerResetLimitInMillsec,
481 final int listenerResetEnforceCounter) {
482 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class,
483 LinkstateSubsequentAddressFamily.class,
484 listenerResetLimitInMillsec, listenerResetEnforceCounter);
487 private static LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
488 return new LinkId(new UriBuilder(base, "link").add(link).toString());
491 private static NodeId buildNodeId(final UriBuilder base, final org.opendaylight.yang.gen.v1.urn.opendaylight
492 .params.xml.ns.yang.bgp.linkstate.rev200120.NodeIdentifier node) {
493 return new NodeId(new UriBuilder(base, "node").addPrefix("", node).toString());
496 private static TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
497 final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
498 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Uint32 id) {
499 final UriBuilder b = new UriBuilder(base, "tp");
500 if (topologyIdentifier != null) {
501 b.add("mt", topologyIdentifier.getValue());
503 if (ipv4InterfaceIdentifier != null) {
504 b.add("ipv4", ipv4InterfaceIdentifier.getValue());
506 if (ipv6InterfaceIdentifier != null) {
507 b.add("ipv6", ipv6InterfaceIdentifier.getValue());
510 return new TpId(b.add("id", id).toString());
513 private static TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
514 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
515 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
518 private static TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
519 final TerminationPointBuilder stpb = new TerminationPointBuilder();
520 stpb.withKey(new TerminationPointKey(id));
524 stpb.addAugmentation(new TerminationPoint1Builder()
525 .setIgpTerminationPointAttributes(new IgpTerminationPointAttributesBuilder()
526 .setTerminationPointType(type)
534 private static TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
535 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Uint32 id) {
536 // Order of preference: Unnumbered first, then IP
538 LOG.debug("Unnumbered termination point type: {}", id);
539 return new UnnumberedBuilder().setUnnumberedId(id).build();
543 if (ipv6InterfaceIdentifier != null) {
544 ip = new IpAddress(ipv6InterfaceIdentifier);
545 } else if (ipv4InterfaceIdentifier != null) {
546 ip = new IpAddress(ipv4InterfaceIdentifier);
552 LOG.debug("IP termination point type: {}", ip);
553 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
559 private static TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
560 final TpId id = buildLocalTpId(base, linkDescriptors);
561 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(),
562 linkDescriptors.getIpv6InterfaceAddress(),
563 linkDescriptors.getLinkLocalIdentifier());
565 return buildTp(id, t);
568 private static TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
569 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
570 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
573 private static TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
574 final TpId id = buildRemoteTpId(base, linkDescriptors);
575 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(),
576 linkDescriptors.getIpv6NeighborAddress(),
577 linkDescriptors.getLinkRemoteIdentifier());
579 return buildTp(id, t);
582 private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
583 return getInstanceIdentifier().child(
584 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology
585 .topology.Link.class, new LinkKey(id));
588 private NodeHolder getNode(final NodeId id) {
589 return this.nodes.computeIfAbsent(id, NodeHolder::new);
592 private void putNode(final WriteTransaction trans, final NodeHolder holder) {
593 if (holder.syncState(trans)) {
594 this.nodes.remove(holder.getNodeId());
598 private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) {
599 if (holder.checkForRemoval(trans)) {
600 this.nodes.remove(holder.getNodeId());
604 private void createLink(final WriteTransaction trans, final UriBuilder base,
605 final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
607 final LinkAttributes la;
608 final Attributes1 attr = attributes.augmentation(Attributes1.class);
610 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
611 if (attrType != null) {
612 la = ((LinkAttributesCase)attrType).getLinkAttributes();
614 LOG.debug("Missing attribute type in link {} route {}, skipping it", linkCase, value);
618 LOG.debug("Missing attributes in link {} route {}, skipping it", linkCase, value);
622 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
625 if (la.getMetric() != null) {
626 ilab.setMetric(la.getMetric().getValue());
628 ilab.setName(la.getLinkName());
629 if (la.getSrAdjIds() != null && !la.getSrAdjIds().isEmpty()) {
630 final SrAdjIds srAdjIds = la.getSrAdjIds().get(0);
631 if (srAdjIds != null) {
632 final SidLabelIndex sidLabelIndex = srAdjIds.getSidLabelIndex();
633 if (sidLabelIndex instanceof LocalLabelCase) {
634 adjSid = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
639 ProtocolUtil.augmentProtocolId(value, ilab, la, linkCase.getLinkDescriptors());
641 final LinkBuilder lb = new LinkBuilder()
642 .setLinkId(buildLinkId(base, linkCase))
643 .addAugmentation(new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
645 final NodeId srcNode = buildNodeId(base, linkCase.getLocalNodeDescriptors());
646 LOG.trace("Link {} implies source node {}", linkCase, srcNode);
648 final NodeId dstNode = buildNodeId(base, linkCase.getRemoteNodeDescriptors());
649 LOG.trace("Link {} implies destination node {}", linkCase, dstNode);
651 final TerminationPoint srcTp = buildLocalTp(base, linkCase.getLinkDescriptors());
652 LOG.trace("Link {} implies source TP {}", linkCase, srcTp);
654 final TerminationPoint dstTp = buildRemoteTp(base, linkCase.getLinkDescriptors());
655 LOG.trace("Link {} implies destination TP {}", linkCase, dstTp);
657 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
658 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
660 LOG.trace("Created TP {} as link source", srcTp);
661 NodeHolder snh = this.nodes.get(srcNode);
663 snh = getNode(srcNode);
664 snh.addTp(srcTp, lb.getLinkId(), false);
665 if (adjSid != null) {
666 snh.createSrHolderIfRequired().addAdjacencySid(trans, false, lb.getLinkId(), adjSid);
670 snh.addTp(srcTp, lb.getLinkId(), false);
671 if (adjSid != null) {
672 snh.createSrHolderIfRequired().addAdjacencySid(trans, true, lb.getLinkId(), adjSid);
674 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
675 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.key()), srcTp);
677 if (adjSid != null) {
678 lb.addAugmentation(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr
679 .rev130819.Link1Builder().setSegment(new SegmentId(Uint32.valueOf(adjSid))).build());
682 LOG.debug("Created TP {} as link destination", dstTp);
683 NodeHolder dnh = this.nodes.get(dstNode);
685 dnh = getNode(dstNode);
686 dnh.addTp(dstTp, lb.getLinkId(), true);
689 dnh.addTp(dstTp, lb.getLinkId(), true);
690 final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
691 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network
692 .topology.topology.Node.class, new NodeKey(dnh.getNodeId()));
693 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.key()), dstTp);
696 final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
697 final Link link = lb.build();
699 trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
700 LOG.debug("Created link {} at {} for {}", link, lid, linkCase);
703 private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
704 final LinkId link, final boolean isRemote) {
705 final NodeHolder nh = this.nodes.get(node);
707 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
708 trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class,
709 new TerminationPointKey(tp)));
710 nh.removeTp(tp, link, isRemote);
712 nh.createSrHolderIfRequired().removeAdjacencySid(trans, link);
714 checkNodeForRemoval(trans, nh);
716 LOG.warn("Removed non-existent node {}", node.getValue());
720 private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase linkCase) {
721 final LinkId id = buildLinkId(base, linkCase);
722 final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
723 trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
724 LOG.debug("Removed link {}", lid);
726 removeTp(trans, buildNodeId(base, linkCase.getLocalNodeDescriptors()),
727 buildLocalTpId(base, linkCase.getLinkDescriptors()), id, false);
728 removeTp(trans, buildNodeId(base, linkCase.getRemoteNodeDescriptors()),
729 buildRemoteTpId(base, linkCase.getLinkDescriptors()), id, true);
732 private void createNode(final WriteTransaction trans, final UriBuilder base,
733 final LinkstateRoute value, final NodeCase nodeCase, final Attributes attributes) {
734 final NodeAttributes na;
736 final Attributes1 attr = attributes.augmentation(Attributes1.class);
738 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
739 if (attrType != null) {
740 na = ((NodeAttributesCase)attrType).getNodeAttributes();
742 LOG.debug("Missing attribute type in node {} route {}, skipping it", nodeCase, value);
746 LOG.debug("Missing attributes in node {} route {}, skipping it", nodeCase, value);
749 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
750 final List<IpAddress> ids = new ArrayList<>();
751 Long srgbFirstValue = null;
752 Integer srgbRangeSize = null;
754 if (na.getIpv4RouterId() != null) {
755 ids.add(new IpAddress(na.getIpv4RouterId()));
757 if (na.getIpv6RouterId() != null) {
758 ids.add(new IpAddress(na.getIpv6RouterId()));
760 if (na.getDynamicHostname() != null) {
761 inab.setName(new DomainName(na.getDynamicHostname()));
763 if (na.getSrCapabilities() != null) {
764 final SidLabelIndex sidLabelIndex = na.getSrCapabilities().getSidLabelIndex();
765 if (sidLabelIndex instanceof LocalLabelCase) {
766 srgbFirstValue = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
768 srgbRangeSize = na.getSrCapabilities().getRangeSize() != null
769 ? na.getSrCapabilities().getRangeSize().getValue().intValue()
773 if (!ids.isEmpty()) {
774 inab.setRouterId(ids);
776 ProtocolUtil.augmentProtocolId(value, inab, na, nodeCase.getNodeDescriptors());
778 final NodeId nid = buildNodeId(base, nodeCase.getNodeDescriptors());
779 final NodeHolder nh = getNode(nid);
781 * Eventhough the the holder creates a dummy structure, we need to duplicate it here,
782 * as that is the API requirement. The reason for it is the possible presence of supporting
783 * node -- something which the holder does not track.
785 final NodeBuilder nb = new NodeBuilder();
787 nb.withKey(new NodeKey(nb.getNodeId()));
789 nh.advertized(nb, inab);
790 if (srgbFirstValue != null && srgbRangeSize != null) {
791 nh.createSrHolderIfRequired().addSrgb(trans, false, srgbFirstValue, srgbRangeSize);
796 private void removeNode(final WriteTransaction trans, final UriBuilder base, final NodeCase nodeCase) {
797 final NodeId id = buildNodeId(base, nodeCase.getNodeDescriptors());
798 final NodeHolder nh = this.nodes.get(id);
801 nh.createSrHolderIfRequired().removeSrgb(trans);
804 LOG.warn("Node {} does not have a holder", id.getValue());
808 private void createPrefix(final WriteTransaction trans, final UriBuilder base,
809 final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
810 final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
812 LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
815 final PrefixBuilder pb = new PrefixBuilder();
816 final PrefixKey pk = new PrefixKey(ippfx);
820 final PrefixAttributes pa;
821 // Very defensive lookup
822 final Attributes1 attr = attributes.augmentation(Attributes1.class);
824 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
825 if (attrType != null) {
826 pa = ((PrefixAttributesCase)attrType).getPrefixAttributes();
828 LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
832 LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
835 SrPrefix srPrefix = null;
837 if (pa.getPrefixMetric() != null) {
838 pb.setMetric(pa.getPrefixMetric().getValue());
840 if (pa.getSrPrefix() != null) {
841 srPrefix = pa.getSrPrefix();
844 ProtocolUtil.augmentProtocolId(value, pa, pb);
846 final Prefix pfx = pb.build();
847 LOG.debug("Created prefix {} for {}", pfx, prefixCase);
850 * All set, but... the hosting node may not exist, we may need to fake it.
852 final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
853 NodeHolder nh = this.nodes.get(node);
857 if (srPrefix != null) {
858 nh.createSrHolderIfRequired().addSrPrefix(trans, false, ippfx, srPrefix);
863 if (srPrefix != null) {
864 nh.createSrHolderIfRequired().addSrPrefix(trans, true, ippfx, srPrefix);
866 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
867 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class)
868 .child(IgpNodeAttributes.class).build();
869 trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
873 private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase prefixCase) {
874 final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
875 final NodeHolder nh = this.nodes.get(node);
877 LOG.debug("Removed prefix {}", prefixCase);
878 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
879 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class)
880 .child(IgpNodeAttributes.class).build();
881 final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
883 LOG.warn("IP reachability not present in prefix {}, skipping it", prefixCase);
886 final PrefixKey pk = new PrefixKey(ippfx);
887 trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
888 nh.removePrefix(prefixCase);
889 nh.createSrHolderIfRequired().removeSrPrefix(trans, ippfx);
890 checkNodeForRemoval(trans, nh);
892 LOG.warn("Removing prefix from non-existing node {}", node.getValue());
896 private InstanceIdentifier<Node> getNodeInstanceIdentifier(final NodeKey nodeKey) {
897 return getInstanceIdentifier().child(
898 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network
899 .topology.topology.Node.class, nodeKey);
902 protected void addSrAwareTopologyType(final WriteTransaction trans) {
903 if (this.srAwareTopologyTypeAdded) {
906 LOG.debug("Adding SR-aware topology-type for topology {}",
907 getInstanceIdentifier().firstKeyOf(Topology.class).getTopologyId().getValue());
908 trans.put(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier().child(TopologyTypes.class),
909 SR_AWARE_LINKSTATE_TOPOLOGY_TYPE);
910 this.srAwareTopologyTypeAdded = true;
913 protected void removeSrAwareTopologyTypeIfRequired(final WriteTransaction trans) {
914 if (!this.srAwareTopologyTypeAdded) {
917 final boolean isSidPresent = this.nodes.values().stream().filter(nh -> nh.getSrHolder() != null)
918 .map(nh -> nh.getSrHolder().getSegmentCount()).anyMatch(cnt -> cnt != 0);
922 LOG.debug("Removing SR-aware topology-type from topology {}",
923 getInstanceIdentifier().firstKeyOf(Topology.class).getTopologyId().getValue());
924 trans.put(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier().child(TopologyTypes.class),
925 LINKSTATE_TOPOLOGY_TYPE);
926 this.srAwareTopologyTypeAdded = false;
930 protected void createObject(final ReadWriteTransaction trans,
931 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
932 final UriBuilder base = new UriBuilder(value);
934 final ObjectType t = value.getObjectType();
935 Preconditions.checkArgument(t != null, "Route %s value %s has null object type", id, value);
937 if (t instanceof LinkCase) {
938 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
939 } else if (t instanceof NodeCase) {
940 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
941 } else if (t instanceof PrefixCase) {
942 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
944 LOG.debug(UNHANDLED_OBJECT_CLASS, t.implementedInterface());
949 protected void removeObject(final ReadWriteTransaction trans,
950 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
952 LOG.error("Empty before-data received in delete data change notification for instance id {}", id);
956 final UriBuilder base = new UriBuilder(value);
958 final ObjectType t = value.getObjectType();
959 if (t instanceof LinkCase) {
960 removeLink(trans, base, (LinkCase) t);
961 } else if (t instanceof NodeCase) {
962 removeNode(trans, base, (NodeCase) t);
963 } else if (t instanceof PrefixCase) {
964 removePrefix(trans, base, (PrefixCase) t);
966 LOG.debug(UNHANDLED_OBJECT_CLASS, t.implementedInterface());
971 protected InstanceIdentifier<LinkstateRoute> getRouteWildcard(final InstanceIdentifier<Tables> tablesId) {
972 return tablesId.child(LinkstateRoutesCase.class, LinkstateRoutes.class).child(LinkstateRoute.class);
976 protected void clearTopology() {
978 this.srAwareTopologyTypeAdded = false;