Refactor TAPI Connectivity Utils
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / connectivity / ConnectivityUtils.java
1 /*
2  * Copyright © 2018 Orange & 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.connectivity;
9
10 import java.math.BigDecimal;
11 import java.nio.charset.Charset;
12 import java.nio.charset.StandardCharsets;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Comparator;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Optional;
20 import java.util.UUID;
21 import java.util.concurrent.ExecutionException;
22 import java.util.stream.Collectors;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
25 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
26 import org.opendaylight.transportpce.tapi.TapiStringConstants;
27 import org.opendaylight.transportpce.tapi.utils.GenericServiceEndpoint;
28 import org.opendaylight.transportpce.tapi.utils.ServiceEndpointType;
29 import org.opendaylight.transportpce.tapi.utils.TapiContext;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.Network;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.MappingKey;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.Nodes;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.NodesKey;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.equipment.types.rev191129.OpticTypes;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.RpcActions;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.Service;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ethernet.subrate.attributes.grp.EthernetAttributesBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.sdnc.request.header.SdncRequestHeaderBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirectionBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirectionKey;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionKey;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.lgx.LgxBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.port.PortBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.subrate.eth.sla.SubrateEthSlaBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU4;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OTU4;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.create.input.ServiceAEnd;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.create.input.ServiceAEndBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.create.input.ServiceZEnd;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.create.input.ServiceZEndBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZKey;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToA;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToAKey;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.Node;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPoint;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.AdministrativeState;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.CAPACITYUNITGBPS;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Direction;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.ForwardingDirection;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LifecycleState;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OperationalState;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.PortRole;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.capacity.TotalSizeBuilder;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameKey;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceInput;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.ProtectionRole;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.ServiceType;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.cep.list.ConnectionEndPoint;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.cep.list.ConnectionEndPointBuilder;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.LowerConnection;
90 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.LowerConnectionBuilder;
91 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.LowerConnectionKey;
92 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.end.point.ClientNodeEdgePoint;
93 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.end.point.ClientNodeEdgePointBuilder;
94 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.end.point.ParentNodeEdgePoint;
95 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connection.end.point.ParentNodeEdgePointBuilder;
96 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityService;
97 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityServiceBuilder;
98 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.Connection;
99 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.ConnectionBuilder;
100 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.ConnectionKey;
101 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.ConnectivityConstraint;
102 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.ConnectivityConstraintBuilder;
103 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPoint;
104 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPointBuilder;
105 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPointKey;
106 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.end.point.CapacityBuilder;
107 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.end.point.ServiceInterfacePointBuilder;
108 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIERMC;
109 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTSiMC;
110 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.context.TopologyContext;
111 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointBuilder;
113 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointKey;
114 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePointKey;
115 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedCepLayerProtocolQualifierInstancesBuilder;
116 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey;
117 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology;
118 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyKey;
119 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
120 import org.opendaylight.yangtools.yang.common.Decimal64;
121 import org.opendaylight.yangtools.yang.common.Uint16;
122 import org.opendaylight.yangtools.yang.common.Uint32;
123 import org.opendaylight.yangtools.yang.common.Uint64;
124 import org.opendaylight.yangtools.yang.common.Uint8;
125 import org.slf4j.Logger;
126 import org.slf4j.LoggerFactory;
127
128 public final class ConnectivityUtils {
129
130     private final Uuid tapiTopoUuid = new Uuid(
131             UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER.getBytes(StandardCharsets.UTF_8)).toString());
132     private static final Logger LOG = LoggerFactory.getLogger(ConnectivityUtils.class);
133
134     private final ServiceDataStoreOperations serviceDataStoreOperations;
135     private final TapiContext tapiContext;
136     private Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap;
137     // this variable is for complete connection objects
138     private final Map<
139         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectionKey,
140         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.Connection>
141             connectionFullMap;
142     private final NetworkTransactionService networkTransactionService;
143     private Connection topConnRdmRdm;
144     private Connection topConnXpdrXpdrPhtn;
145     private Connection topConnXpdrXpdrOdu;
146
147     // TODO -> handle cases for which node id is ROADM-A1 and not ROADMA01 or XPDR-A1 and not XPDRA01
148     public ConnectivityUtils(ServiceDataStoreOperations serviceDataStoreOperations,
149                              Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap, TapiContext tapiContext,
150                              NetworkTransactionService networkTransactionService) {
151         this.serviceDataStoreOperations = serviceDataStoreOperations;
152         this.tapiContext = tapiContext;
153         this.sipMap = sipMap;
154         this.connectionFullMap = new HashMap<>();
155         this.networkTransactionService = networkTransactionService;
156         this.topConnRdmRdm = null;
157         this.topConnXpdrXpdrPhtn = null;
158         this.topConnXpdrXpdrOdu = null;
159     }
160
161     public static ServiceCreateInput buildServiceCreateInput(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
162         ServiceAEnd serviceAEnd = getServiceAEnd(sepA, sepZ);
163         ServiceZEnd serviceZEnd = getServiceZEnd(sepA, sepZ);
164         if (serviceAEnd == null || serviceZEnd == null) {
165             LOG.warn("One of the endpoints could not be identified");
166             return null;
167         }
168         return new ServiceCreateInputBuilder()
169             .setCommonId("commonId")
170             .setConnectionType(ConnectionType.Service)
171             .setCustomer("Customer")
172             .setServiceName("service test")
173             .setServiceAEnd(serviceAEnd)
174             .setServiceZEnd(serviceZEnd)
175             .setSdncRequestHeader(
176                 new SdncRequestHeaderBuilder()
177                     .setRequestId("request-1")
178                     .setRpcAction(RpcActions.ServiceCreate)
179                     .setNotificationUrl("notification url")
180                     .setRequestSystemId("appname")
181                     .build())
182             .build();
183     }
184
185     public static ServiceAEnd buildServiceAEnd(
186             String nodeid, String clli, String txPortDeviceName,
187             String txPortName, String rxPortDeviceName, String rxPortName) {
188         return new ServiceAEndBuilder()
189             .setClli(clli)
190             .setNodeId(new NodeIdType(nodeid))
191             .setOpticType(OpticTypes.Gray)
192             .setServiceFormat(ServiceFormat.Ethernet)
193             .setServiceRate(Uint32.valueOf(100))
194             .setTxDirection(Map.of(
195                 new TxDirectionKey(Uint8.ZERO),
196                 new TxDirectionBuilder()
197                     .setPort(new PortBuilder()
198                         .setPortDeviceName(txPortDeviceName)
199                         .setPortName(txPortName)
200                         .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
201                         .setPortShelf("00")
202                         .setPortType(TapiStringConstants.PORT_TYPE)
203                         .build())
204                     .setLgx(new LgxBuilder()
205                         .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
206                         .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
207                         .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
208                         .setLgxPortShelf("00")
209                         .build())
210                     .build()))
211             .setRxDirection(Map.of(
212                 new RxDirectionKey(Uint8.ZERO),
213                 new RxDirectionBuilder()
214                     .setPort(new PortBuilder()
215                         .setPortDeviceName(rxPortDeviceName)
216                         .setPortName(rxPortName)
217                         .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
218                         .setPortShelf("00")
219                         .setPortType(TapiStringConstants.PORT_TYPE)
220                         .build())
221                     .setLgx(new LgxBuilder()
222                         .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
223                         .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
224                         .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
225                         .setLgxPortShelf("00")
226                         .build())
227                     .build()))
228             .build();
229     }
230
231     public static ServiceZEnd buildServiceZEnd(
232             String nodeid, String clli, String txPortDeviceName,
233             String txPortName, String rxPortDeviceName, String rxPortName) {
234         return  new ServiceZEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid))
235             .setOpticType(OpticTypes.Gray)
236             .setServiceFormat(ServiceFormat.Ethernet)
237             .setServiceRate(Uint32.valueOf(100))
238             .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO), new TxDirectionBuilder()
239                 .setPort(new PortBuilder()
240                     .setPortDeviceName(txPortDeviceName)
241                     .setPortName(txPortName)
242                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
243                     .setPortShelf("00")
244                     .setPortType(TapiStringConstants.PORT_TYPE)
245                     .build())
246                 .setLgx(new LgxBuilder()
247                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
248                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
249                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
250                     .setLgxPortShelf("00")
251                     .build())
252                 .build()))
253             .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO), new RxDirectionBuilder()
254                 .setPort(new PortBuilder()
255                     .setPortDeviceName(rxPortDeviceName)
256                     .setPortName(rxPortName)
257                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
258                     .setPortShelf("00")
259                     .setPortType(TapiStringConstants.PORT_TYPE)
260                     .build())
261                 .setLgx(new LgxBuilder()
262                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
263                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
264                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
265                     .setLgxPortShelf("00")
266                     .build())
267                 .build()))
268             .build();
269     }
270
271     public void setSipMap(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips) {
272         this.sipMap = sips;
273     }
274
275     public ConnectivityService mapORServiceToTapiConnectivity(Service service) {
276         // Get service path with the description in OR based models.
277         LOG.info("Service = {}", service);
278         Optional<ServicePaths> optServicePaths =
279             this.serviceDataStoreOperations.getServicePath(service.getServiceName());
280         if (optServicePaths.isEmpty()) {
281             LOG.error("No service path found for service {}", service.getServiceName());
282             return null;
283         }
284         PathDescription pathDescription = optServicePaths.orElseThrow().getPathDescription();
285         LOG.info("Path description of service = {}", pathDescription);
286         org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.ServiceAEnd serviceAEnd =
287             service.getServiceAEnd();
288         // Endpoint creation
289         EndPoint endPoint1 = mapServiceAEndPoint(serviceAEnd, pathDescription);
290         EndPoint endPoint2 = mapServiceZEndPoint(service.getServiceZEnd(), pathDescription);
291         Map<EndPointKey, EndPoint> endPointMap = new HashMap<>(Map.of(
292                 endPoint1.key(), endPoint1,
293                 endPoint2.key(), endPoint2));
294         LOG.info("EndPoints of connectivity services = {}", endPointMap);
295         // Services Names
296         Name name =
297             new NameBuilder().setValueName("Connectivity Service Name").setValue(service.getServiceName()).build();
298         // Connection creation
299         Map<ConnectionKey, Connection> connMap =
300             createConnectionsFromService(pathDescription, mapServiceLayerToAend(serviceAEnd));
301         LOG.debug("connectionMap for service {} = {} ", name, connMap);
302         ConnectivityConstraint conConstr =
303             new ConnectivityConstraintBuilder().setServiceType(ServiceType.POINTTOPOINTCONNECTIVITY).build();
304         // TODO: full connectivity service?? With constraints and the rest of fields...
305         return new ConnectivityServiceBuilder()
306             .setAdministrativeState(AdministrativeState.UNLOCKED)
307             .setOperationalState(OperationalState.ENABLED)
308             .setLifecycleState(LifecycleState.INSTALLED)
309             .setUuid(new Uuid(
310                 UUID.nameUUIDFromBytes(service.getServiceName().getBytes(StandardCharsets.UTF_8)).toString()))
311             .setLayerProtocolName(mapServiceLayer(serviceAEnd.getServiceFormat(), endPoint1, endPoint2))
312             .setConnectivityConstraint(conConstr)
313             .setDirection(ForwardingDirection.BIDIRECTIONAL)
314             .setName(Map.of(name.key(), name))
315             .setConnection(connMap)
316             .setEndPoint(endPointMap)
317             .build();
318     }
319
320     public Map<ConnectionKey, Connection> createConnectionsFromService(
321             PathDescription pathDescription, LayerProtocolName lpn) {
322         Map<ConnectionKey, Connection> connectionServMap = new HashMap<>();
323         // build lists with ROADM nodes, XPDR/MUX/SWITCH nodes, ROADM DEG TTPs, ROADM SRG TTPs, XPDR CLIENT TTPs
324         //  and XPDR NETWORK TTPs (if any). From the path description. This will help to build the uuid of the CEPs
325         //  and the connections
326         String resourceType;
327         List<String> xpdrClientTplist = new ArrayList<>();
328         List<String> xpdrNetworkTplist = new ArrayList<>();
329         List<String> rdmAddDropTplist = new ArrayList<>();
330         List<String> rdmDegTplist = new ArrayList<>();
331         List<String> rdmNodelist = new ArrayList<>();
332         List<String> xpdrNodelist = new ArrayList<>();
333         for (AToZ elem:pathDescription.getAToZDirection().getAToZ().values().stream()
334                 .sorted((Comparator.comparing(atoz -> Integer.valueOf(atoz.getId())))).collect(Collectors.toList())) {
335             resourceType = elem.getResource().getResource().implementedInterface().getSimpleName();
336             switch (resourceType) {
337                 case TapiStringConstants.TP:
338                     TerminationPoint tp = (TerminationPoint) elem.getResource().getResource();
339                     String tpID = tp.getTpId();
340                     String tpNode;
341                     if (tpID.contains("CLIENT")) {
342                         tpNode = tp.getTpNodeId();
343                         if (!xpdrClientTplist.contains(String.join("+", tpNode, tpID))) {
344                             xpdrClientTplist.add(String.join("+", tpNode, tpID));
345                         }
346                     }
347                     if (tpID.contains("NETWORK")) {
348                         tpNode = tp.getTpNodeId();
349                         if (!xpdrNetworkTplist.contains(String.join("+", tpNode, tpID))) {
350                             xpdrNetworkTplist.add(String.join("+", tpNode, tpID));
351                         }
352                     }
353                     if (tpID.contains("PP")) {
354                         tpNode = getIdBasedOnModelVersion(tp.getTpNodeId());
355                         LOG.info("ROADM Node of tp = {}", tpNode);
356                         if (!rdmAddDropTplist.contains(String.join("+", tpNode, tpID))) {
357                             rdmAddDropTplist.add(String.join("+", tpNode, tpID));
358                         }
359                     }
360                     if (tpID.contains("TTP")) {
361                         tpNode = getIdBasedOnModelVersion(tp.getTpNodeId());
362                         LOG.info("ROADM Node of tp = {}", tpNode);
363                         if (!rdmDegTplist.contains(String.join("+", tpNode, tpID))) {
364                             rdmDegTplist.add(String.join("+", tpNode, tpID));
365                         }
366                     }
367                     break;
368                 case TapiStringConstants.NODE:
369                     Node node = (Node) elem.getResource().getResource();
370                     String nodeId = node.getNodeId();
371                     if (nodeId.contains("XPDR") || nodeId.contains("SPDR") || nodeId.contains("MXPDR")) {
372                         LOG.info("Node id = {}", nodeId);
373                         if (!xpdrNodelist.contains(nodeId)) {
374                             xpdrNodelist.add(nodeId); // should contain only 2
375                         }
376                     }
377                     if (nodeId.contains("ROADM")) {
378                         nodeId = getIdBasedOnModelVersion(nodeId);
379                         LOG.info("Node id = {}", nodeId);
380                         if (!rdmNodelist.contains(nodeId)) {
381                             rdmNodelist.add(nodeId);
382                         }
383                     }
384                     break;
385                 default:
386                     LOG.warn("Resource is a {}", resourceType);
387             }
388         }
389         LOG.info("ROADM node list = {}", rdmNodelist);
390         LOG.info("ROADM degree list = {}", rdmDegTplist);
391         LOG.info("ROADM addrop list = {}", rdmAddDropTplist);
392         LOG.info("XPDR node list = {}", xpdrNodelist);
393         LOG.info("XPDR network list = {}", xpdrNetworkTplist);
394         LOG.info("XPDR client list = {}", xpdrClientTplist);
395         // TODO -> for 10GB eth and ODU services there are no ROADMs in path description as they use the OTU link,
396         //  but for 100GB eth all is created at once. Check if the roadm list is empty to determine whether we need
397         //  to trigger all the steps or not
398         String edgeRoadm1 = "";
399         String edgeRoadm2 = "";
400         if (!rdmNodelist.isEmpty()) {
401             edgeRoadm1 = rdmNodelist.get(0);
402             edgeRoadm2 = rdmNodelist.get(rdmNodelist.size() - 1);
403             LOG.info("edgeRoadm1 = {}", edgeRoadm1);
404             LOG.info("edgeRoadm2 = {}", edgeRoadm2);
405         }
406         // create corresponding CEPs and Connections. Connections should be added to the corresponding context
407         // CEPs must be included in the topology context as an augmentation for each ONEP!!
408         // TODO -> Maybe we dont need to create the connections and ceps if the previous service doesnt exist??
409         //  As mentioned above, for 100GbE service creation there are ROADMs in the path description.
410         //  What are the configurations needed here? No OTU, ODU... what kind of cross connections is needed?
411         //  this needs to be changed
412         // TODO: OpenROADM getNodeType from the NamesList to verify what needs to be created
413         OpenroadmNodeType openroadmNodeType = getOpenRoadmNodeType(xpdrNodelist);
414         switch (lpn) {
415             case PHOTONICMEDIA:
416                 // Identify number of ROADMs
417                 // - XC Connection between MC CEPs mapped from MC NEPs (within a roadm)
418                 // - XC Connection between OTSiMC CEPs mapped from OTSiMC NEPs (within a roadm)
419                 // - Top Connection MC betwwen MC CEPs of different roadms
420                 // - Top Connection OTSiMC betwwen OTSiMC CEPs of extreme roadms
421                 connectionServMap.putAll(
422                     createRoadmCepsAndConnections(rdmAddDropTplist, rdmDegTplist, rdmNodelist, edgeRoadm1, edgeRoadm2));
423                 if (!pathDescription.getAToZDirection().getAToZ().values().stream().findFirst().orElseThrow().getId()
424                         .contains("ROADM")) {
425                     // - XC Connection OTSi betwwen iOTSi y eOTSi of xpdr
426                     // - Top connection OTSi between network ports of xpdrs in the Photonic media layer -> i_OTSi
427                     connectionServMap.putAll(createXpdrCepsAndConnectionsPht(xpdrNetworkTplist, xpdrNodelist));
428                 }
429                 this.topConnRdmRdm = null;
430                 break;
431             case ODU:
432                 // TODO: verify if this is correct
433                 // - XC Connection OTSi betwwen iODU and eODU of xpdr
434                 // - Top connection in the ODU layer, between xpdr eODU ports (?)
435                 if (openroadmNodeType.equals(OpenroadmNodeType.MUXPDR)) {
436                     connectionServMap.putAll(createXpdrCepsAndConnectionsOdu(xpdrNetworkTplist, xpdrNodelist));
437                     this.topConnXpdrXpdrPhtn = null;
438                 }
439                 break;
440             case ETH:
441                 // Check if OC, OTU and ODU are created
442                 if (openroadmNodeType.equals(OpenroadmNodeType.TPDR)) {
443                     LOG.info("WDM ETH service");
444                     connectionServMap.putAll(
445                         createRoadmCepsAndConnections(
446                             rdmAddDropTplist, rdmDegTplist, rdmNodelist, edgeRoadm1, edgeRoadm2));
447                     connectionServMap.putAll(createXpdrCepsAndConnectionsPht(xpdrNetworkTplist, xpdrNodelist));
448                     this.topConnRdmRdm = null;
449                     xpdrClientTplist = getAssociatedClientsPort(xpdrNetworkTplist);
450                     LOG.info("Associated client ports = {}", xpdrClientTplist);
451                     connectionServMap.putAll(
452                         createXpdrCepsAndConnectionsEth(xpdrClientTplist, xpdrNodelist, connectionServMap));
453                     this.topConnXpdrXpdrPhtn = null;
454                 }
455                 break;
456             case DSR:
457                 LOG.info("OTN XGE/ODUe service");
458                 // - XC connection between iODU and eODU
459                 // - Top connection between eODU ports
460                 // - Top connection between DSR ports
461                 if (openroadmNodeType.equals(OpenroadmNodeType.SWITCH)) {
462                     // TODO: We create both ODU and DSR because there is no ODU service creation for the switch
463                     // - XC Connection OTSi between iODU and eODU of xpdr
464                     // - Top connection in the ODU layer, between xpdr eODU ports (?)
465                     connectionServMap.putAll(
466                         createXpdrCepsAndConnectionsDsr(xpdrClientTplist, xpdrNetworkTplist, xpdrNodelist));
467                     this.topConnXpdrXpdrPhtn = null;
468                 }
469                 if (openroadmNodeType.equals(OpenroadmNodeType.MUXPDR)) {
470                     // TODO: OTN service but mux has 3 steps at rendering. Verify that things exist
471                     connectionServMap.putAll(
472                         createXpdrCepsAndConnectionsDsr(xpdrClientTplist, xpdrNetworkTplist, xpdrNodelist));
473                     this.topConnXpdrXpdrOdu = null;
474                 }
475                 break;
476             default:
477                 LOG.error("Service type format not supported");
478         }
479         LOG.debug("CONNSERVERMAP = {}", connectionServMap);
480         return connectionServMap;
481     }
482
483     public void updateTopologyWithNep(Uuid topoUuid, Uuid nodeUuid, Uuid nepUuid, OwnedNodeEdgePoint onep) {
484         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
485         InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
486             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1.class)
487             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.context.TopologyContext.class)
488             .child(Topology.class, new TopologyKey(topoUuid))
489             .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node.class,
490                 new NodeKey(nodeUuid))
491             .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
492             .build();
493         try {
494             Optional<OwnedNodeEdgePoint> optionalOnep =
495                 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, onepIID).get();
496             if (optionalOnep.isPresent()) {
497                 LOG.error("ONEP is already present in datastore");
498                 return;
499             }
500             // merge in datastore
501             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, onepIID, onep);
502             this.networkTransactionService.commit().get();
503             LOG.info("NEP {} added successfully.", onep.getName());
504         } catch (InterruptedException | ExecutionException e) {
505             LOG.error("Couldnt put NEP {} in topology, error = ", onep.getName(), e);
506         }
507     }
508
509     public Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
510                 .connectivity.context.ConnectionKey,
511             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
512                 .connectivity.context.Connection> getConnectionFullMap() {
513         return this.connectionFullMap;
514     }
515
516     public ServiceCreateInput createORServiceInput(CreateConnectivityServiceInput input, Uuid serviceUuid) {
517         // TODO: not taking into account all the constraints. Only using EndPoints and Connectivity Constraint.
518         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
519                 .create.connectivity.service.input.EndPointKey,
520             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
521                 .create.connectivity.service.input.EndPoint> endPointMap = input.getEndPoint();
522         ConnectionType connType = null;
523         ServiceFormat serviceFormat = null;
524         String nodeAid = String.join("+",
525             endPointMap.values().stream().findFirst().orElseThrow().getLocalId(),
526             TapiStringConstants.XPDR);
527         String nodeZid = String.join("+",
528             endPointMap.values().stream().skip(1).findFirst().orElseThrow().getLocalId(),
529             TapiStringConstants.XPDR);
530         LOG.info("NodeAid = {}", nodeAid);
531         LOG.info("NodeZid = {}", nodeZid);
532         //switch (constraint.getServiceLayer().getIntValue()) {
533         switch (input.getLayerProtocolName().getIntValue()) {
534             case 0:
535                 LOG.info("ODU");
536                 connType = ConnectionType.Infrastructure;
537                 serviceFormat = ServiceFormat.ODU;
538                 break;
539             case 1:
540                 LOG.info("ETH, no need to create OTU and ODU");
541                 connType = ConnectionType.Service;
542                 serviceFormat = ServiceFormat.Ethernet;
543                 break;
544             case 2:
545                 LOG.info("DSR, need to create OTU and ODU");
546                 connType = ConnectionType.Service;
547                 serviceFormat = ServiceFormat.Ethernet;
548                 break;
549             case 3:
550                 LOG.info("PHOTONIC");
551                 connType = getConnectionTypePhtnc(endPointMap.values());
552                 serviceFormat = getServiceFormatPhtnc(endPointMap.values());
553                 LOG.debug("Node a photonic = {}", nodeAid);
554                 LOG.debug("Node z photonic = {}", nodeZid);
555                 break;
556             default:
557                 LOG.info("Service type {} not supported", input.getLayerProtocolName().getName());
558         }
559         // Requested Capacity for connectivity service
560         Uint64 capacity = Uint64.valueOf(Math.abs(
561             input.getConnectivityConstraint().getRequestedCapacity().getTotalSize().getValue().intValue()));
562         // map endpoints into service end points. Map the type of service from TAPI to OR
563         ServiceAEnd serviceAEnd = tapiEndPointToServiceAPoint(
564             endPointMap.values().stream().findFirst().orElseThrow(),
565             serviceFormat, nodeAid, capacity, input.getLayerProtocolName());
566         ServiceZEnd serviceZEnd = tapiEndPointToServiceZPoint(
567             endPointMap.values().stream().skip(1).findFirst().orElseThrow(),
568             serviceFormat, nodeZid, capacity, input.getLayerProtocolName());
569         if (serviceAEnd == null || serviceZEnd == null) {
570             LOG.error("Couldnt map endpoints to service end");
571             return null;
572         }
573         LOG.info("Service a end = {}", serviceAEnd);
574         LOG.info("Service z end = {}", serviceZEnd);
575         return new ServiceCreateInputBuilder()
576             .setServiceAEnd(serviceAEnd)
577             .setServiceZEnd(serviceZEnd)
578             .setConnectionType(connType)
579             .setServiceName(serviceUuid.getValue())
580             .setCommonId("common id")
581             .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request-1")
582                 .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url")
583                 .setRequestSystemId("appname")
584                 .build())
585             .setCustomer("customer")
586             .setDueDate(DateAndTime.getDefaultInstance("2018-06-15T00:00:01Z"))
587             .setOperatorContact("pw1234")
588             .build();
589     }
590
591     private static ServiceAEnd getServiceAEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
592         if (sepA.getType().equals(ServiceEndpointType.SERVICEAEND)) {
593             return new ServiceAEndBuilder(sepA.getValue()).build();
594         }
595         if (sepZ.getType().equals(ServiceEndpointType.SERVICEAEND)) {
596             return new ServiceAEndBuilder(sepZ.getValue()).build();
597         }
598         return null;
599     }
600
601     private static ServiceZEnd getServiceZEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
602         if (sepA.getType().equals(ServiceEndpointType.SERVICEZEND)) {
603             return new ServiceZEndBuilder(sepA.getValue()).build();
604         }
605         if (sepZ.getType().equals(ServiceEndpointType.SERVICEZEND)) {
606             return new ServiceZEndBuilder(sepZ.getValue()).build();
607         }
608         return null;
609     }
610
611     private LayerProtocolName mapServiceLayerToAend(
612             org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526
613                 .service.ServiceAEnd serviceAEnd) {
614         ServiceFormat serviceFormat = serviceAEnd.getServiceFormat();
615         switch (serviceFormat) {
616             case OC:
617             case OTU:
618                 return LayerProtocolName.PHOTONICMEDIA;
619             case ODU:
620                 return LayerProtocolName.ODU;
621             case Ethernet:
622                 if (getOpenroadmType(
623                             serviceAEnd.getTxDirection().values().stream().findFirst().orElseThrow()
624                                 .getPort().getPortDeviceName())
625                         .equals(OpenroadmNodeType.TPDR)) {
626                     return LayerProtocolName.ETH;
627                 }
628                 return LayerProtocolName.DSR;
629             default:
630                 LOG.info("Service layer mapping not supported for {}", serviceFormat.getName());
631         }
632         return null;
633     }
634
635     private LayerProtocolName mapServiceLayer(ServiceFormat serviceFormat, EndPoint endPoint1, EndPoint endPoint2) {
636         switch (serviceFormat) {
637             case OC:
638             case OTU:
639                 return LayerProtocolName.PHOTONICMEDIA;
640             case ODU:
641                 return LayerProtocolName.ODU;
642             case Ethernet:
643                 String node1 = endPoint1.getLocalId();
644                 String node2 = endPoint2.getLocalId();
645                 if (getOpenroadmType(node1).equals(OpenroadmNodeType.TPDR)
646                         && getOpenroadmType(node2).equals(OpenroadmNodeType.TPDR)) {
647                     return LayerProtocolName.ETH;
648                 }
649                 return LayerProtocolName.DSR;
650             default:
651                 LOG.info("Service layer mapping not supported for {}", serviceFormat.getName());
652         }
653         return null;
654     }
655     //TODO factorize these two similar methods
656
657     private OpenroadmNodeType getOpenroadmType(String nodeName) {
658         LOG.info("Node name = {}", nodeName);
659         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node tapiNode =
660             this.tapiContext.getTapiNode(
661                 this.tapiTopoUuid,
662                 new Uuid(UUID.nameUUIDFromBytes(
663                         (String.join("+",nodeName, TapiStringConstants.XPDR)).getBytes(StandardCharsets.UTF_8))
664                     .toString()));
665         return tapiNode == null
666             ? null
667             : OpenroadmNodeType.forName(tapiNode.getName().get(new NameKey("Node Type")).getValue());
668     }
669
670     private Map<ConnectionKey, Connection> createXpdrCepsAndConnectionsEth(
671             List<String> xpdrClientTplist, List<String> xpdrNodelist, Map<ConnectionKey, Connection> lowerConn) {
672         // TODO: do we need to create cross connection between iODU and eODU??
673         // add the lower connections of the previous steps for this kind of service
674         Map<LowerConnectionKey, LowerConnection> xcMap = new HashMap<>();
675         for (Connection lowConn: lowerConn.values()) {
676             LowerConnection conn = new LowerConnectionBuilder().setConnectionUuid(lowConn.getConnectionUuid()).build();
677             xcMap.put(conn.key(), conn);
678         }
679         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
680                 .cep.list.ConnectionEndPointKey, ConnectionEndPoint> cepMapDsr = new HashMap<>();
681         // Create 1 cep per Xpdr in the CLIENT
682         // 1 top connection DSR between the CLIENT xpdrs
683         for (String xpdr:xpdrNodelist) {
684             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
685             String spcXpdrClient =
686                 xpdrClientTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().orElseThrow();
687             ConnectionEndPoint netCep1 =
688                 createCepXpdr(spcXpdrClient, TapiStringConstants.DSR, TapiStringConstants.XPDR, LayerProtocolName.DSR);
689             putXpdrCepInTopologyContext(
690                 xpdr, spcXpdrClient, TapiStringConstants.DSR, TapiStringConstants.XPDR, netCep1);
691             cepMapDsr.put(netCep1.key(), netCep1);
692         }
693         // DSR top connection between edge xpdr CLIENT DSR
694         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
695                 .connectivity.context.Connection connectionDsr =
696             createTopConnection(
697                 //spcXpdr1,
698                 xpdrClientTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(0)))
699                     .findFirst().orElseThrow(),
700                 //spcXpdr2,
701                 xpdrClientTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(xpdrNodelist.size() - 1)))
702                     .findFirst().orElseThrow(),
703                 cepMapDsr, TapiStringConstants.DSR, LayerProtocolName.DSR, xcMap, this.topConnXpdrXpdrPhtn);
704         this.connectionFullMap.put(connectionDsr.key(), connectionDsr);
705         // DSR top connection that will be added to the service object
706         Connection conn1 = new ConnectionBuilder().setConnectionUuid(connectionDsr.getUuid()).build();
707         return new HashMap<>(Map.of(conn1.key(), conn1));
708     }
709
710     private Map<ConnectionKey,Connection> createXpdrCepsAndConnectionsDsr(
711             List<String> xpdrClientTplist, List<String> xpdrNetworkTplist, List<String> xpdrNodelist) {
712         Map<ConnectionKey, Connection> connServMap = new HashMap<>();
713         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
714                 .cep.list.ConnectionEndPointKey, ConnectionEndPoint> cepMapDsr = new HashMap<>();
715         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
716                 .cep.list.ConnectionEndPointKey, ConnectionEndPoint> cepMapOdu = new HashMap<>();
717         // TODO: when upgrading the models to 2.1.3, get the connection inclusion because those connections will
718         //  be added to the lower connection of a top connection
719         Map<LowerConnectionKey, LowerConnection> xcMap = new HashMap<>();
720
721         // Create 1 cep per Xpdr in the CLIENT, 1 cep per Xpdr eODU, 1 XC between eODU and iODE,
722         // 1 top connection between eODU and a top connection DSR between the CLIENT xpdrs
723         for (String xpdr:xpdrNodelist) {
724             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
725             String spcXpdrClient =
726                 xpdrClientTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().orElseThrow();
727             ConnectionEndPoint clientCep1 =
728                 createCepXpdr(spcXpdrClient, TapiStringConstants.DSR, TapiStringConstants.XPDR, LayerProtocolName.DSR);
729             putXpdrCepInTopologyContext(
730                 xpdr, spcXpdrClient, TapiStringConstants.DSR, TapiStringConstants.XPDR, clientCep1);
731             ConnectionEndPoint clientCep2 = createCepXpdr(
732                     spcXpdrClient, TapiStringConstants.E_ODU, TapiStringConstants.XPDR, LayerProtocolName.ODU);
733             putXpdrCepInTopologyContext(
734                 xpdr, spcXpdrClient, TapiStringConstants.E_ODU, TapiStringConstants.XPDR, clientCep2);
735             cepMapDsr.put(clientCep1.key(), clientCep1);
736             cepMapOdu.put(clientCep2.key(), clientCep2);
737
738             String spcXpdrNetwork = getAssociatedNetworkPort(spcXpdrClient, xpdrNetworkTplist);
739             // Create x connection between I_ODU and E_ODU within xpdr
740             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
741                     .connectivity.context.Connection connection =
742                 createXCBetweenCeps(
743                     clientCep2, getAssociatediODUCep(spcXpdrNetwork),
744                      spcXpdrClient, spcXpdrNetwork, TapiStringConstants.ODU, LayerProtocolName.ODU);
745             this.connectionFullMap.put(connection.key(), connection);
746
747             // Create X connection that will be added to the service object
748             LowerConnection conn = new LowerConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
749             xcMap.put(conn.key(), conn);
750         }
751
752         // DSR top connection between edge xpdr CLIENT DSR
753         String spcXpdr1 =
754             xpdrClientTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(0)))
755                 .findFirst().orElseThrow();
756         String spcXpdr2 =
757             xpdrClientTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(xpdrNodelist.size() - 1)))
758                 .findFirst().orElseThrow();
759
760         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
761                 .connectivity.context.Connection connectionOdu =
762             createTopConnection(
763                 spcXpdr1, spcXpdr2, cepMapOdu, TapiStringConstants.E_ODU,
764                 LayerProtocolName.ODU, xcMap, this.topConnXpdrXpdrOdu);
765         this.connectionFullMap.put(connectionOdu.key(), connectionOdu);
766
767         // ODU top connection that will be added to the service object
768         Connection conn = new ConnectionBuilder().setConnectionUuid(connectionOdu.getUuid()).build();
769         connServMap.put(conn.key(), conn);
770         LowerConnection lowerConn = new LowerConnectionBuilder().setConnectionUuid(connectionOdu.getUuid()).build();
771         xcMap.put(lowerConn.key(), lowerConn);
772
773         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
774                 .connectivity.context.Connection connectionDsr =
775             createTopConnection(
776                 spcXpdr1, spcXpdr2, cepMapDsr, TapiStringConstants.DSR,
777                 LayerProtocolName.DSR, xcMap, this.topConnXpdrXpdrPhtn);
778         this.connectionFullMap.put(connectionDsr.key(), connectionDsr);
779         // DSR top connection that will be added to the service object
780         Connection conn1 = new ConnectionBuilder().setConnectionUuid(connectionDsr.getUuid()).build();
781         connServMap.put(conn1.key(), conn1);
782         return connServMap;
783     }
784
785     private Map<ConnectionKey, Connection> createXpdrCepsAndConnectionsOdu(
786             List<String> xpdrNetworkTplist, List<String> xpdrNodelist) {
787         Map<ConnectionKey, Connection> connServMap = new HashMap<>();
788         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
789                 .cep.list.ConnectionEndPointKey, ConnectionEndPoint> cepMap = new HashMap<>();
790         // TODO: when upgrading the models to 2.1.3, get the connection inclusion because those connections will
791         //  be added to the lower connection of a top connection
792         // Create 1 cep per Xpdr in the I_ODU and a top
793         // connection iODU between the xpdrs
794         for (String xpdr:xpdrNodelist) {
795             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
796             String spcXpdrNetwork =
797                 xpdrNetworkTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().orElseThrow();
798             ConnectionEndPoint netCep1 =
799                 createCepXpdr(
800                     spcXpdrNetwork, TapiStringConstants.I_ODU, TapiStringConstants.XPDR, LayerProtocolName.ODU);
801             putXpdrCepInTopologyContext(
802                 xpdr, spcXpdrNetwork, TapiStringConstants.I_ODU, TapiStringConstants.XPDR, netCep1);
803             cepMap.put(netCep1.key(), netCep1);
804         }
805         // ODU top connection between edge xpdr i_ODU
806         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
807                 .connectivity.context.Connection connection =
808             createTopConnection(
809                 //spcXpdr1,
810                 xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(0)))
811                     .findFirst().orElseThrow(),
812                 //spcXpdr2,
813                 xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(xpdrNodelist.size() - 1)))
814                     .findFirst().orElseThrow(),
815                 cepMap, TapiStringConstants.I_ODU,
816                 LayerProtocolName.ODU, new HashMap<>(), this.topConnXpdrXpdrPhtn);
817         this.connectionFullMap.put(connection.key(), connection);
818         // ODU top connection that will be added to the service object
819         Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
820         connServMap.put(conn.key(), conn);
821         this.topConnXpdrXpdrOdu = conn;
822         return connServMap;
823     }
824
825     private Map<ConnectionKey, Connection> createXpdrCepsAndConnectionsPht(
826                 List<String> xpdrNetworkTplist, List<String> xpdrNodelist) {
827         // TODO: when upgrading the models to 2.1.3, get the connection inclusion because those connections will
828         //  be added to the lower connection of a top connection
829         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.cep.list.ConnectionEndPointKey,
830             ConnectionEndPoint> cepMap = new HashMap<>();
831         // create ceps and x connections within xpdr
832         for (String xpdr:xpdrNodelist) {
833             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
834             String spcXpdrNetwork =
835                 xpdrNetworkTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().orElseThrow();
836             // There should be 1 network tp per xpdr
837             //   Just create 2 different CEPs (1 OTS + 1 OTSI_MC)
838             ConnectionEndPoint netCep1 = createCepXpdr(
839                     spcXpdrNetwork, TapiStringConstants.PHTNC_MEDIA_OTS,
840                     TapiStringConstants.XPDR, LayerProtocolName.PHOTONICMEDIA);
841             putXpdrCepInTopologyContext(
842                 xpdr, spcXpdrNetwork, TapiStringConstants.PHTNC_MEDIA_OTS, TapiStringConstants.XPDR, netCep1);
843             ConnectionEndPoint netCep2 = createCepXpdr(
844                     spcXpdrNetwork, TapiStringConstants.OTSI_MC,
845                     TapiStringConstants.XPDR, LayerProtocolName.PHOTONICMEDIA);
846             putXpdrCepInTopologyContext(
847                 xpdr, spcXpdrNetwork, TapiStringConstants.OTSI_MC, TapiStringConstants.XPDR, netCep2);
848 //            ConnectionEndPoint netCep3 = createCepXpdr(spcXpdrNetwork, TapiStringConstants.I_OTSI,
849 //                TapiStringConstants.XPDR, LayerProtocolName.PHOTONICMEDIA);
850 //            putXpdrCepInTopologyContext(xpdr, spcXpdrNetwork, TapiStringConstants.I_OTSI, TapiStringConstants.OTSI,
851 //                netCep3);
852             cepMap.put(netCep1.key(), netCep1);
853             cepMap.put(netCep2.key(), netCep2);
854 //            cepMap.put(netCep3.key(), netCep3);
855
856         }
857         // OTSi top connection between edge OTSI_MC Xpdr
858         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
859                 .connectivity.context.Connection connection =
860             createTopConnection(
861                 //spcXpdr1,
862                 xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(0)))
863                     .findFirst().orElseThrow(),
864                 //spcXpdr2,
865                 xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist.get(xpdrNodelist.size() - 1)))
866                     .findFirst().orElseThrow(),
867                 cepMap, TapiStringConstants.OTSI_MC,
868                 LayerProtocolName.PHOTONICMEDIA, new HashMap<>(), this.topConnRdmRdm);
869         this.connectionFullMap.put(connection.key(), connection);
870         // OTSi top connection that will be added to the service object
871         Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
872         this.topConnXpdrXpdrPhtn = conn;
873         return new HashMap<>(Map.of(conn.key(), conn));
874     }
875
876     private Map<ConnectionKey, Connection> createRoadmCepsAndConnections(
877             List<String> rdmAddDropTplist, List<String> rdmDegTplist, List<String> rdmNodelist,
878             String edgeRoadm1, String edgeRoadm2) {
879         // TODO: will need to check if things exist already or not
880         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
881                 .cep.list.ConnectionEndPointKey, ConnectionEndPoint> cepMap = new HashMap<>();
882         // create ceps and x connections within roadm
883         Map<LowerConnectionKey, LowerConnection> xcLowerMap = new HashMap<>();
884         for (String roadm : rdmNodelist) {
885             LOG.info("Creating ceps and xc for roadm {}", roadm);
886             if (roadm.equals(edgeRoadm1) || roadm.equals(edgeRoadm2)) {
887                 LOG.info("EDGE ROADM, cross connections needed between SRG and DEG");
888                 String spcRdmAD = rdmAddDropTplist.stream().filter(adp -> adp.contains(roadm))
889                     .findFirst().orElseThrow();
890                 LOG.info("AD port of ROADm {} = {}", roadm, spcRdmAD);
891                 // There should be only 1 AD and 1 DEG per roadm
892                 // TODO photonic media model should be updated to have the corresponding CEPs. I will just create
893                 //  3 different MC CEPs giving different IDs to show that they are different
894                 // Create 3 CEPs for each AD and DEG and the corresponding cross connections, matching the NEPs
895                 // created in the topology creation
896                 // add CEPs to the topology to the corresponding ONEP
897                 ConnectionEndPoint adCep1 = createCepRoadm(spcRdmAD, TapiStringConstants.PHTNC_MEDIA_OTS);
898                 putRdmCepInTopologyContext(roadm, spcRdmAD, TapiStringConstants.PHTNC_MEDIA_OTS, adCep1);
899                 ConnectionEndPoint adCep2 = createCepRoadm(spcRdmAD, TapiStringConstants.MC);
900                 putRdmCepInTopologyContext(roadm, spcRdmAD, TapiStringConstants.MC, adCep2);
901                 ConnectionEndPoint adCep3 = createCepRoadm(spcRdmAD, TapiStringConstants.OTSI_MC);
902                 putRdmCepInTopologyContext(roadm, spcRdmAD, TapiStringConstants.OTSI_MC, adCep3);
903                 cepMap.put(adCep1.key(), adCep1);
904                 cepMap.put(adCep2.key(), adCep2);
905                 cepMap.put(adCep3.key(), adCep3);
906
907                 String spcRdmDEG = rdmDegTplist.stream().filter(adp -> adp.contains(roadm)).findFirst().orElseThrow();
908                 LOG.info("Degree port of ROADm {} = {}", roadm, spcRdmDEG);
909
910                 ConnectionEndPoint degCep0 = createCepRoadm(spcRdmDEG, TapiStringConstants.PHTNC_MEDIA_OTS);
911                 putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.PHTNC_MEDIA_OTS, degCep0);
912                 ConnectionEndPoint degCep1 = createCepRoadm(spcRdmDEG, TapiStringConstants.PHTNC_MEDIA_OMS);
913                 putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.PHTNC_MEDIA_OMS, degCep1);
914                 ConnectionEndPoint degCep2 = createCepRoadm(spcRdmDEG, TapiStringConstants.MC);
915                 putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.MC, degCep2);
916                 ConnectionEndPoint degCep3 = createCepRoadm(spcRdmDEG, TapiStringConstants.OTSI_MC);
917                 putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.OTSI_MC, degCep3);
918                 cepMap.put(degCep0.key(), degCep0);
919                 cepMap.put(degCep1.key(), degCep1);
920                 cepMap.put(degCep2.key(), degCep2);
921                 cepMap.put(degCep3.key(), degCep3);
922
923                 LOG.info("Going to create cross connections for ROADM {}", roadm);
924                 // Create X connections between MC and OTSi_MC for full map
925                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
926                         .connectivity.context.Connection connection1 =
927                     createXCBetweenCeps(
928                         adCep2, degCep2, spcRdmAD, spcRdmDEG, TapiStringConstants.MC,
929                         LayerProtocolName.PHOTONICMEDIA);
930                 LOG.info("Cross connection 1 created = {}", connection1);
931                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
932                         .connectivity.context.Connection connection2 =
933                     createXCBetweenCeps(
934                         adCep3, degCep3, spcRdmAD, spcRdmDEG, TapiStringConstants.OTSI_MC,
935                         LayerProtocolName.PHOTONICMEDIA);
936                 LOG.info("Cross connection 2 created = {}", connection2);
937                 this.connectionFullMap.put(connection1.key(), connection1);
938                 this.connectionFullMap.put(connection2.key(), connection2);
939
940                 // Create X connections that will be added to the service object
941                 LowerConnection conn1 = new LowerConnectionBuilder().setConnectionUuid(connection1.getUuid()).build();
942                 LowerConnection conn2 = new LowerConnectionBuilder().setConnectionUuid(connection2.getUuid()).build();
943
944                 xcLowerMap.put(conn1.key(), conn1);
945                 xcLowerMap.put(conn2.key(), conn2);
946             } else {
947                 LOG.info("MIDDLE ROADM, cross connections needed between DEG and DEG");
948                 String spcRdmDEG1 = rdmDegTplist.stream().filter(adp -> adp.contains(roadm)).findFirst().orElseThrow();
949                 LOG.info("Degree 1 port of ROADm {} = {}", roadm, spcRdmDEG1);
950
951                 ConnectionEndPoint deg1Cep0 = createCepRoadm(spcRdmDEG1, TapiStringConstants.PHTNC_MEDIA_OTS);
952                 putRdmCepInTopologyContext(roadm, spcRdmDEG1, TapiStringConstants.PHTNC_MEDIA_OTS, deg1Cep0);
953                 ConnectionEndPoint deg1Cep1 = createCepRoadm(spcRdmDEG1, TapiStringConstants.PHTNC_MEDIA_OMS);
954                 putRdmCepInTopologyContext(roadm, spcRdmDEG1, TapiStringConstants.PHTNC_MEDIA_OMS, deg1Cep1);
955                 ConnectionEndPoint deg1Cep2 = createCepRoadm(spcRdmDEG1, TapiStringConstants.MC);
956                 putRdmCepInTopologyContext(roadm, spcRdmDEG1, TapiStringConstants.MC, deg1Cep2);
957                 ConnectionEndPoint deg1Cep3 = createCepRoadm(spcRdmDEG1, TapiStringConstants.OTSI_MC);
958                 putRdmCepInTopologyContext(roadm, spcRdmDEG1, TapiStringConstants.OTSI_MC, deg1Cep3);
959                 cepMap.put(deg1Cep0.key(), deg1Cep0);
960                 cepMap.put(deg1Cep1.key(), deg1Cep1);
961                 cepMap.put(deg1Cep2.key(), deg1Cep2);
962                 cepMap.put(deg1Cep3.key(), deg1Cep3);
963
964                 String spcRdmDEG2 =
965                     rdmDegTplist.stream().filter(adp -> adp.contains(roadm)).skip(1).findFirst().orElseThrow();
966                 LOG.info("Degree 2 port of ROADm {} = {}", roadm, spcRdmDEG2);
967
968                 ConnectionEndPoint deg2Cep0 = createCepRoadm(spcRdmDEG2, TapiStringConstants.PHTNC_MEDIA_OTS);
969                 putRdmCepInTopologyContext(roadm, spcRdmDEG2, TapiStringConstants.PHTNC_MEDIA_OTS, deg2Cep0);
970                 ConnectionEndPoint deg2Cep1 = createCepRoadm(spcRdmDEG2, TapiStringConstants.PHTNC_MEDIA_OMS);
971                 putRdmCepInTopologyContext(roadm, spcRdmDEG2, TapiStringConstants.PHTNC_MEDIA_OMS, deg2Cep1);
972                 ConnectionEndPoint deg2Cep2 = createCepRoadm(spcRdmDEG2, TapiStringConstants.MC);
973                 putRdmCepInTopologyContext(roadm, spcRdmDEG2, TapiStringConstants.MC, deg2Cep2);
974                 ConnectionEndPoint deg2Cep3 = createCepRoadm(spcRdmDEG2, TapiStringConstants.OTSI_MC);
975                 putRdmCepInTopologyContext(roadm, spcRdmDEG2, TapiStringConstants.OTSI_MC, deg2Cep3);
976                 cepMap.put(deg2Cep0.key(), deg2Cep0);
977                 cepMap.put(deg2Cep1.key(), deg2Cep1);
978                 cepMap.put(deg2Cep2.key(), deg2Cep2);
979                 cepMap.put(deg2Cep3.key(), deg2Cep3);
980
981                 LOG.info("Going to create cross connections for ROADM {}", roadm);
982                 // Create X connections between MC and OTSi_MC for full map
983                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
984                         .connectivity.context.Connection connection1 =
985                     createXCBetweenCeps(
986                         deg1Cep2, deg2Cep2, spcRdmDEG1, spcRdmDEG2,
987                         TapiStringConstants.MC, LayerProtocolName.PHOTONICMEDIA);
988                 LOG.info("Cross connection 1 created = {}", connection1);
989                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
990                         .connectivity.context.Connection connection2 =
991                     createXCBetweenCeps(
992                         deg1Cep3, deg2Cep3, spcRdmDEG1, spcRdmDEG2,
993                         TapiStringConstants.OTSI_MC, LayerProtocolName.PHOTONICMEDIA);
994                 LOG.info("Cross connection 2 created = {}", connection2.toString());
995                 this.connectionFullMap.put(connection1.key(), connection1);
996                 this.connectionFullMap.put(connection2.key(), connection2);
997
998                 // Create X connections that will be added to the service object
999                 LowerConnection conn1 = new LowerConnectionBuilder().setConnectionUuid(connection1.getUuid()).build();
1000                 xcLowerMap.put(conn1.key(), conn1);
1001                 LowerConnection conn2 = new LowerConnectionBuilder().setConnectionUuid(connection2.getUuid()).build();
1002                 xcLowerMap.put(conn2.key(), conn2);
1003             }
1004         }
1005         LOG.info("Going to create top connections between roadms");
1006         String spcRdmAD1 = rdmAddDropTplist.stream().filter(adp -> adp.contains(edgeRoadm1)).findFirst().orElseThrow();
1007         String spcRdmAD2 = rdmAddDropTplist.stream().filter(adp -> adp.contains(edgeRoadm2)).findFirst().orElseThrow();
1008         // MC top connection between edge roadms
1009         LOG.info("Going to created top connection between MC");
1010         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1011                 .connectivity.context.Connection connection =
1012             createTopConnection(
1013                 spcRdmAD1, spcRdmAD2, cepMap, TapiStringConstants.MC,
1014                 LayerProtocolName.PHOTONICMEDIA, xcLowerMap, null);
1015         this.connectionFullMap.put(connection.key(), connection);
1016         LOG.info("Top connection created = {}", connection);
1017
1018         LowerConnection conn1 = new LowerConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
1019         // OTSiMC top connection between edge roadms
1020         LOG.info("Going to created top connection between OTSiMC");
1021         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1022                 .connectivity.context.Connection connection1 =
1023             createTopConnection(
1024                 spcRdmAD1, spcRdmAD2, cepMap, TapiStringConstants.OTSI_MC,
1025                 LayerProtocolName.PHOTONICMEDIA,
1026                 //topLowerMap,
1027                 new HashMap<>(Map.of(conn1.key(), conn1)),
1028                 null);
1029         this.connectionFullMap.put(connection1.key(), connection1);
1030         LOG.info("Top connection created = {}", connection1);
1031
1032         // OTSiMC top connections that will be added to the service object
1033         Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
1034         Connection conn2 = new ConnectionBuilder().setConnectionUuid(connection1.getUuid()).build();
1035         this.topConnRdmRdm = conn2;
1036         return new HashMap<>(Map.of(conn.key(), conn, conn2.key(), conn2));
1037     }
1038
1039     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1040                 .connectivity.context.Connection createTopConnection(
1041             String tp1,
1042             String tp2,
1043             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1044                     .cep.list.ConnectionEndPointKey, ConnectionEndPoint> cepMap,
1045             String qual, LayerProtocolName topPortocol,
1046             Map<LowerConnectionKey, LowerConnection> xcMap,
1047             Connection additionalLowerConn) {
1048         // find cep for each AD MC of roadm 1 and 2
1049         String topConnName = String.join("+", "TOP", tp1, tp2, qual);
1050         LOG.info("Top connection name = {}", topConnName);
1051         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.ConnectionEndPoint adCep1 =
1052             cepMap.get(
1053                 new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1054                         .cep.list.ConnectionEndPointKey(new Uuid(UUID.nameUUIDFromBytes(
1055                     (String.join("+", "CEP", tp1.split("\\+")[0], qual, tp1.split("\\+")[1]))
1056                         .getBytes(StandardCharsets.UTF_8)).toString())));
1057         LOG.info("ADCEP1 = {}", adCep1);
1058         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1059                 .connection.ConnectionEndPoint cep1 =
1060             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1061                     .connection.ConnectionEndPointBuilder()
1062                 .setNodeEdgePointUuid(adCep1.getParentNodeEdgePoint().getNodeEdgePointUuid())
1063                 .setNodeUuid(adCep1.getParentNodeEdgePoint().getNodeUuid())
1064                 .setTopologyUuid(adCep1.getParentNodeEdgePoint().getTopologyUuid())
1065                 .setConnectionEndPointUuid(adCep1.getUuid())
1066                 .build();
1067         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.ConnectionEndPoint adCep2 =
1068             cepMap.get(
1069                 new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1070                         .cep.list.ConnectionEndPointKey(
1071                     new Uuid(UUID.nameUUIDFromBytes(
1072                         (String.join("+", "CEP", tp2.split("\\+")[0], qual, tp2.split("\\+")[1]))
1073                             .getBytes(StandardCharsets.UTF_8)).toString())));
1074         LOG.info("ADCEP2 = {}", adCep2);
1075         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1076                 .connection.ConnectionEndPoint cep2 =
1077             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1078                     .connection.ConnectionEndPointBuilder()
1079                 .setNodeEdgePointUuid(adCep2.getParentNodeEdgePoint().getNodeEdgePointUuid())
1080                 .setNodeUuid(adCep2.getParentNodeEdgePoint().getNodeUuid())
1081                 .setTopologyUuid(adCep2.getParentNodeEdgePoint().getTopologyUuid())
1082                 .setConnectionEndPointUuid(adCep1.getUuid())
1083                 .build();
1084         Name connName = new NameBuilder()
1085             .setValueName("Connection name")
1086             .setValue(topConnName)
1087             .build();
1088         // TODO: lower connection, supported link.......
1089         if (additionalLowerConn != null) {
1090             xcMap.putIfAbsent(new LowerConnectionKey(additionalLowerConn.getConnectionUuid()),
1091                 new LowerConnectionBuilder().setConnectionUuid(additionalLowerConn.getConnectionUuid()).build());
1092         }
1093         return new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1094                 .connectivity.context.ConnectionBuilder()
1095             .setUuid(new Uuid(UUID.nameUUIDFromBytes(topConnName.getBytes(StandardCharsets.UTF_8)).toString()))
1096             .setName(Map.of(connName.key(), connName))
1097             .setConnectionEndPoint(new HashMap<>(Map.of(cep1.key(), cep1, cep2.key(), cep2)))
1098             .setOperationalState(OperationalState.ENABLED)
1099             .setLayerProtocolName(topPortocol)
1100             .setLifecycleState(LifecycleState.INSTALLED)
1101             .setDirection(ForwardingDirection.BIDIRECTIONAL)
1102             .setLowerConnection(xcMap)
1103             .build();
1104     }
1105
1106     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1107                 .connectivity.context.Connection createXCBetweenCeps(
1108             ConnectionEndPoint cep1, ConnectionEndPoint cep2,
1109             String tp1, String tp2, String qual, LayerProtocolName xcProtocol) {
1110         String crossConnName = String.join("+", "XC", tp1, tp2, qual);
1111         LOG.info("Creation cross connection between: {} and {}", tp1, tp2);
1112         LOG.info("Cross connection name = {}", crossConnName);
1113         LOG.debug("Parent NEP of CEP1 = {}", cep1.getParentNodeEdgePoint());
1114         LOG.debug("Parent NEP CEP2 = {}", cep2.getParentNodeEdgePoint());
1115         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1116                 .connection.ConnectionEndPoint cepServ1 =
1117             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1118                     .connection.ConnectionEndPointBuilder()
1119                 .setNodeEdgePointUuid(cep1.getParentNodeEdgePoint().getNodeEdgePointUuid())
1120                 .setNodeUuid(cep1.getParentNodeEdgePoint().getNodeUuid())
1121                 .setTopologyUuid(cep1.getParentNodeEdgePoint().getTopologyUuid())
1122                 .setConnectionEndPointUuid(cep1.getUuid())
1123                 .build();
1124         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1125                 .connection.ConnectionEndPoint cepServ2 =
1126             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1127                     .connection.ConnectionEndPointBuilder()
1128                 .setNodeEdgePointUuid(cep2.getParentNodeEdgePoint().getNodeEdgePointUuid())
1129                 .setNodeUuid(cep2.getParentNodeEdgePoint().getNodeUuid())
1130                 .setTopologyUuid(cep2.getParentNodeEdgePoint().getTopologyUuid())
1131                 .setConnectionEndPointUuid(cep2.getUuid())
1132                 .build();
1133         Name connName = new NameBuilder()
1134             .setValueName("Connection name")
1135             .setValue(crossConnName)
1136             .build();
1137         // TODO: lower connection, supported link.......
1138         return new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1139                 .connectivity.context.ConnectionBuilder()
1140             .setUuid(new Uuid(UUID.nameUUIDFromBytes(crossConnName.getBytes(StandardCharsets.UTF_8)).toString()))
1141             .setName(Map.of(connName.key(), connName))
1142             .setConnectionEndPoint(new HashMap<>(Map.of(cepServ1.key(), cepServ1, cepServ2.key(), cepServ2)))
1143             .setOperationalState(OperationalState.ENABLED)
1144             .setLayerProtocolName(xcProtocol)
1145             .setLifecycleState(LifecycleState.INSTALLED)
1146             .setDirection(ForwardingDirection.BIDIRECTIONAL)
1147             .build();
1148     }
1149
1150     private ConnectionEndPoint createCepRoadm(String id, String qualifier) {
1151         String nepId = String.join("+", id.split("\\+")[0], qualifier, id.split("\\+")[1]);
1152         String nodeNepId = String.join("+",id.split("\\+")[0], TapiStringConstants.PHTNC_MEDIA);
1153         LOG.info("NEP = {}", nepId);
1154         Name cepName = new NameBuilder()
1155             .setValueName("ConnectionEndPoint name")
1156             .setValue(nepId)
1157             .build();
1158         ParentNodeEdgePoint pnep = new ParentNodeEdgePointBuilder()
1159             .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes(
1160                     nepId.getBytes(StandardCharsets.UTF_8))
1161                 .toString()))
1162             .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1163                     nodeNepId.getBytes(StandardCharsets.UTF_8))
1164                 .toString()))
1165             .setTopologyUuid(new Uuid(UUID.nameUUIDFromBytes(
1166                     TapiStringConstants.T0_FULL_MULTILAYER.getBytes(StandardCharsets.UTF_8))
1167                 .toString()))
1168             .build();
1169         String clientQualifier = "";
1170         switch (qualifier) {
1171             case TapiStringConstants.PHTNC_MEDIA_OTS:
1172                 clientQualifier = TapiStringConstants.PHTNC_MEDIA_OMS;
1173                 break;
1174             case TapiStringConstants.PHTNC_MEDIA_OMS:
1175                 clientQualifier = TapiStringConstants.MC;
1176                 OwnedNodeEdgePoint onepMC = createRoadmNep(id.split("\\+")[0], id.split("\\+")[1],
1177                     false, OperationalState.ENABLED, AdministrativeState.UNLOCKED, clientQualifier);
1178                 putRdmNepInTopologyContext(id.split("\\+")[0], id.split("\\+")[1], TapiStringConstants.MC, onepMC);
1179                 break;
1180             case TapiStringConstants.MC:
1181                 clientQualifier = TapiStringConstants.OTSI_MC;
1182                 OwnedNodeEdgePoint onepOTSiMC = createRoadmNep(id.split("\\+")[0], id.split("\\+")[1],
1183                     false, OperationalState.ENABLED, AdministrativeState.UNLOCKED, clientQualifier);
1184                 putRdmNepInTopologyContext(id.split("\\+")[0], id.split("\\+")[1],
1185                     TapiStringConstants.OTSI_MC, onepOTSiMC);
1186                 break;
1187             default:
1188                 LOG.debug("not currently handling client NEP for OTSiMC CEP {}", nepId);
1189                 break;
1190         }
1191         ClientNodeEdgePoint cnep = new ClientNodeEdgePointBuilder()
1192             .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes(
1193                     (String.join("+", id.split("\\+")[0], clientQualifier, id.split("\\+")[1]))
1194                         .getBytes(StandardCharsets.UTF_8))
1195                 .toString()))
1196             .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1197                     nodeNepId.getBytes(StandardCharsets.UTF_8))
1198                 .toString()))
1199             .setTopologyUuid(new Uuid(UUID.nameUUIDFromBytes(
1200                     TapiStringConstants.T0_FULL_MULTILAYER.getBytes(StandardCharsets.UTF_8))
1201                 .toString()))
1202             .build();
1203         // TODO: add augmentation with the corresponding cep-spec (i.e. MC, OTSiMC...)
1204         // TODO: add parent ONEP??
1205         ConnectionEndPointBuilder cepBldr = new ConnectionEndPointBuilder()
1206             .setUuid(new Uuid(UUID.nameUUIDFromBytes(
1207                     (String.join("+", "CEP", id.split("\\+")[0], qualifier, id.split("\\+")[1]))
1208                         .getBytes(StandardCharsets.UTF_8))
1209                 .toString()))
1210             .setParentNodeEdgePoint(pnep)
1211             .setName(Map.of(cepName.key(), cepName))
1212             .setConnectionPortRole(PortRole.SYMMETRIC)
1213             .setDirection(Direction.BIDIRECTIONAL)
1214             .setOperationalState(OperationalState.ENABLED)
1215             .setLifecycleState(LifecycleState.INSTALLED)
1216             .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA);
1217         return TapiStringConstants.OTSI_MC.equals(qualifier)
1218             ? cepBldr.build()
1219             : cepBldr.setClientNodeEdgePoint(Map.of(cnep.key(), cnep)).build();
1220     }
1221
1222     private ConnectionEndPoint createCepXpdr(
1223             String id, String qualifier, String nodeLayer, LayerProtocolName cepProtocol) {
1224         String nepId = String.join("+", id.split("\\+")[0], qualifier, id.split("\\+")[1]);
1225         String nepNodeId = String.join("+",id.split("\\+")[0], TapiStringConstants.XPDR);
1226         Name cepName = new NameBuilder()
1227             .setValueName("ConnectionEndPoint name")
1228             .setValue(nepId)
1229             .build();
1230         ParentNodeEdgePoint pnep = new ParentNodeEdgePointBuilder()
1231             .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes(
1232                     nepId.getBytes(StandardCharsets.UTF_8)).toString()))
1233             .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1234                     nepNodeId.getBytes(StandardCharsets.UTF_8)).toString()))
1235             .setTopologyUuid(new Uuid(UUID.nameUUIDFromBytes(
1236                 TapiStringConstants.T0_FULL_MULTILAYER
1237                     .getBytes(StandardCharsets.UTF_8)).toString()))
1238             .build();
1239         String clientQualifier = "";
1240         String clientNodeLayer = TapiStringConstants.PHTNC_MEDIA;
1241         switch (qualifier) {
1242             case TapiStringConstants.PHTNC_MEDIA_OTS:
1243                 clientQualifier = TapiStringConstants.OTSI_MC;
1244                 break;
1245             case TapiStringConstants.OTSI_MC:
1246                 clientQualifier = TapiStringConstants.E_ODU;
1247                 clientNodeLayer = TapiStringConstants.ODU;
1248                 break;
1249             case TapiStringConstants.E_ODU:
1250                 clientQualifier = TapiStringConstants.DSR;
1251                 clientNodeLayer = TapiStringConstants.DSR;
1252                 break;
1253             default :
1254                 LOG.debug("no client CEP for DSR NEP {}", nepId);
1255                 break;
1256         }
1257         ClientNodeEdgePoint cnep = new ClientNodeEdgePointBuilder()
1258             .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes(
1259                 (String.join("+", id.split("\\+")[0], clientQualifier, id.split("\\+")[1]))
1260                     .getBytes(StandardCharsets.UTF_8)).toString()))
1261             .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1262                     nepNodeId.getBytes(StandardCharsets.UTF_8)).toString()))
1263             .setTopologyUuid(new Uuid(UUID.nameUUIDFromBytes(
1264                 TapiStringConstants.T0_FULL_MULTILAYER
1265                     .getBytes(StandardCharsets.UTF_8)).toString()))
1266             .build();
1267         // TODO: add augmentation with the corresponding cep-spec (i.e. MC, OTSiMC...)
1268         // TODO: add parent ONEP??
1269         ConnectionEndPointBuilder cepBldr = new ConnectionEndPointBuilder()
1270             .setUuid(new Uuid(UUID.nameUUIDFromBytes(
1271                 (String.join("+", "CEP", id.split("\\+")[0], qualifier, id.split("\\+")[1]))
1272                     .getBytes(StandardCharsets.UTF_8)).toString()))
1273             .setParentNodeEdgePoint(pnep)
1274             .setName(Map.of(cepName.key(), cepName))
1275             .setConnectionPortRole(PortRole.SYMMETRIC)
1276             .setDirection(Direction.BIDIRECTIONAL)
1277             .setOperationalState(OperationalState.ENABLED)
1278             .setLifecycleState(LifecycleState.INSTALLED)
1279             .setLayerProtocolName(cepProtocol);
1280         return TapiStringConstants.DSR.equals(qualifier)
1281             ? cepBldr.build()
1282             : cepBldr.setClientNodeEdgePoint(Map.of(cnep.key(), cnep)).build();
1283     }
1284
1285     private EndPoint mapServiceZEndPoint(
1286             org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526
1287                 .service.ServiceZEnd serviceZEnd, PathDescription pathDescription) {
1288         EndPointBuilder endPointBuilder = new EndPointBuilder();
1289         // 1. Service Format: ODU, OTU, ETH
1290         ServiceFormat serviceFormat = serviceZEnd.getServiceFormat();
1291         String serviceNodeId = serviceZEnd.getNodeId().getValue();
1292         // Identify SIP name
1293         Uuid sipUuid = getSipIdFromZend(pathDescription.getZToADirection().getZToA(), serviceNodeId, serviceFormat);
1294         LOG.info("Uuid of z end {}", sipUuid);
1295         LayerProtocolName layerProtocols = null;
1296         // Layer protocol name
1297         switch (serviceFormat) {
1298             case Ethernet:
1299                 layerProtocols = LayerProtocolName.DSR;
1300                 break;
1301             case OTU:
1302             case OC:
1303                 layerProtocols = LayerProtocolName.PHOTONICMEDIA;
1304                 break;
1305             case ODU:
1306                 layerProtocols = LayerProtocolName.ODU;
1307                 break;
1308             default:
1309                 LOG.error("Service Format not supported");
1310         }
1311         var portZEnd = serviceZEnd.getTxDirection().values().stream().findFirst().orElseThrow().getPort();
1312         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.Name name =
1313             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.NameBuilder()
1314                 .setValueName("OpenROADM info")
1315                 .setValue(String.join("-", serviceZEnd.getClli(), portZEnd.getPortDeviceName(), portZEnd.getPortName()))
1316                 .build();
1317         return endPointBuilder
1318             .setServiceInterfacePoint(new ServiceInterfacePointBuilder()
1319                 .setServiceInterfacePointUuid(sipUuid)
1320                 .build())
1321             .setName(Map.of(name.key(), name))
1322             .setAdministrativeState(AdministrativeState.UNLOCKED)
1323             .setDirection(Direction.BIDIRECTIONAL)
1324             .setLifecycleState(LifecycleState.INSTALLED)
1325             .setOperationalState(OperationalState.ENABLED)
1326             .setLayerProtocolName(layerProtocols)
1327             .setCapacity(new CapacityBuilder()
1328                 .setTotalSize(new TotalSizeBuilder()
1329                     .setValue(Decimal64.valueOf(BigDecimal.valueOf(serviceZEnd.getServiceRate().doubleValue())))
1330                     .setUnit(CAPACITYUNITGBPS.VALUE)
1331                     .build())
1332 //                .setBandwidthProfile(new BandwidthProfileBuilder().build()) // TODO: implement bandwidth profile
1333                 .build())
1334             .setProtectionRole(ProtectionRole.WORK)
1335             .setRole(PortRole.SYMMETRIC)
1336             .setLocalId(portZEnd.getPortDeviceName())
1337             .build();
1338     }
1339
1340     private EndPoint mapServiceAEndPoint(
1341         org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.ServiceAEnd
1342             serviceAEnd, PathDescription pathDescription) {
1343         EndPointBuilder endPointBuilder = new EndPointBuilder();
1344         // 1. Service Format: ODU, OTU, ETH
1345         ServiceFormat serviceFormat = serviceAEnd.getServiceFormat();
1346         String serviceNodeId = serviceAEnd.getNodeId().getValue();
1347         // Identify SIP name
1348         Uuid sipUuid = getSipIdFromAend(pathDescription.getAToZDirection().getAToZ(), serviceNodeId, serviceFormat);
1349         LOG.info("Uuid of a end {}", sipUuid);
1350         LayerProtocolName layerProtocols = null;
1351         // Layer protocol name
1352         switch (serviceFormat) {
1353             case Ethernet:
1354                 layerProtocols = LayerProtocolName.DSR;
1355                 break;
1356             case OTU:
1357             case OC:
1358                 layerProtocols = LayerProtocolName.PHOTONICMEDIA;
1359                 break;
1360             case ODU:
1361                 layerProtocols = LayerProtocolName.ODU;
1362                 break;
1363             default:
1364                 LOG.error("Service Format not supported");
1365         }
1366         var portAEnd = serviceAEnd.getTxDirection().values().stream().findFirst().orElseThrow().getPort();
1367         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.Name name =
1368             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.NameBuilder()
1369                 .setValueName("OpenROADM info")
1370                 .setValue(String.join("-", serviceAEnd.getClli(), portAEnd.getPortDeviceName(), portAEnd.getPortName()))
1371                 .build();
1372         return endPointBuilder
1373             .setServiceInterfacePoint(new ServiceInterfacePointBuilder()
1374                 .setServiceInterfacePointUuid(sipUuid)
1375                 .build())
1376             .setName(Map.of(name.key(), name))
1377             .setAdministrativeState(AdministrativeState.UNLOCKED)
1378             .setDirection(Direction.BIDIRECTIONAL)
1379             .setLifecycleState(LifecycleState.INSTALLED)
1380             .setOperationalState(OperationalState.ENABLED)
1381             .setLayerProtocolName(layerProtocols)
1382             .setCapacity(new CapacityBuilder()
1383                 .setTotalSize(new TotalSizeBuilder()
1384                     .setValue(Decimal64.valueOf(BigDecimal.valueOf(serviceAEnd.getServiceRate().doubleValue())))
1385                     .setUnit(CAPACITYUNITGBPS.VALUE)
1386                     .build())
1387 //                .setBandwidthProfile(new BandwidthProfileBuilder().build()) // TODO: implement bandwidth profile
1388                 .build())
1389             .setProtectionRole(ProtectionRole.WORK)
1390             .setRole(PortRole.SYMMETRIC)
1391             .setLocalId(serviceAEnd.getTxDirection().values().stream().findFirst().orElseThrow().getPort()
1392                     .getPortDeviceName())
1393             .build();
1394     }
1395
1396     private Uuid getSipIdFromZend(Map<ZToAKey, ZToA> mapztoa, String serviceNodeId, ServiceFormat serviceFormat) {
1397         if (serviceNodeId.contains("ROADM")) {
1398             // Service from ROADM to ROADM
1399             // AddDrop-AddDrop ports --> MC layer SIPs
1400             ZToA firstElement =
1401                 mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("0")).findFirst().orElseThrow();
1402             TerminationPoint tp = (TerminationPoint) firstElement.getResource().getResource();
1403             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1404                 (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId()))
1405                     .getBytes(StandardCharsets.UTF_8)).toString());
1406             LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId()));
1407             for (ServiceInterfacePoint sip:this.sipMap.values()) {
1408                 if (sip.getUuid().equals(sipUuid)) {
1409                     return sip.getUuid();
1410                 }
1411                 LOG.debug("SIP {} does not match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1412             }
1413             return null;
1414         }
1415         // Service from XPDR to XPDR
1416         ZToA firstElement;
1417         TerminationPoint tp;
1418         Uuid sipUuid;
1419         switch (serviceFormat) {
1420             case ODU:
1421                 firstElement =
1422                     mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("2")).findFirst().orElseThrow();
1423                 tp = (TerminationPoint) firstElement.getResource().getResource();
1424                 // Network-Network ports --> iODU layer SIPs TODO --> updated to E_ODU
1425                 sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1426                     (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.I_ODU, tp.getTpId()))
1427                         .getBytes(StandardCharsets.UTF_8)).toString());
1428                 LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.I_ODU, tp.getTpId()));
1429                 break;
1430             case OTU:
1431                 firstElement =
1432                     mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("2")).findFirst().orElseThrow();
1433                 tp = (TerminationPoint) firstElement.getResource().getResource();
1434                 // Network-Network ports --> iOTSi layer SIPs
1435                 sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1436                     (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.I_OTSI, tp.getTpId()))
1437                         .getBytes(StandardCharsets.UTF_8)).toString());
1438                 LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.I_OTSI, tp.getTpId()));
1439                 break;
1440             case Ethernet:
1441                 LOG.info("Elements ZA = {}", mapztoa.values());
1442                 firstElement =
1443                     mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("0")).findFirst().orElseThrow();
1444                 tp = (TerminationPoint) firstElement.getResource().getResource();
1445                 // Client-client ports --> DSR layer SIPs
1446                 sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1447                     (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.DSR, tp.getTpId()))
1448                         .getBytes(StandardCharsets.UTF_8)).toString());
1449                 LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.DSR, tp.getTpId()));
1450                 break;
1451             default:
1452                 sipUuid = null;
1453                 LOG.warn("Service format {} not supported (?)", serviceFormat.getName());
1454         }
1455         for (ServiceInterfacePoint sip:this.sipMap.values()) {
1456             if (sip.getUuid().equals(sipUuid)) {
1457                 return sip.getUuid();
1458             }
1459             LOG.debug("SIP {} does not match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1460         }
1461         return null;
1462     }
1463
1464     private Uuid getSipIdFromAend(Map<AToZKey, AToZ> mapatoz, String serviceNodeId, ServiceFormat serviceFormat) {
1465         LOG.info("ServiceNode = {} and ServiceFormat = {}", serviceNodeId, serviceFormat.getName());
1466         LOG.info("Map a to z = {}", mapatoz);
1467         if (serviceNodeId.contains("ROADM")) {
1468             // Service from ROADM to ROADM
1469             // AddDrop-AddDrop ports --> MC layer SIPs
1470             AToZ firstElement =
1471                 mapatoz.values().stream().filter(atoz -> atoz.getId().equals("0")).findFirst().orElseThrow();
1472             LOG.info("First element of service path = {}", firstElement.getResource().getResource());
1473             TerminationPoint tp = (TerminationPoint) firstElement.getResource().getResource();
1474             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1475                 (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId()))
1476                     .getBytes(StandardCharsets.UTF_8)).toString());
1477             LOG.info("ROADM SIP name = {}",
1478                 String.join("+", tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId()));
1479             for (ServiceInterfacePoint sip:this.sipMap.values()) {
1480                 if (sip.getUuid().equals(sipUuid)) {
1481                     return sip.getUuid();
1482                 }
1483                 LOG.debug("SIP {} does not match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1484             }
1485             return null;
1486         }
1487         // Service from XPDR to XPDR
1488         AToZ firstElement;
1489         TerminationPoint tp;
1490         Uuid sipUuid;
1491         switch (serviceFormat) {
1492             case ODU:
1493                 firstElement =
1494                     mapatoz.values().stream().filter(atoz -> atoz.getId().equals("2")).findFirst().orElseThrow();
1495                 tp = (TerminationPoint) firstElement.getResource().getResource();
1496                 // Network-Network ports --> iODU layer SIPs. TODO -> updated to eODU
1497                 sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1498                     (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.I_ODU, tp.getTpId()))
1499                         .getBytes(StandardCharsets.UTF_8)).toString());
1500                 LOG.info("ODU XPDR SIP name = {}",
1501                     String.join("+", tp.getTpNodeId(), TapiStringConstants.I_ODU, tp.getTpId()));
1502                 break;
1503             case OTU:
1504                 firstElement =
1505                     mapatoz.values().stream().filter(atoz -> atoz.getId().equals("2")).findFirst().orElseThrow();
1506                 tp = (TerminationPoint) firstElement.getResource().getResource();
1507                 // Network-Network ports --> iOTSi layer SIPs
1508                 sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1509                     (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.I_OTSI, tp.getTpId()))
1510                         .getBytes(StandardCharsets.UTF_8)).toString());
1511                 LOG.info("OTU XPDR SIP name = {}",
1512                     String.join("+", tp.getTpNodeId(), TapiStringConstants.I_OTSI, tp.getTpId()));
1513                 break;
1514             case Ethernet:
1515                 LOG.info("Elements AZ = {}", mapatoz.values());
1516                 firstElement =
1517                     mapatoz.values().stream().filter(atoz -> atoz.getId().equals("0")).findFirst().orElseThrow();
1518                 tp = (TerminationPoint) firstElement.getResource().getResource();
1519                 // Client-client ports --> DSR layer SIPs
1520                 sipUuid = new Uuid(UUID.nameUUIDFromBytes(
1521                     (String.join("+", "SIP", tp.getTpNodeId(), TapiStringConstants.DSR, tp.getTpId()))
1522                         .getBytes(StandardCharsets.UTF_8)).toString());
1523                 LOG.info("DSR XPDR SIP name = {}",
1524                     String.join("+", tp.getTpNodeId(), TapiStringConstants.DSR, tp.getTpId()));
1525                 break;
1526             default:
1527                 sipUuid = null;
1528                 LOG.warn("Service format {} not supported (?)", serviceFormat.getName());
1529         }
1530         for (ServiceInterfacePoint sip:this.sipMap.values()) {
1531             if (sip.getUuid().equals(sipUuid)) {
1532                 return sip.getUuid();
1533             }
1534             LOG.debug("SIP {} does not match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1535         }
1536         return null;
1537     }
1538
1539     private void putRdmCepInTopologyContext(String node, String spcRdmAD, String qual, ConnectionEndPoint cep) {
1540         String nepId = String.join("+", node, qual, spcRdmAD.split("\\+")[1]);
1541         String nodeNepId = String.join("+", node, TapiStringConstants.PHTNC_MEDIA);
1542         LOG.info("NEP id before Merge = {}", nepId);
1543         LOG.info("Node of NEP id before Merge = {}", nodeNepId);
1544         // Give uuids so that it is easier to look for things: topology uuid, node uuid, nep uuid, cep
1545         this.tapiContext.updateTopologyWithCep(
1546             //topoUuid,
1547             new Uuid(UUID.nameUUIDFromBytes(
1548                     TapiStringConstants.T0_FULL_MULTILAYER.getBytes(StandardCharsets.UTF_8)).toString()),
1549             //nodeUuid,
1550             new Uuid(UUID.nameUUIDFromBytes(nodeNepId.getBytes(StandardCharsets.UTF_8)).toString()),
1551             //nepUuid,
1552             new Uuid(UUID.nameUUIDFromBytes(nepId.getBytes(StandardCharsets.UTF_8)).toString()),
1553             cep);
1554     }
1555
1556     private void putXpdrCepInTopologyContext(
1557             String node, String spcXpdrNet, String qual, String nodeLayer, ConnectionEndPoint cep) {
1558         // Give uuids so that it is easier to look for things: topology uuid, node uuid, nep uuid, cep
1559         this.tapiContext.updateTopologyWithCep(
1560             //topoUuid,
1561             new Uuid(UUID.nameUUIDFromBytes(
1562                     TapiStringConstants.T0_FULL_MULTILAYER.getBytes(StandardCharsets.UTF_8))
1563                 .toString()),
1564             //nodeUuid,
1565             new Uuid(UUID.nameUUIDFromBytes(
1566                     String.join("+", node, nodeLayer).getBytes(StandardCharsets.UTF_8))
1567                 .toString()),
1568             //nepUuid,
1569             new Uuid(UUID.nameUUIDFromBytes(
1570                     String.join("+", node, qual, spcXpdrNet.split("\\+")[1]).getBytes(StandardCharsets.UTF_8))
1571                 .toString()),
1572             cep);
1573     }
1574
1575
1576     private void putRdmNepInTopologyContext(String orNodeId, String orTpId, String qual, OwnedNodeEdgePoint onep) {
1577         String nepId = String.join("+", orNodeId, qual, orTpId);
1578         String nepNodeId = String.join("+", orNodeId, TapiStringConstants.PHTNC_MEDIA);
1579         LOG.info("NEP id before Merge = {}", nepId);
1580         LOG.info("Node of NEP id before Merge = {}", nepNodeId);
1581         // Give uuids so that it is easier to look for things: topology uuid, node uuid, nep uuid, cep
1582         updateTopologyWithNep(
1583             //topoUuid,
1584              new Uuid(UUID.nameUUIDFromBytes(
1585                     TapiStringConstants.T0_FULL_MULTILAYER.getBytes(Charset.forName("UTF-8")))
1586                  .toString()),
1587             //nodeUuid,
1588             new Uuid(UUID.nameUUIDFromBytes(
1589                     nepNodeId.getBytes(Charset.forName("UTF-8")))
1590                 .toString()),
1591             //nepUuid,
1592             new Uuid(UUID.nameUUIDFromBytes(
1593                     nepId.getBytes(Charset.forName("UTF-8")))
1594                 .toString()),
1595             onep);
1596     }
1597
1598     private String getIdBasedOnModelVersion(String nodeid) {
1599         return nodeid.matches("[A-Z]{5}-[A-Z0-9]{2}-.*")
1600             ? String.join("-", nodeid.split("-")[0], nodeid.split("-")[1])
1601             : nodeid.split("-")[0];
1602     }
1603
1604     private ServiceZEnd tapiEndPointToServiceZPoint(
1605             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1606                 .create.connectivity.service.input.EndPoint endPoint,
1607             ServiceFormat serviceFormat, String nodeZid, Uint64 capacity, LayerProtocolName serviceLayer) {
1608         // TODO -> change way this is being created. The name includes only SPDR-SA1-XPDR1.
1609         //  Not the rest which is needed in the txPortDeviceName.
1610         //  It could be obtained from the SIP which has the NEP and includes all the OR name.
1611         Uuid sipUuid = endPoint.getServiceInterfacePoint().getServiceInterfacePointUuid();
1612         // Todo -> need to find the NEP associated to that SIP
1613         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeZid.getBytes(StandardCharsets.UTF_8)).toString());
1614         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node =
1615             this.tapiContext.getTapiNode(this.tapiTopoUuid, nodeUuid);
1616         if (node == null) {
1617             LOG.error("Node not found in datastore");
1618             return null;
1619         }
1620         // TODO -> in case of a DSR service, for some requests we need the NETWORK PORT and not the CLIENT although the
1621         //  connection is between 2 CLIENT ports. Otherwise it will not work...
1622         OwnedNodeEdgePoint nep = null;
1623         for (OwnedNodeEdgePoint onep : node.getOwnedNodeEdgePoint().values()) {
1624             if (onep.getMappedServiceInterfacePoint() != null
1625                     && onep.getMappedServiceInterfacePoint().containsKey(new MappedServiceInterfacePointKey(sipUuid))) {
1626                 nep = onep;
1627                 break;
1628             }
1629         }
1630         if (nep == null) {
1631             LOG.error("Nep not found in datastore");
1632             return null;
1633         }
1634         String nodeName = "";
1635         for (Map.Entry<
1636                     org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.NameKey,
1637                     org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.Name> entry:
1638                 endPoint.getName().entrySet()) {
1639             if (!("Node Type").equals(entry.getValue().getValueName())) {
1640                 nodeName = entry.getValue().getValue();
1641             }
1642         }
1643 //        String nodeName = endPoint.getName().values().stream().findFirst().orElseThrow().getValue();
1644         String nodeid = String.join("-", nodeName.split("-")[0], nodeName.split("-")[1]);
1645         String nepName = nep.getName().values().stream().findFirst().orElseThrow().getValue();
1646         String txPortDeviceName = nepName.split("\\+")[0];
1647         String txPortName = nepName.split("\\+")[2];
1648         String rxPortDeviceName = txPortDeviceName;
1649         String rxPortName = txPortName;
1650         LOG.debug("Node z id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1651         LOG.debug("Node z id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1652         // TODO --> get clli from datastore?
1653         String clli = "NodeSC";
1654         LOG.info("Node z id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1655         LOG.info("Node z id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1656         ServiceZEndBuilder serviceZEndBuilder = new ServiceZEndBuilder()
1657             .setClli(clli)
1658             .setNodeId(new NodeIdType(nodeid))
1659             .setOpticType(OpticTypes.Gray)
1660             .setServiceFormat(serviceFormat)
1661             .setServiceRate(Uint32.valueOf(capacity))
1662             .setEthernetAttributes(new EthernetAttributesBuilder().setSubrateEthSla(new SubrateEthSlaBuilder()
1663                     .setCommittedBurstSize(Uint16.valueOf(64))
1664                     .setCommittedInfoRate(Uint32.valueOf(100000))
1665                     .build())
1666                 .build())
1667             .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO), new TxDirectionBuilder()
1668                 .setPort(new PortBuilder()
1669                     .setPortDeviceName(txPortDeviceName)
1670                     .setPortName(txPortName)
1671                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1672                     .setPortShelf("00")
1673                     .setPortType(TapiStringConstants.PORT_TYPE)
1674                     .build())
1675                 .setLgx(new LgxBuilder()
1676                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1677                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1678                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1679                     .setLgxPortShelf("00")
1680                     .build())
1681                 .setIndex(Uint8.ZERO)
1682                 .build()))
1683             .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO), new RxDirectionBuilder()
1684                 .setPort(new PortBuilder()
1685                     .setPortDeviceName(rxPortDeviceName)
1686                     .setPortName(rxPortName)
1687                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1688                     .setPortShelf("00")
1689                     .setPortType(TapiStringConstants.PORT_TYPE)
1690                     .build())
1691                 .setLgx(new LgxBuilder()
1692                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1693                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1694                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1695                     .setLgxPortShelf("00")
1696                     .build())
1697                 .setIndex(Uint8.ZERO)
1698                 .build()));
1699         if (serviceFormat.equals(ServiceFormat.ODU)) {
1700             serviceZEndBuilder.setOduServiceRate(ODU4.VALUE);
1701         }
1702         if (serviceFormat.equals(ServiceFormat.OTU)) {
1703             serviceZEndBuilder.setOtuServiceRate(OTU4.VALUE);
1704         }
1705         return serviceLayer.equals(LayerProtocolName.ETH)
1706             ? serviceZEndBuilder.build()
1707             : serviceZEndBuilder
1708                 .setEthernetAttributes(new EthernetAttributesBuilder()
1709                     .setSubrateEthSla(new SubrateEthSlaBuilder()
1710                         .setCommittedBurstSize(Uint16.valueOf(64))
1711                         .setCommittedInfoRate(Uint32.valueOf(100000))
1712                         .build())
1713                     .build())
1714                 .build();
1715     }
1716
1717     private ServiceAEnd tapiEndPointToServiceAPoint(
1718             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1719                 .create.connectivity.service.input.EndPoint endPoint,
1720             ServiceFormat serviceFormat, String nodeAid, Uint64 capacity, LayerProtocolName serviceLayer) {
1721         // TODO -> change way this is being created. The name includes only SPDR-SA1-XPDR1.
1722         //  Not the rest which is needed in the txPortDeviceName.
1723         //  It could be obtained from the SIP which has the NEP and includes all the OR name.
1724         Uuid sipUuid = endPoint.getServiceInterfacePoint().getServiceInterfacePointUuid();
1725         // Todo -> need to find the NEP associated to that SIP
1726         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeAid.getBytes(StandardCharsets.UTF_8)).toString());
1727         LOG.info("NodeA {} Uuid is {}", nodeAid, nodeUuid);
1728         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node =
1729             this.tapiContext.getTapiNode(this.tapiTopoUuid, nodeUuid);
1730         if (node == null) {
1731             LOG.error("Node not found in datastore");
1732             return null;
1733         }
1734         // TODO -> in case of a DSR service, for some requests we need the NETWORK PORT and not the CLIENT although the
1735         //  connection is between 2 CLIENT ports. Otherwise it will not work...
1736         OwnedNodeEdgePoint nep = null;
1737         for (OwnedNodeEdgePoint onep : node.getOwnedNodeEdgePoint().values()) {
1738             if (onep.getMappedServiceInterfacePoint() != null
1739                     && onep.getMappedServiceInterfacePoint().containsKey(new MappedServiceInterfacePointKey(sipUuid))) {
1740                 nep = onep;
1741                 break;
1742             }
1743         }
1744         if (nep == null) {
1745             LOG.error("Nep not found in datastore");
1746             return null;
1747         }
1748         String nodeName = "";
1749         for (Map.Entry<
1750                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.NameKey,
1751                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.Name> entry:
1752                     endPoint.getName().entrySet()) {
1753             if (!("Node Type").equals(entry.getValue().getValueName())) {
1754                 nodeName = entry.getValue().getValue();
1755             }
1756         }
1757 //        String nodeName = endPoint.getName().values().stream().findFirst().orElseThrow().getValue();
1758         String nodeid = String.join("-", nodeName.split("-")[0], nodeName.split("-")[1]);
1759         String nepName = nep.getName().values().stream().findFirst().orElseThrow().getValue();
1760         String txPortDeviceName = nepName.split("\\+")[0];
1761         String txPortName = nepName.split("\\+")[2];
1762         String rxPortDeviceName = txPortDeviceName;
1763         String rxPortName = txPortName;
1764         LOG.debug("Node a id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1765         LOG.debug("Node a id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1766         // TODO --> get clli from datastore?
1767         String clli = "NodeSA";
1768         LOG.info("Node a id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1769         LOG.info("Node a id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1770         ServiceAEndBuilder serviceAEndBuilder = new ServiceAEndBuilder()
1771             .setClli(clli)
1772             .setNodeId(new NodeIdType(nodeid))
1773             .setOpticType(OpticTypes.Gray)
1774             .setServiceFormat(serviceFormat)
1775             .setServiceRate(Uint32.valueOf(capacity))
1776             .setEthernetAttributes(new EthernetAttributesBuilder().setSubrateEthSla(
1777                     new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526
1778                             .subrate.eth.sla.SubrateEthSlaBuilder()
1779                         .setCommittedBurstSize(Uint16.valueOf(64))
1780                         .setCommittedInfoRate(Uint32.valueOf(100000))
1781                         .build())
1782                 .build())
1783             .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO), new TxDirectionBuilder()
1784                 .setPort(new PortBuilder()
1785                     .setPortDeviceName(txPortDeviceName)
1786                     .setPortName(txPortName)
1787                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1788                     .setPortShelf("00")
1789                     .setPortType(TapiStringConstants.PORT_TYPE)
1790                     .build())
1791                 .setLgx(new LgxBuilder()
1792                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1793                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1794                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1795                     .setLgxPortShelf("00")
1796                     .build())
1797                 .setIndex(Uint8.ZERO)
1798                 .build()))
1799             .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO), new RxDirectionBuilder()
1800                 .setPort(new PortBuilder()
1801                     .setPortDeviceName(rxPortDeviceName)
1802                     .setPortName(rxPortName)
1803                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1804                     .setPortShelf("00")
1805                     .setPortType(TapiStringConstants.PORT_TYPE)
1806                     .build())
1807                 .setLgx(new LgxBuilder()
1808                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1809                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1810                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1811                     .setLgxPortShelf("00")
1812                     .build())
1813                 .setIndex(Uint8.ZERO)
1814                 .build()));
1815         if (serviceFormat.equals(ServiceFormat.ODU)) {
1816             serviceAEndBuilder.setOduServiceRate(ODU4.VALUE);
1817         } else if (serviceFormat.equals(ServiceFormat.OTU)) {
1818             serviceAEndBuilder.setOtuServiceRate(OTU4.VALUE);
1819         }
1820         return serviceLayer.equals(LayerProtocolName.ETH)
1821             ? serviceAEndBuilder.build()
1822             : serviceAEndBuilder
1823                 .setEthernetAttributes(new EthernetAttributesBuilder()
1824                     .setSubrateEthSla(new SubrateEthSlaBuilder()
1825                         .setCommittedBurstSize(Uint16.valueOf(64))
1826                         .setCommittedInfoRate(Uint32.valueOf(100000))
1827                         .build())
1828                     .build())
1829                 .build();
1830     }
1831
1832     private ConnectionType getConnectionTypePhtnc(
1833             Collection<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1834                 .create.connectivity.service.input.EndPoint> endPoints) {
1835         return endPoints.stream()
1836                 .anyMatch(ep -> ep.getName().values().stream().anyMatch(name -> name.getValue().contains("ROADM")))
1837             // EndPoints are ROADMs
1838             ? ConnectionType.RoadmLine
1839             // EndPoints are not ROADMs -> XPDR, MUXPDR, SWTICHPDR
1840             : ConnectionType.Infrastructure;
1841     }
1842
1843     private ServiceFormat getServiceFormatPhtnc(
1844             Collection<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
1845                 .create.connectivity.service.input.EndPoint> endPoints) {
1846         return endPoints.stream()
1847                 .anyMatch(ep -> ep.getName().values().stream().anyMatch(name -> name.getValue().contains("ROADM")))
1848             // EndPoints are ROADMs
1849             ? ServiceFormat.OC
1850             // EndPoints ar not ROADMs -> XPDR, MUXPDR, SWTICHPDR
1851             : ServiceFormat.OTU;
1852     }
1853
1854     private ConnectionEndPoint getAssociatediODUCep(String spcXpdrNetwork) {
1855         return this.tapiContext.getTapiCEP(
1856             this.tapiTopoUuid,
1857             //nodeUuid,
1858             new Uuid(UUID.nameUUIDFromBytes(
1859                 (String.join("+",
1860                         spcXpdrNetwork.split("\\+")[0],
1861                         TapiStringConstants.XPDR)
1862                     .getBytes(StandardCharsets.UTF_8))).toString()),
1863             //nepUuid,
1864             new Uuid(UUID.nameUUIDFromBytes(
1865                 (String.join("+",
1866                         spcXpdrNetwork.split("\\+")[0],
1867                         TapiStringConstants.I_ODU,
1868                         spcXpdrNetwork.split("\\+")[1])
1869                     .getBytes(StandardCharsets.UTF_8))).toString()),
1870             //cepUuid,
1871             new Uuid(UUID.nameUUIDFromBytes(
1872                 (String.join("+",
1873                         "CEP",
1874                         spcXpdrNetwork.split("\\+")[0],
1875                         TapiStringConstants.I_ODU,
1876                         spcXpdrNetwork.split("\\+")[1]))
1877                     .getBytes(StandardCharsets.UTF_8)).toString()));
1878     }
1879
1880     private String getAssociatedNetworkPort(String spcXpdrClient, List<String> xpdrNetworkTplist) {
1881         for (String networkPort:xpdrNetworkTplist) {
1882             if (networkPort.split("\\+")[0].equals(spcXpdrClient.split("\\+")[0])) {
1883                 return networkPort;
1884             }
1885         }
1886         return null;
1887     }
1888
1889     private List<String> getAssociatedClientsPort(List<String> xpdrNetworkTplist) {
1890         List<String> clientPortList = new ArrayList<>();
1891         for (String networkPort:xpdrNetworkTplist) {
1892             String nodeId = String.join("-",
1893                 networkPort.split("\\+")[0].split("-")[0],
1894                 networkPort.split("\\+")[0].split("-")[1]);
1895             String tpId = networkPort.split("\\+")[1];
1896             InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.builder(Network.class)
1897                 .child(Nodes.class, new NodesKey(nodeId))
1898                 .child(Mapping.class, new MappingKey(tpId)).build();
1899             try {
1900                 Optional<Mapping> optMapping =
1901                     this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, mapIID).get();
1902                 if (optMapping.isEmpty()) {
1903                     LOG.error("Couldnt find mapping for port {} of node {}", tpId, nodeId);
1904                 }
1905                 Mapping mapping = optMapping.orElseThrow();
1906                 LOG.info("Mapping for node+port {}+{} = {}", nodeId, tpId, mapping);
1907                 String key = String.join("+",
1908                     String.join("-", nodeId, tpId.split("\\-")[0]),
1909                     mapping.getConnectionMapLcp());
1910                 LOG.info("Key to be added to list = {}", key);
1911                 if (!clientPortList.contains(key)) {
1912                     clientPortList.add(key);
1913                 }
1914             } catch (InterruptedException | ExecutionException e) {
1915                 LOG.error("Couldnt read mapping from datastore", e);
1916                 return null;
1917             }
1918
1919         }
1920         return clientPortList;
1921     }
1922
1923     private OpenroadmNodeType getOpenRoadmNodeType(List<String> xpdrNodelist) {
1924         List<OpenroadmNodeType> openroadmNodeTypeList = new ArrayList<>();
1925         for (String xpdrNode:xpdrNodelist) {
1926             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1927                     .topology.Node> nodeIID =
1928                 InstanceIdentifier.builder(Context.class)
1929                     .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1.class)
1930                     .child(TopologyContext.class)
1931                     .child(Topology.class, new TopologyKey(this.tapiTopoUuid))
1932                     .child(
1933                         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node.class,
1934                         new NodeKey(
1935                             //nodeUUID
1936                             new Uuid(UUID.nameUUIDFromBytes(
1937                                 (String.join("+",xpdrNode, TapiStringConstants.XPDR))
1938                                     .getBytes(StandardCharsets.UTF_8)).toString())))
1939                     .build();
1940             try {
1941                 Optional<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> optNode =
1942                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID).get();
1943                 if (optNode.isEmpty()) {
1944                     return null;
1945                 }
1946                 OpenroadmNodeType openroadmNodeType =
1947                     OpenroadmNodeType.forName(optNode.orElseThrow().getName().get(new NameKey("Node Type")).getValue());
1948                 if (!openroadmNodeTypeList.contains(openroadmNodeType)) {
1949                     openroadmNodeTypeList.add(openroadmNodeType);
1950                 }
1951             } catch (InterruptedException | ExecutionException e) {
1952                 LOG.error("Couldnt read node in topology", e);
1953                 return null;
1954             }
1955         }
1956         // TODO for now check that there is only one type, otherwise error
1957         if (openroadmNodeTypeList.size() == 1) {
1958             return openroadmNodeTypeList.get(0);
1959         }
1960         LOG.error("More than one xpdr type. List = {}", openroadmNodeTypeList);
1961         return null;
1962     }
1963
1964     private OwnedNodeEdgePoint createRoadmNep(
1965             String orNodeId, String tpId, boolean withSip,
1966             OperationalState operState, AdministrativeState adminState, String nepPhotonicSublayer) {
1967         //TODO : complete implementation with SIP
1968         Name nepName = new NameBuilder()
1969                 .setValueName(TapiStringConstants.PHTNC_MEDIA + "NodeEdgePoint")
1970                 .setValue(String.join("+", orNodeId, nepPhotonicSublayer, tpId))
1971                 .build();
1972         return new OwnedNodeEdgePointBuilder()
1973             .setUuid(
1974                 new Uuid(UUID.nameUUIDFromBytes(
1975                         (String.join("+", orNodeId, nepPhotonicSublayer,tpId)).getBytes(StandardCharsets.UTF_8))
1976                     .toString()))
1977             .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA)
1978             .setName(Map.of(nepName.key(), nepName))
1979             .setSupportedCepLayerProtocolQualifierInstances(
1980                 new ArrayList<>(List.of(
1981                     new SupportedCepLayerProtocolQualifierInstancesBuilder()
1982                         .setLayerProtocolQualifier(
1983                             TapiStringConstants.MC.equals(nepPhotonicSublayer)
1984                                 ? PHOTONICLAYERQUALIFIERMC.VALUE
1985                                 : PHOTONICLAYERQUALIFIEROTSiMC.VALUE)
1986                         .setNumberOfCepInstances(Uint64.valueOf(1))
1987                         .build())))
1988             .setDirection(Direction.BIDIRECTIONAL)
1989             .setLinkPortRole(PortRole.SYMMETRIC)
1990             .setAdministrativeState(adminState).setOperationalState(operState)
1991             .setLifecycleState(LifecycleState.INSTALLED)
1992             .build();
1993     }
1994 }