BUG-731: do not throw Exceptions
[bgpcep.git] / bgp / topology-provider / src / main / java / org / opendaylight / bgpcep / bgp / topology / provider / LinkstateTopologyBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.bgpcep.bgp.topology.provider;
9
10 import java.math.BigDecimal;
11 import java.nio.ByteBuffer;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Set;
18
19 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
20 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
21 import org.opendaylight.protocol.bgp.rib.RibReference;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.DomainName;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeFlagBits;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.LinkstateRoute;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.Attributes1;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.ObjectType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.link._case.LinkAttributes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.node._case.NodeAttributes;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.prefix._case.PrefixAttributes;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.LinkCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.NodeCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.PrefixCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.link._case.LinkDescriptors;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.node._case.NodeDescriptors;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.CRouterIdentifier;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
60 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
61 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1Builder;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
85 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;
86 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;
87 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;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
89 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;
90 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;
91 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;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.AbrBuilder;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.InternalBuilder;
98 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.PseudonodeBuilder;
99 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
100 import org.opendaylight.yangtools.yang.binding.DataObject;
101 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
102 import org.slf4j.Logger;
103 import org.slf4j.LoggerFactory;
104
105 import com.google.common.base.Function;
106 import com.google.common.base.Preconditions;
107 import com.google.common.collect.Collections2;
108 import com.google.common.collect.Lists;
109
110 public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
111         private static final class TpHolder {
112                 private final Set<LinkId> local = new HashSet<>();
113                 private final Set<LinkId> remote = new HashSet<>();
114
115                 private final TerminationPoint tp;
116
117                 private TpHolder(final TerminationPoint tp) {
118                         this.tp = Preconditions.checkNotNull(tp);
119                 }
120
121                 private synchronized void addLink(final LinkId id, final boolean isRemote) {
122                         if (isRemote) {
123                                 this.remote.add(id);
124                         } else {
125                                 this.local.add(id);
126                         }
127                 }
128
129                 private synchronized boolean removeLink(final LinkId id, final boolean isRemote) {
130                         final boolean removed;
131                         if (isRemote) {
132                                 removed = this.remote.remove(id);
133                         } else {
134                                 removed = this.local.remove(id);
135                         }
136                         if (!removed) {
137                                 LOG.warn("Removed non-reference link {} from TP {} isRemote {}", this.tp.getTpId(), id, isRemote);
138                         }
139
140                         return this.local.isEmpty() && this.remote.isEmpty();
141                 }
142
143                 private TerminationPoint getTp() {
144                         return this.tp;
145                 }
146         }
147
148         private final class NodeHolder {
149                 private final Map<PrefixKey, Prefix> prefixes = new HashMap<>();
150                 private final Map<TpId, TpHolder> tps = new HashMap<>();
151                 private boolean advertized = false;
152                 private IgpNodeAttributesBuilder inab;
153                 private NodeBuilder nb;
154
155                 private NodeHolder(final NodeId id) {
156                         this.inab = new IgpNodeAttributesBuilder();
157                         this.nb = new NodeBuilder().setKey(new NodeKey(id)).setNodeId(id);
158                 }
159
160                 /**
161                  * Synchronized in-core state of a node into the backing store using the transaction
162                  *
163                  * @param trans data modification transaction which to use
164                  * @return True if the node has been purged, false otherwise.
165                  */
166                 private boolean syncState(final DataModification<InstanceIdentifier<?>, DataObject> trans) {
167                         final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
168                                         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
169                                         this.nb.getKey());
170
171                         /*
172                          * Transaction's putOperationalData() does a merge. Force it onto a replace
173                          * by removing the data. If we decide to remove the node -- we just skip the put.
174                          */
175                         trans.removeOperationalData(nid);
176
177                         if (!this.advertized) {
178                                 if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
179                                         LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
180                                         return true;
181                                 }
182
183                                 LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
184                         }
185
186                         // Re-generate termination points
187                         this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(),
188                                         new Function<TpHolder, TerminationPoint>() {
189                                 @Override
190                                 public TerminationPoint apply(final TpHolder input) {
191                                         return input.getTp();
192                                 }
193                         })));
194
195                         // Re-generate prefixes
196                         this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
197
198                         // Write the node out
199                         final Node n = this.nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(this.inab.build()).build()).build();
200                         trans.putOperationalData(nid, n);
201                         LOG.debug("Created node {} at {}", n, nid);
202                         return false;
203                 }
204
205                 private synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
206                         final TpHolder h = this.tps.get(tp);
207                         if (h != null) {
208                                 if (h.removeLink(link, isRemote)) {
209                                         this.tps.remove(tp);
210                                         LOG.debug("Removed TP {}", tp);
211                                 }
212                         } else {
213                                 LOG.warn("Removed non-present TP {} by link {}", tp, link);
214                         }
215                 }
216
217                 private void addTp(final TerminationPoint tp, final LinkId link, final boolean isRemote) {
218                         TpHolder h = this.tps.get(tp.getTpId());
219                         if (h == null) {
220                                 h = new TpHolder(tp);
221                                 this.tps.put(tp.getTpId(), h);
222                         }
223
224                         h.addLink(link, isRemote);
225                 }
226
227                 private void addPrefix(final Prefix pfx) {
228                         this.prefixes.put(pfx.getKey(), pfx);
229                 }
230
231                 private void removePrefix(final PrefixCase p) {
232                         this.prefixes.remove(new PrefixKey(p.getIpReachabilityInformation()));
233                 }
234
235                 private void unadvertized() {
236                         this.inab = new IgpNodeAttributesBuilder();
237                         this.nb = new NodeBuilder().setKey(this.nb.getKey()).setNodeId(this.nb.getNodeId());
238                         this.advertized = false;
239                         LOG.debug("Node {} is unadvertized", this.nb.getNodeId());
240                 }
241
242                 private void advertized(final NodeBuilder nb, final IgpNodeAttributesBuilder inab) {
243                         this.nb = Preconditions.checkNotNull(nb);
244                         this.inab = Preconditions.checkNotNull(inab);
245                         this.advertized = true;
246                         LOG.debug("Node {} is advertized", nb.getNodeId());
247                 }
248
249                 private Object getNodeId() {
250                         return this.nb.getNodeId();
251                 }
252         }
253
254         private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
255         private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
256
257         public LinkstateTopologyBuilder(final DataProviderService dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
258                 super(dataProvider, locRibReference, topologyId, new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class,
259                                 new TopologyTypes1Builder().build()).build(), LinkstateRoute.class);
260         }
261
262         private LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
263                 return new LinkId(new UriBuilder(base, "link").add(link).toString());
264         }
265
266         private NodeId buildNodeId(final UriBuilder base, final NodeIdentifier node) {
267                 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
268         }
269
270         private TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
271                         final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
272                 final UriBuilder b = new UriBuilder(base, "tp");
273                 if (topologyIdentifier != null) {
274                         b.add("mt", topologyIdentifier.getValue());
275                 }
276                 if (ipv4InterfaceIdentifier != null) {
277                         b.add("ipv4", ipv4InterfaceIdentifier.getValue());
278                 }
279                 if (ipv6InterfaceIdentifier != null) {
280                         b.add("ipv6", ipv6InterfaceIdentifier.getValue());
281                 }
282
283                 return new TpId(b.add("id", id).toString());
284         }
285
286         private TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
287                 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
288                                 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
289         }
290
291         private TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
292                 final TerminationPointBuilder stpb = new TerminationPointBuilder();
293                 stpb.setKey(new TerminationPointKey(id));
294                 stpb.setTpId(id);
295
296                 if (type != null) {
297                         stpb.addAugmentation(
298                                         TerminationPoint1.class,
299                                         new TerminationPoint1Builder().setIgpTerminationPointAttributes(
300                                                         new IgpTerminationPointAttributesBuilder().setTerminationPointType(null).build()).build());
301                 }
302
303                 return stpb.build();
304         }
305
306         private TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
307                         final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
308                 // Order of preference: Unnumbered first, then IP
309                 if (id != null) {
310                         LOG.debug("Unnumbered termination point type: {}", id);
311                         return new UnnumberedBuilder().setUnnumberedId(id).build();
312                 }
313
314                 final IpAddress ip;
315                 if (ipv6InterfaceIdentifier != null) {
316                         ip = new IpAddress(ipv6InterfaceIdentifier);
317                 } else if (ipv4InterfaceIdentifier != null) {
318                         ip = new IpAddress(ipv4InterfaceIdentifier);
319                 } else {
320                         ip = null;
321                 }
322
323                 if (ip != null) {
324                         LOG.debug("IP termination point type: {}", ip);
325                         return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
326                 }
327
328                 return null;
329         }
330
331         private TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
332                 final TpId id = buildLocalTpId(base, linkDescriptors);
333                 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
334                                 linkDescriptors.getLinkLocalIdentifier());
335
336                 return buildTp(id, t);
337         }
338
339         private TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
340                 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
341                                 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
342         }
343
344         private TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
345                 final TpId id = buildRemoteTpId(base, linkDescriptors);
346                 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
347                                 linkDescriptors.getLinkRemoteIdentifier());
348
349                 return buildTp(id, t);
350         }
351
352         private InstanceIdentifier<?> buildLinkIdentifier(final UriBuilder base, final LinkId id) {
353                 return getInstanceIdentifier().child(
354                                 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
355                                 new LinkKey(id));
356         }
357
358         private static Float bandwidthToFloat(final Bandwidth bandwidth) {
359                 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
360         }
361
362         private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
363                 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
364         }
365
366         private static List<UnreservedBandwidth> unreservedBandwidthList(
367                         final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth> input) {
368                 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
369
370                 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth i : input) {
371                         ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
372                                         new UnreservedBandwidthKey(i.getPriority())).build());
373                 }
374
375                 return ret;
376         }
377
378         private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
379                         final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
380                 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();
381
382                 if (la != null) {
383                         if (la.getAdminGroup() != null) {
384                                 tb.setColor(la.getAdminGroup().getValue());
385                         }
386                         if (la.getTeMetric() != null) {
387                                 tb.setTeDefaultMetric(la.getTeMetric().getValue());
388                         }
389                         if (la.getUnreservedBandwidth() != null) {
390                                 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
391                         }
392                         if (la.getMaxLinkBandwidth() != null) {
393                                 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
394                         }
395                         if (la.getMaxReservableBandwidth() != null) {
396                                 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
397                         }
398                 }
399
400                 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
401                 ilab.setTed(tb.build());
402                 if (topologyIdentifier != null) {
403                         ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
404                 }
405
406                 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
407                                 ilab.build()).build();
408         }
409
410         private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
411                         final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
412                 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();
413
414                 if (la != null) {
415                         if (la.getAdminGroup() != null) {
416                                 tb.setColor(la.getAdminGroup().getValue());
417                         }
418                         if (la.getTeMetric() != null) {
419                                 tb.setTeDefaultMetric(la.getTeMetric().getValue());
420                         }
421                         if (la.getUnreservedBandwidth() != null) {
422                                 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
423                         }
424                         if (la.getMaxLinkBandwidth() != null) {
425                                 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
426                         }
427                         if (la.getMaxReservableBandwidth() != null) {
428                                 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
429                         }
430                 }
431
432                 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
433                 ilab.setTed(tb.build());
434                 if (topologyIdentifier != null) {
435                         ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
436                 }
437
438                 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
439                                 ilab.build()).build();
440         }
441
442         private NodeHolder getNode(final NodeId id) {
443                 if (this.nodes.containsKey(id)) {
444                         LOG.debug("Node {} is already present", id);
445                         return this.nodes.get(id);
446                 }
447
448                 final NodeHolder ret = new NodeHolder(id);
449                 this.nodes.put(id, ret);
450                 return ret;
451         }
452
453         private void putNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final NodeHolder holder) {
454                 if (holder.syncState(trans)) {
455                         this.nodes.remove(holder.getNodeId());
456                 }
457         }
458
459         private void createLink(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
460                         final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
461                 final LinkAttributes la = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.LinkCase) attributes.getAugmentation(
462                                 Attributes1.class).getAttributeType()).getLinkAttributes();
463
464                 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
465                 if (la != null) {
466                         if (la.getMetric() != null) {
467                                 ilab.setMetric(la.getMetric().getValue());
468                         }
469                         ilab.setName(la.getLinkName());
470                 }
471
472                 switch (value.getProtocolId()) {
473                 case Direct:
474                 case Static:
475                 case Unknown:
476                         break;
477                 case IsisLevel1:
478                 case IsisLevel2:
479                         ilab.addAugmentation(
480                                         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
481                                         isisLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
482                         break;
483                 case Ospf:
484                         ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
485                                         ospfLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
486                         break;
487                 }
488
489                 final LinkBuilder lb = new LinkBuilder();
490                 lb.setLinkId(buildLinkId(base, l));
491                 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
492
493                 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
494                 LOG.debug("Link {} implies source node {}", l, srcNode);
495
496                 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
497                 LOG.debug("Link {} implies destination node {}", l, dstNode);
498
499                 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
500                 LOG.debug("Link {} implies source TP {}", l, srcTp);
501
502                 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
503                 LOG.debug("Link {} implies destination TP {}", l, dstTp);
504
505                 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
506                 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
507
508                 final NodeHolder snh = getNode(srcNode);
509                 snh.addTp(srcTp, lb.getLinkId(), false);
510                 LOG.debug("Created TP {} as link source", srcTp);
511                 putNode(trans, snh);
512
513                 final NodeHolder dnh = getNode(dstNode);
514                 dnh.addTp(dstTp, lb.getLinkId(), true);
515                 LOG.debug("Created TP {} as link destination", dstTp);
516                 putNode(trans, dnh);
517
518                 final InstanceIdentifier<?> lid = buildLinkIdentifier(base, lb.getLinkId());
519                 final Link link = lb.build();
520
521                 /*
522                  * Transaction's putOperationalData() does a merge. Force it onto a replace
523                  * by removing the data.
524                  */
525                 trans.removeOperationalData(lid);
526                 trans.putOperationalData(lid, link);
527                 LOG.debug("Created link {} at {} for {}", link, lid, l);
528         }
529
530         private void removeTp(final DataModification<InstanceIdentifier<?>, DataObject> trans, final NodeId node, final TpId tp,
531                         final LinkId link, final boolean isRemote) {
532                 final NodeHolder nh = this.nodes.get(node);
533                 if (nh != null) {
534                         nh.removeTp(tp, link, isRemote);
535                         putNode(trans, nh);
536                 } else {
537                         LOG.warn("Removed non-existent node {}", node);
538                 }
539         }
540
541         private void removeLink(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final LinkCase l) {
542                 final LinkId id = buildLinkId(base, l);
543                 final InstanceIdentifier<?> lid = buildLinkIdentifier(base, id);
544                 trans.removeOperationalData(lid);
545                 LOG.debug("Removed link {}", lid);
546
547                 removeTp(trans, buildNodeId(base, l.getLocalNodeDescriptors()), buildLocalTpId(base, l.getLinkDescriptors()), id, false);
548                 removeTp(trans, buildNodeId(base, l.getRemoteNodeDescriptors()), buildRemoteTpId(base, l.getLinkDescriptors()), id, true);
549         }
550
551         private List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
552                 final List<Short> ret = new ArrayList<>(list.size());
553                 for (final TopologyIdentifier id : list) {
554                         ret.add(id.getValue().shortValue());
555                 }
556                 return ret;
557         }
558
559         private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
560                         final NodeIdentifier node, final NodeAttributes na) {
561                 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();
562                 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
563
564                 if (na != null) {
565                         if (na.getIpv4RouterId() != null) {
566                                 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
567                         }
568                         if (na.getIpv6RouterId() != null) {
569                                 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
570                         }
571                         if (na.getTopologyIdentifier() != null) {
572                                 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
573                         }
574                 }
575
576                 final CRouterIdentifier ri = node.getCRouterIdentifier();
577                 if (ri instanceof IsisPseudonodeCase) {
578                         final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
579                         ab.setIso(new IsoBuilder().setIsoPseudonodeId(new IsoPseudonodeId(pn.toString())).build());
580                 } else if (ri instanceof IsisNodeCase) {
581                         final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
582                         ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(in.getIsoSystemId().toString())).build());
583                 }
584
585                 ab.setTed(tb.build());
586
587                 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
588                                 ab.build()).build();
589         }
590
591         private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
592                         final NodeDescriptors node, final NodeAttributes na) {
593                 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();
594                 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
595
596                 if (na != null) {
597                         if (na.getIpv4RouterId() != null) {
598                                 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
599                         }
600                         if (na.getIpv6RouterId() != null) {
601                                 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
602                         }
603                         if (na.getTopologyIdentifier() != null) {
604                                 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
605                         }
606                 }
607
608                 final CRouterIdentifier ri = node.getCRouterIdentifier();
609                 if (ri instanceof OspfPseudonodeCase) {
610                         final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
611
612                         ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
613                         ab.setDrInterfaceId(pn.getLanInterface().getValue());
614                 } else if (ri instanceof OspfNodeCase) {
615                         // TODO: what should we do with in.getOspfRouterId()?
616                         // final OspfNode in = ((OspfNodeCase) ri).getOspfNode();
617
618                         if (na != null) {
619                                 final NodeFlagBits nf = na.getNodeFlags();
620                                 if (nf != null) {
621                                         if (nf.isAbr()) {
622                                                 ab.setRouterType(new AbrBuilder().setAbr(Boolean.TRUE).build());
623                                         } else if (!nf.isExternal()) {
624                                                 ab.setRouterType(new InternalBuilder().setInternal(Boolean.TRUE).build());
625                                         }
626                                 }
627                         }
628                 }
629
630                 ab.setTed(tb.build());
631
632                 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
633                                 ab.build()).build();
634         }
635
636         private void createNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
637                         final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
638                 final NodeAttributes na = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.NodeCase) attributes.getAugmentation(
639                                 Attributes1.class).getAttributeType()).getNodeAttributes();
640                 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
641
642                 final List<IpAddress> ids = new ArrayList<>();
643                 if (na != null) {
644                         if (na.getIpv4RouterId() != null) {
645                                 ids.add(new IpAddress(na.getIpv4RouterId()));
646                         }
647                         if (na.getIpv6RouterId() != null) {
648                                 ids.add(new IpAddress(na.getIpv6RouterId()));
649                         }
650                         if (na.getDynamicHostname() != null) {
651                                 inab.setName(new DomainName(na.getDynamicHostname()));
652                         }
653                 }
654
655                 if (!ids.isEmpty()) {
656                         inab.setRouterId(ids);
657                 }
658
659                 switch (value.getProtocolId()) {
660                 case Direct:
661                 case Static:
662                 case Unknown:
663                         break;
664                 case IsisLevel1:
665                 case IsisLevel2:
666                         inab.addAugmentation(
667                                         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
668                                         isisNodeAttributes(n.getNodeDescriptors(), na));
669                         break;
670                 case Ospf:
671                         inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
672                                         ospfNodeAttributes(n.getNodeDescriptors(), na));
673                         break;
674                 }
675
676                 final NodeId nid = buildNodeId(base, n.getNodeDescriptors());
677                 final NodeHolder nh = getNode(nid);
678
679                 /*
680                  *  Eventhough the the holder creates a dummy structure, we need to duplicate it here,
681                  *  as that is the API requirement. The reason for it is the possible presence of supporting
682                  *  node -- something which the holder does not track.
683                  */
684                 final NodeBuilder nb = new NodeBuilder();
685                 nb.setNodeId(nid);
686                 nb.setKey(new NodeKey(nb.getNodeId()));
687
688                 nh.advertized(nb, inab);
689                 putNode(trans, nh);
690         }
691
692         private void removeNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final NodeCase n) {
693                 final NodeId id = buildNodeId(base, n.getNodeDescriptors());
694                 final NodeHolder nh = this.nodes.get(id);
695                 if (nh != null) {
696                         nh.unadvertized();
697                         putNode(trans, nh);
698                 } else {
699                         LOG.warn("Node {} does not have a holder", id);
700                 }
701         }
702
703         private void createPrefix(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
704                         final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
705                 final IpPrefix ippfx = p.getIpReachabilityInformation();
706                 if (ippfx == null) {
707                         LOG.warn("IP reachability not present in prefix {} route {}, skipping it", p, value);
708                         return;
709                 }
710
711                 final PrefixBuilder pb = new PrefixBuilder();
712                 pb.setKey(new PrefixKey(ippfx));
713                 pb.setPrefix(ippfx);
714
715                 final PrefixAttributes pa = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.PrefixCase) attributes.getAugmentation(
716                                 Attributes1.class).getAttributeType()).getPrefixAttributes();
717                 if (pa != null) {
718                         pb.setMetric(pa.getPrefixMetric().getValue());
719                 }
720
721                 switch (value.getProtocolId()) {
722                 case Direct:
723                 case IsisLevel1:
724                 case IsisLevel2:
725                 case Static:
726                 case Unknown:
727                         break;
728                 case Ospf:
729                         if (pa != null) {
730                                 pb.addAugmentation(
731                                                 Prefix1.class,
732                                                 new Prefix1Builder().setOspfPrefixAttributes(
733                                                                 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
734                         }
735                         break;
736                 }
737
738                 final Prefix pfx = pb.build();
739
740                 /*
741                  * All set, but... the hosting node may not exist, we may need to fake it.
742                  */
743                 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
744                 final NodeHolder nh = getNode(node);
745                 nh.addPrefix(pfx);
746                 LOG.debug("Created prefix {} for {}", pfx, p);
747                 putNode(trans, nh);
748         }
749
750         private void removePrefix(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final PrefixCase p) {
751                 final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
752                 final NodeHolder nh = this.nodes.get(node);
753                 if (nh != null) {
754                         nh.removePrefix(p);
755                         LOG.debug("Removed prefix {}", p);
756                         putNode(trans, nh);
757                 } else {
758                         LOG.warn("Removing prefix from non-existing node {}", node);
759                 }
760         }
761
762         @Override
763         protected void createObject(final DataModification<InstanceIdentifier<?>, DataObject> trans,
764                         final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
765                 final UriBuilder base = new UriBuilder(value);
766
767                 final ObjectType t = value.getObjectType();
768                 if (t instanceof LinkCase) {
769                         createLink(trans, base, value, (LinkCase) t, value.getAttributes());
770                 } else if (t instanceof NodeCase) {
771                         createNode(trans, base, value, (NodeCase) t, value.getAttributes());
772                 } else if (t instanceof PrefixCase) {
773                         createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
774                 } else {
775                         throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());
776                 }
777         }
778
779         @Override
780         protected void removeObject(final DataModification<InstanceIdentifier<?>, DataObject> trans,
781                         final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
782                 final UriBuilder base = new UriBuilder(value);
783
784                 final ObjectType t = value.getObjectType();
785                 if (t instanceof LinkCase) {
786                         removeLink(trans, base, (LinkCase) t);
787                 } else if (t instanceof NodeCase) {
788                         removeNode(trans, base, (NodeCase) t);
789                 } else if (t instanceof PrefixCase) {
790                         removePrefix(trans, base, (PrefixCase) t);
791                 } else {
792                         throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());
793                 }
794         }
795 }