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