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.LinkstateAddressFamily;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeFlagBits;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.LinkStateAttribute;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
48 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;
49 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;
50 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;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoNetId;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValues;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValuesBuilder;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.SrlgBuilder;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
98 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
99 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
100 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
101 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
102 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
103 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
104 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
105 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
106 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
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.Prefix;
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.PrefixBuilder;
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.PrefixKey;
110 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
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.TerminationPointType;
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.IpBuilder;
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.UnnumberedBuilder;
114 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
115 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
116 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
117 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
118 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.AbrBuilder;
119 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.InternalBuilder;
120 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.PseudonodeBuilder;
121 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
122 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
123 import org.slf4j.Logger;
124 import org.slf4j.LoggerFactory;
126 public class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
127 private static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder()
128 .addAugmentation(TopologyTypes1.class,
129 new TopologyTypes1Builder()
130 .setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build())
133 private static final String UNHANDLED_OBJECT_CLASS = "Unhandled object class {}";
135 private static final class TpHolder {
136 private final Set<LinkId> local = new HashSet<>();
137 private final Set<LinkId> remote = new HashSet<>();
139 private final TerminationPoint tp;
141 private TpHolder(final TerminationPoint tp) {
142 this.tp = Preconditions.checkNotNull(tp);
145 private synchronized void addLink(final LinkId id, final boolean isRemote) {
153 private synchronized boolean removeLink(final LinkId id, final boolean isRemote) {
154 final boolean removed;
156 removed = this.remote.remove(id);
158 removed = this.local.remove(id);
161 LOG.warn("Removed non-reference link {} from TP {} isRemote {}", this.tp.getTpId(), id, isRemote);
164 return this.local.isEmpty() && this.remote.isEmpty();
167 private TerminationPoint getTp() {
172 private final class NodeHolder {
173 private final Map<PrefixKey, Prefix> prefixes = new HashMap<>();
174 private final Map<TpId, TpHolder> tps = new HashMap<>();
175 private boolean advertized = false;
176 private IgpNodeAttributesBuilder inab;
177 private NodeBuilder nb;
179 private NodeHolder(final NodeId id) {
180 this.inab = new IgpNodeAttributesBuilder();
181 this.nb = new NodeBuilder().setKey(new NodeKey(id)).setNodeId(id);
185 * Synchronized in-core state of a node into the backing store using the transaction
187 * @param trans data modification transaction which to use
188 * @return True if the node has been purged, false otherwise.
190 private boolean syncState(final WriteTransaction trans) {
191 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
194 * Transaction's putOperationalData() does a merge. Force it onto a replace
195 * by removing the data. If we decide to remove the node -- we just skip the put.
197 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
199 if (!this.advertized) {
200 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
201 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
205 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
208 // Re-generate termination points
209 this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), new Function<TpHolder, TerminationPoint>() {
211 public TerminationPoint apply(final TpHolder input) {
212 return input.getTp();
216 // Re-generate prefixes
217 this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
219 // Write the node out
220 final Node n = this.nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(this.inab.build()).build()).build();
221 trans.put(LogicalDatastoreType.OPERATIONAL, nid, n);
222 LOG.debug("Created node {} at {}", n, nid);
226 private boolean checkForRemoval(final WriteTransaction trans) {
227 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
229 if (!this.advertized) {
230 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
231 trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
232 LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
236 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
241 private synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
242 final TpHolder h = this.tps.get(tp);
244 if (h.removeLink(link, isRemote)) {
246 LOG.debug("Removed TP {}", tp);
249 LOG.warn("Removed non-present TP {} by link {}", tp, link);
253 private void addTp(final TerminationPoint tp, final LinkId link, final boolean isRemote) {
254 TpHolder h = this.tps.get(tp.getTpId());
256 h = new TpHolder(tp);
257 this.tps.put(tp.getTpId(), h);
260 h.addLink(link, isRemote);
263 private void addPrefix(final Prefix pfx) {
264 this.prefixes.put(pfx.getKey(), pfx);
267 private void removePrefix(final PrefixCase p) {
268 this.prefixes.remove(new PrefixKey(p.getPrefixDescriptors().getIpReachabilityInformation()));
271 private void unadvertized() {
272 this.inab = new IgpNodeAttributesBuilder();
273 this.nb = new NodeBuilder().setKey(this.nb.getKey()).setNodeId(this.nb.getNodeId());
274 this.advertized = false;
275 LOG.debug("Node {} is unadvertized", this.nb.getNodeId());
278 private void advertized(final NodeBuilder nb, final IgpNodeAttributesBuilder inab) {
279 this.nb = Preconditions.checkNotNull(nb);
280 this.inab = Preconditions.checkNotNull(inab);
281 this.advertized = true;
282 LOG.debug("Node {} is advertized", nb.getNodeId());
285 private Object getNodeId() {
286 return this.nb.getNodeId();
290 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
291 private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
293 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
294 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
297 public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
298 final TopologyId topologyId, final long listenerResetLimitInMillsec, final int listenerResetEnforceCounter) {
299 super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
300 listenerResetLimitInMillsec, listenerResetEnforceCounter);
303 private static LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
304 return new LinkId(new UriBuilder(base, "link").add(link).toString());
307 private static NodeId buildNodeId(final UriBuilder base,
308 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier node) {
309 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
312 private static TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
313 final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
314 final UriBuilder b = new UriBuilder(base, "tp");
315 if (topologyIdentifier != null) {
316 b.add("mt", topologyIdentifier.getValue());
318 if (ipv4InterfaceIdentifier != null) {
319 b.add("ipv4", ipv4InterfaceIdentifier.getValue());
321 if (ipv6InterfaceIdentifier != null) {
322 b.add("ipv6", ipv6InterfaceIdentifier.getValue());
325 return new TpId(b.add("id", id).toString());
328 private static TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
329 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
330 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
333 private static TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
334 final TerminationPointBuilder stpb = new TerminationPointBuilder();
335 stpb.setKey(new TerminationPointKey(id));
339 stpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes(
340 new IgpTerminationPointAttributesBuilder().setTerminationPointType(null).build()).build());
346 private static TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
347 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
348 // Order of preference: Unnumbered first, then IP
350 LOG.debug("Unnumbered termination point type: {}", id);
351 return new UnnumberedBuilder().setUnnumberedId(id).build();
355 if (ipv6InterfaceIdentifier != null) {
356 ip = new IpAddress(ipv6InterfaceIdentifier);
357 } else if (ipv4InterfaceIdentifier != null) {
358 ip = new IpAddress(ipv4InterfaceIdentifier);
364 LOG.debug("IP termination point type: {}", ip);
365 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
371 private static TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
372 final TpId id = buildLocalTpId(base, linkDescriptors);
373 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
374 linkDescriptors.getLinkLocalIdentifier());
376 return buildTp(id, t);
379 private static TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
380 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
381 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
384 private static TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
385 final TpId id = buildRemoteTpId(base, linkDescriptors);
386 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
387 linkDescriptors.getLinkRemoteIdentifier());
389 return buildTp(id, t);
392 private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
393 return getInstanceIdentifier().child(
394 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
398 private static Float bandwidthToFloat(final Bandwidth bandwidth) {
399 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
402 private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
403 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
406 private static List<UnreservedBandwidth> unreservedBandwidthList(
407 final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth> input) {
408 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
410 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth i : input) {
411 ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
412 new UnreservedBandwidthKey(i.getPriority())).build());
418 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
419 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
420 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();
423 if (la.getAdminGroup() != null) {
424 tb.setColor(la.getAdminGroup().getValue());
426 if (la.getTeMetric() != null) {
427 tb.setTeDefaultMetric(la.getTeMetric().getValue());
429 if (la.getUnreservedBandwidth() != null) {
430 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
432 if (la.getMaxLinkBandwidth() != null) {
433 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
435 if (la.getMaxReservableBandwidth() != null) {
436 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
438 if (la.getSharedRiskLinkGroups() != null) {
439 final List<SrlgValues> srlgs = new ArrayList<>();
440 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
441 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
443 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
447 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
448 ilab.setTed(tb.build());
449 if (topologyIdentifier != null) {
450 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
453 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
454 ilab.build()).build();
457 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
458 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
459 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();
462 if (la.getAdminGroup() != null) {
463 tb.setColor(la.getAdminGroup().getValue());
465 if (la.getTeMetric() != null) {
466 tb.setTeDefaultMetric(la.getTeMetric().getValue());
468 if (la.getUnreservedBandwidth() != null) {
469 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
471 if (la.getMaxLinkBandwidth() != null) {
472 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
474 if (la.getMaxReservableBandwidth() != null) {
475 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
477 if (la.getSharedRiskLinkGroups() != null) {
478 final List<SrlgValues> srlgs = new ArrayList<>();
479 for (final SrlgId id : la.getSharedRiskLinkGroups()) {
480 srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
482 tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
486 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
487 ilab.setTed(tb.build());
488 if (topologyIdentifier != null) {
489 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
492 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
493 ilab.build()).build();
496 private NodeHolder getNode(final NodeId id) {
497 if (this.nodes.containsKey(id)) {
498 LOG.debug("Node {} is already present", id);
499 return this.nodes.get(id);
502 final NodeHolder ret = new NodeHolder(id);
503 this.nodes.put(id, ret);
507 private void putNode(final WriteTransaction trans, final NodeHolder holder) {
508 if (holder.syncState(trans)) {
509 this.nodes.remove(holder.getNodeId());
513 private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) {
514 if (holder.checkForRemoval(trans)) {
515 this.nodes.remove(holder.getNodeId());
519 private static void augmentProtocolId(final LinkstateRoute value, final IgpLinkAttributesBuilder ilab,
520 final LinkAttributes la, final LinkDescriptors ld) {
521 switch (value.getProtocolId()) {
526 ilab.addAugmentation(
527 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
528 isisLinkAttributes(ld.getMultiTopologyId(), la));
532 ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
533 ospfLinkAttributes(ld.getMultiTopologyId(), la));
540 private void createLink(final WriteTransaction trans, final UriBuilder base,
541 final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
543 final LinkAttributes la;
544 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
546 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
547 if (attrType != null) {
548 la = ((LinkAttributesCase)attrType).getLinkAttributes();
550 LOG.debug("Missing attribute type in link {} route {}, skipping it", l, value);
554 LOG.debug("Missing attributes in link {} route {}, skipping it", l, value);
558 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
560 if (la.getMetric() != null) {
561 ilab.setMetric(la.getMetric().getValue());
563 ilab.setName(la.getLinkName());
565 augmentProtocolId(value, ilab, la, l.getLinkDescriptors());
567 final LinkBuilder lb = new LinkBuilder();
568 lb.setLinkId(buildLinkId(base, l));
569 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
571 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
572 LOG.debug("Link {} implies source node {}", l, srcNode);
574 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
575 LOG.debug("Link {} implies destination node {}", l, dstNode);
577 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
578 LOG.debug("Link {} implies source TP {}", l, srcTp);
580 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
581 LOG.debug("Link {} implies destination TP {}", l, dstTp);
583 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
584 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
586 LOG.debug("Created TP {} as link source", srcTp);
587 NodeHolder snh = this.nodes.get(srcNode);
589 snh = getNode(srcNode);
590 snh.addTp(srcTp, lb.getLinkId(), false);
593 snh.addTp(srcTp, lb.getLinkId(), false);
594 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) snh.getNodeId()));
595 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
598 LOG.debug("Created TP {} as link destination", dstTp);
599 NodeHolder dnh = this.nodes.get(dstNode);
601 dnh = getNode(dstNode);
602 dnh.addTp(dstTp, lb.getLinkId(), true);
605 dnh.addTp(dstTp, lb.getLinkId(), true);
606 final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
607 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
608 new NodeKey((NodeId) dnh.getNodeId()));
609 trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
612 final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
613 final Link link = lb.build();
615 trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
616 LOG.debug("Created link {} at {} for {}", link, lid, l);
619 private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
620 final LinkId link, final boolean isRemote) {
621 final NodeHolder nh = this.nodes.get(node);
623 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
624 trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp)));
625 nh.removeTp(tp, link, isRemote);
626 checkNodeForRemoval(trans, nh);
628 LOG.warn("Removed non-existent node {}", node);
632 private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase l) {
633 final LinkId id = buildLinkId(base, l);
634 final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
635 trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
636 LOG.debug("Removed link {}", lid);
638 removeTp(trans, buildNodeId(base, l.getLocalNodeDescriptors()), buildLocalTpId(base, l.getLinkDescriptors()), id, false);
639 removeTp(trans, buildNodeId(base, l.getRemoteNodeDescriptors()), buildRemoteTpId(base, l.getLinkDescriptors()), id, true);
642 private static List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
643 final List<Short> ret = new ArrayList<>(list.size());
644 for (final TopologyIdentifier id : list) {
645 ret.add(id.getValue().shortValue());
650 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
651 final NodeIdentifier node, final NodeAttributes na) {
652 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();
653 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
656 if (na.getIpv4RouterId() != null) {
657 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
659 if (na.getIpv6RouterId() != null) {
660 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
662 if (na.getTopologyIdentifier() != null) {
663 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
667 final CRouterIdentifier ri = node.getCRouterIdentifier();
668 if (ri instanceof IsisPseudonodeCase) {
669 final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
670 final IsoBuilder b = new IsoBuilder();
671 final String systemId = UriBuilder.isoId(pn.getIsIsRouterIdentifier().getIsoSystemId());
672 b.setIsoSystemId(new IsoSystemId(systemId));
673 b.setIsoPseudonodeId(new IsoPseudonodeId(BaseEncoding.base16().encode(new byte[] {pn.getPsn().byteValue()})));
674 ab.setIso(b.build());
676 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
678 } else if (ri instanceof IsisNodeCase) {
679 final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
680 final String systemId = UriBuilder.isoId(in.getIsoSystemId());
681 ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(systemId)).build());
683 ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
687 ab.setTed(tb.build());
689 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
693 private static List<IsoNetId> toIsoNetIds(final List<IsisAreaIdentifier> areaIds, final String systemId) {
694 return Lists.transform(areaIds, new Function<IsisAreaIdentifier, IsoNetId>() {
696 public IsoNetId apply(final IsisAreaIdentifier input) {
697 return new IsoNetId(UriBuilder.toIsoNetId(input, systemId));
702 private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
703 final NodeIdentifier node, final NodeAttributes na) {
704 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();
705 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
707 if (na.getIpv4RouterId() != null) {
708 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
710 if (na.getIpv6RouterId() != null) {
711 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
713 if (na.getTopologyIdentifier() != null) {
714 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
716 final CRouterIdentifier ri = node.getCRouterIdentifier();
717 if (ri instanceof OspfPseudonodeCase) {
718 final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
720 ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
721 ab.setDrInterfaceId(pn.getLanInterface().getValue());
722 } else if (ri instanceof OspfNodeCase && na.getNodeFlags() != null) {
723 // TODO: what should we do with in.getOspfRouterId()?
725 final NodeFlagBits nf = na.getNodeFlags();
726 if (nf.isAbr() != null) {
727 ab.setRouterType(new AbrBuilder().setAbr(nf.isAbr()).build());
728 } else if (nf.isExternal() != null) {
729 ab.setRouterType(new InternalBuilder().setInternal(!nf.isExternal()).build());
733 ab.setTed(tb.build());
734 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
738 private static void augmentProtocolId(final LinkstateRoute value, final IgpNodeAttributesBuilder inab,
739 final NodeAttributes na, final NodeIdentifier nd) {
740 switch (value.getProtocolId()) {
745 inab.addAugmentation(
746 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
747 isisNodeAttributes(nd, na));
750 inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
751 ospfNodeAttributes(nd, na));
758 private void createNode(final WriteTransaction trans, final UriBuilder base,
759 final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
760 final NodeAttributes na;
762 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
764 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
765 if (attrType != null) {
766 na = ((NodeAttributesCase)attrType).getNodeAttributes();
768 LOG.debug("Missing attribute type in node {} route {}, skipping it", n, value);
772 LOG.debug("Missing attributes in node {} route {}, skipping it", n, value);
775 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
776 final List<IpAddress> ids = new ArrayList<>();
778 if (na.getIpv4RouterId() != null) {
779 ids.add(new IpAddress(na.getIpv4RouterId()));
781 if (na.getIpv6RouterId() != null) {
782 ids.add(new IpAddress(na.getIpv6RouterId()));
784 if (na.getDynamicHostname() != null) {
785 inab.setName(new DomainName(na.getDynamicHostname()));
788 if (!ids.isEmpty()) {
789 inab.setRouterId(ids);
791 augmentProtocolId(value, inab, na, n.getNodeDescriptors());
793 final NodeId nid = buildNodeId(base, n.getNodeDescriptors());
794 final NodeHolder nh = getNode(nid);
796 * Eventhough the the holder creates a dummy structure, we need to duplicate it here,
797 * as that is the API requirement. The reason for it is the possible presence of supporting
798 * node -- something which the holder does not track.
800 final NodeBuilder nb = new NodeBuilder();
802 nb.setKey(new NodeKey(nb.getNodeId()));
804 nh.advertized(nb, inab);
808 private void removeNode(final WriteTransaction trans, final UriBuilder base, final NodeCase n) {
809 final NodeId id = buildNodeId(base, n.getNodeDescriptors());
810 final NodeHolder nh = this.nodes.get(id);
815 LOG.warn("Node {} does not have a holder", id);
819 private static void augmentProtocolId(final LinkstateRoute value, final PrefixAttributes pa, final PrefixBuilder pb) {
820 switch (value.getProtocolId()) {
826 if (pa != null && pa.getOspfForwardingAddress() != null) {
829 new Prefix1Builder().setOspfPrefixAttributes(
830 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
838 private void createPrefix(final WriteTransaction trans, final UriBuilder base,
839 final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
840 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
842 LOG.warn("IP reachability not present in prefix {} route {}, skipping it", p, value);
845 final PrefixBuilder pb = new PrefixBuilder();
846 final PrefixKey pk = new PrefixKey(ippfx);
850 final PrefixAttributes pa;
851 // Very defensive lookup
852 final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
854 final LinkStateAttribute attrType = attr.getLinkStateAttribute();
855 if (attrType != null) {
856 pa = ((PrefixAttributesCase)attrType).getPrefixAttributes();
858 LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, p, value);
862 LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, p, value);
866 pb.setMetric(pa.getPrefixMetric().getValue());
868 augmentProtocolId(value, pa, pb);
870 final Prefix pfx = pb.build();
871 LOG.debug("Created prefix {} for {}", pfx, p);
874 * All set, but... the hosting node may not exist, we may need to fake it.
876 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
877 NodeHolder nh = this.nodes.get(node);
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 trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
890 private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase p) {
891 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
892 final NodeHolder nh = this.nodes.get(node);
894 LOG.debug("Removed prefix {}", p);
895 final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
896 final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
897 final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
899 LOG.warn("IP reachability not present in prefix {}, skipping it", p);
902 final PrefixKey pk = new PrefixKey(ippfx);
903 trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
905 checkNodeForRemoval(trans, nh);
907 LOG.warn("Removing prefix from non-existing node {}", node);
911 private InstanceIdentifier<Node> getNodeInstanceIdentifier(final NodeKey nodeKey) {
912 return getInstanceIdentifier().child(
913 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
918 protected void createObject(final ReadWriteTransaction trans,
919 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
920 final UriBuilder base = new UriBuilder(value);
922 final ObjectType t = value.getObjectType();
923 Preconditions.checkArgument(t != null, "Route %s value %s has null object type", id, value);
925 if (t instanceof LinkCase) {
926 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
927 } else if (t instanceof NodeCase) {
928 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
929 } else if (t instanceof PrefixCase) {
930 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
932 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
937 protected void removeObject(final ReadWriteTransaction trans,
938 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
939 final UriBuilder base = new UriBuilder(value);
941 final ObjectType t = value.getObjectType();
942 if (t instanceof LinkCase) {
943 removeLink(trans, base, (LinkCase) t);
944 } else if (t instanceof NodeCase) {
945 removeNode(trans, base, (NodeCase) t);
946 } else if (t instanceof PrefixCase) {
947 removePrefix(trans, base, (PrefixCase) t);
949 LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
953 @SuppressWarnings({ "rawtypes", "unchecked" })
955 protected InstanceIdentifier<LinkstateRoute> getRouteWildcard(final InstanceIdentifier<Tables> tablesId) {
956 return tablesId.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class);