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.Function;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Collections2;
13 import com.google.common.collect.Lists;
14 import com.google.common.io.BaseEncoding;
15 import java.math.BigDecimal;
16 import java.nio.ByteBuffer;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.HashSet;
20 import java.util.List;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.protocol.bgp.rib.RibReference;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.IsisAreaIdentifier;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeFlagBits;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.LinkStateAttribute;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
46 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;
47 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;
48 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;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoNetId;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValues;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValuesBuilder;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.SrlgBuilder;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
98 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
99 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
100 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
101 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
102 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
103 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
104 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
105 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;
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.PrefixBuilder;
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.PrefixKey;
108 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
109 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;
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.termination.point.type.IpBuilder;
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.UnnumberedBuilder;
112 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
113 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
114 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
115 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
116 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.AbrBuilder;
117 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.InternalBuilder;
118 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.PseudonodeBuilder;
119 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
120 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
121 import org.slf4j.Logger;
122 import org.slf4j.LoggerFactory;
124 public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
125 private static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder()
126 .addAugmentation(TopologyTypes1.class,
127 new TopologyTypes1Builder()
128 .setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build())
131 private static final String UNHANDLED_OBJECT_CLASS = "Unhandled object class {}";
133 private static final class TpHolder {
134 private final Set<LinkId> local = new HashSet<>();
135 private final Set<LinkId> remote = new HashSet<>();
137 private final TerminationPoint tp;
139 private TpHolder(final TerminationPoint tp) {
140 this.tp = Preconditions.checkNotNull(tp);
143 private synchronized void addLink(final LinkId id, final boolean isRemote) {
151 private synchronized boolean removeLink(final LinkId id, final boolean isRemote) {
152 final boolean removed;
154 removed = this.remote.remove(id);
156 removed = this.local.remove(id);
159 LOG.warn("Removed non-reference link {} from TP {} isRemote {}", this.tp.getTpId(), id, isRemote);
162 return this.local.isEmpty() && this.remote.isEmpty();
165 private TerminationPoint getTp() {
170 private final class NodeHolder {
171 private final Map<PrefixKey, Prefix> prefixes = new HashMap<>();
172 private final Map<TpId, TpHolder> tps = new HashMap<>();
173 private boolean advertized = false;
174 private IgpNodeAttributesBuilder inab;
175 private NodeBuilder nb;
177 private NodeHolder(final NodeId id) {
178 this.inab = new IgpNodeAttributesBuilder();
179 this.nb = new NodeBuilder().setKey(new NodeKey(id)).setNodeId(id);
183 * Synchronized in-core state of a node into the backing store using the transaction
185 * @param trans data modification transaction which to use
186 * @return True if the node has been purged, false otherwise.
188 private boolean syncState(final WriteTransaction trans) {
189 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
192 * Transaction's putOperationalData() does a merge. Force it onto a replace
193 * by removing the data. If we decide to remove the node -- we just skip the put.
195 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
197 if (!this.advertized) {
198 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
199 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
203 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
206 // Re-generate termination points
207 this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), new Function<TpHolder, TerminationPoint>() {
209 public TerminationPoint apply(final TpHolder input) {
210 return input.getTp();
214 // Re-generate prefixes
215 this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
217 // Write the node out
218 final Node n = this.nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(this.inab.build()).build()).build();
219 trans.put(LogicalDatastoreType.OPERATIONAL, nid, n);
220 LOG.debug("Created node {} at {}", n, nid);
224 private boolean checkForRemoval(final WriteTransaction trans) {
225 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
227 if (!this.advertized) {
228 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
229 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
230 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
234 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
239 private synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
240 final TpHolder h = this.tps.get(tp);
242 if (h.removeLink(link, isRemote)) {
244 LOG.debug("Removed TP {}", tp);
247 LOG.warn("Removed non-present TP {} by link {}", tp, link);
251 private void addTp(final TerminationPoint tp, final LinkId link, final boolean isRemote) {
252 TpHolder h = this.tps.get(tp.getTpId());
254 h = new TpHolder(tp);
255 this.tps.put(tp.getTpId(), h);
258 h.addLink(link, isRemote);
261 private void addPrefix(final Prefix pfx) {
262 this.prefixes.put(pfx.getKey(), pfx);
265 private void removePrefix(final PrefixCase p) {
266 this.prefixes.remove(new PrefixKey(p.getPrefixDescriptors().getIpReachabilityInformation()));
269 private void unadvertized() {
270 this.inab = new IgpNodeAttributesBuilder();
271 this.nb = new NodeBuilder().setKey(this.nb.getKey()).setNodeId(this.nb.getNodeId());
272 this.advertized = false;
273 LOG.debug("Node {} is unadvertized", this.nb.getNodeId());
276 private void advertized(final NodeBuilder nb, final IgpNodeAttributesBuilder inab) {
277 this.nb = Preconditions.checkNotNull(nb);
278 this.inab = Preconditions.checkNotNull(inab);
279 this.advertized = true;
280 LOG.debug("Node {} is advertized", nb.getNodeId());
283 private Object getNodeId() {
284 return this.nb.getNodeId();
288 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
289 private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
291 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
292 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE);
295 private static LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
296 return new LinkId(new UriBuilder(base, "link").add(link).toString());
299 private static NodeId buildNodeId(final UriBuilder base,
300 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier node) {
301 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
304 private static TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
305 final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
306 final UriBuilder b = new UriBuilder(base, "tp");
307 if (topologyIdentifier != null) {
308 b.add("mt", topologyIdentifier.getValue());
310 if (ipv4InterfaceIdentifier != null) {
311 b.add("ipv4", ipv4InterfaceIdentifier.getValue());
313 if (ipv6InterfaceIdentifier != null) {
314 b.add("ipv6", ipv6InterfaceIdentifier.getValue());
317 return new TpId(b.add("id", id).toString());
320 private static TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
321 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
322 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
325 private static TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
326 final TerminationPointBuilder stpb = new TerminationPointBuilder();
327 stpb.setKey(new TerminationPointKey(id));
331 stpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes(
332 new IgpTerminationPointAttributesBuilder().setTerminationPointType(null).build()).build());
338 private static TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
339 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
340 // Order of preference: Unnumbered first, then IP
342 LOG.debug("Unnumbered termination point type: {}", id);
343 return new UnnumberedBuilder().setUnnumberedId(id).build();
347 if (ipv6InterfaceIdentifier != null) {
348 ip = new IpAddress(ipv6InterfaceIdentifier);
349 } else if (ipv4InterfaceIdentifier != null) {
350 ip = new IpAddress(ipv4InterfaceIdentifier);
356 LOG.debug("IP termination point type: {}", ip);
357 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
363 private static TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
364 final TpId id = buildLocalTpId(base, linkDescriptors);
365 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
366 linkDescriptors.getLinkLocalIdentifier());
368 return buildTp(id, t);
371 private static TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
372 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
373 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
376 private static TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
377 final TpId id = buildRemoteTpId(base, linkDescriptors);
378 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
379 linkDescriptors.getLinkRemoteIdentifier());
381 return buildTp(id, t);
384 private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
385 return getInstanceIdentifier().child(
386 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
390 private static Float bandwidthToFloat(final Bandwidth bandwidth) {
391 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
394 private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
395 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
398 private static List<UnreservedBandwidth> unreservedBandwidthList(
399 final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth> input) {
400 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
402 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth i : input) {
403 ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
404 new UnreservedBandwidthKey(i.getPriority())).build());
410 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
411 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
412 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();
415 if (la.getAdminGroup() != null) {
416 tb.setColor(la.getAdminGroup().getValue());
418 if (la.getTeMetric() != null) {
419 tb.setTeDefaultMetric(la.getTeMetric().getValue());
421 if (la.getUnreservedBandwidth() != null) {
422 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
424 if (la.getMaxLinkBandwidth() != null) {
425 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
427 if (la.getMaxReservableBandwidth() != null) {
428 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
430 if (la.getSharedRiskLinkGroups() != null) {
431 final List<SrlgValues> srlgs = new ArrayList<>();
432 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
433 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
435 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
439 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
440 ilab.setTed(tb.build());
441 if (topologyIdentifier != null) {
442 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
445 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
446 ilab.build()).build();
449 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
450 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
451 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();
454 if (la.getAdminGroup() != null) {
455 tb.setColor(la.getAdminGroup().getValue());
457 if (la.getTeMetric() != null) {
458 tb.setTeDefaultMetric(la.getTeMetric().getValue());
460 if (la.getUnreservedBandwidth() != null) {
461 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
463 if (la.getMaxLinkBandwidth() != null) {
464 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
466 if (la.getMaxReservableBandwidth() != null) {
467 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
469 if (la.getSharedRiskLinkGroups() != null) {
470 final List<SrlgValues> srlgs = new ArrayList<>();
471 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
472 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
474 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
478 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
479 ilab.setTed(tb.build());
480 if (topologyIdentifier != null) {
481 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
484 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
485 ilab.build()).build();
488 private NodeHolder getNode(final NodeId id) {
489 if (this.nodes.containsKey(id)) {
490 LOG.debug("Node {} is already present", id);
491 return this.nodes.get(id);
494 final NodeHolder ret = new NodeHolder(id);
495 this.nodes.put(id, ret);
499 private void putNode(final WriteTransaction trans, final NodeHolder holder) {
500 if (holder.syncState(trans)) {
501 this.nodes.remove(holder.getNodeId());
505 private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) {
506 if (holder.checkForRemoval(trans)) {
507 this.nodes.remove(holder.getNodeId());
511 private static void augmentProtocolId(final LinkstateRoute value, final IgpLinkAttributesBuilder ilab,
512 final LinkAttributes la, final LinkDescriptors ld) {
513 switch (value.getProtocolId()) {
518 ilab.addAugmentation(
519 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
520 isisLinkAttributes(ld.getMultiTopologyId(), la));
524 ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
525 ospfLinkAttributes(ld.getMultiTopologyId(), la));
532 private void createLink(final WriteTransaction trans, final UriBuilder base,
533 final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
535 final LinkAttributes la;
536 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
538 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
539 if (attrType != null) {
540 la = ((LinkAttributesCase)attrType).getLinkAttributes();
542 LOG.debug("Missing attribute type in link {} route {}, skipping it", l, value);
546 LOG.debug("Missing attributes in link {} route {}, skipping it", l, value);
550 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
552 if (la.getMetric() != null) {
553 ilab.setMetric(la.getMetric().getValue());
555 ilab.setName(la.getLinkName());
557 augmentProtocolId(value, ilab, la, l.getLinkDescriptors());
559 final LinkBuilder lb = new LinkBuilder();
560 lb.setLinkId(buildLinkId(base, l));
561 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
563 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
564 LOG.debug("Link {} implies source node {}", l, srcNode);
566 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
567 LOG.debug("Link {} implies destination node {}", l, dstNode);
569 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
570 LOG.debug("Link {} implies source TP {}", l, srcTp);
572 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
573 LOG.debug("Link {} implies destination TP {}", l, dstTp);
575 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
576 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
578 LOG.debug("Created TP {} as link source", srcTp);
579 NodeHolder snh = this.nodes.get(srcNode);
581 snh = getNode(srcNode);
582 snh.addTp(srcTp, lb.getLinkId(), false);
585 snh.addTp(srcTp, lb.getLinkId(), false);
586 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) snh.getNodeId()));
587 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
590 LOG.debug("Created TP {} as link destination", dstTp);
591 NodeHolder dnh = this.nodes.get(dstNode);
593 dnh = getNode(dstNode);
594 dnh.addTp(dstTp, lb.getLinkId(), true);
597 dnh.addTp(dstTp, lb.getLinkId(), true);
598 final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
599 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
600 new NodeKey((NodeId) dnh.getNodeId()));
601 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
604 final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
605 final Link link = lb.build();
607 trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
608 LOG.debug("Created link {} at {} for {}", link, lid, l);
611 private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
612 final LinkId link, final boolean isRemote) {
613 final NodeHolder nh = this.nodes.get(node);
615 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
616 trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp)));
617 nh.removeTp(tp, link, isRemote);
618 checkNodeForRemoval(trans, nh);
620 LOG.warn("Removed non-existent node {}", node);
624 private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase l) {
625 final LinkId id = buildLinkId(base, l);
626 final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
627 trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
628 LOG.debug("Removed link {}", lid);
630 removeTp(trans, buildNodeId(base, l.getLocalNodeDescriptors()), buildLocalTpId(base, l.getLinkDescriptors()), id, false);
631 removeTp(trans, buildNodeId(base, l.getRemoteNodeDescriptors()), buildRemoteTpId(base, l.getLinkDescriptors()), id, true);
634 private static List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
635 final List<Short> ret = new ArrayList<>(list.size());
636 for (final TopologyIdentifier id : list) {
637 ret.add(id.getValue().shortValue());
642 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
643 final NodeIdentifier node, final NodeAttributes na) {
644 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();
645 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
648 if (na.getIpv4RouterId() != null) {
649 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
651 if (na.getIpv6RouterId() != null) {
652 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
654 if (na.getTopologyIdentifier() != null) {
655 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
659 final CRouterIdentifier ri = node.getCRouterIdentifier();
660 if (ri instanceof IsisPseudonodeCase) {
661 final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
662 final IsoBuilder b = new IsoBuilder();
663 final String systemId = UriBuilder.isoId(pn.getIsIsRouterIdentifier().getIsoSystemId());
664 b.setIsoSystemId(new IsoSystemId(systemId));
665 b.setIsoPseudonodeId(new IsoPseudonodeId(BaseEncoding.base16().encode(new byte[] {pn.getPsn().byteValue()})));
666 ab.setIso(b.build());
668 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
670 } else if (ri instanceof IsisNodeCase) {
671 final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
672 final String systemId = UriBuilder.isoId(in.getIsoSystemId());
673 ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(systemId)).build());
675 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
679 ab.setTed(tb.build());
681 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
685 private static List<IsoNetId> toIsoNetIds(final List<IsisAreaIdentifier> areaIds, final String systemId) {
686 return Lists.transform(areaIds, new Function<IsisAreaIdentifier, IsoNetId>() {
688 public IsoNetId apply(final IsisAreaIdentifier input) {
689 return new IsoNetId(UriBuilder.toIsoNetId(input, systemId));
694 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
695 final NodeIdentifier node, final NodeAttributes na) {
696 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();
697 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
699 if (na.getIpv4RouterId() != null) {
700 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
702 if (na.getIpv6RouterId() != null) {
703 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
705 if (na.getTopologyIdentifier() != null) {
706 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
708 final CRouterIdentifier ri = node.getCRouterIdentifier();
709 if (ri instanceof OspfPseudonodeCase) {
710 final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
712 ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
713 ab.setDrInterfaceId(pn.getLanInterface().getValue());
714 } else if (ri instanceof OspfNodeCase && na.getNodeFlags() != null) {
715 // TODO: what should we do with in.getOspfRouterId()?
717 final NodeFlagBits nf = na.getNodeFlags();
718 if (nf.isAbr() != null) {
719 ab.setRouterType(new AbrBuilder().setAbr(nf.isAbr()).build());
720 } else if (nf.isExternal() != null) {
721 ab.setRouterType(new InternalBuilder().setInternal(!nf.isExternal()).build());
725 ab.setTed(tb.build());
726 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
730 private static void augmentProtocolId(final LinkstateRoute value, final IgpNodeAttributesBuilder inab,
731 final NodeAttributes na, final NodeIdentifier nd) {
732 switch (value.getProtocolId()) {
737 inab.addAugmentation(
738 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
739 isisNodeAttributes(nd, na));
742 inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
743 ospfNodeAttributes(nd, na));
750 private void createNode(final WriteTransaction trans, final UriBuilder base,
751 final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
752 final NodeAttributes na;
754 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
756 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
757 if (attrType != null) {
758 na = ((NodeAttributesCase)attrType).getNodeAttributes();
760 LOG.debug("Missing attribute type in node {} route {}, skipping it", n, value);
764 LOG.debug("Missing attributes in node {} route {}, skipping it", n, value);
767 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
768 final List<IpAddress> ids = new ArrayList<>();
770 if (na.getIpv4RouterId() != null) {
771 ids.add(new IpAddress(na.getIpv4RouterId()));
773 if (na.getIpv6RouterId() != null) {
774 ids.add(new IpAddress(na.getIpv6RouterId()));
776 if (na.getDynamicHostname() != null) {
777 inab.setName(new DomainName(na.getDynamicHostname()));
780 if (!ids.isEmpty()) {
781 inab.setRouterId(ids);
783 augmentProtocolId(value, inab, na, n.getNodeDescriptors());
785 final NodeId nid = buildNodeId(base, n.getNodeDescriptors());
786 final NodeHolder nh = getNode(nid);
788 * Eventhough the the holder creates a dummy structure, we need to duplicate it here,
789 * as that is the API requirement. The reason for it is the possible presence of supporting
790 * node -- something which the holder does not track.
792 final NodeBuilder nb = new NodeBuilder();
794 nb.setKey(new NodeKey(nb.getNodeId()));
796 nh.advertized(nb, inab);
800 private void removeNode(final WriteTransaction trans, final UriBuilder base, final NodeCase n) {
801 final NodeId id = buildNodeId(base, n.getNodeDescriptors());
802 final NodeHolder nh = this.nodes.get(id);
807 LOG.warn("Node {} does not have a holder", id);
811 private static void augmentProtocolId(final LinkstateRoute value, final PrefixAttributes pa, final PrefixBuilder pb) {
812 switch (value.getProtocolId()) {
818 if (pa != null && pa.getOspfForwardingAddress() != null) {
821 new Prefix1Builder().setOspfPrefixAttributes(
822 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
830 private void createPrefix(final WriteTransaction trans, final UriBuilder base,
831 final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
832 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
834 LOG.warn("IP reachability not present in prefix {} route {}, skipping it", p, value);
837 final PrefixBuilder pb = new PrefixBuilder();
838 final PrefixKey pk = new PrefixKey(ippfx);
842 final PrefixAttributes pa;
843 // Very defensive lookup
844 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
846 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
847 if (attrType != null) {
848 pa = ((PrefixAttributesCase)attrType).getPrefixAttributes();
850 LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, p, value);
854 LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, p, value);
858 pb.setMetric(pa.getPrefixMetric().getValue());
860 augmentProtocolId(value, pa, pb);
862 final Prefix pfx = pb.build();
863 LOG.debug("Created prefix {} for {}", pfx, p);
866 * All set, but... the hosting node may not exist, we may need to fake it.
868 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
869 NodeHolder nh = this.nodes.get(node);
876 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
877 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
878 trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
882 private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase p) {
883 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
884 final NodeHolder nh = this.nodes.get(node);
886 LOG.debug("Removed prefix {}", p);
887 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
888 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
889 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
891 LOG.warn("IP reachability not present in prefix {}, skipping it", p);
894 final PrefixKey pk = new PrefixKey(ippfx);
895 trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
897 checkNodeForRemoval(trans, nh);
899 LOG.warn("Removing prefix from non-existing node {}", node);
903 private InstanceIdentifier<Node> getNodeInstanceIdentifier(final NodeKey nodeKey) {
904 return getInstanceIdentifier().child(
905 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
910 protected void createObject(final ReadWriteTransaction trans,
911 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
912 final UriBuilder base = new UriBuilder(value);
914 final ObjectType t = value.getObjectType();
915 Preconditions.checkArgument(t != null, "Route %s value %s has null object type", id, value);
917 if (t instanceof LinkCase) {
918 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
919 } else if (t instanceof NodeCase) {
920 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
921 } else if (t instanceof PrefixCase) {
922 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
924 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
929 protected void removeObject(final ReadWriteTransaction trans,
930 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
931 final UriBuilder base = new UriBuilder(value);
933 final ObjectType t = value.getObjectType();
934 if (t instanceof LinkCase) {
935 removeLink(trans, base, (LinkCase) t);
936 } else if (t instanceof NodeCase) {
937 removeNode(trans, base, (NodeCase) t);
938 } else if (t instanceof PrefixCase) {
939 removePrefix(trans, base, (PrefixCase) t);
941 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
945 @SuppressWarnings({ "rawtypes", "unchecked" })
947 protected InstanceIdentifier<LinkstateRoute> getRouteWildcard(final InstanceIdentifier<Tables> tablesId) {
948 return tablesId.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class);