2 * Copyright © 2021 Nokia, Inc. 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.tapi.topology;
10 import com.google.common.util.concurrent.FluentFuture;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.nio.charset.Charset;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
17 import java.util.NoSuchElementException;
18 import java.util.Optional;
20 import java.util.UUID;
21 import java.util.concurrent.ExecutionException;
22 import java.util.stream.Collectors;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.opendaylight.mdsal.binding.api.DataBroker;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.transportpce.common.InstanceIdentifiers;
27 import org.opendaylight.transportpce.common.NetworkUtils;
28 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
29 import org.opendaylight.transportpce.tapi.TapiStringConstants;
30 import org.opendaylight.transportpce.tapi.utils.TapiLink;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.MappingKey;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.Nodes;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.NodesKey;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Link1;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
53 //import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.OwnedNodeEdgePoint1;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.context.TopologyContext;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointBuilder;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointKey;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.LinkKey;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeBuilder;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyBuilder;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyKey;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
69 public final class TopologyUtils {
71 private final NetworkTransactionService networkTransactionService;
72 private final DataBroker dataBroker;
73 private static final Logger LOG = LoggerFactory.getLogger(TopologyUtils.class);
74 private Map<ServiceInterfacePointKey, ServiceInterfacePoint> tapiSips;
75 private final TapiLink tapiLink;
76 private String topologicalMode;
77 public static final String NOOPMODEDECLARED = "No operational mode declared in Topo for Tp {}, assumes by default ";
80 NetworkTransactionService networkTransactionService, DataBroker dataBroker, TapiLink tapiLink) {
81 this.networkTransactionService = networkTransactionService;
82 this.dataBroker = dataBroker;
83 this.tapiSips = new HashMap<>();
84 this.tapiLink = tapiLink;
85 // TODO: Initially set topological mode to Full. Shall be set through the setter at controller initialization
86 this.topologicalMode = "Full";
89 public Network readTopology(InstanceIdentifier<Network> networkIID) throws TapiTopologyException {
90 ListenableFuture<Optional<Network>> topologyFuture =
91 this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, networkIID);
93 return topologyFuture.get().orElseThrow();
94 } catch (InterruptedException e) {
95 Thread.currentThread().interrupt();
96 throw new TapiTopologyException(
97 "Unable to get from mdsal topology: " + networkIID.firstKeyOf(Network.class).getNetworkId().getValue(),
99 } catch (ExecutionException e) {
100 throw new TapiTopologyException(
101 "Unable to get from mdsal topology: " + networkIID.firstKeyOf(Network.class).getNetworkId().getValue(),
103 } catch (NoSuchElementException e) {
108 public List<String> readTopologyName(Uuid topoUuid) throws TapiTopologyException {
109 Topology topology = null;
110 InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
111 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1.class)
112 .child(TopologyContext.class)
113 .child(Topology.class, new TopologyKey(topoUuid))
115 ListenableFuture<Optional<Topology>> topologyFuture =
116 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, topoIID);
118 topology = topologyFuture.get().orElseThrow();
119 } catch (InterruptedException e) {
120 Thread.currentThread().interrupt();
121 throw new TapiTopologyException(
122 "Unable to get from mdsal topology: " + topoIID.firstKeyOf(Topology.class).getUuid().getValue(), e);
123 } catch (ExecutionException e) {
124 throw new TapiTopologyException(
125 "Unable to get from mdsal topology: " + topoIID.firstKeyOf(Topology.class).getUuid().getValue(), e);
126 } catch (NoSuchElementException e) {
129 List<String> nameList = new ArrayList<>();
130 for (Name value : topology.getName().values()) {
131 nameList.add(value.getValue());
133 LOG.debug("Topology nameList {} = ", nameList);
137 public Topology createFullOtnTopology() throws TapiTopologyException {
138 // read openroadm-topology
139 Network openroadmTopo = readTopology(InstanceIdentifiers.OVERLAY_NETWORK_II);
140 String topoType = this.topologicalMode.equals("Full") ? TapiStringConstants.T0_FULL_MULTILAYER
141 : TapiStringConstants.T0_TAPI_MULTILAYER;
142 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(topoType.getBytes(Charset.forName("UTF-8"))).toString());
143 Name name = new NameBuilder().setValue(topoType).setValueName("TAPI Topology Name").build();
144 var topoBdr = new TopologyBuilder()
145 .setName(Map.of(name.key(), name))
147 .setLayerProtocolName(Set.of(
148 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.ODU,
149 LayerProtocolName.DSR, LayerProtocolName.DIGITALOTN));
150 if (openroadmTopo == null) {
151 return topoBdr.build();
153 List<Link> linkList = openroadmTopo.augmentation(Network1.class) == null ? new ArrayList<>()
154 : new ArrayList<>(openroadmTopo.augmentation(Network1.class).getLink().values());
155 List<Link> xponderOutLinkList = new ArrayList<>();
156 List<Link> xponderInLinkList = new ArrayList<>();
157 for (Link lk : linkList) {
158 switch (lk.augmentation(Link1.class).getLinkType()) {
160 xponderOutLinkList.add(lk);
163 xponderInLinkList.add(lk);
170 Network otnTopo = readTopology(InstanceIdentifiers.OTN_NETWORK_II);
172 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node>
174 otnTopo.nonnullNode().values().stream()
175 .collect(Collectors.toMap(
176 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226
177 .networks.network.Node::getNodeId, node -> node));
178 Map<String, List<String>> networkPortMap = new HashMap<>();
179 for (var entry : otnNodeMap.entrySet()) {
180 var entVal = entry.getValue();
181 String portMappingNodeId = entVal.getSupportingNode().values().stream()
182 .filter(sn -> sn.getNetworkRef().getValue().equals(NetworkUtils.UNDERLAY_NETWORK_ID))
184 .orElseThrow().getNodeRef().getValue();
185 List<String> networkPortList = new ArrayList<>();
186 var entKeyVal = entry.getKey().getValue();
187 for (TerminationPoint tp: entVal.augmentation(Node1.class).getTerminationPoint().values()) {
188 // TODO -> why are we checking with respect to XPDR links?? Is there a real purpose on doing that?
189 if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)
190 && checkTp(entKeyVal, portMappingNodeId, tp, xponderOutLinkList, xponderInLinkList)) {
191 networkPortList.add(tp.getTpId().getValue());
194 if (!networkPortList.isEmpty()) {
195 networkPortMap.put(entKeyVal, networkPortList);
198 Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node>
199 tapiNodeList = new HashMap<>();
200 Map<LinkKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link>
201 tapiLinkList = new HashMap<>();
202 ConvertORTopoToTapiFullTopo tapiFullFactory = new ConvertORTopoToTapiFullTopo(topoUuid, this.tapiLink);
203 ConvertORToTapiTopology tapiFactory = new ConvertORToTapiTopology(topoUuid);
204 for (var entry : networkPortMap.entrySet()) {
205 tapiFactory.convertNode(otnNodeMap.get(new NodeId(entry.getKey())), entry.getValue());
206 this.tapiSips.putAll(tapiFactory.getTapiSips());
207 tapiFullFactory.setTapiNodes(tapiFactory.getTapiNodes());
208 tapiFullFactory.setTapiSips(tapiFactory.getTapiSips());
209 tapiNodeList.putAll(tapiFactory.getTapiNodes());
210 tapiLinkList.putAll(tapiFullFactory.getTapiLinks());
212 // roadm infrastructure not abstracted
213 // read openroadm-network
214 Network openroadmNet = readTopology(InstanceIdentifiers.UNDERLAY_NETWORK_II);
215 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226
216 .networks.network.Node> rdmList =
217 openroadmNet == null ? new ArrayList<>()
218 : openroadmNet.nonnullNode().values().stream()
221 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1.class)
223 .equals(OpenroadmNodeType.ROADM))
224 .collect(Collectors.toList());
225 if (rdmList.isEmpty()) {
226 LOG.warn("No roadm nodes exist in the network");
229 if (this.topologicalMode.equals("Full")) {
230 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226
231 .networks.network.Node roadm : rdmList) {
232 tapiFullFactory.convertRoadmNode(roadm, openroadmTopo, "Full");
233 this.tapiSips.putAll(tapiFullFactory.getTapiSips());
234 tapiNodeList.putAll(tapiFullFactory.getTapiNodes());
235 tapiLinkList.putAll(tapiFullFactory.getTapiLinks());
236 tapiFullFactory.convertRdmToRdmLinks(
237 // map roadm to roadm link
239 .filter(lk -> lk.augmentation(Link1.class).getLinkType()
240 .equals(OpenroadmLinkType.ROADMTOROADM))
241 .collect(Collectors.toList()));
242 tapiLinkList.putAll(tapiFullFactory.getTapiLinks());
245 tapiFullFactory.convertRoadmNode(null, openroadmTopo, "Abstracted");
246 this.tapiSips.putAll(tapiFullFactory.getTapiSips());
247 tapiNodeList.putAll(tapiFullFactory.getTapiNodes());
248 tapiLinkList.putAll(tapiFullFactory.getTapiLinks());
251 // map xpdr_input to roadm and xpdr_output to roadm links.
252 xponderInLinkList.addAll(xponderOutLinkList);
253 tapiFullFactory.convertXpdrToRdmLinks(xponderInLinkList);
254 tapiLinkList.putAll(tapiFullFactory.getTapiLinks());
255 // Retrieve created sips map in TapiFactory when mapping all the nodes
256 this.tapiSips.putAll(tapiFullFactory.getTapiSips());
257 return topoBdr.setNode(tapiNodeList).setLink(tapiLinkList).build();
260 public boolean checkTp(
261 String nodeIdTopo, String nodeIdPortMap, TerminationPoint tp, List<Link> xpdOut, List<Link> xpdIn) {
262 LOG.info("Inside Checktp for node {}-{}", nodeIdTopo, nodeIdPortMap);
263 String networkLcp = tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERCLIENT)
265 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1.class)
266 .getAssociatedConnectionMapTp().iterator().next().getValue()
267 : tp.getTpId().getValue();
268 LOG.info("Network LCP associated = {}", networkLcp);
270 FluentFuture<Optional<Mapping>> mappingOpt = this.dataBroker.newReadOnlyTransaction().read(
271 LogicalDatastoreType.CONFIGURATION,
272 InstanceIdentifier.create(
273 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.Network.class)
274 .child(Nodes.class, new NodesKey(nodeIdPortMap))
275 .child(Mapping.class, new MappingKey(networkLcp)));
276 if (!mappingOpt.isDone()) {
277 LOG.error("Impossible to get mapping of associated network port {} of tp {}",
278 networkLcp, tp.getTpId().getValue());
281 Mapping mapping = null;
283 mapping = mappingOpt.get().orElseThrow();
284 } catch (InterruptedException | ExecutionException e) {
285 LOG.error("Error getting mapping for {}", networkLcp, e);
288 LOG.info("Mapping found = {}", mapping);
289 switch (mapping.getPortDirection()) {
290 // TODO -> remove the part of counting only if the Network LCP is part of a Link.
291 // We want to have all OTN nodes in the TAPI topology
292 case "bidirectional":
296 LOG.info("PartnerLCP = {}", mapping.getPartnerLcp());
299 LOG.error("Invalid port direction for {}", networkLcp);
304 public org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
305 .get.topology.details.output.Topology transformTopology(Topology topology) {
306 var topologyBuilder = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
307 .get.topology.details.output.TopologyBuilder()
308 .setUuid(topology.getUuid())
309 .setName(topology.getName())
310 .setLayerProtocolName(topology.getLayerProtocolName())
311 .setLink(topology.getLink());
312 if (topology.nonnullNode().isEmpty()) {
313 return topologyBuilder.build();
315 Map<NodeKey, Node> mapNode = new HashMap<>();
316 for (Node node: topology.nonnullNode().values()) {
317 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
318 for (OwnedNodeEdgePoint onep: node.nonnullOwnedNodeEdgePoint().values()) {
319 // OwnedNodeEdgePoint1 onep1 = onep.augmentation(OwnedNodeEdgePoint1.class);
320 // if (onep1 == null) {
321 // onepMap.put(onep.key(), onep);
324 OwnedNodeEdgePoint newOnep = new OwnedNodeEdgePointBuilder()
325 .setUuid(onep.getUuid())
326 .setLayerProtocolName(onep.getLayerProtocolName())
327 .setName(onep.getName())
328 .setSupportedCepLayerProtocolQualifierInstances(onep
329 .getSupportedCepLayerProtocolQualifierInstances())
330 .setAdministrativeState(onep.getAdministrativeState())
331 .setOperationalState(onep.getOperationalState())
332 .setLifecycleState(onep.getLifecycleState())
333 // .setTerminationDirection(onep.getTerminationDirection())
334 // .setTerminationState(onep.getTerminationState())
335 .setDirection(onep.getDirection())
336 .setSupportedPayloadStructure(onep.getSupportedPayloadStructure())
337 .setAvailablePayloadStructure(onep.getAvailablePayloadStructure())
338 .setLinkPortRole(onep.getLinkPortRole())
339 .setMappedServiceInterfacePoint(onep.nonnullMappedServiceInterfacePoint())
341 onepMap.put(newOnep.key(), newOnep);
343 Node newNode = new NodeBuilder()
344 .setUuid(node.getUuid())
345 .setName(node.getName())
346 .setOperationalState(node.getOperationalState())
347 .setAdministrativeState(node.getAdministrativeState())
348 .setLifecycleState(node.getLifecycleState())
349 .setLayerProtocolName(node.getLayerProtocolName())
350 .setNodeRuleGroup(node.getNodeRuleGroup())
351 .setInterRuleGroup(node.getInterRuleGroup())
352 .setOwnedNodeEdgePoint(onepMap)
354 mapNode.put(newNode.key(), newNode);
356 return topologyBuilder.setNode(mapNode).build();
359 public Map<ServiceInterfacePointKey, ServiceInterfacePoint> getSipMap() {
363 public void setTopologicalMode(String topoMode) {
364 this.topologicalMode = topoMode;
367 public String getTopologicalMode() {
368 return topologicalMode;