Merge "Fix func. tests utils base URL generation issue"
[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.rev220114.OpenroadmNodeVersion;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mapping.Mapping;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.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.rev210930.link.tp.LinkTp;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.link.tp.LinkTpBuilder;
49 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.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 OTUC2:
402             case OTUC3:
403             case OTUC4:
404                 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, null, null, linkType);
405                 break;
406             case ODTU4:
407             case ODUC2:
408             case ODUC3:
409             case ODUC4:
410                 List<LinkId> linkIdList = new ArrayList<>();
411                 if (suppLinks != null) {
412                     suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
413                 }
414                 List<Link> supportedOtu4links = getOtnLinks(linkIdList);
415                 String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
416                     notifLink.getATermination().getTpId());
417                 String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
418                     notifLink.getZTermination().getTpId());
419                 List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, notifLink.getATermination().getTpId(), nodeTopoZ,
420                     notifLink.getZTermination().getTpId());
421                 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, supportedOtu4links, tps, linkType);
422                 break;
423             default:
424                 LOG.error("unknown otn link type {}", linkType);
425                 otnTopologyShard = new TopologyShard(null, null);
426         }
427         if (otnTopologyShard.getLinks() != null) {
428             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
429                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
430                     NetworkUtils.OVERLAY_NETWORK_ID);
431                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
432                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
433                     .augmentation(Network1.class)
434                     .child(Link.class, otnTopologyLink.key())
435                     .build();
436                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
437             }
438         }
439         if (otnTopologyShard.getTps() != null) {
440             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
441                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
442                 List<SupportingTerminationPoint> supportingTerminationPoint =
443                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
444                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
445                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
446                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
447                     .augmentation(Node1.class)
448                     .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
449                     .build();
450                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
451             }
452         }
453         try {
454             networkTransactionService.commit().get();
455         } catch (InterruptedException | ExecutionException e) {
456             LOG.error("Error adding OTN links in otn-topology", e);
457         }
458         LOG.info("OTN links created");
459     }
460
461     @Override
462     public void deleteOtnLinks(
463         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
464         notifLink, List<String> suppLinks, OtnLinkType linkType) {
465
466         TopologyShard otnTopologyShard;
467         String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
468             notifLink.getATermination().getTpId());
469         String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
470             notifLink.getZTermination().getTpId());
471         String tpA = notifLink.getATermination().getTpId();
472         String tpZ = notifLink.getZTermination().getTpId();
473         List<Link> otuLinks;
474         List<LinkId> linkIdList = new ArrayList<>();
475         switch (linkType) {
476             case OTU4:
477             case OTUC2:
478             case OTUC3:
479             case OTUC4:
480                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, linkType.getName()));
481                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, linkType.getName()));
482                 otuLinks = getOtnLinks(linkIdList);
483                 if (checkLinks(otuLinks)) {
484                     deleteLinks(otuLinks);
485                 } else {
486                     LOG.error("Error deleting OTU4 links");
487                 }
488                 otnTopologyShard = new TopologyShard(null, null);
489                 break;
490             case ODTU4:
491             case ODUC2:
492             case ODUC3:
493             case ODUC4:
494                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, linkType.getName()));
495                 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, linkType.getName()));
496                 List<Link> oduLinks = getOtnLinks(linkIdList);
497                 List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, tpA, nodeTopoZ, tpZ);
498                 if (checkLinks(oduLinks) && checkTerminationPoints(tps)) {
499                     deleteLinks(oduLinks);
500                     linkIdList.clear();
501                     if (suppLinks != null) {
502                         suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
503                     }
504                     otuLinks = getOtnLinks(linkIdList);
505
506                     otnTopologyShard = OpenRoadmOtnTopology.deleteOtnLinks(otuLinks, tps, linkType);
507                 } else {
508                     LOG.error("Error deleting ODU4 links");
509                     otnTopologyShard = new TopologyShard(null, null);
510                 }
511                 break;
512             default:
513                 LOG.error("unknown otn link type {}", linkType);
514                 otnTopologyShard = new TopologyShard(null, null);
515         }
516
517         if (otnTopologyShard.getLinks() != null) {
518             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
519                 LOG.info("deleting and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
520                     NetworkUtils.OVERLAY_NETWORK_ID);
521                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
522                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
523                     .augmentation(Network1.class)
524                     .child(Link.class, otnTopologyLink.key())
525                     .build();
526                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
527             }
528         }
529         if (otnTopologyShard.getTps() != null) {
530             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
531                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
532                 List<SupportingTerminationPoint> supportingTerminationPoint =
533                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
534                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
535                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
536                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
537                     .augmentation(Node1.class)
538                     .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
539                     .build();
540                 networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
541             }
542         }
543         try {
544             networkTransactionService.commit().get();
545         } catch (InterruptedException | ExecutionException e) {
546             LOG.error("Error deleting OTN links in otn-topology", e);
547         }
548         LOG.info("OTN links deletion terminated");
549     }
550
551     @Override
552     public void updateOtnLinks(
553         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
554             notifLink, List<String> suppLinks, Uint32 serviceRate, Short tribPortNb, Short minTribSoltNb,
555             Short maxTribSlotNb, boolean isDeletion) {
556
557         List<LinkTp> linkTerminations = new ArrayList<>();
558         List<Link> supportedOdu4Links = null;
559         if (notifLink != null) {
560             // retreive termination-points to be updated
561             linkTerminations.add(new LinkTpBuilder()
562                     .setNodeId(notifLink.getATermination().getNodeId())
563                     .setTpId(notifLink.getATermination().getTpId())
564                     .build());
565             linkTerminations.add(new LinkTpBuilder()
566                     .setNodeId(notifLink.getZTermination().getNodeId())
567                     .setTpId(notifLink.getZTermination().getTpId())
568                     .build());
569             // retreive supported links
570             supportedOdu4Links = getSupportingOdu4Links(linkTerminations, serviceRate);
571         } else if (suppLinks != null) {
572              // retreive supported links
573             List<LinkId> linkIdList = new ArrayList<>();
574             if (suppLinks != null) {
575                 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
576             }
577             supportedOdu4Links = getOtnLinks(linkIdList);
578             // retreive termination-points to be updated
579             for (Link link : supportedOdu4Links) {
580                 LinkTp atermination = new LinkTpBuilder()
581                     .setNodeId(link.getSource().getSourceNode().getValue())
582                     .setTpId(link.getSource().getSourceTp().getValue())
583                     .build();
584                 linkTerminations.add(atermination);
585             }
586         } else {
587             LOG.error("Impossible to update OTN links and their associated termination points in otn-topology");
588             return;
589         }
590         List<TerminationPoint> tps = getOtnNodeTps(linkTerminations);
591         TopologyShard otnTopologyShard;
592         otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOdu4Links, tps, serviceRate, tribPortNb,
593             minTribSoltNb, maxTribSlotNb, isDeletion);
594         if (otnTopologyShard.getLinks() != null) {
595             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
596                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
597                     NetworkUtils.OVERLAY_NETWORK_ID);
598                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
599                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
600                     .augmentation(Network1.class)
601                     .child(Link.class, new LinkKey(new LinkId(otnTopologyLink.getLinkId().getValue())))
602                     .build();
603                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
604             }
605         }
606         if (otnTopologyShard.getTps() != null) {
607             for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
608                 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
609                 List<SupportingTerminationPoint> supportingTerminationPoint =
610                     new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
611                 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
612                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
613                     .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
614                     .augmentation(Node1.class)
615                     .child(TerminationPoint.class, new TerminationPointKey(new TpId(otnTopologyTp.getTpId()
616                         .getValue())))
617                     .build();
618                 if (isDeletion) {
619                     networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
620                 } else {
621                     networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
622                 }
623             }
624         }
625         try {
626             networkTransactionService.commit().get();
627         } catch (InterruptedException | ExecutionException e) {
628             LOG.error("Error updating OTN links in otn-topology", e);
629         }
630     }
631
632     @Override
633     public void updateOtnLinks(List<String> suppLinks, boolean isDeletion) {
634         List<LinkId> linkIdList = new ArrayList<>();
635         if (suppLinks != null) {
636             suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
637         }
638         List<Link> supportedOtu4links = getOtnLinks(linkIdList);
639
640         TopologyShard otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOtu4links, isDeletion);
641         if (otnTopologyShard.getLinks() != null) {
642             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
643                 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
644                     NetworkUtils.OVERLAY_NETWORK_ID);
645                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
646                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
647                     .augmentation(Network1.class)
648                     .child(Link.class, otnTopologyLink.key())
649                     .build();
650                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
651             }
652         }
653         try {
654             networkTransactionService.commit().get();
655         } catch (InterruptedException | ExecutionException e) {
656             LOG.error("Error adding OTN links in otn-topology", e);
657         }
658         LOG.info("OTN links updated");
659     }
660
661     private List<Link> getOtnLinks(List<LinkId> linkIds) {
662         List<Link> links = new ArrayList<>();
663         for (LinkId linkId : linkIds) {
664             InstanceIdentifier<Link> iiLink = InstanceIdentifier.builder(Networks.class)
665                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
666                 .augmentation(Network1.class)
667                 .child(Link.class, new LinkKey(linkId))
668                 .build();
669             ListenableFuture<Optional<Link>> linkOptLf = networkTransactionService
670                 .read(LogicalDatastoreType.CONFIGURATION, iiLink);
671             if (linkOptLf.isDone()) {
672                 try {
673                     if (linkOptLf.get().isPresent()) {
674                         links.add(linkOptLf.get().get());
675                     }
676                 } catch (InterruptedException | ExecutionException e) {
677                     LOG.error("Error retreiving OTN links from otn-topology", e);
678                 }
679             } else {
680                 LOG.error("Error retreiving link {} from otn-topology", linkId.getValue());
681             }
682         }
683         return links;
684     }
685
686     private boolean checkLinks(List<Link> links) {
687         if (links.isEmpty()) {
688             return false;
689         }
690         for (Link link : links) {
691             if (link.augmentation(Link1.class) != null
692                     && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
693                 return false;
694             }
695         }
696         return true;
697     }
698
699     private boolean checkTerminationPoints(List<TerminationPoint> tps) {
700         if (tps.isEmpty()) {
701             return false;
702         }
703         for (TerminationPoint tp : tps) {
704             if (tp.augmentation(TerminationPoint1.class) != null && tp.augmentation(TerminationPoint1.class)
705                     .getXpdrTpPortConnectionAttributes().getTsPool() != null && tp.augmentation(TerminationPoint1.class)
706                     .getXpdrTpPortConnectionAttributes().getTsPool().size() != 80) {
707                 return false;
708             }
709         }
710         return true;
711     }
712
713     private List<TerminationPoint> getOtnNodeTps(String nodeTopoA, String tpA, String nodeTopoZ, String tpZ) {
714         List<TerminationPoint> tps = new ArrayList<>();
715         InstanceIdentifier<TerminationPoint> iiTpA = InstanceIdentifier.builder(Networks.class)
716             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
717             .child(Node.class, new NodeKey(new NodeId(nodeTopoA)))
718             .augmentation(Node1.class)
719             .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpA)))
720             .build();
721         Optional<TerminationPoint> tpAOpt = Optional.empty();
722         InstanceIdentifier<TerminationPoint> iiTpZ = InstanceIdentifier.builder(Networks.class)
723             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
724             .child(Node.class, new NodeKey(new NodeId(nodeTopoZ)))
725             .augmentation(Node1.class)
726             .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpZ)))
727             .build();
728         Optional<TerminationPoint> tpZOpt = Optional.empty();
729
730         if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
731                 && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
732             try {
733                 tpAOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).get();
734                 tpZOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).get();
735             } catch (InterruptedException | ExecutionException e) {
736                 LOG.error("Error retreiving tp {} of node {} or tp {} from node {} from otn-topology", tpA, nodeTopoA,
737                     tpZ, nodeTopoZ, e);
738             }
739         } else {
740             LOG.error("error getting node termination points from the datastore");
741         }
742
743         if (tpAOpt.isPresent() && tpZOpt.isPresent()) {
744             tps.add(tpAOpt.get());
745             tps.add(tpZOpt.get());
746         }
747         return tps;
748     }
749
750     private List<TerminationPoint> getOtnNodeTps(List<LinkTp> linkTerminations) {
751         List<TerminationPoint> tps = new ArrayList<>();
752         for (LinkTp linkTp : linkTerminations) {
753             String tp = linkTp.getTpId();
754             String nodeId = formatNodeName(linkTp.getNodeId(), tp);
755             InstanceIdentifier<TerminationPoint> iiTp = InstanceIdentifier.builder(Networks.class)
756                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
757                 .child(Node.class, new NodeKey(new NodeId(nodeId)))
758                 .augmentation(Node1.class)
759                 .child(TerminationPoint.class, new TerminationPointKey(new TpId(tp)))
760                 .build();
761             Optional<TerminationPoint> tpOpt;
762             if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).isDone()) {
763                 try {
764                     tpOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).get();
765                     if (tpOpt.isPresent()) {
766                         tps.add(tpOpt.get());
767                     }
768                 } catch (InterruptedException | ExecutionException e) {
769                     LOG.error("Error retreiving tp {} of node {} from otn-topology", tp, nodeId, e);
770                 }
771             } else {
772                 LOG.error("error getting node termination points from the datastore");
773             }
774         }
775         return tps;
776     }
777
778     private void deleteLinks(List<Link> links) {
779         for (Link otnTopologyLink : links) {
780             LOG.info("deleting link {} from {}", otnTopologyLink.getLinkId().getValue(),
781                 NetworkUtils.OVERLAY_NETWORK_ID);
782             InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
783                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
784                 .augmentation(Network1.class)
785                 .child(Link.class, otnTopologyLink.key())
786                 .build();
787             networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink);
788         }
789         try {
790             networkTransactionService.commit().get();
791         } catch (InterruptedException | ExecutionException e) {
792             LOG.error("Error deleting OTN links from otn-topology", e);
793         }
794     }
795
796     private List<Link> getSupportingOdu4Links(List<LinkTp> nodesTopoTps, Uint32 serviceRate) {
797         InstanceIdentifier<Network1> iiOtnTopologyLinks = InstanceIdentifier.builder(Networks.class)
798             .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
799             .augmentation(Network1.class)
800             .build();
801         ListenableFuture<Optional<Network1>> netw1Fl = networkTransactionService
802             .read(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLinks);
803         Optional<Network1> netw1Opt = Optional.empty();
804         if (netw1Fl.isDone()) {
805             try {
806                 netw1Opt = netw1Fl.get();
807             } catch (InterruptedException | ExecutionException e) {
808                 LOG.error("Error retreiving list of links from otn-topology", e);
809             }
810         }
811         List<Link> odu4links = null;
812         if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
813             odu4links = netw1Opt
814                 .get()
815                 .nonnullLink().values()
816                 .stream().filter(lk -> lk.getLinkId().getValue()
817                     .startsWith(Uint32.valueOf(100).equals(serviceRate) ? "ODUC4" : "ODTU4"))
818                 .collect(Collectors.toList());
819         }
820         if (odu4links == null) {
821             return null;
822         }
823         List<Link> links = new ArrayList<>();
824         for (LinkTp linkTp : nodesTopoTps) {
825             String tp = linkTp.getTpId();
826             String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
827                 .append(tp.split("-")[0]).toString();
828             Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
829                 .equals(nodeId) && lk.getSource().getSourceTp().getValue().equals(tp)).findFirst().get();
830             if (!links.contains(slink)) {
831                 links.add(slink);
832             }
833             Link dlink = odu4links.stream().filter(lk -> lk.getDestination().getDestNode().getValue()
834                 .equals(nodeId) && lk.getDestination().getDestTp().getValue().equals(tp)).findFirst().get();
835             if (!links.contains(dlink)) {
836                 links.add(dlink);
837             }
838         }
839         LOG.debug("odu4oduC4links = {}", links);
840         return links;
841     }
842
843     private void createOpenRoadmOtnNode(String nodeId) {
844         TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
845         if (otnTopologyShard != null) {
846             this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
847             for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
848                 LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
849                     NetworkUtils.OTN_NETWORK_ID);
850                 InstanceIdentifier<Node> iiOtnTopologyNode = InstanceIdentifier.builder(Networks.class)
851                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
852                     .child(Node.class, otnTopologyNode.key())
853                     .build();
854                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
855             }
856             for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
857                 LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
858                     NetworkUtils.OVERLAY_NETWORK_ID);
859                 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
860                     .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
861                     .augmentation(Network1.class)
862                     .child(Link.class, otnTopologyLink.key())
863                     .build();
864                 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
865             }
866         } else {
867             LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
868         }
869     }
870
871     private String convertNetconfNodeIdToTopoNodeId(String nodeId, String tpId) {
872         return new StringBuilder(nodeId).append("-").append(tpId.split("-")[0]).toString();
873     }
874
875     private static String formatNodeName(String nodeName, String tpName) {
876         return nodeName.contains("-XPDR")
877             ? nodeName
878             : new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
879     }
880
881     @SuppressFBWarnings(
882             value = "UPM_UNCALLED_PRIVATE_METHOD",
883             justification = "false positive, this method is used by public updateOpenRoadmNetworkTopology")
884     private void sendNotification() {
885         if (topologyChanges.isEmpty()) {
886             LOG.warn("Empty Topology Change List. No updates in topology");
887             return;
888         }
889         this.notification = new TopologyUpdateResultBuilder()
890             .setTopologyChanges(topologyChanges)
891             .build();
892         try {
893             notificationPublishService.putNotification(this.notification);
894         } catch (InterruptedException e) {
895             LOG.error("Notification offer rejected. Error={}", e.getMessage());
896         }
897     }
898 }