Merge "Update diagram and developer guide for Si and P"
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / TapiContext.java
1 /*
2  * Copyright © 2021 Nokia, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.tapi.utils;
9
10 import java.nio.charset.Charset;
11 import java.util.HashMap;
12 import java.util.Map;
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.Uuid;
21 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
23 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint;
24 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey;
25 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1;
26 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1Builder;
27 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.OwnedNodeEdgePoint1;
28 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.OwnedNodeEdgePoint1Builder;
29 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPoint;
30 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityService;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceKey;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContextBuilder;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.topology.context.topology.node.owned.node.edge.point.CepList;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.topology.context.topology.node.owned.node.edge.point.CepListBuilder;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContextBuilder;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointBuilder;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.NwTopologyServiceBuilder;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class TapiContext {
56
57     private static final Logger LOG = LoggerFactory.getLogger(TapiContext.class);
58     public static final String TAPI_CONTEXT = "T-API context";
59     public static final String NODE_NOT_PRESENT = "Node is not present in datastore";
60     private final NetworkTransactionService networkTransactionService;
61
62     public TapiContext(NetworkTransactionService networkTransactionService) {
63         this.networkTransactionService = networkTransactionService;
64         createTapiContext();
65     }
66
67     private void createTapiContext() {
68         try {
69             // Augmenting tapi context to include topology and connectivity contexts
70             Name contextName = new NameBuilder().setValue(TAPI_CONTEXT).setValueName("TAPI Context Name").build();
71
72             Context1 connectivityContext =
73                 new Context1Builder()
74                     .setConnectivityContext(
75                         new ConnectivityContextBuilder()
76                             .setConnection(new HashMap<>())
77                             .setConnectivityService(new HashMap<>())
78                             .build())
79                     .build();
80
81             Name nwTopoServiceName =
82                 new NameBuilder()
83                     .setValue("Network Topo Service")
84                     .setValueName("Network Topo Service Name")
85                     .build();
86
87             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1 topologyContext
88                 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1Builder()
89                     .setTopologyContext(new TopologyContextBuilder()
90                         .setNwTopologyService(new NwTopologyServiceBuilder()
91                             .setTopology(new HashMap<>())
92                             .setUuid(
93                                 new Uuid(
94                                     UUID.nameUUIDFromBytes("Network Topo Service".getBytes(Charset.forName("UTF-8")))
95                                         .toString()))
96                             .setName(Map.of(nwTopoServiceName.key(), nwTopoServiceName))
97                             .build())
98                         .setTopology(new HashMap<>())
99                         .build())
100                     .build();
101
102             ContextBuilder contextBuilder = new ContextBuilder()
103                     .setName(Map.of(contextName.key(), contextName))
104                     .setUuid(
105                         new Uuid(UUID.nameUUIDFromBytes(TAPI_CONTEXT.getBytes(Charset.forName("UTF-8"))).toString()))
106                     .setServiceInterfacePoint(new HashMap<>())
107                     .addAugmentation(connectivityContext)
108                     .addAugmentation(topologyContext);
109
110             // todo: add notification context
111             InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
112             // put in datastore
113             this.networkTransactionService.put(LogicalDatastoreType.OPERATIONAL, contextIID, contextBuilder.build());
114             this.networkTransactionService.commit().get();
115             LOG.info("TAPI context created successfully.");
116         } catch (InterruptedException | ExecutionException e) {
117             LOG.error("Failed to create TAPI context", e);
118         }
119     }
120
121     public Context getTapiContext() {
122         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
123         //  There is no Identifiable in Context model
124         InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
125         try {
126             Optional<Context> optionalContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
127                     contextIID).get();
128             if (!optionalContext.isPresent()) {
129                 LOG.error("Tapi context is not present in datastore");
130                 return null;
131             }
132             return optionalContext.get();
133         } catch (InterruptedException | ExecutionException e) {
134             LOG.error("Couldnt read tapi context from datastore", e);
135             return null;
136         }
137     }
138
139     public void deleteTapiContext() {
140
141     }
142
143     public void updateTopologyContext(Map<TopologyKey, Topology> topologyMap) {
144         // TODO: solve error when merging: Topology is not a valid child of topology context?
145         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
146         try {
147             TopologyContext topologyContext = new TopologyContextBuilder()
148                     //.setNwTopologyService(new NwTopologyServiceBuilder().build())
149                     .setTopology(topologyMap)
150                     .build();
151             InstanceIdentifier<TopologyContext> topologycontextIID =
152                     InstanceIdentifier.builder(Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
153                             .onf.otcc.yang.tapi.topology.rev181210.Context1.class)
154                             .child(TopologyContext.class)
155                             .build();
156             // merge in datastore
157             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topologycontextIID,
158                     topologyContext);
159             this.networkTransactionService.commit().get();
160             LOG.info("TAPI topology merged successfully.");
161         } catch (InterruptedException | ExecutionException e) {
162             LOG.error("Failed to merge TAPI topology", e);
163         }
164     }
165
166     public void updateSIPContext(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap) {
167         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
168         try {
169             ContextBuilder contextBuilder = new ContextBuilder().setServiceInterfacePoint(sipMap);
170             InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
171             // merge in datastore
172             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, contextIID,
173                     contextBuilder.build());
174             this.networkTransactionService.commit().get();
175             LOG.info("TAPI SIPs merged successfully.");
176         } catch (InterruptedException | ExecutionException e) {
177             LOG.error("Failed to merge TAPI SIPs", e);
178         }
179     }
180
181     public void updateConnectivityContext(Map<ConnectivityServiceKey, ConnectivityService> connServMap,
182                                           Map<ConnectionKey, Connection> connectionFullMap) {
183         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
184         try {
185             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext
186                 connectivityContext = new ConnectivityContextBuilder()
187                 .setConnectivityService(connServMap)
188                 .setConnection(connectionFullMap)
189                 .build();
190             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
191                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> connectivitycontextIID =
192                     InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
193                         .child(org.opendaylight.yang.gen.v1.urn
194                             .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
195                         .build();
196             // merge in datastore
197             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectivitycontextIID,
198                 connectivityContext);
199             this.networkTransactionService.commit().get();
200             LOG.info("TAPI connectivity merged successfully.");
201         } catch (InterruptedException | ExecutionException e) {
202             LOG.error("Failed to merge TAPI connectivity", e);
203         }
204     }
205
206     public void updateTopologyWithCep(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, ConnectionEndPoint cep) {
207         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
208         InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
209             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
210             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
211             .child(Topology.class, new TopologyKey(topoUuid))
212             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
213                     new NodeKey(nodeUuid))
214             .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
215             .build();
216         try {
217             Optional<OwnedNodeEdgePoint> optionalOnep = this.networkTransactionService.read(
218                     LogicalDatastoreType.OPERATIONAL, onepIID).get();
219             if (!optionalOnep.isPresent()) {
220                 LOG.error("ONEP is not present in datastore");
221                 return;
222             }
223             OwnedNodeEdgePoint onep = optionalOnep.get();
224             LOG.info("ONEP found = {}", onep);
225             // TODO -> If cep exists -> skip merging to datasore
226             OwnedNodeEdgePoint1 onep1 = onep.augmentation(OwnedNodeEdgePoint1.class);
227             if (onep1 != null && onep1.getCepList() != null && onep1.getCepList().getConnectionEndPoint() != null
228                     && onep1.getCepList().getConnectionEndPoint().containsKey(new ConnectionEndPointKey(cep.key()))) {
229                 LOG.info("CEP already in topology, skipping merge");
230                 return;
231             }
232             // Updated ONEP
233             CepList cepList = new CepListBuilder().setConnectionEndPoint(Map.of(cep.key(), cep)).build();
234             OwnedNodeEdgePoint1 onep1Bldr = new OwnedNodeEdgePoint1Builder().setCepList(cepList).build();
235             OwnedNodeEdgePoint newOnep = new OwnedNodeEdgePointBuilder(onep)
236                     .addAugmentation(onep1Bldr)
237                     .build();
238             LOG.info("New ONEP is {}", newOnep);
239             // merge in datastore
240             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, onepIID,
241                     newOnep);
242             this.networkTransactionService.commit().get();
243             LOG.info("CEP added successfully.");
244         } catch (InterruptedException | ExecutionException e) {
245             LOG.error("Couldnt update cep in topology", e);
246         }
247     }
248
249     public Node getTapiNode(Uuid topoUuid, Uuid nodeUuid) {
250         InstanceIdentifier<Node> nodeIID = InstanceIdentifier.builder(Context.class)
251             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
252             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
253             .child(Topology.class, new TopologyKey(topoUuid))
254             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
255                         new NodeKey(nodeUuid)).build();
256         try {
257             Optional<Node> optNode = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID)
258                     .get();
259             if (!optNode.isPresent()) {
260                 LOG.error(NODE_NOT_PRESENT);
261                 return null;
262             }
263             // TODO -> Need to remove CEPs from NEPs. If not error from get Topology details output
264             Node node = optNode.get();
265             LOG.debug("NEPs of node before creating map to be returned to the getTapiNode function = {}",
266                 node.getOwnedNodeEdgePoint().size());
267             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
268             for (OwnedNodeEdgePoint onep: node.getOwnedNodeEdgePoint().values()) {
269                 if (onep.augmentation(OwnedNodeEdgePoint1.class) == null) {
270                     onepMap.put(onep.key(), onep);
271                     continue;
272                 }
273                 OwnedNodeEdgePointBuilder newOnepBuilder = new OwnedNodeEdgePointBuilder()
274                     .setUuid(onep.getUuid())
275                     .setLayerProtocolName(onep.getLayerProtocolName())
276                     .setName(onep.getName())
277                     .setSupportedCepLayerProtocolQualifier(onep.getSupportedCepLayerProtocolQualifier())
278                     .setAdministrativeState(onep.getAdministrativeState())
279                     .setOperationalState(onep.getOperationalState())
280                     .setLifecycleState(onep.getLifecycleState())
281                     .setTerminationDirection(onep.getTerminationDirection())
282                     .setTerminationState(onep.getTerminationState())
283                     .setLinkPortDirection(onep.getLinkPortDirection())
284                     .setLinkPortRole(onep.getLinkPortRole());
285                 if (onep.getMappedServiceInterfacePoint() != null) {
286                     newOnepBuilder.setMappedServiceInterfacePoint(onep.getMappedServiceInterfacePoint());
287                 }
288                 OwnedNodeEdgePoint newOnep = newOnepBuilder.build();
289                 onepMap.put(newOnep.key(), newOnep);
290             }
291             LOG.debug("NEPs of node after creating map to be returned to the getTapiNode function = {}",
292                 onepMap.size());
293             return new NodeBuilder(node)
294                 .setOwnedNodeEdgePoint(onepMap)
295                 .build();
296         } catch (InterruptedException | ExecutionException e) {
297             LOG.error("Couldnt read node in topology", e);
298             return null;
299         }
300     }
301
302     public OwnedNodeEdgePoint getTapiNEP(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid) {
303         InstanceIdentifier<OwnedNodeEdgePoint> nepIID = InstanceIdentifier.builder(Context.class)
304             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
305             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
306             .child(Topology.class, new TopologyKey(topoUuid))
307             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
308                 new NodeKey(nodeUuid)).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid)).build();
309         try {
310             Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
311                     .read(LogicalDatastoreType.OPERATIONAL, nepIID)
312                     .get();
313             if (!optNode.isPresent()) {
314                 LOG.error(NODE_NOT_PRESENT);
315                 return null;
316             }
317             return optNode.get();
318         } catch (InterruptedException | ExecutionException e) {
319             LOG.error("Couldnt read NEP in topology", e);
320             return null;
321         }
322     }
323
324     public Link getTapiLink(Uuid topoUuid, Uuid linkUuid) {
325         InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
326             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
327             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
328             .child(Topology.class, new TopologyKey(topoUuid))
329             .child(Link.class, new LinkKey(linkUuid)).build();
330         try {
331             Optional<Link> optLink = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, linkIID)
332                     .get();
333             if (!optLink.isPresent()) {
334                 LOG.error(NODE_NOT_PRESENT);
335                 return null;
336             }
337             return optLink.get();
338         } catch (InterruptedException | ExecutionException e) {
339             LOG.error("Couldnt read link in topology", e);
340             return null;
341         }
342     }
343
344     public Map<TopologyKey, Topology> getTopologyContext() {
345         InstanceIdentifier<TopologyContext> topologycontextIID =
346                 InstanceIdentifier.builder(Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
347                         .onf.otcc.yang.tapi.topology.rev181210.Context1.class)
348                         .child(TopologyContext.class)
349                         .build();
350         try {
351             Optional<TopologyContext> optTopoContext = this.networkTransactionService.read(
352                     LogicalDatastoreType.OPERATIONAL, topologycontextIID).get();
353             if (!optTopoContext.isPresent()) {
354                 LOG.error("Topology context is not present in datastore");
355                 return null;
356             }
357             return optTopoContext.get().getTopology();
358         } catch (InterruptedException | ExecutionException e) {
359             LOG.error("Couldnt read topology context", e);
360             return null;
361         }
362     }
363
364     public ConnectivityService getConnectivityService(Uuid serviceUuid) {
365         try {
366             // First read connectivity service with service uuid and update info
367             InstanceIdentifier<ConnectivityService> connectivityServIID =
368                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
369                     .child(org.opendaylight.yang.gen.v1.urn
370                         .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
371                     .child(ConnectivityService.class, new ConnectivityServiceKey(serviceUuid))
372                     .build();
373
374             Optional<ConnectivityService> optConnServ =
375                 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivityServIID).get();
376             if (!optConnServ.isPresent()) {
377                 LOG.error("Connectivity service not found in tapi context");
378                 return null;
379             }
380             return optConnServ.get();
381         } catch (InterruptedException | ExecutionException e) {
382             LOG.error("Connectivity service not found in tapi context. Error:", e);
383             return null;
384         }
385     }
386
387     public void deleteConnectivityService(Uuid serviceUuid) {
388         ConnectivityService connectivityService = getConnectivityService(serviceUuid);
389         if (connectivityService == null) {
390             LOG.error("Service doesnt exist in tapi context");
391             return;
392         }
393         for (org.opendaylight.yang.gen.v1
394                 .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.Connection connection:
395                     connectivityService.getConnection().values()) {
396             deleteConnection(connection.getConnectionUuid());
397         }
398         InstanceIdentifier<ConnectivityService> connectivityServIID =
399                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
400                         .child(org.opendaylight.yang.gen.v1.urn
401                                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
402                         .child(ConnectivityService.class, new ConnectivityServiceKey(serviceUuid))
403                         .build();
404         try {
405             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, connectivityServIID);
406             this.networkTransactionService.commit().get();
407             LOG.info("Connectivity service deleted");
408         } catch (InterruptedException | ExecutionException e) {
409             LOG.error("Failed to delete Connectivity service", e);
410         }
411     }
412
413     private void deleteConnection(Uuid connectionUuid) {
414         // First read connectivity service with service uuid and update info
415         InstanceIdentifier<org.opendaylight.yang.gen.v1
416             .urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection> connectionIID =
417             InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
418                 .child(org.opendaylight.yang.gen.v1.urn
419                     .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
420                 .child(org.opendaylight.yang.gen.v1.urn
421                         .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection.class,
422                     new org.opendaylight.yang.gen.v1.urn
423                         .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey(
424                             connectionUuid))
425                 .build();
426         try {
427             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, connectionIID);
428             this.networkTransactionService.commit().get();
429         } catch (InterruptedException | ExecutionException e) {
430             LOG.error("Failed to delete TAPI Connection", e);
431         }
432     }
433
434     public Connection getConnection(Uuid connectionUuid) {
435         try {
436             // First read connectivity service with service uuid and update info
437             InstanceIdentifier<Connection> connIID =
438                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
439                     .child(org.opendaylight.yang.gen.v1.urn
440                         .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
441                     .child(Connection.class, new ConnectionKey(connectionUuid))
442                     .build();
443
444             Optional<Connection> optConn =
445                 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connIID).get();
446             if (!optConn.isPresent()) {
447                 LOG.error("Connection not found in tapi context");
448                 return null;
449             }
450             return optConn.get();
451         } catch (InterruptedException | ExecutionException e) {
452             LOG.error("Connection not found in tapi context. Error:", e);
453             return null;
454         }
455     }
456
457     public Map<ConnectivityServiceKey, ConnectivityService> getConnectivityServices() {
458         try {
459             // First read connectivity service with service uuid and update info
460             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
461                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> connectivityContextIID =
462                 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
463                     .child(org.opendaylight.yang.gen.v1.urn
464                         .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext.class)
465                     .build();
466
467             Optional<org.opendaylight.yang.gen.v1.urn
468                 .onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext> optConnContext =
469                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivityContextIID)
470                         .get();
471             if (!optConnContext.isPresent()) {
472                 LOG.error("Connectivity context not found in tapi context");
473                 return null;
474             }
475             return optConnContext.get().getConnectivityService();
476         } catch (InterruptedException | ExecutionException e) {
477             LOG.error("Connectivity context not found in tapi context. Error:", e);
478             return null;
479         }
480     }
481
482     public ConnectionEndPoint getTapiCEP(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, Uuid cepUuid) {
483         InstanceIdentifier<OwnedNodeEdgePoint> nepIID = InstanceIdentifier.builder(Context.class)
484             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1.class)
485             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext.class)
486             .child(Topology.class, new TopologyKey(topoUuid))
487             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
488                 new NodeKey(nodeUuid)).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid)).build();
489         try {
490             Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
491                 .read(LogicalDatastoreType.OPERATIONAL, nepIID).get();
492             if (!optNode.isPresent()) {
493                 LOG.error(NODE_NOT_PRESENT);
494                 return null;
495             }
496             if (optNode.get().augmentation(OwnedNodeEdgePoint1.class) == null) {
497                 LOG.error("Node doesnt have ceps");
498                 return null;
499             }
500             return optNode.get().augmentation(OwnedNodeEdgePoint1.class).getCepList().getConnectionEndPoint()
501                 .get(new ConnectionEndPointKey(cepUuid));
502         } catch (InterruptedException | ExecutionException e) {
503             LOG.error("Couldnt read node in topology", e);
504             return null;
505         }
506     }
507 }