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.base.Preconditions;
13 import com.google.common.collect.Collections2;
14 import com.google.common.collect.Lists;
15 import com.google.common.io.BaseEncoding;
16 import java.math.BigDecimal;
17 import java.nio.ByteBuffer;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.List;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
26 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
27 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
28 import org.opendaylight.protocol.bgp.rib.RibReference;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.IsisAreaIdentifier;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeFlagBits;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.LinkStateAttribute;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
49 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;
50 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;
51 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;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoNetId;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValues;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValuesBuilder;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.SrlgBuilder;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
98 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
99 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
100 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
101 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
102 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
103 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
104 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
105 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
106 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
107 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
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.Prefix;
109 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;
110 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;
111 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
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.TerminationPointType;
113 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;
114 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;
115 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
116 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
117 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
118 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
119 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.AbrBuilder;
120 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.InternalBuilder;
121 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.PseudonodeBuilder;
122 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
123 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
124 import org.slf4j.Logger;
125 import org.slf4j.LoggerFactory;
127 public class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
128 public static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder()
129 .addAugmentation(TopologyTypes1.class,
130 new TopologyTypes1Builder()
131 .setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build())
134 private static final String UNHANDLED_OBJECT_CLASS = "Unhandled object class {}";
136 private static final class TpHolder {
137 private final Set<LinkId> local = new HashSet<>();
138 private final Set<LinkId> remote = new HashSet<>();
140 private final TerminationPoint tp;
142 private TpHolder(final TerminationPoint tp) {
143 this.tp = requireNonNull(tp);
146 private synchronized void addLink(final LinkId id, final boolean isRemote) {
154 private synchronized boolean removeLink(final LinkId id, final boolean isRemote) {
155 final boolean removed;
157 removed = this.remote.remove(id);
159 removed = this.local.remove(id);
162 LOG.warn("Removed non-reference link {} from TP {} isRemote {}", this.tp.getTpId(), id, isRemote);
165 return this.local.isEmpty() && this.remote.isEmpty();
168 private TerminationPoint getTp() {
173 private final class NodeHolder {
174 private final Map<PrefixKey, Prefix> prefixes = new HashMap<>();
175 private final Map<TpId, TpHolder> tps = new HashMap<>();
176 private boolean advertized = false;
177 private IgpNodeAttributesBuilder inab;
178 private NodeBuilder nb;
180 private NodeHolder(final NodeId id) {
181 this.inab = new IgpNodeAttributesBuilder();
182 this.nb = new NodeBuilder().setKey(new NodeKey(id)).setNodeId(id);
186 * Synchronized in-core state of a node into the backing store using the transaction
188 * @param trans data modification transaction which to use
189 * @return True if the node has been purged, false otherwise.
191 private boolean syncState(final WriteTransaction trans) {
192 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
195 * Transaction's putOperationalData() does a merge. Force it onto a replace
196 * by removing the data. If we decide to remove the node -- we just skip the put.
198 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
200 if (!this.advertized) {
201 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
202 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
206 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
209 // Re-generate termination points
210 this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), TpHolder::getTp)));
212 // Re-generate prefixes
213 this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
215 // Write the node out
216 final Node n = this.nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(this.inab.build()).build()).build();
217 trans.put(LogicalDatastoreType.OPERATIONAL, nid, n);
218 LOG.debug("Created node {} at {}", n, nid);
222 private boolean checkForRemoval(final WriteTransaction trans) {
223 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
225 if (!this.advertized) {
226 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
227 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
228 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
232 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
237 private synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
238 final TpHolder h = this.tps.get(tp);
240 if (h.removeLink(link, isRemote)) {
242 LOG.debug("Removed TP {}", tp);
245 LOG.warn("Removed non-present TP {} by link {}", tp, link);
249 private void addTp(final TerminationPoint tp, final LinkId link, final boolean isRemote) {
250 final TpHolder h = this.tps.computeIfAbsent(tp.getTpId(), k -> new TpHolder(tp));
251 h.addLink(link, isRemote);
254 private void addPrefix(final Prefix pfx) {
255 this.prefixes.put(pfx.getKey(), pfx);
258 private void removePrefix(final PrefixCase p) {
259 this.prefixes.remove(new PrefixKey(p.getPrefixDescriptors().getIpReachabilityInformation()));
262 private void unadvertized() {
263 this.inab = new IgpNodeAttributesBuilder();
264 this.nb = new NodeBuilder().setKey(this.nb.getKey()).setNodeId(this.nb.getNodeId());
265 this.advertized = false;
266 LOG.debug("Node {} is unadvertized", this.nb.getNodeId());
269 private void advertized(final NodeBuilder nb, final IgpNodeAttributesBuilder inab) {
270 this.nb = requireNonNull(nb);
271 this.inab = requireNonNull(inab);
272 this.advertized = true;
273 LOG.debug("Node {} is advertized", nb.getNodeId());
276 private NodeId getNodeId() {
277 return this.nb.getNodeId();
281 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
282 private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
284 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
285 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
288 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
289 final TopologyId topologyId, final long listenerResetLimitInMillsec, final int listenerResetEnforceCounter) {
290 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
291 listenerResetLimitInMillsec, listenerResetEnforceCounter);
294 private static LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
295 return new LinkId(new UriBuilder(base, "link").add(link).toString());
298 private static NodeId buildNodeId(final UriBuilder base,
299 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier node) {
300 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
303 private static TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
304 final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
305 final UriBuilder b = new UriBuilder(base, "tp");
306 if (topologyIdentifier != null) {
307 b.add("mt", topologyIdentifier.getValue());
309 if (ipv4InterfaceIdentifier != null) {
310 b.add("ipv4", ipv4InterfaceIdentifier.getValue());
312 if (ipv6InterfaceIdentifier != null) {
313 b.add("ipv6", ipv6InterfaceIdentifier.getValue());
316 return new TpId(b.add("id", id).toString());
319 private static TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
320 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
321 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
324 private static TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
325 final TerminationPointBuilder stpb = new TerminationPointBuilder();
326 stpb.setKey(new TerminationPointKey(id));
330 stpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes(
331 new IgpTerminationPointAttributesBuilder().setTerminationPointType(type).build()).build());
337 private static TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
338 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
339 // Order of preference: Unnumbered first, then IP
341 LOG.debug("Unnumbered termination point type: {}", id);
342 return new UnnumberedBuilder().setUnnumberedId(id).build();
346 if (ipv6InterfaceIdentifier != null) {
347 ip = new IpAddress(ipv6InterfaceIdentifier);
348 } else if (ipv4InterfaceIdentifier != null) {
349 ip = new IpAddress(ipv4InterfaceIdentifier);
355 LOG.debug("IP termination point type: {}", ip);
356 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
362 private static TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
363 final TpId id = buildLocalTpId(base, linkDescriptors);
364 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
365 linkDescriptors.getLinkLocalIdentifier());
367 return buildTp(id, t);
370 private static TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
371 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
372 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
375 private static TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
376 final TpId id = buildRemoteTpId(base, linkDescriptors);
377 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
378 linkDescriptors.getLinkRemoteIdentifier());
380 return buildTp(id, t);
383 private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
384 return getInstanceIdentifier().child(
385 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
389 private static Float bandwidthToFloat(final Bandwidth bandwidth) {
390 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
393 private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
394 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
397 private static List<UnreservedBandwidth> unreservedBandwidthList(
398 final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth> input) {
399 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
401 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth i : input) {
402 ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
403 new UnreservedBandwidthKey(i.getPriority())).build());
409 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
410 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
411 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();
414 if (la.getAdminGroup() != null) {
415 tb.setColor(la.getAdminGroup().getValue());
417 if (la.getTeMetric() != null) {
418 tb.setTeDefaultMetric(la.getTeMetric().getValue());
420 if (la.getUnreservedBandwidth() != null) {
421 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
423 if (la.getMaxLinkBandwidth() != null) {
424 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
426 if (la.getMaxReservableBandwidth() != null) {
427 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
429 if (la.getSharedRiskLinkGroups() != null) {
430 final List<SrlgValues> srlgs = new ArrayList<>();
431 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
432 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
434 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
438 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
439 ilab.setTed(tb.build());
440 if (topologyIdentifier != null) {
441 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
444 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
445 ilab.build()).build();
448 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
449 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
450 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();
453 if (la.getAdminGroup() != null) {
454 tb.setColor(la.getAdminGroup().getValue());
456 if (la.getTeMetric() != null) {
457 tb.setTeDefaultMetric(la.getTeMetric().getValue());
459 if (la.getUnreservedBandwidth() != null) {
460 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
462 if (la.getMaxLinkBandwidth() != null) {
463 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
465 if (la.getMaxReservableBandwidth() != null) {
466 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
468 if (la.getSharedRiskLinkGroups() != null) {
469 final List<SrlgValues> srlgs = new ArrayList<>();
470 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
471 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
473 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
477 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
478 ilab.setTed(tb.build());
479 if (topologyIdentifier != null) {
480 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
483 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
484 ilab.build()).build();
487 private NodeHolder getNode(final NodeId id) {
488 if (this.nodes.containsKey(id)) {
489 LOG.debug("Node {} is already present", id);
490 return this.nodes.get(id);
493 final NodeHolder ret = new NodeHolder(id);
494 this.nodes.put(id, ret);
498 private void putNode(final WriteTransaction trans, final NodeHolder holder) {
499 if (holder.syncState(trans)) {
500 this.nodes.remove(holder.getNodeId());
504 private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) {
505 if (holder.checkForRemoval(trans)) {
506 this.nodes.remove(holder.getNodeId());
510 private static void augmentProtocolId(final LinkstateRoute value, final IgpLinkAttributesBuilder ilab,
511 final LinkAttributes la, final LinkDescriptors ld) {
512 switch (value.getProtocolId()) {
517 ilab.addAugmentation(
518 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
519 isisLinkAttributes(ld.getMultiTopologyId(), la));
523 ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
524 ospfLinkAttributes(ld.getMultiTopologyId(), la));
531 private void createLink(final WriteTransaction trans, final UriBuilder base,
532 final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
534 final LinkAttributes la;
535 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
537 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
538 if (attrType != null) {
539 la = ((LinkAttributesCase)attrType).getLinkAttributes();
541 LOG.debug("Missing attribute type in link {} route {}, skipping it", l, value);
545 LOG.debug("Missing attributes in link {} route {}, skipping it", l, value);
549 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
551 if (la.getMetric() != null) {
552 ilab.setMetric(la.getMetric().getValue());
554 ilab.setName(la.getLinkName());
556 augmentProtocolId(value, ilab, la, l.getLinkDescriptors());
558 final LinkBuilder lb = new LinkBuilder();
559 lb.setLinkId(buildLinkId(base, l));
560 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
562 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
563 LOG.debug("Link {} implies source node {}", l, srcNode);
565 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
566 LOG.debug("Link {} implies destination node {}", l, dstNode);
568 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
569 LOG.debug("Link {} implies source TP {}", l, srcTp);
571 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
572 LOG.debug("Link {} implies destination TP {}", l, dstTp);
574 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
575 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
577 LOG.debug("Created TP {} as link source", srcTp);
578 NodeHolder snh = this.nodes.get(srcNode);
580 snh = getNode(srcNode);
581 snh.addTp(srcTp, lb.getLinkId(), false);
584 snh.addTp(srcTp, lb.getLinkId(), false);
585 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
586 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
589 LOG.debug("Created TP {} as link destination", dstTp);
590 NodeHolder dnh = this.nodes.get(dstNode);
592 dnh = getNode(dstNode);
593 dnh.addTp(dstTp, lb.getLinkId(), true);
596 dnh.addTp(dstTp, lb.getLinkId(), true);
597 final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
598 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
599 new NodeKey(dnh.getNodeId()));
600 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
603 final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
604 final Link link = lb.build();
606 trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
607 LOG.debug("Created link {} at {} for {}", link, lid, l);
610 private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
611 final LinkId link, final boolean isRemote) {
612 final NodeHolder nh = this.nodes.get(node);
614 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
615 trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp)));
616 nh.removeTp(tp, link, isRemote);
617 checkNodeForRemoval(trans, nh);
619 LOG.warn("Removed non-existent node {}", node);
623 private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase l) {
624 final LinkId id = buildLinkId(base, l);
625 final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
626 trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
627 LOG.debug("Removed link {}", lid);
629 removeTp(trans, buildNodeId(base, l.getLocalNodeDescriptors()), buildLocalTpId(base, l.getLinkDescriptors()), id, false);
630 removeTp(trans, buildNodeId(base, l.getRemoteNodeDescriptors()), buildRemoteTpId(base, l.getLinkDescriptors()), id, true);
633 private static List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
634 final List<Short> ret = new ArrayList<>(list.size());
635 for (final TopologyIdentifier id : list) {
636 ret.add(id.getValue().shortValue());
641 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
642 final NodeIdentifier node, final NodeAttributes na) {
643 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();
644 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
647 if (na.getIpv4RouterId() != null) {
648 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
650 if (na.getIpv6RouterId() != null) {
651 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
653 if (na.getTopologyIdentifier() != null) {
654 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
658 final CRouterIdentifier ri = node.getCRouterIdentifier();
659 if (ri instanceof IsisPseudonodeCase) {
660 final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
661 final IsoBuilder b = new IsoBuilder();
662 final String systemId = UriBuilder.isoId(pn.getIsIsRouterIdentifier().getIsoSystemId());
663 b.setIsoSystemId(new IsoSystemId(systemId));
664 b.setIsoPseudonodeId(new IsoPseudonodeId(BaseEncoding.base16().encode(new byte[] {pn.getPsn().byteValue()})));
665 ab.setIso(b.build());
667 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
669 } else if (ri instanceof IsisNodeCase) {
670 final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
671 final String systemId = UriBuilder.isoId(in.getIsoSystemId());
672 ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(systemId)).build());
674 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
678 ab.setTed(tb.build());
680 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
684 private static List<IsoNetId> toIsoNetIds(final List<IsisAreaIdentifier> areaIds, final String systemId) {
685 return Lists.transform(areaIds, input -> new IsoNetId(UriBuilder.toIsoNetId(input, systemId)));
688 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
689 final NodeIdentifier node, final NodeAttributes na) {
690 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();
691 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
693 if (na.getIpv4RouterId() != null) {
694 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
696 if (na.getIpv6RouterId() != null) {
697 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
699 if (na.getTopologyIdentifier() != null) {
700 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
702 final CRouterIdentifier ri = node.getCRouterIdentifier();
703 if (ri instanceof OspfPseudonodeCase) {
704 final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
706 ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
707 ab.setDrInterfaceId(pn.getLanInterface().getValue());
708 } else if (ri instanceof OspfNodeCase && na.getNodeFlags() != null) {
709 // TODO: what should we do with in.getOspfRouterId()?
711 final NodeFlagBits nf = na.getNodeFlags();
712 if (nf.isAbr() != null) {
713 ab.setRouterType(new AbrBuilder().setAbr(nf.isAbr()).build());
714 } else if (nf.isExternal() != null) {
715 ab.setRouterType(new InternalBuilder().setInternal(!nf.isExternal()).build());
719 ab.setTed(tb.build());
720 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
724 private static void augmentProtocolId(final LinkstateRoute value, final IgpNodeAttributesBuilder inab,
725 final NodeAttributes na, final NodeIdentifier nd) {
726 switch (value.getProtocolId()) {
731 inab.addAugmentation(
732 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
733 isisNodeAttributes(nd, na));
736 inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
737 ospfNodeAttributes(nd, na));
744 private void createNode(final WriteTransaction trans, final UriBuilder base,
745 final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
746 final NodeAttributes na;
748 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
750 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
751 if (attrType != null) {
752 na = ((NodeAttributesCase)attrType).getNodeAttributes();
754 LOG.debug("Missing attribute type in node {} route {}, skipping it", n, value);
758 LOG.debug("Missing attributes in node {} route {}, skipping it", n, value);
761 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
762 final List<IpAddress> ids = new ArrayList<>();
764 if (na.getIpv4RouterId() != null) {
765 ids.add(new IpAddress(na.getIpv4RouterId()));
767 if (na.getIpv6RouterId() != null) {
768 ids.add(new IpAddress(na.getIpv6RouterId()));
770 if (na.getDynamicHostname() != null) {
771 inab.setName(new DomainName(na.getDynamicHostname()));
774 if (!ids.isEmpty()) {
775 inab.setRouterId(ids);
777 augmentProtocolId(value, inab, na, n.getNodeDescriptors());
779 final NodeId nid = buildNodeId(base, n.getNodeDescriptors());
780 final NodeHolder nh = getNode(nid);
782 * Eventhough the the holder creates a dummy structure, we need to duplicate it here,
783 * as that is the API requirement. The reason for it is the possible presence of supporting
784 * node -- something which the holder does not track.
786 final NodeBuilder nb = new NodeBuilder();
788 nb.setKey(new NodeKey(nb.getNodeId()));
790 nh.advertized(nb, inab);
794 private void removeNode(final WriteTransaction trans, final UriBuilder base, final NodeCase n) {
795 final NodeId id = buildNodeId(base, n.getNodeDescriptors());
796 final NodeHolder nh = this.nodes.get(id);
801 LOG.warn("Node {} does not have a holder", id);
805 private static void augmentProtocolId(final LinkstateRoute value, final PrefixAttributes pa, final PrefixBuilder pb) {
806 switch (value.getProtocolId()) {
812 if (pa != null && pa.getOspfForwardingAddress() != null) {
815 new Prefix1Builder().setOspfPrefixAttributes(
816 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
824 private void createPrefix(final WriteTransaction trans, final UriBuilder base,
825 final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
826 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
828 LOG.warn("IP reachability not present in prefix {} route {}, skipping it", p, value);
831 final PrefixBuilder pb = new PrefixBuilder();
832 final PrefixKey pk = new PrefixKey(ippfx);
836 final PrefixAttributes pa;
837 // Very defensive lookup
838 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
840 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
841 if (attrType != null) {
842 pa = ((PrefixAttributesCase)attrType).getPrefixAttributes();
844 LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, p, value);
848 LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, p, value);
852 pb.setMetric(pa.getPrefixMetric().getValue());
854 augmentProtocolId(value, pa, pb);
856 final Prefix pfx = pb.build();
857 LOG.debug("Created prefix {} for {}", pfx, p);
860 * All set, but... the hosting node may not exist, we may need to fake it.
862 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
863 NodeHolder nh = this.nodes.get(node);
870 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
871 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
872 trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
876 private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase p) {
877 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
878 final NodeHolder nh = this.nodes.get(node);
880 LOG.debug("Removed prefix {}", p);
881 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
882 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
883 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
885 LOG.warn("IP reachability not present in prefix {}, skipping it", p);
888 final PrefixKey pk = new PrefixKey(ippfx);
889 trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
891 checkNodeForRemoval(trans, nh);
893 LOG.warn("Removing prefix from non-existing node {}", node);
897 private InstanceIdentifier<Node> getNodeInstanceIdentifier(final NodeKey nodeKey) {
898 return getInstanceIdentifier().child(
899 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
904 protected void createObject(final ReadWriteTransaction trans,
905 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
906 final UriBuilder base = new UriBuilder(value);
908 final ObjectType t = value.getObjectType();
909 Preconditions.checkArgument(t != null, "Route %s value %s has null object type", id, value);
911 if (t instanceof LinkCase) {
912 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
913 } else if (t instanceof NodeCase) {
914 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
915 } else if (t instanceof PrefixCase) {
916 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
918 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
923 protected void removeObject(final ReadWriteTransaction trans,
924 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
926 LOG.error("Empty before-data received in delete data change notification for instance id {}", id);
930 final UriBuilder base = new UriBuilder(value);
932 final ObjectType t = value.getObjectType();
933 if (t instanceof LinkCase) {
934 removeLink(trans, base, (LinkCase) t);
935 } else if (t instanceof NodeCase) {
936 removeNode(trans, base, (NodeCase) t);
937 } else if (t instanceof PrefixCase) {
938 removePrefix(trans, base, (PrefixCase) t);
940 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
944 @SuppressWarnings({ "rawtypes", "unchecked" })
946 protected InstanceIdentifier<LinkstateRoute> getRouteWildcard(final InstanceIdentifier<Tables> tablesId) {
947 return tablesId.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class);
951 protected void clearTopology() {