Manage low order otn services over multiple ODU4
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / service / NetworkModelServiceImpl.java
1 /*
2  * Copyright © 2016 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.networkmodel.service;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Optional;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.TimeUnit;
19 import java.util.concurrent.TimeoutException;
20 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.transportpce.common.InstanceIdentifiers;
25 import org.opendaylight.transportpce.common.NetworkUtils;
26 import org.opendaylight.transportpce.common.mapping.PortMapping;
27 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
28 import org.opendaylight.transportpce.networkmodel.R2RLinkDiscovery;
29 import org.opendaylight.transportpce.networkmodel.dto.TopologyShard;
30 import org.opendaylight.transportpce.networkmodel.util.ClliNetwork;
31 import org.opendaylight.transportpce.networkmodel.util.LinkIdUtil;
32 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmNetwork;
33 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmOtnTopology;
34 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmTopology;
35 import org.opendaylight.transportpce.networkmodel.util.TopologyUtils;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TopologyUpdateResult;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TopologyUpdateResultBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.TopologyChanges;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.TopologyChangesBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.TopologyChangesKey;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.OpenroadmNodeVersion;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.nodes.NodeInfo;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Link1;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.TerminationPoint1;
47 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTp;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTpBuilder;
49 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev210511.OtnLinkType;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointKey;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.termination.point.SupportingTerminationPoint;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
67 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
68 import org.opendaylight.yangtools.yang.common.Uint32;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
71
72 public class NetworkModelServiceImpl implements NetworkModelService {
73
74     private static final Logger LOG = LoggerFactory.getLogger(NetworkModelServiceImpl.class);
75
76     private NetworkTransactionService networkTransactionService;
77     private final R2RLinkDiscovery linkDiscovery;
78     private final PortMapping portMapping;
79     private Map<String, TopologyShard> topologyShardMountedDevice;
80     private Map<String, TopologyShard> otnTopologyShardMountedDevice;
81     // Variables for creating and sending topology update notification
82     private final NotificationPublishService notificationPublishService;
83     private Map<TopologyChangesKey, TopologyChanges> topologyChanges;
84     private TopologyUpdateResult notification = null;
85
86     public NetworkModelServiceImpl(final NetworkTransactionService networkTransactionService,
87             final R2RLinkDiscovery linkDiscovery, PortMapping portMapping,
88             final NotificationPublishService notificationPublishService) {
89
90         this.networkTransactionService = networkTransactionService;
91         this.linkDiscovery = linkDiscovery;
92         this.portMapping = portMapping;
93         this.topologyShardMountedDevice = new HashMap<String, TopologyShard>();
94         this.otnTopologyShardMountedDevice = new HashMap<String, TopologyShard>();
95         this.notificationPublishService = notificationPublishService;
96         this.topologyChanges = new HashMap<TopologyChangesKey, TopologyChanges>();
97     }
98
99     public void init() {
100         LOG.info("init ...");
101     }
102
103     public void close() {
104     }
105
106     @Override
107     public void createOpenRoadmNode(String nodeId, String openRoadmVersion) {
108         try {
109             LOG.info("createOpenROADMNode: {} ", nodeId);
110
111             if (!portMapping.createMappingData(nodeId, openRoadmVersion)) {
112                 LOG.warn("Could not generate port mapping for {} skipping network model creation", nodeId);
113                 return;
114             }
115             NodeInfo nodeInfo = portMapping.getNode(nodeId).getNodeInfo();
116             // node creation in clli-network
117             Node clliNode = ClliNetwork.createNode(nodeId, nodeInfo);
118             InstanceIdentifier<Node> iiClliNode = InstanceIdentifier.builder(Networks.class)
119                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID)))
120                 .child(Node.class, clliNode.key())
121                 .build();
122             LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
123             networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode);
124
125             // node creation in openroadm-network
126             Node openroadmNetworkNode = OpenRoadmNetwork.createNode(nodeId, nodeInfo);
127             InstanceIdentifier<Node> iiopenroadmNetworkNode = InstanceIdentifier.builder(Networks.class)
128                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
129                 .child(Node.class, openroadmNetworkNode.key())
130                 .build();
131             LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
132             networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode,
133                 openroadmNetworkNode);
134
135             // nodes/links creation in openroadm-topology
136             TopologyShard topologyShard = OpenRoadmTopology.createTopologyShard(portMapping.getNode(nodeId));
137             if (topologyShard != null) {
138                 this.topologyShardMountedDevice.put(nodeId, topologyShard);
139                 for (Node openRoadmTopologyNode : topologyShard.getNodes()) {
140                     LOG.info("creating node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
141                         NetworkUtils.OVERLAY_NETWORK_ID);
142                     InstanceIdentifier<Node> iiOpenRoadmTopologyNode = InstanceIdentifier.builder(Networks.class)
143                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
144                         .child(Node.class, openRoadmTopologyNode.key())
145                         .build();
146                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
147                         openRoadmTopologyNode);
148                 }
149                 for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
150                     LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
151                         NetworkUtils.OVERLAY_NETWORK_ID);
152                     InstanceIdentifier<Link> iiOpenRoadmTopologyLink = InstanceIdentifier.builder(Networks.class)
153                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
154                         .augmentation(Network1.class)
155                         .child(Link.class, openRoadmTopologyLink.key())
156                         .build();
157                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
158                         openRoadmTopologyLink);
159                 }
160             } else {
161                 LOG.error("Unable to create openroadm-topology shard for node {}!", nodeId);
162             }
163             // nodes/links creation in otn-topology
164             if (nodeInfo.getNodeType().getIntValue() == 2 && (nodeInfo.getOpenroadmVersion().getIntValue() != 1)) {
165                 createOpenRoadmOtnNode(nodeId);
166             }
167             networkTransactionService.commit().get();
168             // neighbour links through LLDP
169             if (nodeInfo.getNodeType().getIntValue() == 1) {
170                 this.linkDiscovery.readLLDP(new NodeId(nodeId), openRoadmVersion);
171             }
172             LOG.info("all nodes and links created");
173         } catch (InterruptedException | ExecutionException e) {
174             LOG.error("ERROR: ", e);
175         }
176     }
177
178     @Override
179     public void setOpenRoadmNodeStatus(String nodeId, NetconfNodeConnectionStatus.ConnectionStatus connectionStatus) {
180         LOG.info("setOpenROADMNodeStatus: {} {}", nodeId, connectionStatus.name());
181         /*
182           TODO: set connection status of the device in model,
183           TODO: so we don't need to keep it in memory (Set<String> currentMountedDevice)
184           TODO: unfortunately there is no connection status OpenROADM in network models
185           TODO: waiting for new model version
186          */
187     }
188
189     /*
190      @see org.opendaylight.transportpce.networkmodel.service.NetworkModelService# deleteOpenROADMnode(java.lang.String)
191      */
192
193     @Override
194     public boolean deleteOpenRoadmnode(String nodeId) {
195         try {
196             if (!this.portMapping.isNodeExist(nodeId)) {
197                 return false;
198             }
199             NodeKey nodeIdKey = new NodeKey(new NodeId(nodeId));
200
201             LOG.info("deleting node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
202             InstanceIdentifier<Node> iiopenroadmNetworkNode = InstanceIdentifier.builder(Networks.class)
203                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
204                 .child(Node.class, nodeIdKey)
205                 .build();
206             this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode);
207
208             TopologyShard topologyShard = this.topologyShardMountedDevice.get(nodeId);
209             if (topologyShard != null) {
210                 for (Node openRoadmTopologyNode : topologyShard.getNodes()) {
211                     LOG.info("deleting node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
212                         NetworkUtils.OVERLAY_NETWORK_ID);
213                     InstanceIdentifier<Node> iiOpenRoadmTopologyNode = InstanceIdentifier.builder(Networks.class)
214                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
215                         .child(Node.class, openRoadmTopologyNode.key())
216                         .build();
217                     this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode);
218                 }
219                 for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
220                     LOG.info("deleting link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
221                         NetworkUtils.OVERLAY_NETWORK_ID);
222                     InstanceIdentifier<Link> iiOpenRoadmTopologyLink = InstanceIdentifier.builder(Networks.class)
223                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
224                         .augmentation(Network1.class)
225                         .child(Link.class, openRoadmTopologyLink.key())
226                         .build();
227                     this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink);
228                 }
229             } else {
230                 LOG.warn("TopologyShard for node '{}' is not present", nodeId);
231             }
232             @Nullable
233             OpenroadmNodeVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
234             @Nullable
235             NodeTypes nodeType = this.portMapping.getNode(nodeId).getNodeInfo().getNodeType();
236             if (nodeType.getIntValue() == 2 && deviceVersion.getIntValue() != 1) {
237                 TopologyShard otnTopologyShard = this.otnTopologyShardMountedDevice.get(nodeId);
238                 if (otnTopologyShard != null) {
239                     LOG.info("suppression de otnTopologyShard = {}", otnTopologyShard.toString());
240                     for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
241                         LOG.info("deleting node {} in {}", otnTopologyNode.getNodeId().getValue(),
242                             NetworkUtils.OTN_NETWORK_ID);
243                         InstanceIdentifier<Node> iiotnTopologyNode = InstanceIdentifier.builder(Networks.class)
244                             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
245                             .child(Node.class, otnTopologyNode.key())
246                             .build();
247                         this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyNode);
248                     }
249                     for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
250                         LOG.info("deleting link {} in {}", otnTopologyLink.getLinkId().getValue(),
251                             NetworkUtils.OTN_NETWORK_ID);
252                         InstanceIdentifier<Link> iiotnTopologyLink = InstanceIdentifier.builder(Networks.class)
253                             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
254                             .augmentation(Network1.class)
255                             .child(Link.class, otnTopologyLink.key())
256                             .build();
257                         this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyLink);
258                     }
259                 }
260             }
261
262             LOG.info("deleteOpenROADMnode: {} version {}", nodeId, deviceVersion.getName());
263             this.portMapping.deletePortMappingNode(nodeId);
264
265             this.networkTransactionService.commit().get(1, TimeUnit.SECONDS);
266             LOG.info("all nodes and links deleted ! ");
267         } catch (InterruptedException | ExecutionException | TimeoutException e) {
268             LOG.error("Error when trying to delete node : {}", nodeId, e);
269             return false;
270         }
271         return true;
272     }
273
274     @Override
275     public void updateOpenRoadmTopologies(String nodeId, Mapping mapping) {
276         LOG.info("update OpenRoadm topologies after change update from: {} ", nodeId);
277         this.topologyChanges.clear();
278         Network openroadmTopology = null;
279         Network otnTopology = null;
280         Map<LinkKey, Link> openroadmTopologyLinks = null;
281         Map<LinkKey, Link> otnTopologyLinks = null;
282         try {
283             openroadmTopology = this.networkTransactionService
284                 .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OVERLAY_NETWORK_II)
285                 .get().get();
286             if (openroadmTopology.augmentation(Network1.class) != null) {
287                 openroadmTopologyLinks = openroadmTopology.augmentation(Network1.class).getLink();
288             }
289             otnTopology = this.networkTransactionService
290                 .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OTN_NETWORK_II)
291                 .get().get();
292             if (otnTopology.augmentation(Network1.class) != null) {
293                 otnTopologyLinks = otnTopology.augmentation(Network1.class).getLink();
294             }
295         } catch (InterruptedException | ExecutionException e) {
296             LOG.error("Error when trying to update node : {}", nodeId, e);
297         }
298         if (openroadmTopology == null || otnTopology == null) {
299             LOG.warn("Error getting topologies from datastore");
300             return;
301         }
302         String abstractNodeid = String.join("-", nodeId, mapping.getLogicalConnectionPoint().split("-")[0]);
303         // nodes/links update in openroadm-topology
304         if (openroadmTopology.getNode() != null) {
305             TopologyShard topologyShard = TopologyUtils.updateTopologyShard(abstractNodeid, mapping,
306                 openroadmTopology.getNode(), openroadmTopologyLinks);
307             if (topologyShard.getLinks() != null) {
308                 for (Link link : topologyShard.getLinks()) {
309                     LOG.info("updating links {} in {}", link.getLinkId().getValue(),
310                         NetworkUtils.OVERLAY_NETWORK_ID);
311                     InstanceIdentifier<Link> iiTopologyLink = InstanceIdentifier.builder(Networks.class)
312                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
313                         .augmentation(Network1.class)
314                         .child(Link.class, link.key())
315                         .build();
316                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
317                 }
318             }
319             if (topologyShard.getTps() != null) {
320                 for (TerminationPoint tp : topologyShard.getTps()) {
321                     LOG.info("updating TP {} in openroadm-topology", tp.getTpId().getValue());
322                     InstanceIdentifier<TerminationPoint> iiTopologyTp = InstanceIdentifier.builder(Networks.class)
323                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
324                         .child(Node.class, new NodeKey(new NodeId(abstractNodeid)))
325                         .augmentation(Node1.class)
326                         .child(TerminationPoint.class, new TerminationPointKey(tp.getTpId()))
327                         .build();
328                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyTp, tp);
329                     TopologyChanges tc = new TopologyChangesBuilder()
330                         .withKey(new TopologyChangesKey(abstractNodeid, tp.getTpId().getValue()))
331                         .setNodeId(abstractNodeid)
332                         .setTpId(tp.getTpId().getValue())
333                         .setState(tp.augmentation(
334                             org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1
335                                 .class).getOperationalState())
336                         .build();
337                     if (!this.topologyChanges.containsKey(tc.key())) {
338                         this.topologyChanges.put(tc.key(), tc);
339                     }
340                 }
341             }
342         }
343         // nodes/links update in otn-topology
344         if (otnTopology.getNode() != null
345             && otnTopology.getNode().containsKey(new NodeKey(new NodeId(abstractNodeid)))) {
346             TopologyShard otnShard = TopologyUtils.updateTopologyShard(abstractNodeid, mapping,
347                 otnTopology.getNode(), otnTopologyLinks);
348             if (otnShard.getLinks() != null) {
349                 for (Link link : otnShard.getLinks()) {
350                     LOG.info("updating links {} in {}", link.getLinkId().getValue(),
351                         NetworkUtils.OVERLAY_NETWORK_ID);
352                     InstanceIdentifier<Link> iiTopologyLink = InstanceIdentifier.builder(Networks.class)
353                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
354                         .augmentation(Network1.class)
355                         .child(Link.class, link.key())
356                         .build();
357                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
358                 }
359             }
360             if (otnShard.getTps() != null) {
361                 for (TerminationPoint tp : otnShard.getTps()) {
362                     LOG.info("updating TP {} in otn-topology", tp.getTpId().getValue());
363                     InstanceIdentifier<TerminationPoint> iiTopologyTp = InstanceIdentifier.builder(Networks.class)
364                         .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
365                         .child(Node.class, new NodeKey(new NodeId(abstractNodeid)))
366                         .augmentation(Node1.class)
367                         .child(TerminationPoint.class, new TerminationPointKey(tp.getTpId()))
368                         .build();
369                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyTp, tp);
370                     TopologyChanges tc = new TopologyChangesBuilder()
371                         .withKey(new TopologyChangesKey(abstractNodeid, tp.getTpId().getValue()))
372                         .setNodeId(abstractNodeid)
373                         .setTpId(tp.getTpId().getValue())
374                         .setState(tp.augmentation(
375                             org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1
376                                 .class).getOperationalState())
377                         .build();
378                     if (!this.topologyChanges.containsKey(tc.key())) {
379                         this.topologyChanges.put(tc.key(), tc);
380                     }
381                 }
382             }
383         }
384         // commit datastore updates
385         try {
386             networkTransactionService.commit().get();
387             sendNotification();
388         } catch (InterruptedException | ExecutionException e) {
389             LOG.error("Error updating openroadm-topology", e);
390         }
391     }
392
393     @Override
394     public void createOtnLinks(
395         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
396         notifLink, List<String> suppLinks, OtnLinkType linkType) {
397
398         TopologyShard otnTopologyShard;
399         switch (linkType) {
400             case OTU4:
401             case OTUC4:
402                 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, null, null, linkType);
403                 break;
404             case ODTU4:
405             case ODUC4:
406                 List<LinkId> linkIdList = new ArrayList<>();
407                 if (suppLinks != null) {
408                     suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
409                 }
410                 List<Link> supportedOtu4links = getOtnLinks(linkIdList);
411                 String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
412                     notifLink.getATermination().getTpId());
413                 String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
414                     notifLink.getZTermination().getTpId());
415                 List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, notifLink.getATermination().getTpId(), nodeTopoZ,
416                     notifLink.getZTermination().getTpId());
417                 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, supportedOtu4links, tps, linkType);
418                 break;
419             default:
420                 LOG.error("unknown otn link type {}", linkType);
421                 otnTopologyShard = new TopologyShard(null, null);
422         }
423         if (otnTopologyShard.getLinks() != null) {
424             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
425                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
426                     NetworkUtils.OVERLAY_NETWORK_ID);
427                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
428                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
429                     .augmentation(Network1.class)
430                     .child(Link.class, otnTopologyLink.key())
431                     .build();
432                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
433             }
434         }
435         if (otnTopologyShard.getTps() != null) {
436             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
437                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
438                 List<SupportingTerminationPoint> supportingTerminationPoint =
439                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
440                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
441                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
442                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
443                     .augmentation(Node1.class)
444                     .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
445                     .build();
446                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
447             }
448         }
449         try {
450             networkTransactionService.commit().get();
451         } catch (InterruptedException | ExecutionException e) {
452             LOG.error("Error adding OTN links in otn-topology", e);
453         }
454         LOG.info("OTN links created");
455     }
456
457     @Override
458     public void deleteOtnLinks(
459         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
460         notifLink, List<String> suppLinks, OtnLinkType linkType) {
461
462         TopologyShard otnTopologyShard;
463         String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
464             notifLink.getATermination().getTpId());
465         String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
466             notifLink.getZTermination().getTpId());
467         String tpA = notifLink.getATermination().getTpId();
468         String tpZ = notifLink.getZTermination().getTpId();
469         List<Link> otuLinks;
470         List<LinkId> linkIdList = new ArrayList<>();
471         switch (linkType) {
472             case OTU4:
473             case OTUC4:
474                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, linkType.getName()));
475                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, linkType.getName()));
476                 otuLinks = getOtnLinks(linkIdList);
477                 if (checkLinks(otuLinks)) {
478                     deleteLinks(otuLinks);
479                 } else {
480                     LOG.error("Error deleting OTU4 links");
481                 }
482                 otnTopologyShard = new TopologyShard(null, null);
483                 break;
484             case ODTU4:
485             case ODUC4:
486                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, linkType.getName()));
487                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, linkType.getName()));
488                 List<Link> oduLinks = getOtnLinks(linkIdList);
489                 List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, tpA, nodeTopoZ, tpZ);
490                 if (checkLinks(oduLinks) && checkTerminationPoints(tps)) {
491                     deleteLinks(oduLinks);
492                     linkIdList.clear();
493                     if (suppLinks != null) {
494                         suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
495                     }
496                     otuLinks = getOtnLinks(linkIdList);
497
498                     otnTopologyShard = OpenRoadmOtnTopology.deleteOtnLinks(otuLinks, tps, linkType);
499                 } else {
500                     LOG.error("Error deleting ODU4 links");
501                     otnTopologyShard = new TopologyShard(null, null);
502                 }
503                 break;
504             default:
505                 LOG.error("unknown otn link type {}", linkType);
506                 otnTopologyShard = new TopologyShard(null, null);
507         }
508
509         if (otnTopologyShard.getLinks() != null) {
510             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
511                 LOG.info("deleting and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
512                     NetworkUtils.OVERLAY_NETWORK_ID);
513                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
514                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
515                     .augmentation(Network1.class)
516                     .child(Link.class, otnTopologyLink.key())
517                     .build();
518                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
519             }
520         }
521         if (otnTopologyShard.getTps() != null) {
522             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
523                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
524                 List<SupportingTerminationPoint> supportingTerminationPoint =
525                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
526                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
527                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
528                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
529                     .augmentation(Node1.class)
530                     .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
531                     .build();
532                 networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
533             }
534         }
535         try {
536             networkTransactionService.commit().get();
537         } catch (InterruptedException | ExecutionException e) {
538             LOG.error("Error deleting OTN links in otn-topology", e);
539         }
540         LOG.info("OTN links deletion terminated");
541     }
542
543     @Override
544     public void updateOtnLinks(
545         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
546             notifLink, List<String> suppLinks, Uint32 serviceRate, Short tribPortNb, Short minTribSoltNb,
547             Short maxTribSlotNb, boolean isDeletion) {
548
549         List<LinkTp> linkTerminations = new ArrayList<>();
550         List<Link> supportedOdu4Links = null;
551         if (notifLink != null) {
552             // retreive termination-points to be updated
553             linkTerminations.add(new LinkTpBuilder()
554                     .setNodeId(notifLink.getATermination().getNodeId())
555                     .setTpId(notifLink.getATermination().getTpId())
556                     .build());
557             linkTerminations.add(new LinkTpBuilder()
558                     .setNodeId(notifLink.getZTermination().getNodeId())
559                     .setTpId(notifLink.getZTermination().getTpId())
560                     .build());
561             // retreive supported links
562             supportedOdu4Links = getSupportingOdu4Links(linkTerminations, serviceRate);
563         } else if (suppLinks != null) {
564              // retreive supported links
565             List<LinkId> linkIdList = new ArrayList<>();
566             if (suppLinks != null) {
567                 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
568             }
569             supportedOdu4Links = getOtnLinks(linkIdList);
570             // retreive termination-points to be updated
571             for (Link link : supportedOdu4Links) {
572                 LinkTp atermination = new LinkTpBuilder()
573                     .setNodeId(link.getSource().getSourceNode().getValue())
574                     .setTpId(link.getSource().getSourceTp().getValue())
575                     .build();
576                 linkTerminations.add(atermination);
577             }
578         } else {
579             LOG.error("Impossible to update OTN links and their associated termination points in otn-topology");
580             return;
581         }
582         List<TerminationPoint> tps = getOtnNodeTps(linkTerminations);
583         TopologyShard otnTopologyShard;
584         otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOdu4Links, tps, serviceRate, tribPortNb,
585             minTribSoltNb, maxTribSlotNb, isDeletion);
586         if (otnTopologyShard.getLinks() != null) {
587             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
588                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
589                     NetworkUtils.OVERLAY_NETWORK_ID);
590                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
591                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
592                     .augmentation(Network1.class)
593                     .child(Link.class, new LinkKey(new LinkId(otnTopologyLink.getLinkId().getValue())))
594                     .build();
595                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
596             }
597         }
598         if (otnTopologyShard.getTps() != null) {
599             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
600                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
601                 List<SupportingTerminationPoint> supportingTerminationPoint =
602                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
603                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
604                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
605                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
606                     .augmentation(Node1.class)
607                     .child(TerminationPoint.class, new TerminationPointKey(new TpId(otnTopologyTp.getTpId()
608                         .getValue())))
609                     .build();
610                 if (isDeletion) {
611                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
612                 } else {
613                     networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
614                 }
615             }
616         }
617         try {
618             networkTransactionService.commit().get();
619         } catch (InterruptedException | ExecutionException e) {
620             LOG.error("Error updating OTN links in otn-topology", e);
621         }
622     }
623
624     @Override
625     public void updateOtnLinks(List<String> suppLinks, boolean isDeletion) {
626         List<LinkId> linkIdList = new ArrayList<>();
627         if (suppLinks != null) {
628             suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
629         }
630         List<Link> supportedOtu4links = getOtnLinks(linkIdList);
631
632         TopologyShard otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOtu4links, isDeletion);
633         if (otnTopologyShard.getLinks() != null) {
634             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
635                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
636                     NetworkUtils.OVERLAY_NETWORK_ID);
637                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
638                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
639                     .augmentation(Network1.class)
640                     .child(Link.class, otnTopologyLink.key())
641                     .build();
642                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
643             }
644         }
645         try {
646             networkTransactionService.commit().get();
647         } catch (InterruptedException | ExecutionException e) {
648             LOG.error("Error adding OTN links in otn-topology", e);
649         }
650         LOG.info("OTN links updated");
651     }
652
653     private List<Link> getOtnLinks(List<LinkId> linkIds) {
654         List<Link> links = new ArrayList<>();
655         for (LinkId linkId : linkIds) {
656             InstanceIdentifier<Link> iiLink = InstanceIdentifier.builder(Networks.class)
657                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
658                 .augmentation(Network1.class)
659                 .child(Link.class, new LinkKey(linkId))
660                 .build();
661             ListenableFuture<Optional<Link>> linkOptLf = networkTransactionService
662                 .read(LogicalDatastoreType.CONFIGURATION, iiLink);
663             if (linkOptLf.isDone()) {
664                 try {
665                     if (linkOptLf.get().isPresent()) {
666                         links.add(linkOptLf.get().get());
667                     }
668                 } catch (InterruptedException | ExecutionException e) {
669                     LOG.error("Error retreiving OTN links from otn-topology", e);
670                 }
671             } else {
672                 LOG.error("Error retreiving link {} from otn-topology", linkId.getValue());
673             }
674         }
675         return links;
676     }
677
678     private boolean checkLinks(List<Link> links) {
679         if (links.isEmpty()) {
680             return false;
681         }
682         for (Link link : links) {
683             if (link.augmentation(Link1.class) != null
684                     && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
685                 return false;
686             }
687         }
688         return true;
689     }
690
691     private boolean checkTerminationPoints(List<TerminationPoint> tps) {
692         if (tps.isEmpty()) {
693             return false;
694         }
695         for (TerminationPoint tp : tps) {
696             if (tp.augmentation(TerminationPoint1.class) != null && tp.augmentation(TerminationPoint1.class)
697                     .getXpdrTpPortConnectionAttributes().getTsPool() != null && tp.augmentation(TerminationPoint1.class)
698                     .getXpdrTpPortConnectionAttributes().getTsPool().size() != 80) {
699                 return false;
700             }
701         }
702         return true;
703     }
704
705     private List<TerminationPoint> getOtnNodeTps(String nodeTopoA, String tpA, String nodeTopoZ, String tpZ) {
706         List<TerminationPoint> tps = new ArrayList<>();
707         InstanceIdentifier<TerminationPoint> iiTpA = InstanceIdentifier.builder(Networks.class)
708             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
709             .child(Node.class, new NodeKey(new NodeId(nodeTopoA)))
710             .augmentation(Node1.class)
711             .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpA)))
712             .build();
713         Optional<TerminationPoint> tpAOpt = Optional.empty();
714         InstanceIdentifier<TerminationPoint> iiTpZ = InstanceIdentifier.builder(Networks.class)
715             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
716             .child(Node.class, new NodeKey(new NodeId(nodeTopoZ)))
717             .augmentation(Node1.class)
718             .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpZ)))
719             .build();
720         Optional<TerminationPoint> tpZOpt = Optional.empty();
721
722         if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
723                 && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
724             try {
725                 tpAOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).get();
726                 tpZOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).get();
727             } catch (InterruptedException | ExecutionException e) {
728                 LOG.error("Error retreiving tp {} of node {} or tp {} from node {} from otn-topology", tpA, nodeTopoA,
729                     tpZ, nodeTopoZ, e);
730             }
731         } else {
732             LOG.error("error getting node termination points from the datastore");
733         }
734
735         if (tpAOpt.isPresent() && tpZOpt.isPresent()) {
736             tps.add(tpAOpt.get());
737             tps.add(tpZOpt.get());
738         }
739         return tps;
740     }
741
742     private List<TerminationPoint> getOtnNodeTps(List<LinkTp> linkTerminations) {
743         List<TerminationPoint> tps = new ArrayList<>();
744         for (LinkTp linkTp : linkTerminations) {
745             String tp = linkTp.getTpId();
746             String nodeId = formatNodeName(linkTp.getNodeId(), tp);
747             InstanceIdentifier<TerminationPoint> iiTp = InstanceIdentifier.builder(Networks.class)
748                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
749                 .child(Node.class, new NodeKey(new NodeId(nodeId)))
750                 .augmentation(Node1.class)
751                 .child(TerminationPoint.class, new TerminationPointKey(new TpId(tp)))
752                 .build();
753             Optional<TerminationPoint> tpOpt;
754             if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).isDone()) {
755                 try {
756                     tpOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).get();
757                     if (tpOpt.isPresent()) {
758                         tps.add(tpOpt.get());
759                     }
760                 } catch (InterruptedException | ExecutionException e) {
761                     LOG.error("Error retreiving tp {} of node {} from otn-topology", tp, nodeId, e);
762                 }
763             } else {
764                 LOG.error("error getting node termination points from the datastore");
765             }
766         }
767         return tps;
768     }
769
770     private void deleteLinks(List<Link> links) {
771         for (Link otnTopologyLink : links) {
772             LOG.info("deleting link {} from {}", otnTopologyLink.getLinkId().getValue(),
773                 NetworkUtils.OVERLAY_NETWORK_ID);
774             InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
775                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
776                 .augmentation(Network1.class)
777                 .child(Link.class, otnTopologyLink.key())
778                 .build();
779             networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink);
780         }
781         try {
782             networkTransactionService.commit().get();
783         } catch (InterruptedException | ExecutionException e) {
784             LOG.error("Error deleting OTN links from otn-topology", e);
785         }
786     }
787
788     private List<Link> getSupportingOdu4Links(List<LinkTp> nodesTopoTps, Uint32 serviceRate) {
789         InstanceIdentifier<Network1> iiOtnTopologyLinks = InstanceIdentifier.builder(Networks.class)
790             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
791             .augmentation(Network1.class)
792             .build();
793         ListenableFuture<Optional<Network1>> netw1Fl = networkTransactionService
794             .read(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLinks);
795         Optional<Network1> netw1Opt = Optional.empty();
796         if (netw1Fl.isDone()) {
797             try {
798                 netw1Opt = netw1Fl.get();
799             } catch (InterruptedException | ExecutionException e) {
800                 LOG.error("Error retreiving list of links from otn-topology", e);
801             }
802         }
803         List<Link> odu4links = null;
804         if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
805             odu4links = netw1Opt
806                 .get()
807                 .nonnullLink().values()
808                 .stream().filter(lk -> lk.getLinkId().getValue()
809                     .startsWith(Uint32.valueOf(100).equals(serviceRate) ? "ODUC4" : "ODTU4"))
810                 .collect(Collectors.toList());
811         }
812         if (odu4links == null) {
813             return null;
814         }
815         List<Link> links = new ArrayList<>();
816         for (LinkTp linkTp : nodesTopoTps) {
817             String tp = linkTp.getTpId();
818             String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
819                 .append(tp.split("-")[0]).toString();
820             Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
821                 .equals(nodeId) && lk.getSource().getSourceTp().getValue().equals(tp)).findFirst().get();
822             if (!links.contains(slink)) {
823                 links.add(slink);
824             }
825             Link dlink = odu4links.stream().filter(lk -> lk.getDestination().getDestNode().getValue()
826                 .equals(nodeId) && lk.getDestination().getDestTp().getValue().equals(tp)).findFirst().get();
827             if (!links.contains(dlink)) {
828                 links.add(dlink);
829             }
830         }
831         LOG.debug("odu4oduC4links = {}", links);
832         return links;
833     }
834
835     private void createOpenRoadmOtnNode(String nodeId) {
836         TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
837         if (otnTopologyShard != null) {
838             this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
839             for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
840                 LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
841                     NetworkUtils.OTN_NETWORK_ID);
842                 InstanceIdentifier<Node> iiOtnTopologyNode = InstanceIdentifier.builder(Networks.class)
843                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
844                     .child(Node.class, otnTopologyNode.key())
845                     .build();
846                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
847             }
848             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
849                 LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
850                     NetworkUtils.OVERLAY_NETWORK_ID);
851                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
852                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
853                     .augmentation(Network1.class)
854                     .child(Link.class, otnTopologyLink.key())
855                     .build();
856                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
857             }
858         } else {
859             LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
860         }
861     }
862
863     private String convertNetconfNodeIdToTopoNodeId(String nodeId, String tpId) {
864         return new StringBuilder(nodeId).append("-").append(tpId.split("-")[0]).toString();
865     }
866
867     private static String formatNodeName(String nodeName, String tpName) {
868         return nodeName.contains("-XPDR")
869             ? nodeName
870             : new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
871     }
872
873     @SuppressFBWarnings(
874             value = "UPM_UNCALLED_PRIVATE_METHOD",
875             justification = "false positive, this method is used by public updateOpenRoadmNetworkTopology")
876     private void sendNotification() {
877         if (topologyChanges.isEmpty()) {
878             LOG.warn("Empty Topology Change List. No updates in topology");
879             return;
880         }
881         this.notification = new TopologyUpdateResultBuilder()
882             .setTopologyChanges(topologyChanges)
883             .build();
884         try {
885             notificationPublishService.putNotification(this.notification);
886         } catch (InterruptedException e) {
887             LOG.error("Notification offer rejected. Error={}", e.getMessage());
888         }
889     }
890 }