Update node-tp and link states on topologies
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / service / NetworkModelServiceImpl.java
index cc9aaf72c193c5f04293bb8ba85a970d0cdf7bae..66e5460d1936f8150104e17c68b8ae29da813212 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.transportpce.networkmodel.service;
 
 import com.google.common.util.concurrent.ListenableFuture;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -19,7 +18,9 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.transportpce.common.InstanceIdentifiers;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
@@ -30,12 +31,14 @@ import org.opendaylight.transportpce.networkmodel.util.LinkIdUtil;
 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmNetwork;
 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmOtnTopology;
 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmTopology;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.NodeInfo;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.NodeInfo.OpenroadmVersion;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.NodeTypes;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Link1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.TerminationPoint1;
-import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.OtnLinkType;
+import org.opendaylight.transportpce.networkmodel.util.TopologyUtils;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.OpenroadmNodeVersion;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.nodes.NodeInfo;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Link1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.TerminationPoint1;
+import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.OtnLinkType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
@@ -51,17 +54,16 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.top
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.termination.point.SupportingTerminationPoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public class NetworkModelServiceImpl implements NetworkModelService {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetworkModelServiceImpl.class);
-    private static final boolean CREATE_MISSING_PARENTS = true;
 
     private NetworkTransactionService networkTransactionService;
     private final R2RLinkDiscovery linkDiscovery;
@@ -70,7 +72,8 @@ public class NetworkModelServiceImpl implements NetworkModelService {
     private Map<String, TopologyShard> otnTopologyShardMountedDevice;
 
     public NetworkModelServiceImpl(final NetworkTransactionService networkTransactionService,
-        final R2RLinkDiscovery linkDiscovery, PortMapping portMapping) {
+            final R2RLinkDiscovery linkDiscovery, PortMapping portMapping,
+            final NotificationPublishService notificationPublishService) {
 
         this.networkTransactionService = networkTransactionService;
         this.linkDiscovery = linkDiscovery;
@@ -96,9 +99,6 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                 return;
             }
             NodeInfo nodeInfo = portMapping.getNode(nodeId).getNodeInfo();
-            if (nodeInfo.getNodeType().getIntValue() == 1) {
-                this.linkDiscovery.readLLDP(new NodeId(nodeId), openRoadmVersion);
-            }
             // node creation in clli-network
             Node clliNode = ClliNetwork.createNode(nodeId, nodeInfo);
             InstanceIdentifier<Node> iiClliNode = InstanceIdentifier.builder(Networks.class)
@@ -106,8 +106,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                 .child(Node.class, clliNode.key())
                 .build();
             LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
-            networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode,
-                CREATE_MISSING_PARENTS);
+            networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode);
 
             // node creation in openroadm-network
             Node openroadmNetworkNode = OpenRoadmNetwork.createNode(nodeId, nodeInfo);
@@ -117,7 +116,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                 .build();
             LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
             networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode,
-                openroadmNetworkNode, CREATE_MISSING_PARENTS);
+                openroadmNetworkNode);
 
             // nodes/links creation in openroadm-topology
             TopologyShard topologyShard = OpenRoadmTopology.createTopologyShard(portMapping.getNode(nodeId));
@@ -131,7 +130,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                         .child(Node.class, openRoadmTopologyNode.key())
                         .build();
                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
-                        openRoadmTopologyNode, CREATE_MISSING_PARENTS);
+                        openRoadmTopologyNode);
                 }
                 for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
                     LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
@@ -142,17 +141,20 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                         .child(Link.class, openRoadmTopologyLink.key())
                         .build();
                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
-                        openRoadmTopologyLink, CREATE_MISSING_PARENTS);
+                        openRoadmTopologyLink);
                 }
             } else {
                 LOG.error("Unable to create openroadm-topology shard for node {}!", nodeId);
             }
-
             // nodes/links creation in otn-topology
             if (nodeInfo.getNodeType().getIntValue() == 2 && (nodeInfo.getOpenroadmVersion().getIntValue() != 1)) {
                 createOpenRoadmOtnNode(nodeId);
             }
             networkTransactionService.commit().get();
+            // neighbour links through LLDP
+            if (nodeInfo.getNodeType().getIntValue() == 1) {
+                this.linkDiscovery.readLLDP(new NodeId(nodeId), openRoadmVersion);
+            }
             LOG.info("all nodes and links created");
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("ERROR: ", e);
@@ -211,13 +213,13 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                 LOG.warn("TopologyShard for node '{}' is not present", nodeId);
             }
             @Nullable
-            OpenroadmVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
+            OpenroadmNodeVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
             @Nullable
             NodeTypes nodeType = this.portMapping.getNode(nodeId).getNodeInfo().getNodeType();
             if (nodeType.getIntValue() == 2 && deviceVersion.getIntValue() != 1) {
                 TopologyShard otnTopologyShard = this.otnTopologyShardMountedDevice.get(nodeId);
-                LOG.info("suppression de otnTopologyShard = {}", otnTopologyShard.toString());
                 if (otnTopologyShard != null) {
+                    LOG.info("suppression de otnTopologyShard = {}", otnTopologyShard.toString());
                     for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
                         LOG.info("deleting node {} in {}", otnTopologyNode.getNodeId().getValue(),
                             NetworkUtils.OTN_NETWORK_ID);
@@ -250,6 +252,101 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         }
     }
 
+    @Override
+    public void updateOpenRoadmTopologies(String nodeId, Mapping mapping) {
+        LOG.info("update OpenRoadm topologies after change update from: {} ", nodeId);
+        Network openroadmTopology = null;
+        Network otnTopology = null;
+        Map<LinkKey, Link> openroadmTopologyLinks = null;
+        Map<LinkKey, Link> otnTopologyLinks = null;
+        try {
+            openroadmTopology = this.networkTransactionService
+                .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OVERLAY_NETWORK_II)
+                .get().get();
+            if (openroadmTopology.augmentation(Network1.class) != null) {
+                openroadmTopologyLinks = openroadmTopology.augmentation(Network1.class).getLink();
+            }
+            otnTopology = this.networkTransactionService
+                .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OTN_NETWORK_II)
+                .get().get();
+            if (otnTopology.augmentation(Network1.class) != null) {
+                otnTopologyLinks = otnTopology.augmentation(Network1.class).getLink();
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error when trying to update node : {}", nodeId, e);
+        }
+        if (openroadmTopology == null || otnTopology == null) {
+            LOG.warn("Error getting topologies from datastore");
+            return;
+        }
+        String abstractNodeid = String.join("-", nodeId, mapping.getLogicalConnectionPoint().split("-")[0]);
+        // nodes/links update in openroadm-topology
+        if (openroadmTopology.getNode() != null) {
+            TopologyShard topologyShard = TopologyUtils.updateTopologyShard(abstractNodeid, mapping,
+                openroadmTopology.getNode(), openroadmTopologyLinks);
+            if (topologyShard.getLinks() != null) {
+                for (Link link : topologyShard.getLinks()) {
+                    LOG.info("updating links {} in {}", link.getLinkId().getValue(),
+                        NetworkUtils.OVERLAY_NETWORK_ID);
+                    InstanceIdentifier<Link> iiTopologyLink = InstanceIdentifier.builder(Networks.class)
+                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                        .augmentation(Network1.class)
+                        .child(Link.class, link.key())
+                        .build();
+                    networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
+                }
+            }
+            if (topologyShard.getTps() != null) {
+                for (TerminationPoint tp : topologyShard.getTps()) {
+                    LOG.info("updating TP {} in openroadm-topology", tp.getTpId().getValue());
+                    InstanceIdentifier<TerminationPoint> iiTopologyTp = InstanceIdentifier.builder(Networks.class)
+                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                        .child(Node.class, new NodeKey(new NodeId(abstractNodeid)))
+                        .augmentation(Node1.class)
+                        .child(TerminationPoint.class, new TerminationPointKey(tp.getTpId()))
+                        .build();
+                    networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyTp, tp);
+                }
+            }
+        }
+        // nodes/links update in otn-topology
+        if (otnTopology.getNode() != null
+            && otnTopology.getNode().containsKey(new NodeKey(new NodeId(abstractNodeid)))) {
+            TopologyShard otnShard = TopologyUtils.updateTopologyShard(abstractNodeid, mapping,
+                otnTopology.getNode(), otnTopologyLinks);
+            if (otnShard.getLinks() != null) {
+                for (Link link : otnShard.getLinks()) {
+                    LOG.info("updating links {} in {}", link.getLinkId().getValue(),
+                        NetworkUtils.OVERLAY_NETWORK_ID);
+                    InstanceIdentifier<Link> iiTopologyLink = InstanceIdentifier.builder(Networks.class)
+                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+                        .augmentation(Network1.class)
+                        .child(Link.class, link.key())
+                        .build();
+                    networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
+                }
+            }
+            if (otnShard.getTps() != null) {
+                for (TerminationPoint tp : otnShard.getTps()) {
+                    LOG.info("updating TP {} in otn-topology", tp.getTpId().getValue());
+                    InstanceIdentifier<TerminationPoint> iiTopologyTp = InstanceIdentifier.builder(Networks.class)
+                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+                        .child(Node.class, new NodeKey(new NodeId(abstractNodeid)))
+                        .augmentation(Node1.class)
+                        .child(TerminationPoint.class, new TerminationPointKey(tp.getTpId()))
+                        .build();
+                    networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyTp, tp);
+                }
+            }
+        }
+        // commit datastore updates
+        try {
+            networkTransactionService.commit().get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error updating openroadm-topology", e);
+        }
+    }
+
     @Override
     public void createOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ, OtnLinkType linkType) {
         TopologyShard otnTopologyShard;
@@ -281,16 +378,17 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, otnTopologyLink.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink,
-                    otnTopologyLink, CREATE_MISSING_PARENTS);
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
             }
         }
         if (otnTopologyShard.getTps() != null) {
             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+                List<SupportingTerminationPoint> supportingTerminationPoint =
+                    new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                    .child(Node.class, new NodeKey(otnTopologyTp.getSupportingTerminationPoint().get(0).getNodeRef()))
+                    .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
                     .augmentation(Node1.class)
                     .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
                     .build();
@@ -354,16 +452,17 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, otnTopologyLink.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink,
-                    CREATE_MISSING_PARENTS);
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
             }
         }
         if (otnTopologyShard.getTps() != null) {
             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+                List<SupportingTerminationPoint> supportingTerminationPoint =
+                    new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                    .child(Node.class, new NodeKey(otnTopologyTp.getSupportingTerminationPoint().get(0).getNodeRef()))
+                    .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
                     .augmentation(Node1.class)
                     .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
                     .build();
@@ -380,7 +479,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
 
     @Override
     public void updateOtnLinks(List<String> nodeTps, String serviceRate, Short tribPortNb, Short tribSoltNb,
-        boolean isDeletion) {
+            boolean isDeletion) {
         List<Link> supportedOdu4Links = getSupportingOdu4Links(nodeTps);
         List<TerminationPoint> tps = getOtnNodeTps(nodeTps);
         TopologyShard otnTopologyShard;
@@ -395,19 +494,20 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, new LinkKey(new LinkId(otnTopologyLink.getLinkId().getValue())))
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink,
-                    otnTopologyLink, CREATE_MISSING_PARENTS);
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
             }
         }
         if (otnTopologyShard.getTps() != null) {
             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+                List<SupportingTerminationPoint> supportingTerminationPoint =
+                    new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                    .child(Node.class, new NodeKey(otnTopologyTp.getSupportingTerminationPoint().get(0).getNodeRef()))
+                    .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
                     .augmentation(Node1.class)
-                    .child(TerminationPoint.class, new TerminationPointKey(
-                        new TpId(otnTopologyTp.getTpId().getValue())))
+                    .child(TerminationPoint.class, new TerminationPointKey(new TpId(otnTopologyTp.getTpId()
+                        .getValue())))
                     .build();
                 if (isDeletion) {
                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
@@ -449,35 +549,30 @@ public class NetworkModelServiceImpl implements NetworkModelService {
     }
 
     private boolean checkLinks(List<Link> links) {
-        boolean canBeDeleted = true;
         if (links.isEmpty()) {
             return false;
-        } else {
-            for (Link link : links) {
-                if (link.augmentation(Link1.class) != null
+        }
+        for (Link link : links) {
+            if (link.augmentation(Link1.class) != null
                     && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
-                    canBeDeleted = false;
-                }
+                return false;
             }
         }
-        return canBeDeleted;
+        return true;
     }
 
     private boolean checkTerminationPoints(List<TerminationPoint> tps) {
-        boolean canBeDeleted = true;
         if (tps.isEmpty()) {
             return false;
-        } else {
-            for (TerminationPoint tp : tps) {
-                if (tp.augmentation(TerminationPoint1.class) != null
-                    && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool() != null
-                    && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool()
-                    .size() != 80) {
-                    canBeDeleted = false;
-                }
+        }
+        for (TerminationPoint tp : tps) {
+            if (tp.augmentation(TerminationPoint1.class) != null && tp.augmentation(TerminationPoint1.class)
+                    .getXpdrTpPortConnectionAttributes().getTsPool() != null && tp.augmentation(TerminationPoint1.class)
+                    .getXpdrTpPortConnectionAttributes().getTsPool().size() != 80) {
+                return false;
             }
         }
-        return canBeDeleted;
+        return true;
     }
 
     private List<TerminationPoint> getOtnNodeTps(String nodeTopoA, String tpA, String nodeTopoZ, String tpZ) {
@@ -498,7 +593,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         Optional<TerminationPoint> tpZOpt = Optional.empty();
 
         if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
-            && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
+                && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
             try {
                 tpAOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).get();
                 tpZOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).get();
@@ -586,7 +681,10 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         }
         List<Link> odu4links = null;
         if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
-            odu4links = netw1Opt.get().getLink().stream().filter(lk -> lk.getLinkId().getValue().startsWith("ODU4"))
+            odu4links = netw1Opt
+                .get()
+                .nonnullLink().values()
+                .stream().filter(lk -> lk.getLinkId().getValue().startsWith("ODU4"))
                 .collect(Collectors.toList());
         }
         List<Link> links = new ArrayList<>();
@@ -597,14 +695,12 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     String nodeId = nodeAndTp[0];
                     String tp = nodeAndTp[1];
                     Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
-                        .equals(nodeId) && lk.getSource().getSourceTp().toString().equals(tp))
-                        .findFirst().get();
+                        .equals(nodeId) && lk.getSource().getSourceTp().toString().equals(tp)).findFirst().get();
                     if (!links.contains(slink)) {
                         links.add(slink);
                     }
                     Link dlink = odu4links.stream().filter(lk -> lk.getDestination().getDestNode().getValue()
-                        .equals(nodeId) && lk.getDestination().getDestTp().toString().equals(tp))
-                        .findFirst().get();
+                        .equals(nodeId) && lk.getDestination().getDestTp().toString().equals(tp)).findFirst().get();
                     if (!links.contains(dlink)) {
                         links.add(dlink);
                     }
@@ -628,8 +724,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
                     .child(Node.class, otnTopologyNode.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode,
-                    otnTopologyNode);
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
             }
             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
                 LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
@@ -639,12 +734,10 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, otnTopologyLink.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink,
-                    otnTopologyLink, CREATE_MISSING_PARENTS);
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
             }
         } else {
             LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
         }
-
     }
 }