Bug 6568 - Termination Point Type is never set in BGP-LS topology
[bgpcep.git] / bgp / topology-provider / src / main / java / org / opendaylight / bgpcep / bgp / topology / provider / LinkstateTopologyBuilder.java
index 9dfb6715aef966b4dcfcc15ae6bb41269b59c29d..05b727481a917a028d25c0bb2b6a6dc032fa3910 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.bgpcep.bgp.topology.provider;
 
-import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
+import com.google.common.io.BaseEncoding;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -24,41 +24,56 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.protocol.bgp.rib.RibReference;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.DomainName;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeFlagBits;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.LinkstateRoute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.AttributeType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.link._case.LinkAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.node._case.NodeAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.prefix._case.PrefixAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.LinkCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.NodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.link._case.LinkDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.node._case.NodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.CRouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.IsisAreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeFlagBits;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoNetId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValues;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.srlg.attributes.SrlgValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.SrlgBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
@@ -74,6 +89,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
@@ -84,9 +100,8 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1Builder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
 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;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder;
@@ -107,7 +122,15 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
+public class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
+    public static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder()
+    .addAugmentation(TopologyTypes1.class,
+            new TopologyTypes1Builder()
+    .setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build())
+    .build();
+
+    private static final String UNHANDLED_OBJECT_CLASS = "Unhandled object class {}";
+
     private static final class TpHolder {
         private final Set<LinkId> local = new HashSet<>();
         private final Set<LinkId> remote = new HashSet<>();
@@ -164,9 +187,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
          * @return True if the node has been purged, false otherwise.
          */
         private boolean syncState(final WriteTransaction trans) {
-            final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
-                org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
-                this.nb.getKey());
+            final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
 
             /*
              * Transaction's putOperationalData() does a merge. Force it onto a replace
@@ -184,12 +205,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
             }
 
             // Re-generate termination points
-            this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), new Function<TpHolder, TerminationPoint>() {
-                @Override
-                public TerminationPoint apply(final TpHolder input) {
-                    return input.getTp();
-                }
-            })));
+            this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), input -> input.getTp())));
 
             // Re-generate prefixes
             this.inab.setPrefix(Lists.newArrayList(this.prefixes.values()));
@@ -201,6 +217,21 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
             return false;
         }
 
+        private boolean checkForRemoval(final WriteTransaction trans) {
+            final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey());
+
+                if (!this.advertized) {
+                    if (this.tps.isEmpty() && this.prefixes.isEmpty()) {
+                        trans.delete(LogicalDatastoreType.OPERATIONAL, nid);
+                        LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId());
+                        return true;
+                    }
+
+                    LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size());
+                }
+                return false;
+        }
+
         private synchronized void removeTp(final TpId tp, final LinkId link, final boolean isRemote) {
             final TpHolder h = this.tps.get(tp);
             if (h != null) {
@@ -228,7 +259,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         }
 
         private void removePrefix(final PrefixCase p) {
-            this.prefixes.remove(new PrefixKey(p.getIpReachabilityInformation()));
+            this.prefixes.remove(new PrefixKey(p.getPrefixDescriptors().getIpReachabilityInformation()));
         }
 
         private void unadvertized() {
@@ -254,20 +285,26 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
     private final Map<NodeId, NodeHolder> nodes = new HashMap<>();
 
     public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
-        super(dataProvider, locRibReference, topologyId, new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class,
-            new TopologyTypes1Builder().build()).build(), LinkstateRoute.class);
+        super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
     }
 
-    private LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
+    public LinkstateTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
+            final TopologyId topologyId, final long listenerResetLimitInMillsec, final int listenerResetEnforceCounter) {
+        super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
+            listenerResetLimitInMillsec, listenerResetEnforceCounter);
+    }
+
+    private static LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
         return new LinkId(new UriBuilder(base, "link").add(link).toString());
     }
 
-    private NodeId buildNodeId(final UriBuilder base, final NodeIdentifier node) {
+    private static NodeId buildNodeId(final UriBuilder base,
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier node) {
         return new NodeId(new UriBuilder(base, "node").add("", node).toString());
     }
 
-    private TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
-        final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
+    private static TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
+            final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
         final UriBuilder b = new UriBuilder(base, "tp");
         if (topologyIdentifier != null) {
             b.add("mt", topologyIdentifier.getValue());
@@ -282,26 +319,26 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         return new TpId(b.add("id", id).toString());
     }
 
-    private TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
+    private static TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
         return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
-            linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
+                linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
     }
 
-    private TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
+    private static TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
         final TerminationPointBuilder stpb = new TerminationPointBuilder();
         stpb.setKey(new TerminationPointKey(id));
         stpb.setTpId(id);
 
         if (type != null) {
             stpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes(
-                new IgpTerminationPointAttributesBuilder().setTerminationPointType(null).build()).build());
+                    new IgpTerminationPointAttributesBuilder().setTerminationPointType(type).build()).build());
         }
 
         return stpb.build();
     }
 
-    private TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
-        final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
+    private static TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
+            final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
         // Order of preference: Unnumbered first, then IP
         if (id != null) {
             LOG.debug("Unnumbered termination point type: {}", id);
@@ -325,31 +362,31 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         return null;
     }
 
-    private TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
+    private static TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
         final TpId id = buildLocalTpId(base, linkDescriptors);
         final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
-            linkDescriptors.getLinkLocalIdentifier());
+                linkDescriptors.getLinkLocalIdentifier());
 
         return buildTp(id, t);
     }
 
-    private TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
+    private static TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
         return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
-            linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
+                linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
     }
 
-    private TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
+    private static TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
         final TpId id = buildRemoteTpId(base, linkDescriptors);
         final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
-            linkDescriptors.getLinkRemoteIdentifier());
+                linkDescriptors.getLinkRemoteIdentifier());
 
         return buildTp(id, t);
     }
 
     private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
         return getInstanceIdentifier().child(
-            org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
-            new LinkKey(id));
+                org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
+                new LinkKey(id));
     }
 
     private static Float bandwidthToFloat(final Bandwidth bandwidth) {
@@ -361,19 +398,19 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
     }
 
     private static List<UnreservedBandwidth> unreservedBandwidthList(
-        final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth> input) {
+            final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth> input) {
         final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
 
-        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth i : input) {
+        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.UnreservedBandwidth i : input) {
             ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
-                new UnreservedBandwidthKey(i.getPriority())).build());
+                    new UnreservedBandwidthKey(i.getPriority())).build());
         }
 
         return ret;
     }
 
-    private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
-        final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
+    private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
+            final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
         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();
 
         if (la != null) {
@@ -392,6 +429,13 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
             if (la.getMaxReservableBandwidth() != null) {
                 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
             }
+            if (la.getSharedRiskLinkGroups() != null) {
+                final List<SrlgValues> srlgs = new ArrayList<>();
+                for (final SrlgId id : la.getSharedRiskLinkGroups()) {
+                    srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
+                }
+                tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
+            }
         }
 
         final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
@@ -401,11 +445,11 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         }
 
         return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
-            ilab.build()).build();
+                ilab.build()).build();
     }
 
-    private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
-        final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
+    private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
+            final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
         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();
 
         if (la != null) {
@@ -424,6 +468,13 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
             if (la.getMaxReservableBandwidth() != null) {
                 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
             }
+            if (la.getSharedRiskLinkGroups() != null) {
+                final List<SrlgValues> srlgs = new ArrayList<>();
+                for (final SrlgId id : la.getSharedRiskLinkGroups()) {
+                    srlgs.add(new SrlgValuesBuilder().setSrlgValue(id.getValue()).build());
+                }
+                tb.setSrlg(new SrlgBuilder().setSrlgValues(srlgs).build());
+            }
         }
 
         final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
@@ -433,7 +484,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         }
 
         return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
-            ilab.build()).build();
+                ilab.build()).build();
     }
 
     private NodeHolder getNode(final NodeId id) {
@@ -453,16 +504,42 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         }
     }
 
+    private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) {
+        if (holder.checkForRemoval(trans)) {
+            this.nodes.remove(holder.getNodeId());
+        }
+    }
+
+    private static void augmentProtocolId(final LinkstateRoute value, final IgpLinkAttributesBuilder ilab,
+            final LinkAttributes la, final LinkDescriptors ld) {
+        switch (value.getProtocolId()) {
+        case Direct:
+        case Static:
+        case IsisLevel1:
+        case IsisLevel2:
+            ilab.addAugmentation(
+                    org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
+                    isisLinkAttributes(ld.getMultiTopologyId(), la));
+            break;
+        case OspfV3:
+        case Ospf:
+            ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
+                    ospfLinkAttributes(ld.getMultiTopologyId(), la));
+            break;
+        default:
+            break;
+        }
+    }
+
     private void createLink(final WriteTransaction trans, final UriBuilder base,
-        final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
+            final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
         // defensive lookup
         final LinkAttributes la;
         final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
         if (attr != null) {
-            final AttributeType attrType = attr.getAttributeType();
+            final LinkStateAttribute attrType = attr.getLinkStateAttribute();
             if (attrType != null) {
-                la = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.LinkCase)
-                    attrType).getLinkAttributes();
+                la = ((LinkAttributesCase)attrType).getLinkAttributes();
             } else {
                 LOG.debug("Missing attribute type in link {} route {}, skipping it", l, value);
                 la = null;
@@ -479,27 +556,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
             }
             ilab.setName(la.getLinkName());
         }
-
-        switch (value.getProtocolId()) {
-        case Direct:
-        case Static:
-        case Unknown:
-            break;
-        case IsisLevel1:
-        case IsisLevel2:
-            ilab.addAugmentation(
-                org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
-                isisLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
-            break;
-        case Ospf:
-            ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
-                ospfLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
-            break;
-        default:
-            break;
-        default:
-            break;
-        }
+        augmentProtocolId(value, ilab, la, l.getLinkDescriptors());
 
         final LinkBuilder lb = new LinkBuilder();
         lb.setLinkId(buildLinkId(base, l));
@@ -520,15 +577,31 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
         lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
 
-        final NodeHolder snh = getNode(srcNode);
-        snh.addTp(srcTp, lb.getLinkId(), false);
         LOG.debug("Created TP {} as link source", srcTp);
-        putNode(trans, snh);
+        NodeHolder snh = this.nodes.get(srcNode);
+        if (snh == null) {
+            snh = getNode(srcNode);
+            snh.addTp(srcTp, lb.getLinkId(), false);
+            putNode(trans, snh);
+        } else {
+            snh.addTp(srcTp, lb.getLinkId(), false);
+            final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) snh.getNodeId()));
+            trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
+        }
 
-        final NodeHolder dnh = getNode(dstNode);
-        dnh.addTp(dstTp, lb.getLinkId(), true);
         LOG.debug("Created TP {} as link destination", dstTp);
-        putNode(trans, dnh);
+        NodeHolder dnh = this.nodes.get(dstNode);
+        if (dnh == null) {
+            dnh = getNode(dstNode);
+            dnh.addTp(dstTp, lb.getLinkId(), true);
+            putNode(trans, dnh);
+        } else {
+            dnh.addTp(dstTp, lb.getLinkId(), true);
+            final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(
+                    org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
+                    new NodeKey((NodeId) dnh.getNodeId()));
+            trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
+        }
 
         final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
         final Link link = lb.build();
@@ -538,11 +611,13 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
     }
 
     private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
-        final LinkId link, final boolean isRemote) {
+            final LinkId link, final boolean isRemote) {
         final NodeHolder nh = this.nodes.get(node);
         if (nh != null) {
+            final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
+            trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp)));
             nh.removeTp(tp, link, isRemote);
-            putNode(trans, nh);
+            checkNodeForRemoval(trans, nh);
         } else {
             LOG.warn("Removed non-existent node {}", node);
         }
@@ -558,7 +633,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         removeTp(trans, buildNodeId(base, l.getRemoteNodeDescriptors()), buildRemoteTpId(base, l.getLinkDescriptors()), id, true);
     }
 
-    private List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
+    private static List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
         final List<Short> ret = new ArrayList<>(list.size());
         for (final TopologyIdentifier id : list) {
             ret.add(id.getValue().shortValue());
@@ -566,8 +641,8 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         return ret;
     }
 
-    private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
-        final NodeIdentifier node, final NodeAttributes na) {
+    private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
+            final NodeIdentifier node, final NodeAttributes na) {
         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();
         final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
 
@@ -586,20 +661,35 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         final CRouterIdentifier ri = node.getCRouterIdentifier();
         if (ri instanceof IsisPseudonodeCase) {
             final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
-            ab.setIso(new IsoBuilder().setIsoPseudonodeId(new IsoPseudonodeId(pn.toString())).build());
+            final IsoBuilder b = new IsoBuilder();
+            final String systemId = UriBuilder.isoId(pn.getIsIsRouterIdentifier().getIsoSystemId());
+            b.setIsoSystemId(new IsoSystemId(systemId));
+            b.setIsoPseudonodeId(new IsoPseudonodeId(BaseEncoding.base16().encode(new byte[] {pn.getPsn().byteValue()})));
+            ab.setIso(b.build());
+            if (na != null) {
+                ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
+            }
         } else if (ri instanceof IsisNodeCase) {
             final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
-            ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(in.getIsoSystemId().toString())).build());
+            final String systemId = UriBuilder.isoId(in.getIsoSystemId());
+            ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(systemId)).build());
+            if (na != null) {
+                ab.setNet(toIsoNetIds(na.getIsisAreaId(), systemId));
+            }
         }
 
         ab.setTed(tb.build());
 
         return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
-            ab.build()).build();
+                ab.build()).build();
+    }
+
+    private static List<IsoNetId> toIsoNetIds(final List<IsisAreaIdentifier> areaIds, final String systemId) {
+        return Lists.transform(areaIds, input -> new IsoNetId(UriBuilder.toIsoNetId(input, systemId)));
     }
 
-    private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
-        final NodeDescriptors node, final NodeAttributes na) {
+    private static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
+            final NodeIdentifier node, final NodeAttributes na) {
         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();
         final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
         if (na != null) {
@@ -631,24 +721,23 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         }
         ab.setTed(tb.build());
         return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
-            ab.build()).build();
+                ab.build()).build();
     }
 
-    private void augmentProtocolId(final LinkstateRoute value, final IgpNodeAttributesBuilder inab, final NodeAttributes na, final NodeDescriptors nd) {
+    private static void augmentProtocolId(final LinkstateRoute value, final IgpNodeAttributesBuilder inab,
+            final NodeAttributes na, final NodeIdentifier nd) {
         switch (value.getProtocolId()) {
         case Direct:
         case Static:
-        case Unknown:
-            break;
         case IsisLevel1:
         case IsisLevel2:
             inab.addAugmentation(
-                org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
-                isisNodeAttributes(nd, na));
+                    org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
+                    isisNodeAttributes(nd, na));
             break;
         case Ospf:
             inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
-                ospfNodeAttributes(nd, na));
+                    ospfNodeAttributes(nd, na));
             break;
         default:
             break;
@@ -656,15 +745,14 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
     }
 
     private void createNode(final WriteTransaction trans, final UriBuilder base,
-        final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
+            final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
         final NodeAttributes na;
         //defensive lookup
         final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
         if (attr != null) {
-            final AttributeType attrType = attr.getAttributeType();
+            final LinkStateAttribute attrType = attr.getLinkStateAttribute();
             if (attrType != null) {
-                na = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.NodeCase)
-                    attrType).getNodeAttributes();
+                na = ((NodeAttributesCase)attrType).getNodeAttributes();
             } else {
                 LOG.debug("Missing attribute type in node {} route {}, skipping it", n, value);
                 na = null;
@@ -717,20 +805,18 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         }
     }
 
-    private void augmentProtocolId(final LinkstateRoute value, final PrefixAttributes pa, final PrefixBuilder pb) {
+    private static void augmentProtocolId(final LinkstateRoute value, final PrefixAttributes pa, final PrefixBuilder pb) {
         switch (value.getProtocolId()) {
         case Direct:
         case IsisLevel1:
         case IsisLevel2:
         case Static:
-        case Unknown:
-            break;
         case Ospf:
             if (pa != null && pa.getOspfForwardingAddress() != null) {
                 pb.addAugmentation(
-                    Prefix1.class,
-                    new Prefix1Builder().setOspfPrefixAttributes(
-                        new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
+                        Prefix1.class,
+                        new Prefix1Builder().setOspfPrefixAttributes(
+                                new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress().getIpv4Address()).build()).build());
             }
             break;
         default:
@@ -739,24 +825,24 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
     }
 
     private void createPrefix(final WriteTransaction trans, final UriBuilder base,
-        final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
-        final IpPrefix ippfx = p.getIpReachabilityInformation();
+            final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
+        final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
         if (ippfx == null) {
             LOG.warn("IP reachability not present in prefix {} route {}, skipping it", p, value);
             return;
         }
         final PrefixBuilder pb = new PrefixBuilder();
-        pb.setKey(new PrefixKey(ippfx));
+        final PrefixKey pk = new PrefixKey(ippfx);
+        pb.setKey(pk);
         pb.setPrefix(ippfx);
 
         final PrefixAttributes pa;
         // Very defensive lookup
         final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
         if (attr != null) {
-            final AttributeType attrType = attr.getAttributeType();
+            final LinkStateAttribute attrType = attr.getLinkStateAttribute();
             if (attrType != null) {
-                pa = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.PrefixCase)
-                    attrType).getPrefixAttributes();
+                pa = ((PrefixAttributesCase)attrType).getPrefixAttributes();
             } else {
                 LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, p, value);
                 pa = null;
@@ -771,32 +857,55 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         augmentProtocolId(value, pa, pb);
 
         final Prefix pfx = pb.build();
+        LOG.debug("Created prefix {} for {}", pfx, p);
 
         /*
          * All set, but... the hosting node may not exist, we may need to fake it.
          */
         final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
-        final NodeHolder nh = getNode(node);
-        nh.addPrefix(pfx);
-        LOG.debug("Created prefix {} for {}", pfx, p);
-        putNode(trans, nh);
+        NodeHolder nh = this.nodes.get(node);
+        if (nh == null) {
+            nh = getNode(node);
+            nh.addPrefix(pfx);
+            putNode(trans, nh);
+        } else {
+            nh.addPrefix(pfx);
+            final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
+            final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
+            trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
+        }
     }
 
     private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase p) {
         final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors());
         final NodeHolder nh = this.nodes.get(node);
         if (nh != null) {
-            nh.removePrefix(p);
             LOG.debug("Removed prefix {}", p);
-            putNode(trans, nh);
+            final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId()));
+            final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
+            final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation();
+            if (ippfx == null) {
+                LOG.warn("IP reachability not present in prefix {}, skipping it", p);
+                return;
+            }
+            final PrefixKey pk = new PrefixKey(ippfx);
+            trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
+            nh.removePrefix(p);
+            checkNodeForRemoval(trans, nh);
         } else {
             LOG.warn("Removing prefix from non-existing node {}", node);
         }
     }
 
+    private InstanceIdentifier<Node> getNodeInstanceIdentifier(final NodeKey nodeKey) {
+        return getInstanceIdentifier().child(
+                org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
+                nodeKey);
+    }
+
     @Override
     protected void createObject(final ReadWriteTransaction trans,
-        final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
+            final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
         final UriBuilder base = new UriBuilder(value);
 
         final ObjectType t = value.getObjectType();
@@ -809,13 +918,13 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         } else if (t instanceof PrefixCase) {
             createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
         } else {
-            throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());
+            LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
         }
     }
 
     @Override
     protected void removeObject(final ReadWriteTransaction trans,
-        final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
+            final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
         final UriBuilder base = new UriBuilder(value);
 
         final ObjectType t = value.getObjectType();
@@ -826,7 +935,13 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         } else if (t instanceof PrefixCase) {
             removePrefix(trans, base, (PrefixCase) t);
         } else {
-            throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());
+            LOG.debug(UNHANDLED_OBJECT_CLASS, t.getImplementedInterface());
         }
     }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
+    protected InstanceIdentifier<LinkstateRoute> getRouteWildcard(final InstanceIdentifier<Tables> tablesId) {
+        return tablesId.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class);
+    }
 }