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.rev210511.OtnLinkType;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointKey;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.termination.point.SupportingTerminationPoint;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
67 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
68 import org.opendaylight.yangtools.yang.common.Uint32;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
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;
402 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, null, null, linkType);
406 List<LinkId> linkIdList = new ArrayList<>();
407 if (suppLinks != null) {
408 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
410 List<Link> supportedOtu4links = getOtnLinks(linkIdList);
411 String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
412 notifLink.getATermination().getTpId());
413 String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
414 notifLink.getZTermination().getTpId());
415 List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, notifLink.getATermination().getTpId(), nodeTopoZ,
416 notifLink.getZTermination().getTpId());
417 otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(notifLink, supportedOtu4links, tps, linkType);
420 LOG.error("unknown otn link type {}", linkType);
421 otnTopologyShard = new TopologyShard(null, null);
423 if (otnTopologyShard.getLinks() != null) {
424 for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
425 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
426 NetworkUtils.OVERLAY_NETWORK_ID);
427 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
428 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
429 .augmentation(Network1.class)
430 .child(Link.class, otnTopologyLink.key())
432 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
435 if (otnTopologyShard.getTps() != null) {
436 for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
437 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
438 List<SupportingTerminationPoint> supportingTerminationPoint =
439 new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
440 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
441 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
442 .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
443 .augmentation(Node1.class)
444 .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
446 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
450 networkTransactionService.commit().get();
451 } catch (InterruptedException | ExecutionException e) {
452 LOG.error("Error adding OTN links in otn-topology", e);
454 LOG.info("OTN links created");
458 public void deleteOtnLinks(
459 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
460 notifLink, List<String> suppLinks, OtnLinkType linkType) {
462 TopologyShard otnTopologyShard;
463 String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
464 notifLink.getATermination().getTpId());
465 String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
466 notifLink.getZTermination().getTpId());
467 String tpA = notifLink.getATermination().getTpId();
468 String tpZ = notifLink.getZTermination().getTpId();
470 List<LinkId> linkIdList = new ArrayList<>();
474 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, linkType.getName()));
475 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, linkType.getName()));
476 otuLinks = getOtnLinks(linkIdList);
477 if (checkLinks(otuLinks)) {
478 deleteLinks(otuLinks);
480 LOG.error("Error deleting OTU4 links");
482 otnTopologyShard = new TopologyShard(null, null);
486 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, linkType.getName()));
487 linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, linkType.getName()));
488 List<Link> oduLinks = getOtnLinks(linkIdList);
489 List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, tpA, nodeTopoZ, tpZ);
490 if (checkLinks(oduLinks) && checkTerminationPoints(tps)) {
491 deleteLinks(oduLinks);
493 if (suppLinks != null) {
494 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
496 otuLinks = getOtnLinks(linkIdList);
498 otnTopologyShard = OpenRoadmOtnTopology.deleteOtnLinks(otuLinks, tps, linkType);
500 LOG.error("Error deleting ODU4 links");
501 otnTopologyShard = new TopologyShard(null, null);
505 LOG.error("unknown otn link type {}", linkType);
506 otnTopologyShard = new TopologyShard(null, null);
509 if (otnTopologyShard.getLinks() != null) {
510 for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
511 LOG.info("deleting and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
512 NetworkUtils.OVERLAY_NETWORK_ID);
513 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
514 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
515 .augmentation(Network1.class)
516 .child(Link.class, otnTopologyLink.key())
518 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
521 if (otnTopologyShard.getTps() != null) {
522 for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
523 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
524 List<SupportingTerminationPoint> supportingTerminationPoint =
525 new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
526 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
527 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
528 .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
529 .augmentation(Node1.class)
530 .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
532 networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
536 networkTransactionService.commit().get();
537 } catch (InterruptedException | ExecutionException e) {
538 LOG.error("Error deleting OTN links in otn-topology", e);
540 LOG.info("OTN links deletion terminated");
544 public void updateOtnLinks(
545 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
546 notifLink, List<String> suppLinks, Uint32 serviceRate, Short tribPortNb, Short minTribSoltNb,
547 Short maxTribSlotNb, boolean isDeletion) {
549 List<LinkTp> linkTerminations = new ArrayList<>();
550 List<Link> supportedOdu4Links = null;
551 if (notifLink != null) {
552 // retreive termination-points to be updated
553 linkTerminations.add(new LinkTpBuilder()
554 .setNodeId(notifLink.getATermination().getNodeId())
555 .setTpId(notifLink.getATermination().getTpId())
557 linkTerminations.add(new LinkTpBuilder()
558 .setNodeId(notifLink.getZTermination().getNodeId())
559 .setTpId(notifLink.getZTermination().getTpId())
561 // retreive supported links
562 supportedOdu4Links = getSupportingOdu4Links(linkTerminations, serviceRate);
563 } else if (suppLinks != null) {
564 // retreive supported links
565 List<LinkId> linkIdList = new ArrayList<>();
566 if (suppLinks != null) {
567 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
569 supportedOdu4Links = getOtnLinks(linkIdList);
570 // retreive termination-points to be updated
571 for (Link link : supportedOdu4Links) {
572 LinkTp atermination = new LinkTpBuilder()
573 .setNodeId(link.getSource().getSourceNode().getValue())
574 .setTpId(link.getSource().getSourceTp().getValue())
576 linkTerminations.add(atermination);
579 LOG.error("Impossible to update OTN links and their associated termination points in otn-topology");
582 List<TerminationPoint> tps = getOtnNodeTps(linkTerminations);
583 TopologyShard otnTopologyShard;
584 otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOdu4Links, tps, serviceRate, tribPortNb,
585 minTribSoltNb, maxTribSlotNb, isDeletion);
586 if (otnTopologyShard.getLinks() != null) {
587 for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
588 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
589 NetworkUtils.OVERLAY_NETWORK_ID);
590 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
591 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
592 .augmentation(Network1.class)
593 .child(Link.class, new LinkKey(new LinkId(otnTopologyLink.getLinkId().getValue())))
595 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
598 if (otnTopologyShard.getTps() != null) {
599 for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
600 LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
601 List<SupportingTerminationPoint> supportingTerminationPoint =
602 new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
603 InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
604 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
605 .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
606 .augmentation(Node1.class)
607 .child(TerminationPoint.class, new TerminationPointKey(new TpId(otnTopologyTp.getTpId()
611 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
613 networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
618 networkTransactionService.commit().get();
619 } catch (InterruptedException | ExecutionException e) {
620 LOG.error("Error updating OTN links in otn-topology", e);
625 public void updateOtnLinks(List<String> suppLinks, boolean isDeletion) {
626 List<LinkId> linkIdList = new ArrayList<>();
627 if (suppLinks != null) {
628 suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
630 List<Link> supportedOtu4links = getOtnLinks(linkIdList);
632 TopologyShard otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOtu4links, isDeletion);
633 if (otnTopologyShard.getLinks() != null) {
634 for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
635 LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
636 NetworkUtils.OVERLAY_NETWORK_ID);
637 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
638 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
639 .augmentation(Network1.class)
640 .child(Link.class, otnTopologyLink.key())
642 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
646 networkTransactionService.commit().get();
647 } catch (InterruptedException | ExecutionException e) {
648 LOG.error("Error adding OTN links in otn-topology", e);
650 LOG.info("OTN links updated");
653 private List<Link> getOtnLinks(List<LinkId> linkIds) {
654 List<Link> links = new ArrayList<>();
655 for (LinkId linkId : linkIds) {
656 InstanceIdentifier<Link> iiLink = InstanceIdentifier.builder(Networks.class)
657 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
658 .augmentation(Network1.class)
659 .child(Link.class, new LinkKey(linkId))
661 ListenableFuture<Optional<Link>> linkOptLf = networkTransactionService
662 .read(LogicalDatastoreType.CONFIGURATION, iiLink);
663 if (linkOptLf.isDone()) {
665 if (linkOptLf.get().isPresent()) {
666 links.add(linkOptLf.get().get());
668 } catch (InterruptedException | ExecutionException e) {
669 LOG.error("Error retreiving OTN links from otn-topology", e);
672 LOG.error("Error retreiving link {} from otn-topology", linkId.getValue());
678 private boolean checkLinks(List<Link> links) {
679 if (links.isEmpty()) {
682 for (Link link : links) {
683 if (link.augmentation(Link1.class) != null
684 && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
691 private boolean checkTerminationPoints(List<TerminationPoint> tps) {
695 for (TerminationPoint tp : tps) {
696 if (tp.augmentation(TerminationPoint1.class) != null && tp.augmentation(TerminationPoint1.class)
697 .getXpdrTpPortConnectionAttributes().getTsPool() != null && tp.augmentation(TerminationPoint1.class)
698 .getXpdrTpPortConnectionAttributes().getTsPool().size() != 80) {
705 private List<TerminationPoint> getOtnNodeTps(String nodeTopoA, String tpA, String nodeTopoZ, String tpZ) {
706 List<TerminationPoint> tps = new ArrayList<>();
707 InstanceIdentifier<TerminationPoint> iiTpA = InstanceIdentifier.builder(Networks.class)
708 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
709 .child(Node.class, new NodeKey(new NodeId(nodeTopoA)))
710 .augmentation(Node1.class)
711 .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpA)))
713 Optional<TerminationPoint> tpAOpt = Optional.empty();
714 InstanceIdentifier<TerminationPoint> iiTpZ = InstanceIdentifier.builder(Networks.class)
715 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
716 .child(Node.class, new NodeKey(new NodeId(nodeTopoZ)))
717 .augmentation(Node1.class)
718 .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpZ)))
720 Optional<TerminationPoint> tpZOpt = Optional.empty();
722 if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
723 && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
725 tpAOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).get();
726 tpZOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).get();
727 } catch (InterruptedException | ExecutionException e) {
728 LOG.error("Error retreiving tp {} of node {} or tp {} from node {} from otn-topology", tpA, nodeTopoA,
732 LOG.error("error getting node termination points from the datastore");
735 if (tpAOpt.isPresent() && tpZOpt.isPresent()) {
736 tps.add(tpAOpt.get());
737 tps.add(tpZOpt.get());
742 private List<TerminationPoint> getOtnNodeTps(List<LinkTp> linkTerminations) {
743 List<TerminationPoint> tps = new ArrayList<>();
744 for (LinkTp linkTp : linkTerminations) {
745 String tp = linkTp.getTpId();
746 String nodeId = formatNodeName(linkTp.getNodeId(), tp);
747 InstanceIdentifier<TerminationPoint> iiTp = InstanceIdentifier.builder(Networks.class)
748 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
749 .child(Node.class, new NodeKey(new NodeId(nodeId)))
750 .augmentation(Node1.class)
751 .child(TerminationPoint.class, new TerminationPointKey(new TpId(tp)))
753 Optional<TerminationPoint> tpOpt;
754 if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).isDone()) {
756 tpOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).get();
757 if (tpOpt.isPresent()) {
758 tps.add(tpOpt.get());
760 } catch (InterruptedException | ExecutionException e) {
761 LOG.error("Error retreiving tp {} of node {} from otn-topology", tp, nodeId, e);
764 LOG.error("error getting node termination points from the datastore");
770 private void deleteLinks(List<Link> links) {
771 for (Link otnTopologyLink : links) {
772 LOG.info("deleting link {} from {}", otnTopologyLink.getLinkId().getValue(),
773 NetworkUtils.OVERLAY_NETWORK_ID);
774 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
775 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
776 .augmentation(Network1.class)
777 .child(Link.class, otnTopologyLink.key())
779 networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink);
782 networkTransactionService.commit().get();
783 } catch (InterruptedException | ExecutionException e) {
784 LOG.error("Error deleting OTN links from otn-topology", e);
788 private List<Link> getSupportingOdu4Links(List<LinkTp> nodesTopoTps, Uint32 serviceRate) {
789 InstanceIdentifier<Network1> iiOtnTopologyLinks = InstanceIdentifier.builder(Networks.class)
790 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
791 .augmentation(Network1.class)
793 ListenableFuture<Optional<Network1>> netw1Fl = networkTransactionService
794 .read(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLinks);
795 Optional<Network1> netw1Opt = Optional.empty();
796 if (netw1Fl.isDone()) {
798 netw1Opt = netw1Fl.get();
799 } catch (InterruptedException | ExecutionException e) {
800 LOG.error("Error retreiving list of links from otn-topology", e);
803 List<Link> odu4links = null;
804 if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
807 .nonnullLink().values()
808 .stream().filter(lk -> lk.getLinkId().getValue()
809 .startsWith(Uint32.valueOf(100).equals(serviceRate) ? "ODUC4" : "ODTU4"))
810 .collect(Collectors.toList());
812 if (odu4links == null) {
815 List<Link> links = new ArrayList<>();
816 for (LinkTp linkTp : nodesTopoTps) {
817 String tp = linkTp.getTpId();
818 String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
819 .append(tp.split("-")[0]).toString();
820 Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
821 .equals(nodeId) && lk.getSource().getSourceTp().getValue().equals(tp)).findFirst().get();
822 if (!links.contains(slink)) {
825 Link dlink = odu4links.stream().filter(lk -> lk.getDestination().getDestNode().getValue()
826 .equals(nodeId) && lk.getDestination().getDestTp().getValue().equals(tp)).findFirst().get();
827 if (!links.contains(dlink)) {
831 LOG.debug("odu4oduC4links = {}", links);
835 private void createOpenRoadmOtnNode(String nodeId) {
836 TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
837 if (otnTopologyShard != null) {
838 this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
839 for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
840 LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
841 NetworkUtils.OTN_NETWORK_ID);
842 InstanceIdentifier<Node> iiOtnTopologyNode = InstanceIdentifier.builder(Networks.class)
843 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
844 .child(Node.class, otnTopologyNode.key())
846 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
848 for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
849 LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
850 NetworkUtils.OVERLAY_NETWORK_ID);
851 InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
852 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
853 .augmentation(Network1.class)
854 .child(Link.class, otnTopologyLink.key())
856 networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
859 LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
863 private String convertNetconfNodeIdToTopoNodeId(String nodeId, String tpId) {
864 return new StringBuilder(nodeId).append("-").append(tpId.split("-")[0]).toString();
867 private static String formatNodeName(String nodeName, String tpName) {
868 return nodeName.contains("-XPDR")
870 : new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
874 value = "UPM_UNCALLED_PRIVATE_METHOD",
875 justification = "false positive, this method is used by public updateOpenRoadmNetworkTopology")
876 private void sendNotification() {
877 if (topologyChanges.isEmpty()) {
878 LOG.warn("Empty Topology Change List. No updates in topology");
881 this.notification = new TopologyUpdateResultBuilder()
882 .setTopologyChanges(topologyChanges)
885 notificationPublishService.putNotification(this.notification);
886 } catch (InterruptedException e) {
887 LOG.error("Notification offer rejected. Error={}", e.getMessage());