Manage ODU4 services over multiple OTU4
[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, Uint32 serviceRate, Short tribPortNb, Short minTribSoltNb, Short maxTribSlotNb,
547             boolean isDeletion) {
548
549         LinkTp atermination = new LinkTpBuilder()
550             .setNodeId(notifLink.getATermination().getNodeId())
551             .setTpId(notifLink.getATermination().getTpId())
552             .build();
553         LinkTp ztermination = new LinkTpBuilder()
554             .setNodeId(notifLink.getZTermination().getNodeId())
555             .setTpId(notifLink.getZTermination().getTpId())
556             .build();
557         List<LinkTp> linkTerminations = new ArrayList<>();
558         linkTerminations.add(atermination);
559         linkTerminations.add(ztermination);
560
561         List<Link> supportedOdu4Links = getSupportingOdu4Links(linkTerminations, serviceRate);
562         List<TerminationPoint> tps = getOtnNodeTps(linkTerminations);
563         TopologyShard otnTopologyShard;
564         otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOdu4Links, tps, serviceRate, tribPortNb,
565             minTribSoltNb, maxTribSlotNb, isDeletion);
566         if (otnTopologyShard.getLinks() != null) {
567             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
568                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
569                     NetworkUtils.OVERLAY_NETWORK_ID);
570                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
571                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
572                     .augmentation(Network1.class)
573                     .child(Link.class, new LinkKey(new LinkId(otnTopologyLink.getLinkId().getValue())))
574                     .build();
575                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
576             }
577         }
578         if (otnTopologyShard.getTps() != null) {
579             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
580                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
581                 List<SupportingTerminationPoint> supportingTerminationPoint =
582                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
583                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
584                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
585                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
586                     .augmentation(Node1.class)
587                     .child(TerminationPoint.class, new TerminationPointKey(new TpId(otnTopologyTp.getTpId()
588                         .getValue())))
589                     .build();
590                 if (isDeletion) {
591                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
592                 } else {
593                     networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
594                 }
595             }
596         }
597         try {
598             networkTransactionService.commit().get();
599         } catch (InterruptedException | ExecutionException e) {
600             LOG.error("Error updating OTN links in otn-topology", e);
601         }
602     }
603
604     @Override
605     public void updateOtnLinks(List<String> suppLinks, boolean isDeletion) {
606         List<LinkId> linkIdList = new ArrayList<>();
607         if (suppLinks != null) {
608             suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
609         }
610         List<Link> supportedOtu4links = getOtnLinks(linkIdList);
611
612         TopologyShard otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOtu4links, isDeletion);
613         if (otnTopologyShard.getLinks() != null) {
614             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
615                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
616                     NetworkUtils.OVERLAY_NETWORK_ID);
617                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
618                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
619                     .augmentation(Network1.class)
620                     .child(Link.class, otnTopologyLink.key())
621                     .build();
622                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
623             }
624         }
625         try {
626             networkTransactionService.commit().get();
627         } catch (InterruptedException | ExecutionException e) {
628             LOG.error("Error adding OTN links in otn-topology", e);
629         }
630         LOG.info("OTN links updated");
631     }
632
633     private List<Link> getOtnLinks(List<LinkId> linkIds) {
634         List<Link> links = new ArrayList<>();
635         for (LinkId linkId : linkIds) {
636             InstanceIdentifier<Link> iiLink = InstanceIdentifier.builder(Networks.class)
637                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
638                 .augmentation(Network1.class)
639                 .child(Link.class, new LinkKey(linkId))
640                 .build();
641             ListenableFuture<Optional<Link>> linkOptLf = networkTransactionService
642                 .read(LogicalDatastoreType.CONFIGURATION, iiLink);
643             if (linkOptLf.isDone()) {
644                 try {
645                     if (linkOptLf.get().isPresent()) {
646                         links.add(linkOptLf.get().get());
647                     }
648                 } catch (InterruptedException | ExecutionException e) {
649                     LOG.error("Error retreiving OTN links from otn-topology", e);
650                 }
651             } else {
652                 LOG.error("Error retreiving link {} from otn-topology", linkId.getValue());
653             }
654         }
655         return links;
656     }
657
658     private boolean checkLinks(List<Link> links) {
659         if (links.isEmpty()) {
660             return false;
661         }
662         for (Link link : links) {
663             if (link.augmentation(Link1.class) != null
664                     && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
665                 return false;
666             }
667         }
668         return true;
669     }
670
671     private boolean checkTerminationPoints(List<TerminationPoint> tps) {
672         if (tps.isEmpty()) {
673             return false;
674         }
675         for (TerminationPoint tp : tps) {
676             if (tp.augmentation(TerminationPoint1.class) != null && tp.augmentation(TerminationPoint1.class)
677                     .getXpdrTpPortConnectionAttributes().getTsPool() != null && tp.augmentation(TerminationPoint1.class)
678                     .getXpdrTpPortConnectionAttributes().getTsPool().size() != 80) {
679                 return false;
680             }
681         }
682         return true;
683     }
684
685     private List<TerminationPoint> getOtnNodeTps(String nodeTopoA, String tpA, String nodeTopoZ, String tpZ) {
686         List<TerminationPoint> tps = new ArrayList<>();
687         InstanceIdentifier<TerminationPoint> iiTpA = InstanceIdentifier.builder(Networks.class)
688             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
689             .child(Node.class, new NodeKey(new NodeId(nodeTopoA)))
690             .augmentation(Node1.class)
691             .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpA)))
692             .build();
693         Optional<TerminationPoint> tpAOpt = Optional.empty();
694         InstanceIdentifier<TerminationPoint> iiTpZ = InstanceIdentifier.builder(Networks.class)
695             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
696             .child(Node.class, new NodeKey(new NodeId(nodeTopoZ)))
697             .augmentation(Node1.class)
698             .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpZ)))
699             .build();
700         Optional<TerminationPoint> tpZOpt = Optional.empty();
701
702         if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
703                 && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
704             try {
705                 tpAOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).get();
706                 tpZOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).get();
707             } catch (InterruptedException | ExecutionException e) {
708                 LOG.error("Error retreiving tp {} of node {} or tp {} from node {} from otn-topology", tpA, nodeTopoA,
709                     tpZ, nodeTopoZ, e);
710             }
711         } else {
712             LOG.error("error getting node termination points from the datastore");
713         }
714
715         if (tpAOpt.isPresent() && tpZOpt.isPresent()) {
716             tps.add(tpAOpt.get());
717             tps.add(tpZOpt.get());
718         }
719         return tps;
720     }
721
722     private List<TerminationPoint> getOtnNodeTps(List<LinkTp> linkTerminations) {
723         List<TerminationPoint> tps = new ArrayList<>();
724         for (LinkTp linkTp : linkTerminations) {
725             String tp = linkTp.getTpId();
726             String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
727                 .append(tp.split("-")[0]).toString();
728             InstanceIdentifier<TerminationPoint> iiTp = InstanceIdentifier.builder(Networks.class)
729                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
730                 .child(Node.class, new NodeKey(new NodeId(nodeId)))
731                 .augmentation(Node1.class)
732                 .child(TerminationPoint.class, new TerminationPointKey(new TpId(tp)))
733                 .build();
734             Optional<TerminationPoint> tpOpt;
735             if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).isDone()) {
736                 try {
737                     tpOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).get();
738                     if (tpOpt.isPresent()) {
739                         tps.add(tpOpt.get());
740                     }
741                 } catch (InterruptedException | ExecutionException e) {
742                     LOG.error("Error retreiving tp {} of node {} from otn-topology", tp, nodeId, e);
743                 }
744             } else {
745                 LOG.error("error getting node termination points from the datastore");
746             }
747         }
748         if (tps.isEmpty()) {
749             LOG.warn("returning null");
750             return null;
751         } else {
752             LOG.info("returning tps = {}", tps.toString());
753             return tps;
754         }
755     }
756
757     private void deleteLinks(List<Link> links) {
758         for (Link otnTopologyLink : links) {
759             LOG.info("deleting link {} from {}", otnTopologyLink.getLinkId().getValue(),
760                 NetworkUtils.OVERLAY_NETWORK_ID);
761             InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
762                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
763                 .augmentation(Network1.class)
764                 .child(Link.class, otnTopologyLink.key())
765                 .build();
766             networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink);
767         }
768         try {
769             networkTransactionService.commit().get();
770         } catch (InterruptedException | ExecutionException e) {
771             LOG.error("Error deleting OTN links from otn-topology", e);
772         }
773     }
774
775     private List<Link> getSupportingOdu4Links(List<LinkTp> nodesTopoTps, Uint32 serviceRate) {
776         InstanceIdentifier<Network1> iiOtnTopologyLinks = InstanceIdentifier.builder(Networks.class)
777             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
778             .augmentation(Network1.class)
779             .build();
780         ListenableFuture<Optional<Network1>> netw1Fl = networkTransactionService
781             .read(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLinks);
782         Optional<Network1> netw1Opt = Optional.empty();
783         if (netw1Fl.isDone()) {
784             try {
785                 netw1Opt = netw1Fl.get();
786             } catch (InterruptedException | ExecutionException e) {
787                 LOG.error("Error retreiving list of links from otn-topology", e);
788             }
789         }
790         List<Link> odu4links = null;
791         if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
792             odu4links = netw1Opt
793                 .get()
794                 .nonnullLink().values()
795                 .stream().filter(lk -> lk.getLinkId().getValue()
796                     .startsWith(Uint32.valueOf(100).equals(serviceRate) ? "ODUC4" : "ODTU4"))
797                 .collect(Collectors.toList());
798         }
799         if (odu4links == null) {
800             return null;
801         }
802         List<Link> links = new ArrayList<>();
803         for (LinkTp linkTp : nodesTopoTps) {
804             String tp = linkTp.getTpId();
805             String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
806                 .append(tp.split("-")[0]).toString();
807             Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
808                 .equals(nodeId) && lk.getSource().getSourceTp().getValue().equals(tp)).findFirst().get();
809             if (!links.contains(slink)) {
810                 links.add(slink);
811             }
812             Link dlink = odu4links.stream().filter(lk -> lk.getDestination().getDestNode().getValue()
813                 .equals(nodeId) && lk.getDestination().getDestTp().getValue().equals(tp)).findFirst().get();
814             if (!links.contains(dlink)) {
815                 links.add(dlink);
816             }
817         }
818         LOG.debug("odu4oduC4links = {}", links);
819         return links;
820     }
821
822     private void createOpenRoadmOtnNode(String nodeId) {
823         TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
824         if (otnTopologyShard != null) {
825             this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
826             for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
827                 LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
828                     NetworkUtils.OTN_NETWORK_ID);
829                 InstanceIdentifier<Node> iiOtnTopologyNode = InstanceIdentifier.builder(Networks.class)
830                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
831                     .child(Node.class, otnTopologyNode.key())
832                     .build();
833                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
834             }
835             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
836                 LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
837                     NetworkUtils.OVERLAY_NETWORK_ID);
838                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
839                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
840                     .augmentation(Network1.class)
841                     .child(Link.class, otnTopologyLink.key())
842                     .build();
843                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
844             }
845         } else {
846             LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
847         }
848     }
849
850     private String convertNetconfNodeIdToTopoNodeId(String nodeId, String tpId) {
851         return new StringBuilder(nodeId).append("-").append(tpId.split("-")[0]).toString();
852     }
853
854     @SuppressFBWarnings(
855             value = "UPM_UNCALLED_PRIVATE_METHOD",
856             justification = "false positive, this method is used by public updateOpenRoadmNetworkTopology")
857     private void sendNotification() {
858         if (topologyChanges.isEmpty()) {
859             LOG.warn("Empty Topology Change List. No updates in topology");
860             return;
861         }
862         this.notification = new TopologyUpdateResultBuilder()
863             .setTopologyChanges(topologyChanges)
864             .build();
865         try {
866             notificationPublishService.putNotification(this.notification);
867         } catch (InterruptedException e) {
868             LOG.error("Notification offer rejected. Error={}", e.getMessage());
869         }
870     }
871 }