Update openroadm-topology layer based on NETCONF event 33/93833/24
authorErrea Moreno, Javier <javier.errea_moreno@nokia.com>
Fri, 13 Nov 2020 16:51:15 +0000 (17:51 +0100)
committerJavier <errea@eurecom.fr>
Wed, 20 Jan 2021 16:01:41 +0000 (17:01 +0100)
- UpdateOpenRoadmNetworkTopology in NetworkModelServiceImpl.java
- Added getTpofNode function to OrdLink.java to add state to R2R links
- Added call to the update function in DeviceListener.java
- Fix relation chain issues

JIRA: TRNSPRTPCE-358
Change-Id: I36558408c21fd7f598711eeb8acaab28c8f5c58a
Signed-off-by: Javier <errea@eurecom.fr>
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/OrdLink.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/listeners/DeviceListener.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelService.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java

index e2bf2da7865756ee23c6626ff03e0712ad07002c..b2c5001d4aa484983a4a9f58c36fe63f192fd1b3 100644 (file)
@@ -106,7 +106,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                 notificationService.get().registerNotificationListener(deOperationsListener);
 
             final OrgOpenroadmDeviceListener deviceListener = new DeviceListener(this.deviceTransactionManager,
-                    nodeId);
+                    nodeId, this.networkModelService);
             LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
             final ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration =
                 notificationService.get().registerNotificationListener(deviceListener);
index 6800d58053bf7b725732abe2b1718049d27e977a..dc310101f816cb77fed11ccea5c502759b370cc3 100644 (file)
@@ -8,8 +8,12 @@
 
 package org.opendaylight.transportpce.networkmodel;
 
+import com.google.common.util.concurrent.FluentFuture;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.NetworkUtils;
@@ -17,16 +21,25 @@ import org.opendaylight.transportpce.networkmodel.util.LinkIdUtil;
 import org.opendaylight.transportpce.networkmodel.util.TopologyUtils;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev170818.InitRoadmNodesInput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1Builder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
 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;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkBuilder;
 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.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,6 +64,16 @@ final class OrdLink {
         String destNode = new StringBuilder(input.getRdmZNode()).append("-DEG").append(input.getDegZNum()).toString();
         String destTp = input.getTerminationPointZ();
 
+        // Check status of TPs to provide R2R link state
+        TerminationPoint rdmSrcTp = getTpofNode(srcNode, srcTp, dataBroker);
+        TerminationPoint rdmDstTp = getTpofNode(destNode, destTp, dataBroker);
+        if (State.InService.equals(rdmSrcTp.augmentation(TerminationPoint1.class).getOperationalState())
+                && State.InService.equals(rdmDstTp.augmentation(TerminationPoint1.class).getOperationalState())) {
+            oppsiteLinkBuilder.setAdministrativeState(AdminStates.InService).setOperationalState(State.InService);
+        } else {
+            oppsiteLinkBuilder.setAdministrativeState(AdminStates.OutOfService).setOperationalState(State.OutOfService);
+        }
+
         //IETF link builder
         LinkBuilder linkBuilder = TopologyUtils.createLink(srcNode, destNode, srcTp, destTp, null);
 
@@ -76,6 +99,33 @@ final class OrdLink {
         }
     }
 
+    private static TerminationPoint getTpofNode(String srcNode, String srcTp, DataBroker dataBroker) {
+        InstanceIdentifier<TerminationPoint> iiTp = InstanceIdentifier.builder(Networks.class)
+                .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                .child(Node.class, new NodeKey(new NodeId(srcNode)))
+                .augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
+                        .Node1.class)
+                .child(TerminationPoint.class, new TerminationPointKey(new TpId(srcTp)))
+                .build();
+        @NonNull
+        ReadTransaction readTransaction = dataBroker.newReadOnlyTransaction();
+        @NonNull
+        FluentFuture<Optional<TerminationPoint>> tpFf = readTransaction.read(LogicalDatastoreType.CONFIGURATION, iiTp);
+        if (tpFf.isDone()) {
+            try {
+                Optional<TerminationPoint> tpOpt;
+                tpOpt = tpFf.get();
+                if (tpOpt.isPresent()) {
+                    return tpOpt.get();
+                }
+            } catch (InterruptedException | ExecutionException e) {
+                LOG.error("Impossible to get tp-id {} of node {} from {}", srcTp, srcNode,
+                        NetworkUtils.OVERLAY_NETWORK_ID, e);
+            }
+        }
+        return null;
+    }
+
     private OrdLink(){
     }
 }
index 1859b2991a27ca94439d6ef6312577c65f9dbb1b..d7eaeeb8321d25304088e9a706d746a888e9e75f 100644 (file)
@@ -15,6 +15,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
+import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.ChangeNotification;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OtdrScanResult;
@@ -36,10 +37,13 @@ public class DeviceListener implements OrgOpenroadmDeviceListener {
     private static final TimeUnit MAX_DURATION_TO_SUBMIT_TIMEUNIT = TimeUnit.MILLISECONDS;
     private final DeviceTransactionManager deviceTransactionManager;
     private final String nodeId;
+    private final NetworkModelService networkModelService;
 
-    public DeviceListener(DeviceTransactionManager deviceTransactionManager, String nodeId) {
+    public DeviceListener(DeviceTransactionManager deviceTransactionManager, String nodeId,
+                          NetworkModelService networkModelService) {
         this.deviceTransactionManager = deviceTransactionManager;
         this.nodeId = nodeId;
+        this.networkModelService = networkModelService;
     }
 
     /**
@@ -121,8 +125,7 @@ public class DeviceListener implements OrgOpenroadmDeviceListener {
                         LOG.info("Component {} configuration: {}", getCircuitPacks().getCircuitPackName(),
                                 getCircuitPacks());
                         // 3. Update openroadm-topology
-                        // TODO
-                        // networkModelService.updateOpenRoadmNode(nodeId, getCircuitPacks());
+                        networkModelService.updateOpenRoadmNetworkTopology(nodeId, getCircuitPacks());
                     }
                 };
                 Thread thread = new Thread(handlenetconfEvent);
index 51ee4a190617c8d493dcac2644740269adbf0246..74a249928bb0ecc183ea4bcea75b1b8487c37329 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.transportpce.networkmodel.service;
 
 import java.util.List;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.OtnLinkType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
 
@@ -35,6 +36,17 @@ public interface NetworkModelService {
      */
     void deleteOpenRoadmnode(String nodeId);
 
+    /**
+     * Update OpenROADM network topology. TODO: update all topologies
+     *
+     * @param nodeId
+     *     unique node ID of OpenROADM node that sent the NETCONF notification.
+     * @param changedCpack
+     *     circuit pack modified from the NETCONF notification.
+     *
+     */
+    void updateOpenRoadmNetworkTopology(String nodeId, CircuitPacks changedCpack);
+
     /**
      * Set/update connection status of OpenROADM node.
      *
index ce7a69884b0e3c37b1ec27ee5ae24798415359cd..42665ef5fbea328ba316d89db38c6cb5ee21a2ee 100644 (file)
@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -31,7 +32,13 @@ 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.rev201012.network.nodes.NodeInfo;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.NodeInfo.OpenroadmVersion;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1Builder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1Builder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
 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;
@@ -41,14 +48,18 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1Builder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkBuilder;
 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.TerminationPointBuilder;
 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;
@@ -57,7 +68,6 @@ 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);
@@ -67,15 +77,20 @@ public class NetworkModelServiceImpl implements NetworkModelService {
     private final PortMapping portMapping;
     private Map<String, TopologyShard> topologyShardMountedDevice;
     private Map<String, TopologyShard> otnTopologyShardMountedDevice;
+    // Maps that include topology component changed with its new operational state <id, state>
+    private Map<String, State> linksChanged;
+    private Map<String, State> terminationPointsChanged;
 
     public NetworkModelServiceImpl(final NetworkTransactionService networkTransactionService,
-        final R2RLinkDiscovery linkDiscovery, PortMapping portMapping) {
+            final R2RLinkDiscovery linkDiscovery, PortMapping portMapping) {
 
         this.networkTransactionService = networkTransactionService;
         this.linkDiscovery = linkDiscovery;
         this.portMapping = portMapping;
         this.topologyShardMountedDevice = new HashMap<String, TopologyShard>();
         this.otnTopologyShardMountedDevice = new HashMap<String, TopologyShard>();
+        this.linksChanged = new HashMap<String, State>();
+        this.terminationPointsChanged = new HashMap<String, State>();
     }
 
     public void init() {
@@ -95,9 +110,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)
@@ -145,12 +157,15 @@ public class NetworkModelServiceImpl implements NetworkModelService {
             } 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);
@@ -248,6 +263,70 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         }
     }
 
+    @Override
+    public void updateOpenRoadmNetworkTopology(String nodeId, CircuitPacks changedCpack) {
+        // Clear maps for each NETCONF notification received
+        this.linksChanged.clear();
+        this.terminationPointsChanged.clear();
+        // 1. Get the list links and nodes of the current openroadm network topology
+        List<Link> linkList = null;
+        List<Node> nodesList = null;
+        try {
+            InstanceIdentifier.InstanceIdentifierBuilder<Network1> network1IID =
+                InstanceIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                    .augmentation(Network1.class);
+            InstanceIdentifier.InstanceIdentifierBuilder<Network> networkIID =
+                InstanceIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)));
+            Optional<Network> networkOptional = this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION,
+                networkIID.build()).get();
+            Optional<Network1> network1Optional =
+                this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, network1IID.build()).get();
+            if (network1Optional.isPresent()) {
+                // Links list
+                linkList = new ArrayList<>(Objects.requireNonNull(network1Optional.get().getLink()).values());
+            }
+            if (networkOptional.isPresent()) {
+                // Nodes list
+                nodesList = new ArrayList<>(Objects.requireNonNull(networkOptional.get().getNode()).values());
+            }
+        } catch (InterruptedException e) {
+            LOG.error("Couldn't get list of links in the network. Error={}", e.getMessage());
+            Thread.currentThread().interrupt();
+        } catch (ExecutionException e) {
+            LOG.error("Couldn't get list of links in the network. Error={}", e.getMessage());
+        }
+        /* 2. For simplicity the update is only considered in the case of a WSSDEG circuit pack change where client and
+        line ports (external ports) of a node are included and there is a 1-to-1 port mapping to the nodes TPs. The
+        mapping between ports and TPs internal of a node is a bit different as the is a 1-to-many port mapping */
+        String cpackType = changedCpack.getCircuitPackType();
+        switch (cpackType) {
+            case "ADDROP":
+                LOG.info("ADDROP circuit pack modified");
+                setTerminationPointsChangedMap(changedCpack);
+                // setTpStateHashmap(changedCpack);
+                break;
+            case "WSSDEG":
+                LOG.info("WSSDEG circuit pack modified");
+                setTerminationPointsChangedMap(changedCpack);
+                // 3. Update the termination points of the node that sent a NETCONF notification
+                updateOpenRoadmNetworkTopologyTPs(nodesList, nodeId);
+                // 4. Update the links of the topology affected by the changes on TPs (if any)
+                updateOpenRoadmNetworkTopologyLinks(linkList, nodesList);
+                // TODO: send notification to service handler
+                break;
+            case "port":
+                LOG.info("port circuit pack modified");
+                break;
+            case "pluggable":
+                LOG.info("pluggable circuit pack modified");
+                break;
+            default:
+                LOG.warn("Circuitp pack of type {} not recognized", cpackType);
+        }
+    }
+
     @Override
     public void createOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ, OtnLinkType linkType) {
         TopologyShard otnTopologyShard;
@@ -279,15 +358,14 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, otnTopologyLink.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink,
-                    otnTopologyLink);
+                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());
+                    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(supportingTerminationPoint.get(0).getNodeRef()))
@@ -354,15 +432,14 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, otnTopologyLink.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION,
-                        iiOtnTopologyLink, otnTopologyLink);
+                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());
+                    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(supportingTerminationPoint.get(0).getNodeRef()))
@@ -382,7 +459,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;
@@ -397,21 +474,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);
+                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());
+                    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(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);
@@ -453,35 +529,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) {
@@ -502,7 +573,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();
@@ -591,9 +662,9 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         List<Link> odu4links = null;
         if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
             odu4links = netw1Opt
-                    .get()
-                    .nonnullLink().values()
-                    .stream().filter(lk -> lk.getLinkId().getValue().startsWith("ODU4"))
+                .get()
+                .nonnullLink().values()
+                .stream().filter(lk -> lk.getLinkId().getValue().startsWith("ODU4"))
                 .collect(Collectors.toList());
         }
         List<Link> links = new ArrayList<>();
@@ -604,14 +675,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);
                     }
@@ -635,8 +704,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(),
@@ -646,12 +714,211 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                     .augmentation(Network1.class)
                     .child(Link.class, otnTopologyLink.key())
                     .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink,
-                    otnTopologyLink);
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
             }
         } else {
             LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
         }
 
     }
+
+    private void setTerminationPointsChangedMap(CircuitPacks changedCpack) {
+        List<Ports> portsList = new ArrayList<>(Objects.requireNonNull(changedCpack.getPorts()).values());
+        for (Ports port : portsList) {
+            String lcp = port.getLogicalConnectionPoint();
+            if (lcp != null && !this.terminationPointsChanged.containsKey(lcp)) {
+                this.terminationPointsChanged.put(lcp, State.forValue(port.getOperationalState().getIntValue()));
+            }
+        }
+    }
+
+    private void updateOpenRoadmNetworkTopologyTPs(List<Node> nodesList, String nodeId) {
+        /* 1. The nodes in nodesList are abstract nodes (i.e. ROADMA01-DEG1) and we have the id of the node that has
+        a change (i.e. ROADMA01). So we only need to look for the abstract nodes that belong to the physical node. */
+        String abstractNodeId;
+        for (Node node : nodesList) {
+            abstractNodeId = Objects.requireNonNull(node.getNodeId()).getValue();
+            // Checking if the node is operationally inService
+            if (abstractNodeId.contains(nodeId) && node.augmentation(org.opendaylight.yang.gen.v1.http
+                    .org.openroadm.common.network.rev200529.Node1.class)
+                    .getOperationalState().equals(State.InService)) {
+                /* 2. Check if the state of the termination points from the topology shard are equal to the state of
+                the termination points in the previously created map. */
+                List<TerminationPoint> tpList = new ArrayList<>(Objects.requireNonNull(node.augmentation(Node1.class))
+                    .getTerminationPoint().values());
+                Map<TerminationPointKey, TerminationPoint> updatedTpMap = new HashMap<>();
+                for (TerminationPoint tp : tpList) {
+                    String tpId = Objects.requireNonNull(tp.getTpId()).getValue();
+                    State tpState = Objects.requireNonNull(tp.augmentation(org.opendaylight.yang.gen.v1.http
+                        .org.openroadm.common.network.rev200529.TerminationPoint1.class)).getOperationalState();
+                    if (this.terminationPointsChanged.containsKey(tpId) && !this.terminationPointsChanged.get(tpId)
+                            .equals(tpState)) {
+                        // The state of a termination point has changed... updating
+                        State newTpOperationalState = null;
+                        AdminStates newTpAdminState = null;
+                        /* 3. If the TP has changed its state, it has to be added to the links Map, as a Link state
+                        is defined by the state of the TPs that model the link. */
+                        switch (this.terminationPointsChanged.get(tpId)) {
+                            case InService:
+                                newTpAdminState = AdminStates.InService;
+                                newTpOperationalState = State.InService;
+                                // Add TP and state inService to the links Map
+                                this.linksChanged.put(tpId, State.InService);
+                                // TODO: update change list for service handler notification
+                                break;
+                            case OutOfService:
+                                newTpAdminState = AdminStates.OutOfService;
+                                newTpOperationalState = State.OutOfService;
+                                // Add TP and state outOfService to the links Map
+                                this.linksChanged.put(tpId, State.OutOfService);
+                                // TODO: update change list for service handler notification
+                                break;
+                            case Degraded:
+                                LOG.warn("Operational state Degraded not handled");
+                                break;
+                            default:
+                                LOG.warn("Unrecognized state!");
+                        }
+                        // 4. Add modified TP to the updated List.
+                        TerminationPoint updTp = new TerminationPointBuilder().withKey(tp.key())
+                            .setTpId(tp.getTpId())
+                            .addAugmentation(new TerminationPoint1Builder()
+                                .setAdministrativeState(newTpAdminState)
+                                .setOperationalState(newTpOperationalState)
+                                .build())
+                            .build();
+                        updatedTpMap.put(tp.key(), updTp);
+                    }
+                    // 5. Update the list of termination points of the corresponding node and merge to the datastore.
+                    if (!updatedTpMap.isEmpty()) {
+                        Node updNode = new NodeBuilder().setNodeId(node.getNodeId()).addAugmentation(new Node1Builder()
+                            .setTerminationPoint(updatedTpMap).build()).build();
+                        InstanceIdentifier<Node> iiOpenRoadmTopologyNode = InstanceIdentifier.builder(
+                            Networks.class).child(Network.class, new NetworkKey(
+                                    new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).child(Node.class, node.key())
+                            .build();
+                        networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
+                            updNode);
+                        try {
+                            networkTransactionService.commit().get();
+                        } catch (InterruptedException e) {
+                            LOG.error("Couldnt commit change to openroadm topology.", e);
+                            Thread.currentThread().interrupt();
+                        } catch (ExecutionException e) {
+                            LOG.error("Couldnt commit change to openroadm topology.", e);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private void updateOpenRoadmNetworkTopologyLinks(List<Link> linkList, List<Node> nodesList) {
+        for (Link link : linkList) {
+            String srcTp = link.getSource().getSourceTp().toString();
+            String dstTp = link.getDestination().getDestTp().toString();
+            String srcNode = link.getSource().getSourceNode().getValue();
+            String dstNode = link.getDestination().getDestNode().getValue();
+            State linkState = link.augmentation(org.opendaylight.yang.gen.v1.http
+                .org.openroadm.common.network.rev200529.Link1.class).getOperationalState();
+            /* 1. Check the current state of the source and dest tps of the link. If these tps exist on the links Map
+            and the states are different, then we need to update the link state accordingly.
+            There are several cases depending on the current link state:
+                - TPs were both inService and one of them (or both) is (are) now outOfService --> link to outOfService
+                - TPs were both outOfService and both of them are now inService --> link to inService
+            However, if only one TP exists on the Link map, we will need to check the state of the other end in order to
+            make a decision: i.e. we cannot assume that if a TP has changed from outOfService to inService the link will
+            become inService, as this can only happen if both TPs are inService, therefore we need to check the other
+            end. */
+            switch (linkState) {
+                case InService:
+                    if (this.linksChanged.containsKey(srcTp) && this.linksChanged.containsKey(dstTp)) {
+                        // Both TPs of the link have been updated. If one of them is outOfService --> link outOfService
+                        if (State.OutOfService.equals(this.linksChanged.get(srcTp)) || State.OutOfService.equals(this
+                                .linksChanged.get(dstTp))) {
+                            updateLinkStates(link, State.OutOfService, AdminStates.OutOfService);
+                        }
+                    } else if (this.linksChanged.containsKey(srcTp) && State.OutOfService.equals(this.linksChanged
+                            .get(srcTp))) {
+                        // Source TP has been changed to outOfService --> link outOfService
+                        updateLinkStates(link, State.OutOfService, AdminStates.OutOfService);
+                    } else if (this.linksChanged.containsKey(dstTp) && State.OutOfService.equals(this.linksChanged
+                            .get(dstTp))) {
+                        // Destination TP has been changed to outOfService --> link outOfService
+                        updateLinkStates(link, State.OutOfService, AdminStates.OutOfService);
+                    }
+                    break;
+                case OutOfService:
+                    if (this.linksChanged.containsKey(srcTp) && this.linksChanged.containsKey(dstTp)) {
+                        // Both TPs of the link have been updated. If both of them are inService --> link inService
+                        if (State.InService.equals(this.linksChanged.get(srcTp)) || State.InService.equals(this
+                                .linksChanged.get(dstTp))) {
+                            updateLinkStates(link, State.InService, AdminStates.InService);
+                        }
+                    } else if (this.linksChanged.containsKey(srcTp) && State.InService.equals(this.linksChanged
+                            .get(srcTp))) {
+                        // Source TP has been changed to inService --> check the second TP and update link to inService
+                        // only if both TPs are inService
+                        if (tpInService(dstNode, dstTp, nodesList)) {
+                            updateLinkStates(link, State.InService, AdminStates.InService);
+                        }
+                    } else if (this.linksChanged.containsKey(dstTp) && State.InService.equals(this.linksChanged
+                            .get(dstTp))) {
+                        // Destination TP has been changed to to inService --> check the second TP and update link to
+                        // inService only if both TPs are inService
+                        if (tpInService(srcNode, srcTp, nodesList)) {
+                            updateLinkStates(link, State.InService, AdminStates.InService);
+                        }
+                    }
+                    break;
+                case Degraded:
+                    LOG.warn("Link state degraded not handled");
+                    break;
+                default:
+                    LOG.warn("Unrecognized state!");
+            }
+        }
+    }
+
+    private boolean tpInService(String nodeId, String tpId, List<Node> nodesList) {
+        // Check the node with dstNode id and check the state of the TP with id dstTP id
+        for (Node node : nodesList) {
+            if (Objects.requireNonNull(node.getNodeId()).getValue().equals(nodeId)) {
+                List<TerminationPoint> tpList = new ArrayList<>(Objects.requireNonNull(Objects.requireNonNull(node
+                    .augmentation(Node1.class)).getTerminationPoint()).values());
+                for (TerminationPoint tp : tpList) {
+                    if (Objects.requireNonNull(tp.getTpId()).getValue().equals(tpId)) {
+                        if (State.InService.equals(tp.augmentation(org.opendaylight.yang.gen.v1.http
+                                .org.openroadm.common.network.rev200529.TerminationPoint1.class)
+                                .getOperationalState())) {
+                            // The second TP is also inService
+                            return true;
+                        }
+                        break;
+                    }
+                }
+                break;
+            }
+        }
+        return false;
+    }
+
+    private void updateLinkStates(Link link, State state, AdminStates adminStates) {
+        // TODO: add change to list of changes
+        org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1 link1 = new Link1Builder()
+            .setOperationalState(state).setAdministrativeState(adminStates).build();
+        Link updLink = new LinkBuilder().withKey(link.key()).addAugmentation(link1).build();
+        InstanceIdentifier.InstanceIdentifierBuilder<Link> linkIID = InstanceIdentifier.builder(Networks.class)
+            .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+            .augmentation(Network1.class).child(Link.class, link.key());
+        networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, linkIID.build(), updLink);
+        try {
+            networkTransactionService.commit().get();
+        } catch (InterruptedException e) {
+            LOG.error("Couldnt commit changed to openroadm topology. Error={}", e.getMessage());
+            Thread.currentThread().interrupt();
+        } catch (ExecutionException e) {
+            LOG.error("Couldnt commit changed to openroadm topology. Error={}", e.getMessage());
+        }
+    }
 }