2 * Copyright © 2016 AT&T and others. All rights reserved.
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
8 package org.opendaylight.transportpce.networkmodel.service;
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;
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;
72 public class NetworkModelServiceImpl implements NetworkModelService {
74 private static final Logger LOG = LoggerFactory.getLogger(NetworkModelServiceImpl.class);
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;
86 public NetworkModelServiceImpl(final NetworkTransactionService networkTransactionService,
87 final R2RLinkDiscovery linkDiscovery, PortMapping portMapping,
88 final NotificationPublishService notificationPublishService) {
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>();
100 LOG.info("init ...");
103 public void close() {
107 public void createOpenRoadmNode(String nodeId, String openRoadmVersion) {
109 LOG.info("createOpenROADMNode: {} ", nodeId);
111 if (!portMapping.createMappingData(nodeId, openRoadmVersion)) {
112 LOG.warn("Could not generate port mapping for {} skipping network model creation", nodeId);
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())
122 LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
123 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode);
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())
131 LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
132 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode,
133 openroadmNetworkNode);
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())
146 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
147 openRoadmTopologyNode);
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())
157 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
158 openRoadmTopologyLink);
161 LOG.error("Unable to create openroadm-topology shard for node {}!", nodeId);
163 // nodes/links creation in otn-topology
164 if (nodeInfo.getNodeType().getIntValue() == 2 && (nodeInfo.getOpenroadmVersion().getIntValue() != 1)) {
165 createOpenRoadmOtnNode(nodeId);
167 networkTransactionService.commit().get();
168 // neighbour links through LLDP
169 if (nodeInfo.getNodeType().getIntValue() == 1) {
170 this.linkDiscovery.readLLDP(new NodeId(nodeId), openRoadmVersion);
172 LOG.info("all nodes and links created");
173 } catch (InterruptedException | ExecutionException e) {
174 LOG.error("ERROR: ", e);
179 public void setOpenRoadmNodeStatus(String nodeId, NetconfNodeConnectionStatus.ConnectionStatus connectionStatus) {
180 LOG.info("setOpenROADMNodeStatus: {} {}", nodeId, connectionStatus.name());
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
190 @see org.opendaylight.transportpce.networkmodel.service.NetworkModelService# deleteOpenROADMnode(java.lang.String)
194 public boolean deleteOpenRoadmnode(String nodeId) {
196 if (!this.portMapping.isNodeExist(nodeId)) {
199 NodeKey nodeIdKey = new NodeKey(new NodeId(nodeId));
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)
206 this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode);
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())
217 this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode);
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())
227 this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink);
230 LOG.warn("TopologyShard for node '{}' is not present", nodeId);
233 OpenroadmNodeVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
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())
247 this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyNode);
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())
257 this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyLink);
262 LOG.info("deleteOpenROADMnode: {} version {}", nodeId, deviceVersion.getName());
263 this.portMapping.deletePortMappingNode(nodeId);
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);
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;
283 openroadmTopology = this.networkTransactionService
284 .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OVERLAY_NETWORK_II)
286 if (openroadmTopology.augmentation(Network1.class) != null) {
287 openroadmTopologyLinks = openroadmTopology.augmentation(Network1.class).getLink();
289 otnTopology = this.networkTransactionService
290 .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OTN_NETWORK_II)
292 if (otnTopology.augmentation(Network1.class) != null) {
293 otnTopologyLinks = otnTopology.augmentation(Network1.class).getLink();
295 } catch (InterruptedException | ExecutionException e) {
296 LOG.error("Error when trying to update node : {}", nodeId, e);
298 if (openroadmTopology == null || otnTopology == null) {
299 LOG.warn("Error getting topologies from datastore");
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())
316 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
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()))
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())
337 if (!this.topologyChanges.containsKey(tc.key())) {
338 this.topologyChanges.put(tc.key(), tc);
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())
357 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
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()))
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())
378 if (!this.topologyChanges.containsKey(tc.key())) {
379 this.topologyChanges.put(tc.key(), tc);
384 // commit datastore updates
386 networkTransactionService.commit().get();
388 } catch (InterruptedException | ExecutionException e) {
389 LOG.error("Error updating openroadm-topology", e);
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) {
398 TopologyShard otnTopologyShard;
404 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, null, null, linkType);
410 List<LinkId> linkIdList = new ArrayList<>();
411 if (suppLinks != null) {
412 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
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);
424 LOG.error("unknown otn link type {}", linkType);
425 otnTopologyShard = new TopologyShard(null, null);
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())
436 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
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()))
450 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
454 networkTransactionService.commit().get();
455 } catch (InterruptedException | ExecutionException e) {
456 LOG.error("Error adding OTN links in otn-topology", e);
458 LOG.info("OTN links created");
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) {
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();
474 List<LinkId> linkIdList = new ArrayList<>();
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);
486 LOG.error("Error deleting OTU4 links");
488 otnTopologyShard = new TopologyShard(null, null);
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);
501 if (suppLinks != null) {
502 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
504 otuLinks = getOtnLinks(linkIdList);
506 otnTopologyShard = OpenRoadmOtnTopology.deleteOtnLinks(otuLinks, tps, linkType);
508 LOG.error("Error deleting ODU4 links");
509 otnTopologyShard = new TopologyShard(null, null);
513 LOG.error("unknown otn link type {}", linkType);
514 otnTopologyShard = new TopologyShard(null, null);
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())
526 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
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()))
540 networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
544 networkTransactionService.commit().get();
545 } catch (InterruptedException | ExecutionException e) {
546 LOG.error("Error deleting OTN links in otn-topology", e);
548 LOG.info("OTN links deletion terminated");
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) {
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())
565 linkTerminations.add(new LinkTpBuilder()
566 .setNodeId(notifLink.getZTermination().getNodeId())
567 .setTpId(notifLink.getZTermination().getTpId())
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)));
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())
584 linkTerminations.add(atermination);
587 LOG.error("Impossible to update OTN links and their associated termination points in otn-topology");
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())))
603 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
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()
619 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
621 networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
626 networkTransactionService.commit().get();
627 } catch (InterruptedException | ExecutionException e) {
628 LOG.error("Error updating OTN links in otn-topology", e);
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)));
638 List<Link> supportedOtu4links = getOtnLinks(linkIdList);
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())
650 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
654 networkTransactionService.commit().get();
655 } catch (InterruptedException | ExecutionException e) {
656 LOG.error("Error adding OTN links in otn-topology", e);
658 LOG.info("OTN links updated");
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))
669 ListenableFuture<Optional<Link>> linkOptLf = networkTransactionService
670 .read(LogicalDatastoreType.CONFIGURATION, iiLink);
671 if (linkOptLf.isDone()) {
673 if (linkOptLf.get().isPresent()) {
674 links.add(linkOptLf.get().get());
676 } catch (InterruptedException | ExecutionException e) {
677 LOG.error("Error retreiving OTN links from otn-topology", e);
680 LOG.error("Error retreiving link {} from otn-topology", linkId.getValue());
686 private boolean checkLinks(List<Link> links) {
687 if (links.isEmpty()) {
690 for (Link link : links) {
691 if (link.augmentation(Link1.class) != null
692 && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
699 private boolean checkTerminationPoints(List<TerminationPoint> tps) {
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) {
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)))
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)))
728 Optional<TerminationPoint> tpZOpt = Optional.empty();
730 if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
731 && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
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,
740 LOG.error("error getting node termination points from the datastore");
743 if (tpAOpt.isPresent() && tpZOpt.isPresent()) {
744 tps.add(tpAOpt.get());
745 tps.add(tpZOpt.get());
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)))
761 Optional<TerminationPoint> tpOpt;
762 if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).isDone()) {
764 tpOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).get();
765 if (tpOpt.isPresent()) {
766 tps.add(tpOpt.get());
768 } catch (InterruptedException | ExecutionException e) {
769 LOG.error("Error retreiving tp {} of node {} from otn-topology", tp, nodeId, e);
772 LOG.error("error getting node termination points from the datastore");
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())
787 networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink);
790 networkTransactionService.commit().get();
791 } catch (InterruptedException | ExecutionException e) {
792 LOG.error("Error deleting OTN links from otn-topology", e);
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)
801 ListenableFuture<Optional<Network1>> netw1Fl = networkTransactionService
802 .read(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLinks);
803 Optional<Network1> netw1Opt = Optional.empty();
804 if (netw1Fl.isDone()) {
806 netw1Opt = netw1Fl.get();
807 } catch (InterruptedException | ExecutionException e) {
808 LOG.error("Error retreiving list of links from otn-topology", e);
811 List<Link> odu4links = null;
812 if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
815 .nonnullLink().values()
816 .stream().filter(lk -> lk.getLinkId().getValue()
817 .startsWith(Uint32.valueOf(100).equals(serviceRate) ? "ODUC4" : "ODTU4"))
818 .collect(Collectors.toList());
820 if (odu4links == null) {
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)) {
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)) {
839 LOG.debug("odu4oduC4links = {}", links);
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())
854 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
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())
864 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
867 LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
871 private String convertNetconfNodeIdToTopoNodeId(String nodeId, String tpId) {
872 return new StringBuilder(nodeId).append("-").append(tpId.split("-")[0]).toString();
875 private static String formatNodeName(String nodeName, String tpName) {
876 return nodeName.contains("-XPDR")
878 : new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
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");
889 this.notification = new TopologyUpdateResultBuilder()
890 .setTopologyChanges(topologyChanges)
893 notificationPublishService.putNotification(this.notification);
894 } catch (InterruptedException e) {
895 LOG.error("Notification offer rejected. Error={}", e.getMessage());