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.utils;
10 import java.nio.charset.Charset;
11 import java.util.HashMap;
13 import java.util.Optional;
14 import java.util.UUID;
15 import java.util.concurrent.ExecutionException;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ContextBuilder;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
21 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
23 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
24 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint;
25 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey;
26 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1;
27 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1Builder;
28 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.OwnedNodeEdgePoint1;
29 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.OwnedNodeEdgePoint1Builder;
30 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPoint;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connection.LowerConnection;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connection.LowerConnectionKey;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityService;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceKey;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContextBuilder;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.topology.context.topology.node.owned.node.edge.point.CepList;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.topology.context.topology.node.owned.node.edge.point.CepListBuilder;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContextBuilder;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointBuilder;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.NwTopologyServiceBuilder;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
54 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
58 public class TapiContext {
60 private static final Logger LOG = LoggerFactory.getLogger(TapiContext.class);
61 public static final String TAPI_CONTEXT = "T-API context";
62 public static final String NODE_NOT_PRESENT = "Node is not present in datastore";
63 private final NetworkTransactionService networkTransactionService;
65 public TapiContext(NetworkTransactionService networkTransactionService) {
66 this.networkTransactionService = networkTransactionService;
70 private void createTapiContext() {
72 // Augmenting tapi context to include topology and connectivity contexts
73 Name contextName = new NameBuilder().setValue(TAPI_CONTEXT).setValueName("TAPI Context Name").build();
75 Context1 connectivityContext =
77 .setConnectivityContext(
78 new ConnectivityContextBuilder()
79 .setConnection(new HashMap<>())
80 .setConnectivityService(new HashMap<>())
84 Name nwTopoServiceName =
86 .setValue("Network Topo Service")
87 .setValueName("Network Topo Service Name")
90 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1 topologyContext
91 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1Builder()
92 .setTopologyContext(new TopologyContextBuilder()
93 .setNwTopologyService(new NwTopologyServiceBuilder()
94 .setTopology(new HashMap<>())
97 UUID.nameUUIDFromBytes("Network Topo Service".getBytes(Charset.forName("UTF-8")))
99 .setName(Map.of(nwTopoServiceName.key(), nwTopoServiceName))
101 .setTopology(new HashMap<>())
105 ContextBuilder contextBuilder = new ContextBuilder()
106 .setName(Map.of(contextName.key(), contextName))
108 new Uuid(UUID.nameUUIDFromBytes(TAPI_CONTEXT.getBytes(Charset.forName("UTF-8"))).toString()))
109 .setServiceInterfacePoint(new HashMap<>())
110 .addAugmentation(connectivityContext)
111 .addAugmentation(topologyContext);
113 // todo: add notification context
114 InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
116 this.networkTransactionService.put(LogicalDatastoreType.OPERATIONAL, contextIID, contextBuilder.build());
117 this.networkTransactionService.commit().get();
118 LOG.info("TAPI context created successfully.");
119 } catch (InterruptedException | ExecutionException e) {
120 LOG.error("Failed to create TAPI context", e);
124 public Context getTapiContext() {
125 // TODO: verify this is correct. Should we identify the context IID with the context UUID??
126 // There is no Identifiable in Context model
127 InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
129 Optional<Context> optionalContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
131 if (!optionalContext.isPresent()) {
132 LOG.error("Tapi context is not present in datastore");
135 return optionalContext.get();
136 } catch (InterruptedException | ExecutionException e) {
137 LOG.error("Couldnt read tapi context from datastore", e);
142 public void deleteTapiContext() {
146 public void updateTopologyContext(Map<TopologyKey, Topology> topologyMap) {
147 // TODO: solve error when merging: Topology is not a valid child of topology context?
148 // TODO: verify this is correct. Should we identify the context IID with the context UUID??
150 TopologyContext topologyContext = new TopologyContextBuilder()
151 //.setNwTopologyService(new NwTopologyServiceBuilder().build())
152 .setTopology(topologyMap)
154 InstanceIdentifier<TopologyContext> topologycontextIID =
155 InstanceIdentifier.builder(Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
156 .onf.otcc.yang.tapi.topology.rev181210.Context1.class)
157 .child(TopologyContext.class)
159 // merge in datastore
160 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topologycontextIID,
162 this.networkTransactionService.commit().get();
163 LOG.info("TAPI topology merged successfully.");
164 } catch (InterruptedException | ExecutionException e) {
165 LOG.error("Failed to merge TAPI topology", e);
169 public void updateSIPContext(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap) {
170 // TODO: verify this is correct. Should we identify the context IID with the context UUID??
172 ContextBuilder contextBuilder = new ContextBuilder().setServiceInterfacePoint(sipMap);
173 InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
174 // merge in datastore
175 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, contextIID,
176 contextBuilder.build());
177 this.networkTransactionService.commit().get();
178 LOG.info("TAPI SIPs merged successfully.");
179 } catch (InterruptedException | ExecutionException e) {
180 LOG.error("Failed to merge TAPI SIPs", e);
184 public void updateConnectivityContext(Map<ConnectivityServiceKey, ConnectivityService> connServMap,
185 Map<ConnectionKey, Connection> connectionFullMap) {
186 // TODO: verify this is correct. Should we identify the context IID with the context UUID??
188 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext
189 connectivityContext = new ConnectivityContextBuilder()
190 .setConnectivityService(connServMap)
191 .setConnection(connectionFullMap)
193 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
194 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> connectivitycontextIID =
195 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
196 .child(org.opendaylight.yang.gen.v1.urn
197 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
199 // merge in datastore
200 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectivitycontextIID,
201 connectivityContext);
202 this.networkTransactionService.commit().get();
203 LOG.info("TAPI connectivity merged successfully.");
204 } catch (InterruptedException | ExecutionException e) {
205 LOG.error("Failed to merge TAPI connectivity", e);
209 public void updateTopologyWithCep(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, ConnectionEndPoint cep) {
210 // TODO: verify this is correct. Should we identify the context IID with the context UUID??
211 InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
212 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
213 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
214 .child(Topology.class, new TopologyKey(topoUuid))
215 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
216 new NodeKey(nodeUuid))
217 .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
220 Optional<OwnedNodeEdgePoint> optionalOnep = this.networkTransactionService.read(
221 LogicalDatastoreType.OPERATIONAL, onepIID).get();
222 if (!optionalOnep.isPresent()) {
223 LOG.error("ONEP is not present in datastore");
226 OwnedNodeEdgePoint onep = optionalOnep.get();
227 LOG.info("ONEP found = {}", onep);
228 // TODO -> If cep exists -> skip merging to datasore
229 OwnedNodeEdgePoint1 onep1 = onep.augmentation(OwnedNodeEdgePoint1.class);
230 if (onep1 != null && onep1.getCepList() != null && onep1.getCepList().getConnectionEndPoint() != null
231 && onep1.getCepList().getConnectionEndPoint().containsKey(new ConnectionEndPointKey(cep.key()))) {
232 LOG.info("CEP already in topology, skipping merge");
236 CepList cepList = new CepListBuilder().setConnectionEndPoint(Map.of(cep.key(), cep)).build();
237 OwnedNodeEdgePoint1 onep1Bldr = new OwnedNodeEdgePoint1Builder().setCepList(cepList).build();
238 OwnedNodeEdgePoint newOnep = new OwnedNodeEdgePointBuilder(onep)
239 .addAugmentation(onep1Bldr)
241 LOG.info("New ONEP is {}", newOnep);
242 // merge in datastore
243 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, onepIID,
245 this.networkTransactionService.commit().get();
246 LOG.info("CEP added successfully.");
247 } catch (InterruptedException | ExecutionException e) {
248 LOG.error("Couldnt update cep in topology", e);
252 public Node getTapiNode(Uuid topoUuid, Uuid nodeUuid) {
253 InstanceIdentifier<Node> nodeIID = InstanceIdentifier.builder(Context.class)
254 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
255 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
256 .child(Topology.class, new TopologyKey(topoUuid))
257 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
258 new NodeKey(nodeUuid)).build();
260 Optional<Node> optNode = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID)
262 if (!optNode.isPresent()) {
263 LOG.error(NODE_NOT_PRESENT);
266 // TODO -> Need to remove CEPs from NEPs. If not error from get Topology details output
267 Node node = optNode.get();
268 LOG.debug("NEPs of node before creating map to be returned to the getTapiNode function = {}",
269 node.getOwnedNodeEdgePoint().size());
270 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
271 for (OwnedNodeEdgePoint onep: node.getOwnedNodeEdgePoint().values()) {
272 if (onep.augmentation(OwnedNodeEdgePoint1.class) == null) {
273 onepMap.put(onep.key(), onep);
276 OwnedNodeEdgePointBuilder newOnepBuilder = new OwnedNodeEdgePointBuilder()
277 .setUuid(onep.getUuid())
278 .setLayerProtocolName(onep.getLayerProtocolName())
279 .setName(onep.getName())
280 .setSupportedCepLayerProtocolQualifier(onep.getSupportedCepLayerProtocolQualifier())
281 .setAdministrativeState(onep.getAdministrativeState())
282 .setOperationalState(onep.getOperationalState())
283 .setLifecycleState(onep.getLifecycleState())
284 .setTerminationDirection(onep.getTerminationDirection())
285 .setTerminationState(onep.getTerminationState())
286 .setLinkPortDirection(onep.getLinkPortDirection())
287 .setLinkPortRole(onep.getLinkPortRole());
288 if (onep.getMappedServiceInterfacePoint() != null) {
289 newOnepBuilder.setMappedServiceInterfacePoint(onep.getMappedServiceInterfacePoint());
291 OwnedNodeEdgePoint newOnep = newOnepBuilder.build();
292 onepMap.put(newOnep.key(), newOnep);
294 LOG.debug("NEPs of node after creating map to be returned to the getTapiNode function = {}",
296 return new NodeBuilder(node)
297 .setOwnedNodeEdgePoint(onepMap)
299 } catch (InterruptedException | ExecutionException e) {
300 LOG.error("Couldnt read node in topology", e);
305 public OwnedNodeEdgePoint getTapiNEP(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid) {
306 InstanceIdentifier<OwnedNodeEdgePoint> nepIID = InstanceIdentifier.builder(Context.class)
307 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
308 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
309 .child(Topology.class, new TopologyKey(topoUuid))
310 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
311 new NodeKey(nodeUuid)).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid)).build();
313 Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
314 .read(LogicalDatastoreType.OPERATIONAL, nepIID)
316 if (!optNode.isPresent()) {
317 LOG.error(NODE_NOT_PRESENT);
320 return optNode.get();
321 } catch (InterruptedException | ExecutionException e) {
322 LOG.error("Couldnt read NEP in topology", e);
327 public Link getTapiLink(Uuid topoUuid, Uuid linkUuid) {
328 InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
329 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
330 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
331 .child(Topology.class, new TopologyKey(topoUuid))
332 .child(Link.class, new LinkKey(linkUuid)).build();
334 Optional<Link> optLink = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, linkIID)
336 if (!optLink.isPresent()) {
337 LOG.error(NODE_NOT_PRESENT);
340 return optLink.get();
341 } catch (InterruptedException | ExecutionException e) {
342 LOG.error("Couldnt read link in topology", e);
347 public Map<TopologyKey, Topology> getTopologyContext() {
348 InstanceIdentifier<TopologyContext> topologycontextIID =
349 InstanceIdentifier.builder(Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
350 .onf.otcc.yang.tapi.topology.rev181210.Context1.class)
351 .child(TopologyContext.class)
354 Optional<TopologyContext> optTopoContext = this.networkTransactionService.read(
355 LogicalDatastoreType.OPERATIONAL, topologycontextIID).get();
356 if (!optTopoContext.isPresent()) {
357 LOG.error("Topology context is not present in datastore");
360 return optTopoContext.get().getTopology();
361 } catch (InterruptedException | ExecutionException e) {
362 LOG.error("Couldnt read topology context", e);
367 public ConnectivityService getConnectivityService(Uuid serviceUuid) {
369 // First read connectivity service with service uuid and update info
370 InstanceIdentifier<ConnectivityService> connectivityServIID =
371 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
372 .child(org.opendaylight.yang.gen.v1.urn
373 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
374 .child(ConnectivityService.class, new ConnectivityServiceKey(serviceUuid))
377 Optional<ConnectivityService> optConnServ =
378 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivityServIID).get();
379 if (!optConnServ.isPresent()) {
380 LOG.error("Connectivity service not found in tapi context");
383 return optConnServ.get();
384 } catch (InterruptedException | ExecutionException e) {
385 LOG.error("Connectivity service not found in tapi context. Error:", e);
390 public void deleteConnectivityService(Uuid serviceUuid) {
391 // TODO: handle case where the infrastructure service is removed before the top level service?
392 ConnectivityService connectivityService = getConnectivityService(serviceUuid);
393 if (connectivityService == null) {
394 LOG.error("Service doesnt exist in tapi context");
397 for (org.opendaylight.yang.gen.v1
398 .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.Connection connection:
399 connectivityService.getConnection().values()) {
400 deleteConnection(connection.getConnectionUuid(), serviceUuid, connectivityService.getServiceLayer());
402 InstanceIdentifier<ConnectivityService> connectivityServIID =
403 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
404 .child(org.opendaylight.yang.gen.v1.urn
405 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
406 .child(ConnectivityService.class, new ConnectivityServiceKey(serviceUuid))
409 this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, connectivityServIID);
410 this.networkTransactionService.commit().get();
411 LOG.info("Connectivity service deleted");
412 } catch (InterruptedException | ExecutionException e) {
413 LOG.error("Failed to delete Connectivity service", e);
417 private void deleteConnection(Uuid connectionUuid, Uuid serviceUuid, LayerProtocolName serviceLayer) {
418 // First read connectivity service with service uuid and update info
419 InstanceIdentifier<org.opendaylight.yang.gen.v1
420 .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection> connectionIID =
421 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
422 .child(org.opendaylight.yang.gen.v1.urn
423 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
424 .child(org.opendaylight.yang.gen.v1.urn
425 .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection.class,
426 new org.opendaylight.yang.gen.v1.urn
427 .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey(
430 Connection connection = getConnection(connectionUuid);
431 if (connection != null && isNotUsedByOtherService(connection, serviceUuid)) {
432 Map<LowerConnectionKey, LowerConnection> lowerConnectionMap = connection.getLowerConnection();
433 if (lowerConnectionMap != null) {
434 for (LowerConnection lowerConnection:lowerConnectionMap.values()) {
435 // check layer of connection, for DSR service we only need to delete DSR layer
436 // connection and XC at ODU. For ODU, only need to delete ODU connections and for
437 // photonic media services all the photonic media. And when it is ETH we need to delete
438 // everything and also without checking the lower connection layer
439 Connection conn1 = getConnection(lowerConnection.getConnectionUuid());
441 // connection not found in tapi context
444 LayerProtocolName lowerConnLayer = conn1.getLayerProtocolName();
445 switch (serviceLayer.getIntValue()) {
449 if (lowerConnLayer.equals(serviceLayer)) {
450 deleteConnection(lowerConnection.getConnectionUuid(), serviceUuid, serviceLayer);
455 deleteConnection(lowerConnection.getConnectionUuid(), serviceUuid, serviceLayer);
459 if (lowerConnLayer.equals(serviceLayer) || (lowerConnLayer.equals(LayerProtocolName.ODU)
460 && conn1.getName().values().stream().anyMatch(
461 name -> name.getValue().contains("XC")))) {
462 deleteConnection(lowerConnection.getConnectionUuid(), serviceUuid, serviceLayer);
466 LOG.info("Unknown service Layer: {}", serviceLayer.getName());
472 this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, connectionIID);
473 this.networkTransactionService.commit().get();
474 } catch (InterruptedException | ExecutionException e) {
475 LOG.error("Failed to delete TAPI Connection", e);
479 private boolean isNotUsedByOtherService(Connection connection, Uuid serviceUuid) {
480 Map<ConnectivityServiceKey, ConnectivityService> connServicesMap = getConnectivityServices();
481 if (connServicesMap == null) {
482 LOG.info("isNotUsedByOtherService: No service in tapi context!");
485 for (ConnectivityService connService: connServicesMap.values()) {
486 if (connService.getConnection() == null || connService.getUuid().equals(serviceUuid)) {
487 LOG.info("isNotUsedByOtherService: There are no connections in service {} or service in loop is the "
488 + "service to be deleted", connService.getUuid().getValue());
491 if (connService.getConnection().containsKey(
492 new org.opendaylight.yang.gen.v1
493 .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.ConnectionKey(
494 connection.getUuid()))) {
495 LOG.info("isNotUsedByOtherService: Connection {} is in used by service {}. Cannot remove it from "
496 + "context", connection.getUuid().getValue(), connService.getUuid().getValue());
499 LOG.info("isNotUsedByOtherService: Going to check lower connections");
500 for (org.opendaylight.yang.gen.v1.urn
501 .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.Connection
502 conn:connService.getConnection().values()) {
503 Connection connection1 = getConnection(conn.getConnectionUuid());
504 if (connection1 == null || connection1.getLowerConnection() == null) {
507 if (connection1.getLowerConnection().containsKey(new LowerConnectionKey(connection.getUuid()))) {
508 LOG.info("isNotUsedByOtherService: Lower Connection {} is in used by service {}. Cannot remove it "
509 + "from context", connection.getUuid().getValue(), connService.getUuid().getValue());
514 LOG.info("isNotUsedByOtherService: No other service uses connection {}, therefore it can be safely deleted",
515 connection.getUuid());
519 public Connection getConnection(Uuid connectionUuid) {
521 // First read connectivity service with service uuid and update info
522 InstanceIdentifier<Connection> connIID =
523 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
524 .child(org.opendaylight.yang.gen.v1.urn
525 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
526 .child(Connection.class, new ConnectionKey(connectionUuid))
529 Optional<Connection> optConn =
530 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connIID).get();
531 if (!optConn.isPresent()) {
532 LOG.error("Connection not found in tapi context");
535 return optConn.get();
536 } catch (InterruptedException | ExecutionException e) {
537 LOG.error("Connection not found in tapi context. Error:", e);
542 public Map<ConnectivityServiceKey, ConnectivityService> getConnectivityServices() {
544 // First read connectivity service with service uuid and update info
545 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
546 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> connectivityContextIID =
547 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
548 .child(org.opendaylight.yang.gen.v1.urn
549 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
552 Optional<org.opendaylight.yang.gen.v1.urn
553 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> optConnContext =
554 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivityContextIID)
556 if (!optConnContext.isPresent()) {
557 LOG.error("Connectivity context not found in tapi context");
560 return optConnContext.get().getConnectivityService();
561 } catch (InterruptedException | ExecutionException e) {
562 LOG.error("Connectivity context not found in tapi context. Error:", e);
567 public ConnectionEndPoint getTapiCEP(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, Uuid cepUuid) {
568 InstanceIdentifier<OwnedNodeEdgePoint> nepIID = InstanceIdentifier.builder(Context.class)
569 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
570 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
571 .child(Topology.class, new TopologyKey(topoUuid))
572 .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
573 new NodeKey(nodeUuid)).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid)).build();
575 Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
576 .read(LogicalDatastoreType.OPERATIONAL, nepIID).get();
577 if (!optNode.isPresent()) {
578 LOG.error(NODE_NOT_PRESENT);
581 if (optNode.get().augmentation(OwnedNodeEdgePoint1.class) == null) {
582 LOG.error("Node doesnt have ceps");
585 return optNode.get().augmentation(OwnedNodeEdgePoint1.class).getCepList().getConnectionEndPoint()
586 .get(new ConnectionEndPointKey(cepUuid));
587 } catch (InterruptedException | ExecutionException e) {
588 LOG.error("Couldnt read node in topology", e);