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