2 * Copyright © 2019 Orange, 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.collect.ImmutableClassToInstanceMap;
11 import com.google.common.util.concurrent.FluentFuture;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.nio.charset.Charset;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
21 import java.util.Map.Entry;
22 import java.util.Optional;
24 import java.util.UUID;
25 import java.util.concurrent.ExecutionException;
26 import java.util.stream.Collectors;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.eclipse.jdt.annotation.Nullable;
29 import org.opendaylight.mdsal.binding.api.DataBroker;
30 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
31 import org.opendaylight.transportpce.common.InstanceIdentifiers;
32 import org.opendaylight.transportpce.common.NetworkUtils;
33 import org.opendaylight.transportpce.tapi.TapiStringConstants;
34 import org.opendaylight.transportpce.tapi.utils.TapiContext;
35 import org.opendaylight.transportpce.tapi.utils.TapiLink;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingKey;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.NodesKey;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Link1;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.AdministrativeState;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetailsInput;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetailsOutput;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetailsOutputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointListInput;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointListOutput;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointListOutputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LifecycleState;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OperationalState;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.TapiCommonService;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.UpdateServiceInterfacePointInput;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.UpdateServiceInterfacePointOutput;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.list.output.Sip;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.list.output.SipBuilder;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.list.output.SipKey;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameKey;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.FORWARDINGRULEMAYFORWARDACROSSGROUP;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetLinkDetailsInput;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetLinkDetailsOutput;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetLinkDetailsOutputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeDetailsInput;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeDetailsOutput;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeDetailsOutputBuilder;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetailsInput;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetailsOutput;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetailsOutputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsInput;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsOutput;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsOutputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyListInput;
90 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyListOutput;
91 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyListOutputBuilder;
92 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.RuleType;
93 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.TapiTopologyService;
94 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.link.details.output.LinkBuilder;
95 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.node.edge.point.details.output.NodeEdgePointBuilder;
96 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.details.output.Topology;
97 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.details.output.TopologyBuilder;
98 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroup;
99 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupBuilder;
100 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupKey;
101 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
102 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointKey;
103 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.Rule;
104 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.RuleBuilder;
105 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.RuleKey;
106 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.LinkKey;
107 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeBuilder;
108 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey;
109 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyKey;
110 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
111 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
112 import org.opendaylight.yangtools.yang.binding.Rpc;
113 import org.opendaylight.yangtools.yang.common.ErrorTag;
114 import org.opendaylight.yangtools.yang.common.ErrorType;
115 import org.opendaylight.yangtools.yang.common.RpcResult;
116 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
117 import org.slf4j.Logger;
118 import org.slf4j.LoggerFactory;
120 public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService {
122 private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImpl.class);
123 private final DataBroker dataBroker;
124 private final TapiContext tapiContext;
125 private final TopologyUtils topologyUtils;
126 private final TapiLink tapiLink;
128 public TapiTopologyImpl(DataBroker dataBroker, TapiContext tapiContext, TopologyUtils topologyUtils,
130 this.dataBroker = dataBroker;
131 this.tapiContext = tapiContext;
132 this.topologyUtils = topologyUtils;
133 this.tapiLink = tapiLink;
136 public ImmutableClassToInstanceMap<Rpc<?, ?>> registerRPCs() {
137 return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
138 .put(GetNodeDetails.class, this::getNodeDetails)
139 .put(GetTopologyDetails.class, this::getTopologyDetails)
140 .put(GetNodeEdgePointDetails.class, this::getNodeEdgePointDetails)
141 .put(GetLinkDetails.class, this::getLinkDetails)
142 .put(GetTopologyList.class, this::getTopologyList)
143 .put(GetServiceInterfacePointDetails.class, this::getServiceInterfacePointDetails)
144 .put(GetServiceInterfacePointList.class, this::getServiceInterfacePointList)
145 .put(UpdateServiceInterfacePoint.class, this::updateServiceInterfacePoint)
150 public ListenableFuture<RpcResult<GetNodeDetailsOutput>> getNodeDetails(GetNodeDetailsInput input) {
151 // TODO Auto-generated method stub
152 // TODO -> maybe we get errors when having CEPs?
153 Uuid topoUuid = input.getTopologyId();
154 // Node id: if roadm -> ROADM+PHOTONIC_MEDIA. if xpdr -> XPDR-XPDR+DSR/OTSi
155 Uuid nodeUuid = input.getNodeId();
156 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node = this.tapiContext
157 .getTapiNode(topoUuid, nodeUuid);
159 LOG.error("Invalid TAPI node name");
160 return RpcResultBuilder.<GetNodeDetailsOutput>failed()
161 .withError(ErrorType.RPC, "Invalid Tapi Node name")
164 return RpcResultBuilder.success(new GetNodeDetailsOutputBuilder()
165 .setNode(new org.opendaylight.yang.gen.v1.urn
166 .onf.otcc.yang.tapi.topology.rev221121.get.node.details.output.NodeBuilder(node).build())
167 .build()).buildFuture();
171 public ListenableFuture<RpcResult<GetTopologyDetailsOutput>> getTopologyDetails(GetTopologyDetailsInput input) {
172 // TODO -> Add check for Full T0 Multilayer
173 List<String> topoNameList = null;
175 topoNameList = topologyUtils.readTopologyName(input.getTopologyId());
176 } catch (TapiTopologyException e) {
177 LOG.error("Topology {} not found in datastore", input.getTopologyId());
178 return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
179 .withError(ErrorType.RPC, "Invalid Topology name")
182 if (!topoNameList.contains(TapiStringConstants.T0_MULTILAYER)
183 && !topoNameList.contains(TapiStringConstants.TPDR_100G)) {
184 if (topoNameList.contains(TapiStringConstants.T0_FULL_MULTILAYER)) {
185 Uuid topoUuid = input.getTopologyId();
186 Context context = this.tapiContext.getTapiContext();
188 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology>
189 topologyMap = context.augmentation(Context1.class).getTopologyContext().getTopology();
190 if (!(topologyMap != null && topologyMap.containsKey(new TopologyKey(topoUuid)))) {
191 LOG.error("Topology {} not found in datastore", input.getTopologyId());
192 return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
193 .withError(ErrorType.RPC, "Invalid Topology name")
196 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology
197 topology = topologyMap.get(new TopologyKey(topoUuid));
198 return RpcResultBuilder
199 .success(new GetTopologyDetailsOutputBuilder()
200 .setTopology(this.topologyUtils.transformTopology(topology))
204 LOG.error("Invalid TAPI topology name");
205 return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
206 .withError(ErrorType.RPC, "Invalid Topology name")
209 Uuid topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.TPDR_100G.getBytes(
210 Charset.forName("UTF-8"))).toString());
212 LOG.info("Building TAPI Topology abstraction for {}", input.getTopologyId());
213 Topology topology = createAbstractedOtnTopology();
214 if (topologyUuid.equals(input.getTopologyId())) {
215 topology = createAbstracted100GTpdrTopology(topology);
217 return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder().setTopology(topology).build())
219 } catch (TapiTopologyException e) {
220 LOG.error("error building TAPI topology");
221 return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
222 .withError(ErrorType.RPC, "Error building topology")
228 public ListenableFuture<RpcResult<GetNodeEdgePointDetailsOutput>> getNodeEdgePointDetails(
229 GetNodeEdgePointDetailsInput input) {
230 // TODO Auto-generated method stub
231 // TODO -> maybe we get errors when having CEPs?
232 Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName());
233 // Node id: if roadm -> ROADMid+PHOTONIC_MEDIA. if xpdr -> XPDRid-XPDRnbr+DSR/OTSi
234 Uuid nodeUuid = getUuidFromIput(input.getNodeIdOrName());
235 // NEP id: if roadm -> ROADMid+PHOTONIC_MEDIA/MC/OTSiMC+TPid.
236 // if xpdr -> XPDRid-XPDRnbr+DSR/eODU/iODU/iOTSi/eOTSi/PHOTONIC_MEDIA+TPid
237 Uuid nepUuid = getUuidFromIput(input.getEpIdOrName());
238 OwnedNodeEdgePoint nep = this.tapiContext.getTapiNEP(topoUuid, nodeUuid, nepUuid);
240 LOG.error("Invalid TAPI nep name");
241 return RpcResultBuilder.<GetNodeEdgePointDetailsOutput>failed()
242 .withError(ErrorType.RPC, "Invalid NEP name")
245 return RpcResultBuilder
246 .success(new GetNodeEdgePointDetailsOutputBuilder()
247 .setNodeEdgePoint(new NodeEdgePointBuilder(nep).build())
253 public ListenableFuture<RpcResult<GetLinkDetailsOutput>> getLinkDetails(GetLinkDetailsInput input) {
254 // TODO Auto-generated method stub
255 Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName());
256 // Link id: same as OR link id
257 Uuid linkUuid = getUuidFromIput(input.getLinkIdOrName());
258 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link link =
259 this.tapiContext.getTapiLink(topoUuid, linkUuid);
261 LOG.error("Invalid TAPI link name");
262 return RpcResultBuilder.<GetLinkDetailsOutput>failed()
263 .withError(ErrorType.RPC, "Invalid Link name")
266 return RpcResultBuilder
267 .success(new GetLinkDetailsOutputBuilder().setLink(new LinkBuilder(link).build()).build())
272 public ListenableFuture<RpcResult<GetTopologyListOutput>> getTopologyList(GetTopologyListInput input) {
273 // TODO Auto-generated method stub
274 // TODO -> maybe we get errors when having CEPs?
276 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology>
277 topologyMap = this.tapiContext.getTopologyContext();
278 if (topologyMap.isEmpty()) {
279 LOG.error("No topologies exist in tapi context");
280 return RpcResultBuilder.<GetTopologyListOutput>failed()
281 .withError(ErrorType.APPLICATION, "No topologies exist in tapi context")
284 Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.TopologyKey,
285 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.Topology>
286 newTopoMap = new HashMap<>();
287 for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology
288 topo:topologyMap.values()) {
289 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.Topology
290 newTopo = new org.opendaylight.yang.gen.v1.urn
291 .onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.TopologyBuilder(topo).build();
292 newTopoMap.put(newTopo.key(), newTopo);
294 return RpcResultBuilder
295 .success(new GetTopologyListOutputBuilder().setTopology(newTopoMap).build())
300 public ListenableFuture<RpcResult<GetServiceInterfacePointDetailsOutput>>
301 getServiceInterfacePointDetails(GetServiceInterfacePointDetailsInput input) {
302 Uuid sipUuid = getUuidFromIput(input.getSipIdOrName());
303 Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
304 this.tapiContext.getTapiContext().getServiceInterfacePoint();
305 if (sips == null || sips.isEmpty()) {
306 return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
307 .withError(ErrorType.RPC, "No sips in datastore")
310 if (!sips.containsKey(new ServiceInterfacePointKey(sipUuid))) {
311 return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
312 .withError(ErrorType.RPC, "Sip doesnt exist in datastore")
315 var outSip = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210
316 .get.service._interface.point.details.output.SipBuilder(sips.get(new ServiceInterfacePointKey(sipUuid)))
318 return RpcResultBuilder
319 .success(new GetServiceInterfacePointDetailsOutputBuilder().setSip(outSip).build())
324 public ListenableFuture<RpcResult<GetServiceInterfacePointListOutput>>
325 getServiceInterfacePointList(GetServiceInterfacePointListInput input) {
326 Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
327 this.tapiContext.getTapiContext().getServiceInterfacePoint();
328 if (sips == null || sips.isEmpty()) {
329 return RpcResultBuilder.<GetServiceInterfacePointListOutput>failed()
330 .withError(ErrorType.RPC, "No sips in datastore")
333 Map<SipKey, Sip> outSipMap = new HashMap<>();
334 for (ServiceInterfacePoint sip : sips.values()) {
335 Sip si = new SipBuilder(sip).build();
336 outSipMap.put(si.key(), si);
338 return RpcResultBuilder
339 .success(new GetServiceInterfacePointListOutputBuilder().setSip(outSipMap).build())
344 public ListenableFuture<RpcResult<UpdateServiceInterfacePointOutput>>
345 updateServiceInterfacePoint(UpdateServiceInterfacePointInput input) {
346 return RpcResultBuilder.<UpdateServiceInterfacePointOutput>failed()
347 .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
351 private Topology createAbstracted100GTpdrTopology(Topology topology) {
352 List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> dsrNodes =
353 topology.nonnullNode().values().stream()
354 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
355 .collect(Collectors.toList());
356 List<OwnedNodeEdgePoint> nep100GTpdrList = new ArrayList<>();
357 for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node2: dsrNodes) {
358 List<OwnedNodeEdgePoint> nepList = node2.getOwnedNodeEdgePoint().values().stream()
359 .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))).collect(Collectors.toList());
360 nep100GTpdrList.addAll(nepList);
362 Name topoName = new NameBuilder().setValue(TapiStringConstants.TPDR_100G)
363 .setValueName("TAPI Topology Name").build();
364 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(
365 TapiStringConstants.TPDR_100G.getBytes(Charset.forName("UTF-8"))).toString());
366 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node =
367 createTapiNode(nep100GTpdrList, topoUuid);
368 return new TopologyBuilder()
369 .setName(Map.of(topoName.key(), topoName))
371 .setNode(Map.of(node.key(), node))
375 private Network readTopology(InstanceIdentifier<Network> networkIID) throws TapiTopologyException {
376 Network topology = null;
377 FluentFuture<Optional<Network>> topologyFuture = dataBroker.newReadOnlyTransaction()
378 .read(LogicalDatastoreType.CONFIGURATION, networkIID);
380 topology = topologyFuture.get().orElseThrow();
381 } catch (InterruptedException e) {
382 Thread.currentThread().interrupt();
383 throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
384 .firstKeyOf(Network.class).getNetworkId().getValue(), e);
385 } catch (ExecutionException e) {
386 throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
387 .firstKeyOf(Network.class).getNetworkId().getValue(), e);
392 private Topology createAbstractedOtnTopology() throws TapiTopologyException {
393 // read openroadm-topology
394 Network openroadmTopo = readTopology(InstanceIdentifiers.OVERLAY_NETWORK_II);
395 List<Link> linkList = new ArrayList<>();
396 if (openroadmTopo.augmentation(Network1.class) != null) {
397 linkList.addAll(openroadmTopo.augmentation(Network1.class).getLink().values());
399 List<Link> xponderOutLinkList = linkList.stream()
400 .filter(lk -> lk.augmentation(Link1.class).getLinkType().equals(OpenroadmLinkType.XPONDEROUTPUT))
401 .collect(Collectors.toList());
402 List<Link> xponderInLinkList = linkList.stream()
403 .filter(lk -> lk.augmentation(Link1.class).getLinkType().equals(OpenroadmLinkType.XPONDERINPUT))
404 .collect(Collectors.toList());
406 Network otnTopo = readTopology(InstanceIdentifiers.OTN_NETWORK_II);
407 Map<NodeId, Node> otnNodeMap = otnTopo.nonnullNode().values().stream()
408 .collect(Collectors.toMap(Node::getNodeId, node -> node));
410 Map<String, List<String>> networkPortMap = new HashMap<>();
411 Iterator<Entry<NodeId, Node>> itOtnNodeMap = otnNodeMap.entrySet().iterator();
412 while (itOtnNodeMap.hasNext()) {
413 Entry<NodeId, Node> entry = itOtnNodeMap.next();
414 String portMappingNodeId = entry.getValue().getSupportingNode().values().stream()
415 .filter(sn -> sn.getNetworkRef().getValue().equals(NetworkUtils.UNDERLAY_NETWORK_ID))
417 .orElseThrow().getNodeRef().getValue();
418 List<String> networkPortList = new ArrayList<>();
419 for (TerminationPoint tp: entry.getValue().augmentation(Node1.class).getTerminationPoint().values()) {
420 if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)
421 && checkTp(entry.getKey().getValue(), portMappingNodeId, tp, xponderOutLinkList,
422 xponderInLinkList)) {
423 networkPortList.add(tp.getTpId().getValue());
426 if (!networkPortList.isEmpty()) {
427 networkPortMap.put(entry.getKey().getValue(), networkPortList);
430 Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node>
431 tapiNodeList = new HashMap<>();
432 Map<LinkKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link>
433 tapiLinkList = new HashMap<>();
434 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER
435 .getBytes(Charset.forName("UTF-8"))).toString());
436 ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topoUuid, this.tapiLink);
437 Iterator<Entry<String, List<String>>> it = networkPortMap.entrySet().iterator();
438 while (it.hasNext()) {
439 String nodeId = it.next().getKey();
440 tapiFactory.convertNode(otnNodeMap.get(new NodeId(nodeId)), networkPortMap.get(nodeId));
441 tapiNodeList.putAll(tapiFactory.getTapiNodes());
442 tapiLinkList.putAll(tapiFactory.getTapiLinks());
444 if (openroadmTopo.nonnullNode().values().stream()
446 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1.class)
448 .equals(OpenroadmNodeType.SRG))
450 tapiFactory.convertRoadmInfrastructure();
451 tapiNodeList.putAll(tapiFactory.getTapiNodes());
452 tapiLinkList.putAll(tapiFactory.getTapiLinks());
454 LOG.warn("Unable to abstract an ROADM infrasctructure from openroadm-topology");
456 if (otnTopo.augmentation(Network1.class) != null) {
457 Map<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
458 .ietf.network.topology.rev180226.networks.network.LinkKey, Link> otnLinkMap =
459 otnTopo.augmentation(Network1.class).getLink();
460 tapiFactory.convertLinks(otnLinkMap);
461 tapiLinkList.putAll(tapiFactory.getTapiLinks());
463 Name name = new NameBuilder()
464 .setValue(TapiStringConstants.T0_MULTILAYER)
465 .setValueName("TAPI Topology Name")
467 return new TopologyBuilder()
468 .setName(Map.of(name.key(), name))
470 .setNode(tapiNodeList)
471 .setLink(tapiLinkList).build();
475 public ListenableFuture<RpcResult<GetNodeEdgePointDetailsOutput>> getNodeEdgePointDetails(
476 GetNodeEdgePointDetailsInput input) {
477 // TODO Auto-generated method stub
478 // TODO -> maybe we get errors when having CEPs?
479 Uuid topoUuid = input.getTopologyId();
480 // Node id: if roadm -> ROADMid+PHOTONIC_MEDIA. if xpdr -> XPDRid-XPDRnbr+DSR/OTSi
481 Uuid nodeUuid = input.getNodeId();
482 // NEP id: if roadm -> ROADMid+PHOTONIC_MEDIA/MC/OTSiMC+TPid.
483 // if xpdr -> XPDRid-XPDRnbr+DSR/eODU/iODU/iOTSi/eOTSi/PHOTONIC_MEDIA+TPid
484 Uuid nepUuid = input.getNodeEdgePointId();
485 OwnedNodeEdgePoint nep = this.tapiContext.getTapiNEP(topoUuid, nodeUuid, nepUuid);
487 LOG.error("Invalid TAPI nep name");
488 return RpcResultBuilder.<GetNodeEdgePointDetailsOutput>failed()
489 .withError(ErrorType.RPC, "Invalid NEP name")
492 return RpcResultBuilder.success(new GetNodeEdgePointDetailsOutputBuilder()
493 .setNodeEdgePoint(new NodeEdgePointBuilder(nep).build()).build()).buildFuture();
497 public ListenableFuture<RpcResult<GetLinkDetailsOutput>> getLinkDetails(GetLinkDetailsInput input) {
498 // TODO Auto-generated method stub
499 Uuid topoUuid = input.getTopologyId();
500 // Link id: same as OR link id
501 Uuid linkUuid = input.getLinkId();
502 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link link = this.tapiContext
503 .getTapiLink(topoUuid, linkUuid);
505 LOG.error("Invalid TAPI link name");
506 return RpcResultBuilder.<GetLinkDetailsOutput>failed()
507 .withError(ErrorType.RPC, "Invalid Link name")
510 return RpcResultBuilder.success(new GetLinkDetailsOutputBuilder().setLink(new LinkBuilder(link).build())
511 .build()).buildFuture();
515 public ListenableFuture<RpcResult<GetTopologyListOutput>> getTopologyList(GetTopologyListInput input) {
516 // TODO Auto-generated method stub
517 // TODO -> maybe we get errors when having CEPs?
519 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology>
520 topologyMap = this.tapiContext.getTopologyContext();
521 if (topologyMap.isEmpty()) {
522 LOG.error("No topologies exist in tapi context");
523 return RpcResultBuilder.<GetTopologyListOutput>failed()
524 .withError(ErrorType.APPLICATION, "No topologies exist in tapi context")
527 Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.TopologyKey,
528 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.Topology>
529 newTopoMap = new HashMap<>();
530 for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology
531 topo:topologyMap.values()) {
532 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.Topology
533 newTopo = new org.opendaylight.yang.gen.v1.urn
534 .onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.TopologyBuilder(topo).build();
535 newTopoMap.put(newTopo.key(), newTopo);
537 return RpcResultBuilder.success(new GetTopologyListOutputBuilder().setTopology(newTopoMap).build())
541 private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node
542 createTapiNode(List<OwnedNodeEdgePoint> nepList, Uuid topoUuid) {
543 Name name = new NameBuilder().setValueName("Tpdr100g node name").setValue("Tpdr100g over WDM node").build();
544 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
545 for (OwnedNodeEdgePoint ownedNodeEdgePoint : nepList) {
546 onepMap.put(ownedNodeEdgePoint.key(), ownedNodeEdgePoint);
548 Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(name.getValue().getBytes(Charset.forName("UTF-8"))).toString());
549 return new NodeBuilder()
551 .setName(Map.of(name.key(), name))
552 .setLayerProtocolName(Set.of(LayerProtocolName.ETH))
553 .setAdministrativeState(AdministrativeState.UNLOCKED)
554 .setOperationalState(OperationalState.ENABLED)
555 .setLifecycleState(LifecycleState.INSTALLED)
556 .setOwnedNodeEdgePoint(onepMap)
557 .setNodeRuleGroup(createNodeRuleGroupFor100gTpdrNode(topoUuid, nodeUuid, nepList))
561 private boolean checkTp(String nodeIdTopo, String nodeIdPortMap, TerminationPoint tp, List<Link> xpdOut,
564 if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERCLIENT)) {
565 networkLcp = tp.augmentation(
566 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1.class)
567 .getAssociatedConnectionMapTp().iterator().next().getValue();
569 networkLcp = tp.getTpId().getValue();
572 KeyedInstanceIdentifier<Mapping, MappingKey> pmIID = InstanceIdentifier.create(
573 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network.class)
574 .child(Nodes.class, new NodesKey(nodeIdPortMap)).child(Mapping.class, new MappingKey(networkLcp));
576 FluentFuture<Optional<Mapping>> mappingOpt = dataBroker.newReadOnlyTransaction().read(
577 LogicalDatastoreType.CONFIGURATION, pmIID);
578 Mapping mapping = null;
579 if (mappingOpt.isDone()) {
581 mapping = mappingOpt.get().orElseThrow();
582 } catch (InterruptedException | ExecutionException e) {
583 LOG.error("Error getting mapping for {}", networkLcp, e);
587 LOG.error("Impossible to get mapping of associated network port {} of tp {}", networkLcp, tp.getTpId()
591 String networkPortDirection = mapping.getPortDirection();
593 switch (networkPortDirection) {
594 case "bidirectional":
595 count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo)
596 && lk.getSource().getSourceTp().getValue().equals(networkLcp)).count();
597 count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo)
598 && lk.getDestination().getDestTp().getValue().equals(networkLcp)).count();
603 String partnerLcp = mapping.getPartnerLcp();
604 if (mapping.getPortQual().equals("tx")) {
605 count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo)
606 && lk.getSource().getSourceTp().getValue().equals(networkLcp)).count();
607 count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo)
608 && lk.getDestination().getDestTp().getValue().equals(partnerLcp)).count();
610 if (mapping.getPortQual().equals("rx")) {
611 count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo)
612 && lk.getDestination().getDestTp().getValue().equals(networkLcp)).count();
613 count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo)
614 && lk.getSource().getSourceTp().getValue().equals(partnerLcp)).count();
618 LOG.error("Invalid port direction for {}", networkLcp);
623 private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupFor100gTpdrNode(Uuid topoUuid, Uuid nodeUuid,
624 Collection<OwnedNodeEdgePoint> onepl) {
626 Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePointKey,
627 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint>
628 nepMap = new HashMap<>();
629 for (OwnedNodeEdgePoint onep: onepl) {
630 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint nep =
631 new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group
632 .NodeEdgePointBuilder()
633 .setTopologyUuid(topoUuid)
634 .setNodeUuid(nodeUuid)
635 .setNodeEdgePointUuid(onep.key().getUuid())
637 nepMap.put(nep.key(), nep);
639 Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
640 Map<RuleKey, Rule> ruleList = new HashMap<>();
641 Set<RuleType> ruleTypes = new HashSet<>();
642 ruleTypes.add(RuleType.FORWARDING);
643 Rule rule = new RuleBuilder()
644 .setLocalId("forward")
645 .setForwardingRule(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE)
646 .setRuleType(ruleTypes)
648 ruleList.put(rule.key(), rule);
649 NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
650 .setUuid(new Uuid(UUID.nameUUIDFromBytes(("rdm infra node rule group").getBytes(Charset.forName("UTF-8")))
653 .setNodeEdgePoint(nepMap)
655 nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
656 return nodeRuleGroupMap;
660 public ListenableFuture<RpcResult<GetServiceInterfacePointDetailsOutput>>
661 getServiceInterfacePointDetails(GetServiceInterfacePointDetailsInput input) {
662 Uuid sipUuid = input.getUuid();
663 Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
664 this.tapiContext.getTapiContext().getServiceInterfacePoint();
665 if (sips == null || sips.isEmpty()) {
666 return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
667 .withError(ErrorType.RPC, "No sips in datastore")
670 if (!sips.containsKey(new ServiceInterfacePointKey(sipUuid))) {
671 return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
672 .withError(ErrorType.RPC, "Sip doesnt exist in datastore")
675 org.opendaylight.yang.gen.v1.urn
676 .onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.details.output.Sip outSip =
677 new org.opendaylight.yang.gen.v1.urn
678 .onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.details.output.SipBuilder(
679 sips.get(new ServiceInterfacePointKey(sipUuid)))
681 return RpcResultBuilder.success(new GetServiceInterfacePointDetailsOutputBuilder().setSip(outSip).build())
686 public ListenableFuture<RpcResult<GetServiceInterfacePointListOutput>>
687 getServiceInterfacePointList(GetServiceInterfacePointListInput input) {
688 Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
689 this.tapiContext.getTapiContext().getServiceInterfacePoint();
690 if (sips == null || sips.isEmpty()) {
691 return RpcResultBuilder.<GetServiceInterfacePointListOutput>failed()
692 .withError(ErrorType.RPC, "No sips in datastore")
695 Map<SipKey, Sip> outSipMap = new HashMap<>();
696 for (ServiceInterfacePoint sip : sips.values()) {
697 Sip si = new SipBuilder(sip).build();
698 outSipMap.put(si.key(), si);
700 return RpcResultBuilder.success(new GetServiceInterfacePointListOutputBuilder().setSip(outSipMap).build())
705 public ListenableFuture<RpcResult<UpdateServiceInterfacePointOutput>>
706 updateServiceInterfacePoint(UpdateServiceInterfacePointInput input) {
707 // TODO --> not yet implemented