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 com.google.common.base.Preconditions;
11 import com.google.common.collect.Collections2;
12 import com.google.common.collect.Lists;
13 import com.google.common.io.BaseEncoding;
14 import java.math.BigDecimal;
15 import java.nio.ByteBuffer;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.List;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
24 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
25 import org.opendaylight.controller.md.sal.common.api.data.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.rev150210.Ipv4InterfaceIdentifier;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.IsisAreaIdentifier;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeFlagBits;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.LinkStateAttribute;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoNetId;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValues;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValuesBuilder;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.SrlgBuilder;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
98 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
99 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
100 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
101 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
102 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
103 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
104 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
105 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
106 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;
107 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;
108 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;
109 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
110 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;
111 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;
112 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;
113 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
114 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
115 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
116 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
117 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.AbrBuilder;
118 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.InternalBuilder;
119 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.PseudonodeBuilder;
120 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
121 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
122 import org.slf4j.Logger;
123 import org.slf4j.LoggerFactory;
125 public class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
126 public static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder()
127 .addAugmentation(TopologyTypes1.class,
128 new TopologyTypes1Builder()
129 .setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build())
132 private static final String UNHANDLED_OBJECT_CLASS = "Unhandled object class {}";
134 private static final class TpHolder {
135 private final Set<LinkId> local = new HashSet<>();
136 private final Set<LinkId> remote = new HashSet<>();
138 private final TerminationPoint tp;
140 private TpHolder(final TerminationPoint tp) {
141 this.tp = Preconditions.checkNotNull(tp);
144 private synchronized void addLink(final LinkId id, final boolean isRemote) {
152 private synchronized boolean removeLink(final LinkId id, final boolean isRemote) {
153 final boolean removed;
155 removed = this.remote.remove(id);
157 removed = this.local.remove(id);
160 LOG.warn("Removed non-reference link {} from TP {} isRemote {}", this.tp.getTpId(), id, isRemote);
163 return this.local.isEmpty() && this.remote.isEmpty();
166 private TerminationPoint getTp() {
171 private final class NodeHolder {
172 private final Map<PrefixKey, Prefix> prefixes = new HashMap<>();
173 private final Map<TpId, TpHolder> tps = new HashMap<>();
174 private boolean advertized = false;
175 private IgpNodeAttributesBuilder inab;
176 private NodeBuilder nb;
178 private NodeHolder(final NodeId id) {
179 this.inab = new IgpNodeAttributesBuilder();
180 this.nb = new NodeBuilder().setKey(new NodeKey(id)).setNodeId(id);
184 * Synchronized in-core state of a node into the backing store using the transaction
186 * @param trans data modification transaction which to use
187 * @return True if the node has been purged, false otherwise.
189 private boolean syncState(final WriteTransaction trans) {
190 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
193 * Transaction's putOperationalData() does a merge. Force it onto a replace
194 * by removing the data. If we decide to remove the node -- we just skip the put.
196 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
198 if (!this.advertized) {
199 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
200 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
204 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
207 // Re-generate termination points
208 this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), TpHolder::getTp)));
210 // Re-generate prefixes
211 this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
213 // Write the node out
214 final Node n = this.nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(this.inab.build()).build()).build();
215 trans.put(LogicalDatastoreType.OPERATIONAL, nid, n);
216 LOG.debug("Created node {} at {}", n, nid);
220 private boolean checkForRemoval(final WriteTransaction trans) {
221 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
223 if (!this.advertized) {
224 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
225 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
226 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
230 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
235 private synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
236 final TpHolder h = this.tps.get(tp);
238 if (h.removeLink(link, isRemote)) {
240 LOG.debug("Removed TP {}", tp);
243 LOG.warn("Removed non-present TP {} by link {}", tp, link);
247 private void addTp(final TerminationPoint tp, final LinkId link, final boolean isRemote) {
248 TpHolder h = this.tps.get(tp.getTpId());
250 h = new TpHolder(tp);
251 this.tps.put(tp.getTpId(), h);
254 h.addLink(link, isRemote);
257 private void addPrefix(final Prefix pfx) {
258 this.prefixes.put(pfx.getKey(), pfx);
261 private void removePrefix(final PrefixCase p) {
262 this.prefixes.remove(new PrefixKey(p.getPrefixDescriptors().getIpReachabilityInformation()));
265 private void unadvertized() {
266 this.inab = new IgpNodeAttributesBuilder();
267 this.nb = new NodeBuilder().setKey(this.nb.getKey()).setNodeId(this.nb.getNodeId());
268 this.advertized = false;
269 LOG.debug("Node {} is unadvertized", this.nb.getNodeId());
272 private void advertized(final NodeBuilder nb, final IgpNodeAttributesBuilder inab) {
273 this.nb = Preconditions.checkNotNull(nb);
274 this.inab = Preconditions.checkNotNull(inab);
275 this.advertized = true;
276 LOG.debug("Node {} is advertized", nb.getNodeId());
279 private Object getNodeId() {
280 return this.nb.getNodeId();
284 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
285 private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
287 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
288 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
291 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
292 final TopologyId topologyId, final long listenerResetLimitInMillsec, final int listenerResetEnforceCounter) {
293 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
294 listenerResetLimitInMillsec, listenerResetEnforceCounter);
297 private static LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
298 return new LinkId(new UriBuilder(base, "link").add(link).toString());
301 private static NodeId buildNodeId(final UriBuilder base,
302 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier node) {
303 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
306 private static TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
307 final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
308 final UriBuilder b = new UriBuilder(base, "tp");
309 if (topologyIdentifier != null) {
310 b.add("mt", topologyIdentifier.getValue());
312 if (ipv4InterfaceIdentifier != null) {
313 b.add("ipv4", ipv4InterfaceIdentifier.getValue());
315 if (ipv6InterfaceIdentifier != null) {
316 b.add("ipv6", ipv6InterfaceIdentifier.getValue());
319 return new TpId(b.add("id", id).toString());
322 private static TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
323 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
324 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
327 private static TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
328 final TerminationPointBuilder stpb = new TerminationPointBuilder();
329 stpb.setKey(new TerminationPointKey(id));
333 stpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes(
334 new IgpTerminationPointAttributesBuilder().setTerminationPointType(type).build()).build());
340 private static TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
341 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
342 // Order of preference: Unnumbered first, then IP
344 LOG.debug("Unnumbered termination point type: {}", id);
345 return new UnnumberedBuilder().setUnnumberedId(id).build();
349 if (ipv6InterfaceIdentifier != null) {
350 ip = new IpAddress(ipv6InterfaceIdentifier);
351 } else if (ipv4InterfaceIdentifier != null) {
352 ip = new IpAddress(ipv4InterfaceIdentifier);
358 LOG.debug("IP termination point type: {}", ip);
359 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
365 private static TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
366 final TpId id = buildLocalTpId(base, linkDescriptors);
367 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
368 linkDescriptors.getLinkLocalIdentifier());
370 return buildTp(id, t);
373 private static TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
374 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
375 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
378 private static TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
379 final TpId id = buildRemoteTpId(base, linkDescriptors);
380 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
381 linkDescriptors.getLinkRemoteIdentifier());
383 return buildTp(id, t);
386 private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
387 return getInstanceIdentifier().child(
388 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
392 private static Float bandwidthToFloat(final Bandwidth bandwidth) {
393 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
396 private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
397 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
400 private static List<UnreservedBandwidth> unreservedBandwidthList(
401 final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth> input) {
402 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
404 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth i : input) {
405 ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
406 new UnreservedBandwidthKey(i.getPriority())).build());
412 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
413 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
414 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.isis.link.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.isis.link.attributes.TedBuilder();
417 if (la.getAdminGroup() != null) {
418 tb.setColor(la.getAdminGroup().getValue());
420 if (la.getTeMetric() != null) {
421 tb.setTeDefaultMetric(la.getTeMetric().getValue());
423 if (la.getUnreservedBandwidth() != null) {
424 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
426 if (la.getMaxLinkBandwidth() != null) {
427 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
429 if (la.getMaxReservableBandwidth() != null) {
430 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
432 if (la.getSharedRiskLinkGroups() != null) {
433 final List<SrlgValues> srlgs = new ArrayList<>();
434 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
435 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
437 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
441 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
442 ilab.setTed(tb.build());
443 if (topologyIdentifier != null) {
444 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
447 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
448 ilab.build()).build();
451 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
452 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
453 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.ospf.link.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.ospf.link.attributes.TedBuilder();
456 if (la.getAdminGroup() != null) {
457 tb.setColor(la.getAdminGroup().getValue());
459 if (la.getTeMetric() != null) {
460 tb.setTeDefaultMetric(la.getTeMetric().getValue());
462 if (la.getUnreservedBandwidth() != null) {
463 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
465 if (la.getMaxLinkBandwidth() != null) {
466 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
468 if (la.getMaxReservableBandwidth() != null) {
469 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
471 if (la.getSharedRiskLinkGroups() != null) {
472 final List<SrlgValues> srlgs = new ArrayList<>();
473 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
474 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
476 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
480 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
481 ilab.setTed(tb.build());
482 if (topologyIdentifier != null) {
483 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
486 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
487 ilab.build()).build();
490 private NodeHolder getNode(final NodeId id) {
491 if (this.nodes.containsKey(id)) {
492 LOG.debug("Node {} is already present", id);
493 return this.nodes.get(id);
496 final NodeHolder ret = new NodeHolder(id);
497 this.nodes.put(id, ret);
501 private void putNode(final WriteTransaction trans, final NodeHolder holder) {
502 if (holder.syncState(trans)) {
503 this.nodes.remove(holder.getNodeId());
507 private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) {
508 if (holder.checkForRemoval(trans)) {
509 this.nodes.remove(holder.getNodeId());
513 private static void augmentProtocolId(final LinkstateRoute value, final IgpLinkAttributesBuilder ilab,
514 final LinkAttributes la, final LinkDescriptors ld) {
515 switch (value.getProtocolId()) {
520 ilab.addAugmentation(
521 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
522 isisLinkAttributes(ld.getMultiTopologyId(), la));
526 ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
527 ospfLinkAttributes(ld.getMultiTopologyId(), la));
534 private void createLink(final WriteTransaction trans, final UriBuilder base,
535 final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
537 final LinkAttributes la;
538 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
540 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
541 if (attrType != null) {
542 la = ((LinkAttributesCase)attrType).getLinkAttributes();
544 LOG.debug("Missing attribute type in link {} route {}, skipping it", l, value);
548 LOG.debug("Missing attributes in link {} route {}, skipping it", l, value);
552 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
554 if (la.getMetric() != null) {
555 ilab.setMetric(la.getMetric().getValue());
557 ilab.setName(la.getLinkName());
559 augmentProtocolId(value, ilab, la, l.getLinkDescriptors());
561 final LinkBuilder lb = new LinkBuilder();
562 lb.setLinkId(buildLinkId(base, l));
563 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
565 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
566 LOG.debug("Link {} implies source node {}", l, srcNode);
568 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
569 LOG.debug("Link {} implies destination node {}", l, dstNode);
571 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
572 LOG.debug("Link {} implies source TP {}", l, srcTp);
574 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
575 LOG.debug("Link {} implies destination TP {}", l, dstTp);
577 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
578 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
580 LOG.debug("Created TP {} as link source", srcTp);
581 NodeHolder snh = this.nodes.get(srcNode);
583 snh = getNode(srcNode);
584 snh.addTp(srcTp, lb.getLinkId(), false);
587 snh.addTp(srcTp, lb.getLinkId(), false);
588 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) snh.getNodeId()));
589 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
592 LOG.debug("Created TP {} as link destination", dstTp);
593 NodeHolder dnh = this.nodes.get(dstNode);
595 dnh = getNode(dstNode);
596 dnh.addTp(dstTp, lb.getLinkId(), true);
599 dnh.addTp(dstTp, lb.getLinkId(), true);
600 final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
601 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
602 new NodeKey((NodeId) dnh.getNodeId()));
603 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
606 final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
607 final Link link = lb.build();
609 trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
610 LOG.debug("Created link {} at {} for {}", link, lid, l);
613 private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
614 final LinkId link, final boolean isRemote) {
615 final NodeHolder nh = this.nodes.get(node);
617 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
618 trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp)));
619 nh.removeTp(tp, link, isRemote);
620 checkNodeForRemoval(trans, nh);
622 LOG.warn("Removed non-existent node {}", node);
626 private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase l) {
627 final LinkId id = buildLinkId(base, l);
628 final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
629 trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
630 LOG.debug("Removed link {}", lid);
632 removeTp(trans, buildNodeId(base, l.getLocalNodeDescriptors()), buildLocalTpId(base, l.getLinkDescriptors()), id, false);
633 removeTp(trans, buildNodeId(base, l.getRemoteNodeDescriptors()), buildRemoteTpId(base, l.getLinkDescriptors()), id, true);
636 private static List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
637 final List<Short> ret = new ArrayList<>(list.size());
638 for (final TopologyIdentifier id : list) {
639 ret.add(id.getValue().shortValue());
644 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
645 final NodeIdentifier node, final NodeAttributes na) {
646 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.TedBuilder();
647 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
650 if (na.getIpv4RouterId() != null) {
651 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
653 if (na.getIpv6RouterId() != null) {
654 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
656 if (na.getTopologyIdentifier() != null) {
657 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
661 final CRouterIdentifier ri = node.getCRouterIdentifier();
662 if (ri instanceof IsisPseudonodeCase) {
663 final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
664 final IsoBuilder b = new IsoBuilder();
665 final String systemId = UriBuilder.isoId(pn.getIsIsRouterIdentifier().getIsoSystemId());
666 b.setIsoSystemId(new IsoSystemId(systemId));
667 b.setIsoPseudonodeId(new IsoPseudonodeId(BaseEncoding.base16().encode(new byte[] {pn.getPsn().byteValue()})));
668 ab.setIso(b.build());
670 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
672 } else if (ri instanceof IsisNodeCase) {
673 final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
674 final String systemId = UriBuilder.isoId(in.getIsoSystemId());
675 ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(systemId)).build());
677 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
681 ab.setTed(tb.build());
683 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
687 private static List<IsoNetId> toIsoNetIds(final List<IsisAreaIdentifier> areaIds, final String systemId) {
688 return Lists.transform(areaIds, input -> new IsoNetId(UriBuilder.toIsoNetId(input, systemId)));
691 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
692 final NodeIdentifier node, final NodeAttributes na) {
693 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.TedBuilder();
694 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
696 if (na.getIpv4RouterId() != null) {
697 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
699 if (na.getIpv6RouterId() != null) {
700 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
702 if (na.getTopologyIdentifier() != null) {
703 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
705 final CRouterIdentifier ri = node.getCRouterIdentifier();
706 if (ri instanceof OspfPseudonodeCase) {
707 final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
709 ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
710 ab.setDrInterfaceId(pn.getLanInterface().getValue());
711 } else if (ri instanceof OspfNodeCase && na.getNodeFlags() != null) {
712 // TODO: what should we do with in.getOspfRouterId()?
714 final NodeFlagBits nf = na.getNodeFlags();
715 if (nf.isAbr() != null) {
716 ab.setRouterType(new AbrBuilder().setAbr(nf.isAbr()).build());
717 } else if (nf.isExternal() != null) {
718 ab.setRouterType(new InternalBuilder().setInternal(!nf.isExternal()).build());
722 ab.setTed(tb.build());
723 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
727 private static void augmentProtocolId(final LinkstateRoute value, final IgpNodeAttributesBuilder inab,
728 final NodeAttributes na, final NodeIdentifier nd) {
729 switch (value.getProtocolId()) {
734 inab.addAugmentation(
735 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
736 isisNodeAttributes(nd, na));
739 inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
740 ospfNodeAttributes(nd, na));
747 private void createNode(final WriteTransaction trans, final UriBuilder base,
748 final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
749 final NodeAttributes na;
751 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
753 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
754 if (attrType != null) {
755 na = ((NodeAttributesCase)attrType).getNodeAttributes();
757 LOG.debug("Missing attribute type in node {} route {}, skipping it", n, value);
761 LOG.debug("Missing attributes in node {} route {}, skipping it", n, value);
764 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
765 final List<IpAddress> ids = new ArrayList<>();
767 if (na.getIpv4RouterId() != null) {
768 ids.add(new IpAddress(na.getIpv4RouterId()));
770 if (na.getIpv6RouterId() != null) {
771 ids.add(new IpAddress(na.getIpv6RouterId()));
773 if (na.getDynamicHostname() != null) {
774 inab.setName(new DomainName(na.getDynamicHostname()));
777 if (!ids.isEmpty()) {
778 inab.setRouterId(ids);
780 augmentProtocolId(value, inab, na, n.getNodeDescriptors());
782 final NodeId nid = buildNodeId(base, n.getNodeDescriptors());
783 final NodeHolder nh = getNode(nid);
785 * Eventhough the the holder creates a dummy structure, we need to duplicate it here,
786 * as that is the API requirement. The reason for it is the possible presence of supporting
787 * node -- something which the holder does not track.
789 final NodeBuilder nb = new NodeBuilder();
791 nb.setKey(new NodeKey(nb.getNodeId()));
793 nh.advertized(nb, inab);
797 private void removeNode(final WriteTransaction trans, final UriBuilder base, final NodeCase n) {
798 final NodeId id = buildNodeId(base, n.getNodeDescriptors());
799 final NodeHolder nh = this.nodes.get(id);
804 LOG.warn("Node {} does not have a holder", id);
808 private static void augmentProtocolId(final LinkstateRoute value, final PrefixAttributes pa, final PrefixBuilder pb) {
809 switch (value.getProtocolId()) {
815 if (pa != null && pa.getOspfForwardingAddress() != null) {
818 new Prefix1Builder().setOspfPrefixAttributes(
819 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
827 private void createPrefix(final WriteTransaction trans, final UriBuilder base,
828 final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
829 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
831 LOG.warn("IP reachability not present in prefix {} route {}, skipping it", p, value);
834 final PrefixBuilder pb = new PrefixBuilder();
835 final PrefixKey pk = new PrefixKey(ippfx);
839 final PrefixAttributes pa;
840 // Very defensive lookup
841 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
843 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
844 if (attrType != null) {
845 pa = ((PrefixAttributesCase)attrType).getPrefixAttributes();
847 LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, p, value);
851 LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, p, value);
855 pb.setMetric(pa.getPrefixMetric().getValue());
857 augmentProtocolId(value, pa, pb);
859 final Prefix pfx = pb.build();
860 LOG.debug("Created prefix {} for {}", pfx, p);
863 * All set, but... the hosting node may not exist, we may need to fake it.
865 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
866 NodeHolder nh = this.nodes.get(node);
873 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
874 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
875 trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
879 private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase p) {
880 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
881 final NodeHolder nh = this.nodes.get(node);
883 LOG.debug("Removed prefix {}", p);
884 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
885 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
886 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
888 LOG.warn("IP reachability not present in prefix {}, skipping it", p);
891 final PrefixKey pk = new PrefixKey(ippfx);
892 trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
894 checkNodeForRemoval(trans, nh);
896 LOG.warn("Removing prefix from non-existing node {}", node);
900 private InstanceIdentifier<Node> getNodeInstanceIdentifier(final NodeKey nodeKey) {
901 return getInstanceIdentifier().child(
902 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
907 protected void createObject(final ReadWriteTransaction trans,
908 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
909 final UriBuilder base = new UriBuilder(value);
911 final ObjectType t = value.getObjectType();
912 Preconditions.checkArgument(t != null, "Route %s value %s has null object type", id, value);
914 if (t instanceof LinkCase) {
915 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
916 } else if (t instanceof NodeCase) {
917 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
918 } else if (t instanceof PrefixCase) {
919 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
921 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
926 protected void removeObject(final ReadWriteTransaction trans,
927 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
929 LOG.error("Empty before-data received in delete data change notification for instance id {}", id);
933 final UriBuilder base = new UriBuilder(value);
935 final ObjectType t = value.getObjectType();
936 if (t instanceof LinkCase) {
937 removeLink(trans, base, (LinkCase) t);
938 } else if (t instanceof NodeCase) {
939 removeNode(trans, base, (NodeCase) t);
940 } else if (t instanceof PrefixCase) {
941 removePrefix(trans, base, (PrefixCase) t);
943 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
947 @SuppressWarnings({ "rawtypes", "unchecked" })
949 protected InstanceIdentifier<LinkstateRoute> getRouteWildcard(final InstanceIdentifier<Tables> tablesId) {
950 return tablesId.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class);
954 protected void clearTopology() {