Adaptation of XPDR mapping from OR to TAPI
[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.nio.charset.Charset;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Comparator;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Optional;
18 import java.util.UUID;
19 import java.util.stream.Collectors;
20 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
21 import org.opendaylight.transportpce.tapi.TapiStringConstants;
22 import org.opendaylight.transportpce.tapi.utils.GenericServiceEndpoint;
23 import org.opendaylight.transportpce.tapi.utils.ServiceEndpointType;
24 import org.opendaylight.transportpce.tapi.utils.TapiContext;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.equipment.types.rev181130.OpticTypes;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.RpcActions;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.Service;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.SubrateEthSlaBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.LgxBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.PortBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.ODU4;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OTU4;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEnd;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEndBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEndBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
46 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
47 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZKey;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToAKey;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Node;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortDirection;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortRole;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.BandwidthProfileBuilder;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.TotalSizeBuilder;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.CreateConnectivityServiceInput;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.ProtectionRole;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.ServiceType;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPoint;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointBuilder;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPointKey;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connection.end.point.ClientNodeEdgePoint;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connection.end.point.ClientNodeEdgePointBuilder;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityService;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceBuilder;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.Connection;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.ConnectionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.ConnectionKey;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.EndPoint;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.EndPointBuilder;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.EndPointKey;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.end.point.CapacityBuilder;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.end.point.ServiceInterfacePointBuilder;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.ConnectivityConstraint;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointKey;
90 import org.opendaylight.yangtools.yang.common.Uint16;
91 import org.opendaylight.yangtools.yang.common.Uint32;
92 import org.opendaylight.yangtools.yang.common.Uint64;
93 import org.slf4j.Logger;
94 import org.slf4j.LoggerFactory;
95
96 public final class ConnectivityUtils {
97
98     private final Uuid tapiTopoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
99         .getBytes(Charset.forName("UTF-8"))).toString());
100     private static final Logger LOG = LoggerFactory.getLogger(ConnectivityUtils.class);
101
102     private final ServiceDataStoreOperations serviceDataStoreOperations;
103     private final TapiContext tapiContext;
104     private Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap;
105     private final Map<org.opendaylight.yang.gen.v1.urn
106         .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey,
107         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection>
108         connectionFullMap; // this variable is for complete connection objects
109     private Map<String, Map<String, Boolean>> networkMap = new HashMap<>();
110
111     // TODO -> handle cases for which node id is ROADM-A1 and not ROADMA01 or XPDR-A1 and not XPDRA01
112     public ConnectivityUtils(ServiceDataStoreOperations serviceDataStoreOperations,
113                              Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap, TapiContext tapiContext) {
114         this.serviceDataStoreOperations = serviceDataStoreOperations;
115         this.tapiContext = tapiContext;
116         this.sipMap = sipMap;
117         this.connectionFullMap = new HashMap<>();
118     }
119
120     public static ServiceCreateInput buildServiceCreateInput(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
121         ServiceAEnd serviceAEnd = getServiceAEnd(sepA, sepZ);
122         ServiceZEnd serviceZEnd = getServiceZEnd(sepA, sepZ);
123         if (serviceAEnd == null || serviceZEnd == null) {
124             LOG.warn("One of the endpoints could not be identified");
125             return null;
126         }
127         return new ServiceCreateInputBuilder()
128             .setCommonId("commonId")
129             .setConnectionType(ConnectionType.Service)
130             .setCustomer("Customer")
131             .setServiceName("service test")
132             .setServiceAEnd(serviceAEnd)
133             .setServiceZEnd(serviceZEnd)
134             .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request-1")
135                 .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").setRequestSystemId(
136                     "appname")
137                 .build())
138             .build();
139     }
140
141     public static ServiceAEnd buildServiceAEnd(String nodeid, String clli, String txPortDeviceName,
142                                                String txPortName, String rxPortDeviceName, String rxPortName) {
143         return new ServiceAEndBuilder()
144             .setClli(clli)
145             .setNodeId(new NodeIdType(nodeid))
146             .setOpticType(OpticTypes.Gray)
147             .setServiceFormat(ServiceFormat.Ethernet)
148             .setServiceRate(Uint32.valueOf(100))
149             .setTxDirection(new TxDirectionBuilder()
150                 .setPort(new PortBuilder()
151                     .setPortDeviceName(txPortDeviceName)
152                     .setPortName(txPortName)
153                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
154                     .setPortShelf("00")
155                     .setPortType(TapiStringConstants.PORT_TYPE)
156                     .build())
157                 .setLgx(new LgxBuilder()
158                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
159                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
160                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
161                     .setLgxPortShelf("00")
162                     .build())
163                 .build())
164             .setRxDirection(new RxDirectionBuilder()
165                 .setPort(new PortBuilder()
166                     .setPortDeviceName(rxPortDeviceName)
167                     .setPortName(rxPortName)
168                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
169                     .setPortShelf("00")
170                     .setPortType(TapiStringConstants.PORT_TYPE)
171                     .build())
172                 .setLgx(new LgxBuilder()
173                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
174                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
175                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
176                     .setLgxPortShelf("00")
177                     .build())
178                 .build())
179             .build();
180     }
181
182     public static ServiceZEnd buildServiceZEnd(String nodeid, String clli, String txPortDeviceName,
183                                                String txPortName, String rxPortDeviceName, String rxPortName) {
184         return  new ServiceZEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid))
185             .setOpticType(OpticTypes.Gray)
186             .setServiceFormat(ServiceFormat.Ethernet)
187             .setServiceRate(Uint32.valueOf(100))
188             .setTxDirection(new TxDirectionBuilder()
189                 .setPort(new PortBuilder()
190                     .setPortDeviceName(txPortDeviceName)
191                     .setPortName(txPortName)
192                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
193                     .setPortShelf("00")
194                     .setPortType(TapiStringConstants.PORT_TYPE)
195                     .build())
196                 .setLgx(new LgxBuilder()
197                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
198                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
199                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
200                     .setLgxPortShelf("00")
201                     .build())
202                 .build())
203             .setRxDirection(new RxDirectionBuilder()
204                 .setPort(new PortBuilder()
205                     .setPortDeviceName(rxPortDeviceName)
206                     .setPortName(rxPortName)
207                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
208                     .setPortShelf("00")
209                     .setPortType(TapiStringConstants.PORT_TYPE)
210                     .build())
211                 .setLgx(new LgxBuilder()
212                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
213                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
214                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
215                     .setLgxPortShelf("00")
216                     .build())
217                 .build())
218             .build();
219     }
220
221     private static ServiceAEnd getServiceAEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
222         if (sepA.getType().equals(ServiceEndpointType.SERVICEAEND)) {
223             return new ServiceAEndBuilder(sepA.getValue()).build();
224         } else if (sepZ.getType().equals(ServiceEndpointType.SERVICEAEND)) {
225             return new ServiceAEndBuilder(sepZ.getValue()).build();
226         } else {
227             return null;
228         }
229     }
230
231     private static ServiceZEnd getServiceZEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
232         if (sepA.getType().equals(ServiceEndpointType.SERVICEZEND)) {
233             return new ServiceZEndBuilder(sepA.getValue()).build();
234         } else if (sepZ.getType().equals(ServiceEndpointType.SERVICEZEND)) {
235             return new ServiceZEndBuilder(sepZ.getValue()).build();
236         } else {
237             return null;
238         }
239     }
240
241     public void setSipMap(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips) {
242         this.sipMap = sips;
243     }
244
245     public ConnectivityService mapORServiceToTapiConnectivity(Service service) {
246         // Get service path with the description in OR based models.
247         LOG.info("Service = {}", service);
248         Optional<ServicePaths> optServicePaths =
249             this.serviceDataStoreOperations.getServicePath(service.getServiceName());
250         if (!optServicePaths.isPresent()) {
251             LOG.error("No service path found for service {}", service.getServiceName());
252             return null;
253         }
254         ServicePaths servicePaths = optServicePaths.get();
255         PathDescription pathDescription = servicePaths.getPathDescription();
256         LOG.info("Path description of service = {}", pathDescription);
257         org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEnd serviceAEnd
258             = service.getServiceAEnd();
259         // Endpoint creation
260         EndPoint endPoint1 = mapServiceAEndPoint(serviceAEnd, pathDescription);
261         org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceZEnd serviceZEnd
262             = service.getServiceZEnd();
263         EndPoint endPoint2 = mapServiceZEndPoint(serviceZEnd, pathDescription);
264         Map<EndPointKey, EndPoint> endPointMap = new HashMap<>();
265         endPointMap.put(endPoint1.key(), endPoint1);
266         endPointMap.put(endPoint2.key(), endPoint2);
267         LOG.info("EndPoints of connectivity services = {}", endPointMap);
268         // Services Names
269         Name name = new NameBuilder().setValueName("Connectivity Service Name").setValue(service.getServiceName())
270             .build();
271         // Connection creation
272         Map<ConnectionKey, Connection> connMap =
273             createConnectionsFromService(serviceAEnd, serviceZEnd, pathDescription);
274         // TODO: full connectivity service?? With constraints and the rest of fields...
275         return new ConnectivityServiceBuilder()
276             .setAdministrativeState(AdministrativeState.UNLOCKED)
277             .setOperationalState(OperationalState.ENABLED)
278             .setLifecycleState(LifecycleState.INSTALLED)
279             .setUuid(new Uuid(UUID.nameUUIDFromBytes(service.getServiceName().getBytes(Charset.forName("UTF-8")))
280                 .toString()))
281             .setServiceLayer(mapServiceLayer(serviceAEnd.getServiceFormat()))
282             .setServiceType(ServiceType.POINTTOPOINTCONNECTIVITY)
283             .setConnectivityDirection(ForwardingDirection.BIDIRECTIONAL)
284             .setName(Map.of(name.key(), name))
285             .setConnection(connMap)
286             .setEndPoint(endPointMap)
287             .build();
288     }
289
290     private LayerProtocolName mapServiceLayer(ServiceFormat serviceFormat) {
291         switch (serviceFormat) {
292             case OC:
293             case OTU:
294                 return LayerProtocolName.PHOTONICMEDIA;
295             case ODU:
296                 return LayerProtocolName.ODU;
297             case Ethernet:
298                 return LayerProtocolName.DSR;
299             default:
300                 LOG.info("Service layer mapping not supported for {}", serviceFormat.getName());
301         }
302         return null;
303     }
304
305     private Map<ConnectionKey, Connection> createConnectionsFromService(
306             org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEnd
307                 serviceAEnd,
308             org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceZEnd
309                 serviceZEnd,
310         PathDescription pathDescription) {
311         Map<ConnectionKey, Connection> connectionServMap = new HashMap<>();
312         // build lists with ROADM nodes, XPDR/MUX/SWITCH nodes, ROADM DEG TTPs, ROADM SRG TTPs, XPDR CLIENT TTPs
313         //  and XPDR NETWORK TTPs (if any). From the path description. This will help to build the uuid of the CEPs
314         //  and the connections
315         String resourceType;
316         List<String> xpdrClientTplist = new ArrayList<>();
317         List<String> xpdrNetworkTplist = new ArrayList<>();
318         List<String> rdmAddDropTplist = new ArrayList<>();
319         List<String> rdmDegTplist = new ArrayList<>();
320         List<String> rdmNodelist = new ArrayList<>();
321         List<String> xpdrNodelist = new ArrayList<>();
322         for (AToZ elem:pathDescription.getAToZDirection().getAToZ().values().stream()
323             .sorted(Comparator.comparing(AToZ::getId)).collect(Collectors.toList())) {
324             resourceType = elem.getResource().getResource().implementedInterface().getSimpleName();
325             switch (resourceType) {
326                 case TapiStringConstants.TP:
327                     TerminationPoint tp = (TerminationPoint) elem.getResource().getResource();
328                     String tpID = tp.getTpId();
329                     String tpNode;
330                     if (tpID.contains("CLIENT")) {
331                         tpNode = tp.getTpNodeId();
332                         if (!xpdrClientTplist.contains(String.join("+", tpNode, tpID))) {
333                             xpdrClientTplist.add(String.join("+", tpNode, tpID));
334                         }
335                     }
336                     if (tpID.contains("NETWORK")) {
337                         tpNode = tp.getTpNodeId();
338                         if (!xpdrNetworkTplist.contains(String.join("+", tpNode, tpID))) {
339                             xpdrNetworkTplist.add(String.join("+", tpNode, tpID));
340                         }
341                     }
342                     if (tpID.contains("PP")) {
343                         tpNode = getIdBasedOnModelVersion(tp.getTpNodeId());
344                         LOG.info("ROADM Node of tp = {}", tpNode);
345                         if (!rdmAddDropTplist.contains(String.join("+", tpNode, tpID))) {
346                             rdmAddDropTplist.add(String.join("+", tpNode, tpID));
347                         }
348                     }
349                     if (tpID.contains("TTP")) {
350                         tpNode = getIdBasedOnModelVersion(tp.getTpNodeId());
351                         LOG.info("ROADM Node of tp = {}", tpNode);
352                         if (!rdmDegTplist.contains(String.join("+", tpNode, tpID))) {
353                             rdmDegTplist.add(String.join("+", tpNode, tpID));
354                         }
355                     }
356                     break;
357                 case TapiStringConstants.NODE:
358                     Node node = (Node) elem.getResource().getResource();
359                     String nodeId = node.getNodeId();
360                     if (nodeId.contains("XPDR") || nodeId.contains("SPDR") || nodeId.contains("MXPDR")) {
361                         LOG.info("Node id = {}", nodeId);
362                         if (!xpdrNodelist.contains(nodeId)) {
363                             xpdrNodelist.add(nodeId); // should contain only 2
364                         }
365                     }
366                     if (nodeId.contains("ROADM")) {
367                         nodeId = getIdBasedOnModelVersion(nodeId);
368                         LOG.info("Node id = {}", nodeId);
369                         if (!rdmNodelist.contains(nodeId)) {
370                             rdmNodelist.add(nodeId);
371                         }
372                     }
373                     break;
374                 default:
375                     LOG.warn("Resource is a {}", resourceType);
376             }
377         }
378         LOG.info("ROADM node list = {}", rdmNodelist);
379         LOG.info("ROADM degree list = {}", rdmDegTplist);
380         LOG.info("ROADM addrop list = {}", rdmAddDropTplist);
381         LOG.info("XPDR node list = {}", xpdrNodelist);
382         LOG.info("XPDR network list = {}", xpdrNetworkTplist);
383         LOG.info("XPDR client list = {}", xpdrClientTplist);
384         // TODO -> for 10GB eth and ODU services there are no ROADMs in path description as they use the OTU link,
385         //  but for 100GB eth all is created at once. Check if the roadm list is empty to determine whether we need
386         //  to trigger all the steps or not
387         String edgeRoadm1 = "";
388         String edgeRoadm2 = "";
389         if (!rdmNodelist.isEmpty()) {
390             edgeRoadm1 = rdmNodelist.get(0);
391             edgeRoadm2 = rdmNodelist.get(rdmNodelist.size() - 1);
392             LOG.info("edgeRoadm1 = {}", edgeRoadm1);
393             LOG.info("edgeRoadm2 = {}", edgeRoadm2);
394         }
395         // create corresponding CEPs and Connections. Connections should be added to the corresponding context
396         // CEPs must be included in the topology context as an augmentation for each ONEP!!
397         ServiceFormat serviceFormat = serviceAEnd.getServiceFormat(); // should be equal to serviceZEnd
398         // TODO -> Maybe we dont need to create the connections and ceps if the previous service doesnt exist??
399         //  As mentioned above, for 100GbE service creation there are ROADMs in the path description.
400         //  What are the configurations needed here? No OTU, ODU... what kind of cross connections is needed?
401         //  this needs to be changed
402         switch (serviceFormat) {
403             case OC:
404                 // Identify number of ROADMs
405                 // - XC Connection between MC CEPs mapped from MC NEPs (within a roadm)
406                 // - XC Connection between OTSiMC CEPs mapped from OTSiMC NEPs (within a roadm)
407                 // - Top Connection MC betwwen MC CEPs of different roadms
408                 // - Top Connection OTSiMC betwwen OTSiMC CEPs of extreme roadms
409                 connectionServMap.putAll(createRoadmCepsAndConnections(rdmAddDropTplist, rdmDegTplist, rdmNodelist,
410                     edgeRoadm1, edgeRoadm2));
411                 break;
412             case OTU:
413                 // Identify number of ROADMs between XPDRs and check if OC is created
414                 // - XC Connection between MC CEPs mapped from MC NEPs (within a roadm)
415                 // - Top Connection MC betwwen MC CEPs of different roadms
416                 // - XC Connection between OTSiMC CEPs mapped from OTSiMC NEPs (within a roadm)
417                 // - Top Connection OTSiMC betwwen OTSiMC CEPs of different roadms
418                 connectionServMap.putAll(createRoadmCepsAndConnections(rdmAddDropTplist, rdmDegTplist, rdmNodelist,
419                     edgeRoadm1, edgeRoadm2));
420                 // - XC Connection OTSi betwwen iOTSi y eOTSi of xpdr
421                 // - Top connection OTSi between network ports of xpdrs in the Photonic media layer -> i_OTSi
422                 connectionServMap.putAll(createXpdrCepsAndConnectionsPht(xpdrNetworkTplist, xpdrNodelist));
423                 break;
424             case ODU:
425                 // Check if OC and OTU are created
426                 if (!rdmNodelist.isEmpty()) {
427                     connectionServMap.putAll(createRoadmCepsAndConnections(rdmAddDropTplist, rdmDegTplist, rdmNodelist,
428                         edgeRoadm1, edgeRoadm2));
429                     connectionServMap.putAll(createXpdrCepsAndConnectionsPht(xpdrNetworkTplist, xpdrNodelist));
430                 }
431                 // - XC Connection OTSi betwwen iODU and eODU of xpdr
432                 // - Top connection in the ODU layer, between xpdr eODU ports (?)
433                 connectionServMap.putAll(createXpdrCepsAndConnectionsOdu(xpdrNetworkTplist, xpdrNodelist));
434                 break;
435             case Ethernet:
436                 // Check if OC, OTU and ODU are created
437                 if (!rdmNodelist.isEmpty()) {
438                     connectionServMap.putAll(createRoadmCepsAndConnections(rdmAddDropTplist, rdmDegTplist, rdmNodelist,
439                         edgeRoadm1, edgeRoadm2));
440                     connectionServMap.putAll(createXpdrCepsAndConnectionsPht(xpdrNetworkTplist, xpdrNodelist));
441                     connectionServMap.putAll(createXpdrCepsAndConnectionsOdu(xpdrNetworkTplist, xpdrNodelist));
442                 }
443                 // Top connection in the DSR layer, between client ports of the xpdrs
444                 // TODO differentiate between 100GbE and OTN 10GbE services
445                 connectionServMap.putAll(createXpdrCepsAndConnectionsDsr(xpdrClientTplist, xpdrNetworkTplist,
446                     xpdrNodelist));
447                 break;
448             default:
449                 LOG.error("Service type format not supported");
450         }
451         return connectionServMap;
452     }
453
454     private Map<ConnectionKey,Connection> createXpdrCepsAndConnectionsDsr(List<String> xpdrClientTplist,
455                                                                           List<String> xpdrNetworkTplist,
456                                                                           List<String> xpdrNodelist) {
457         Map<ConnectionKey, Connection> connServMap = new HashMap<>();
458         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey,
459             ConnectionEndPoint> cepMapDsr = new HashMap<>();
460         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey,
461             ConnectionEndPoint> cepMapOdu = new HashMap<>();
462
463         // Create 1 cep per Xpdr in the CLIENT, 1 cep per Xpdr eODU, 1 XC between eODU and iODE,
464         // 1 top connection between eODU and a top connection DSR between the CLIENT xpdrs
465         for (String xpdr:xpdrNodelist) {
466             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
467             String spcXpdrClient = xpdrClientTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().get();
468
469             ConnectionEndPoint netCep1 = createCepXpdr(spcXpdrClient, TapiStringConstants.DSR, TapiStringConstants.DSR,
470                 LayerProtocolName.DSR);
471             putXpdrCepInTopologyContext(xpdr, spcXpdrClient, TapiStringConstants.DSR, TapiStringConstants.DSR, netCep1);
472
473             ConnectionEndPoint netCep2 = createCepXpdr(spcXpdrClient, TapiStringConstants.E_ODU,
474                 TapiStringConstants.DSR, LayerProtocolName.ODU);
475             putXpdrCepInTopologyContext(xpdr, spcXpdrClient, TapiStringConstants.E_ODU, TapiStringConstants.DSR,
476                 netCep2);
477
478             String spcXpdrNetwork = getAssociatedNetworkPort(spcXpdrClient, xpdrNetworkTplist);
479             ConnectionEndPoint netCep3 = getAssociatediODUCep(spcXpdrNetwork);
480
481             cepMapDsr.put(netCep1.key(), netCep1);
482             cepMapOdu.put(netCep2.key(), netCep2);
483             // Create x connection between I_ODU and E_ODU within xpdr
484             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
485                 connection = createXCBetweenCeps(netCep2, netCep3, spcXpdrClient, spcXpdrNetwork,
486                 TapiStringConstants.ODU, LayerProtocolName.ODU);
487             this.connectionFullMap.put(connection.key(), connection);
488
489             // Create X connection that will be added to the service object
490             Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
491             connServMap.put(conn.key(), conn);
492         }
493
494         // DSR top connection between edge xpdr CLIENT DSR
495         String spcXpdr1 = xpdrClientTplist.stream().filter(adp -> adp.contains(xpdrNodelist
496             .get(0))).findFirst().get();
497         String spcXpdr2 = xpdrClientTplist.stream().filter(adp -> adp.contains(xpdrNodelist
498             .get(xpdrNodelist.size() - 1))).findFirst().get();
499
500         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
501             connectionOdu = createTopConnection(spcXpdr1, spcXpdr2, cepMapOdu, TapiStringConstants.E_ODU,
502             LayerProtocolName.ODU);
503         this.connectionFullMap.put(connectionOdu.key(), connectionOdu);
504
505         // ODU top connection that will be added to the service object
506         Connection conn = new ConnectionBuilder().setConnectionUuid(connectionOdu.getUuid()).build();
507         connServMap.put(conn.key(), conn);
508
509         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
510             connectionDsr = createTopConnection(spcXpdr1, spcXpdr2, cepMapDsr, TapiStringConstants.DSR,
511                 LayerProtocolName.DSR);
512         this.connectionFullMap.put(connectionDsr.key(), connectionDsr);
513
514         // DSR top connection that will be added to the service object
515         Connection conn1 = new ConnectionBuilder().setConnectionUuid(connectionDsr.getUuid()).build();
516         connServMap.put(conn1.key(), conn1);
517
518         return connServMap;
519     }
520
521     private Map<ConnectionKey, Connection> createXpdrCepsAndConnectionsOdu(List<String> xpdrNetworkTplist,
522                                                                            List<String> xpdrNodelist) {
523         Map<ConnectionKey, Connection> connServMap = new HashMap<>();
524         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey,
525             ConnectionEndPoint> cepMap = new HashMap<>();
526         // Create 1 cep per Xpdr in the I_ODU and a top
527         // connection iODU between the xpdrs
528         for (String xpdr:xpdrNodelist) {
529             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
530             String spcXpdrNetwork = xpdrNetworkTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().get();
531
532             ConnectionEndPoint netCep1 = createCepXpdr(spcXpdrNetwork, TapiStringConstants.I_ODU,
533                 TapiStringConstants.DSR, LayerProtocolName.ODU);
534             putXpdrCepInTopologyContext(xpdr, spcXpdrNetwork, TapiStringConstants.I_ODU, TapiStringConstants.DSR,
535                 netCep1);
536
537             cepMap.put(netCep1.key(), netCep1);
538         }
539
540         // ODU top connection between edge xpdr i_ODU
541         String spcXpdr1 = xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist
542             .get(0))).findFirst().get();
543         String spcXpdr2 = xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist
544             .get(xpdrNodelist.size() - 1))).findFirst().get();
545         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
546             connection = createTopConnection(spcXpdr1, spcXpdr2, cepMap, TapiStringConstants.I_ODU,
547             LayerProtocolName.ODU);
548         this.connectionFullMap.put(connection.key(), connection);
549
550         // ODU top connection that will be added to the service object
551         Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
552         connServMap.put(conn.key(), conn);
553
554         return connServMap;
555     }
556
557     private Map<ConnectionKey, Connection> createXpdrCepsAndConnectionsPht(List<String> xpdrNetworkTplist,
558                                                                            List<String> xpdrNodelist) {
559         Map<ConnectionKey, Connection> connServMap = new HashMap<>();
560         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey,
561             ConnectionEndPoint> cepMap = new HashMap<>();
562
563         // create ceps and x connections within xpdr
564         for (String xpdr:xpdrNodelist) {
565             LOG.info("Creating ceps and xc for xpdr {}", xpdr);
566             String spcXpdrNetwork = xpdrNetworkTplist.stream().filter(netp -> netp.contains(xpdr)).findFirst().get();
567             // There should be 1 network tp per xpdr
568             // TODO photonic media model should be updated to have the corresponding CEPs. I will just create
569             //  3 different MC CEPs giving different IDs to show that they are different
570             // Create 3 CEPs for each xpdr otsi node and the corresponding cross connection matchin the NEPs
571             ConnectionEndPoint netCep1 = createCepXpdr(spcXpdrNetwork, TapiStringConstants.PHTNC_MEDIA,
572                 TapiStringConstants.OTSI, LayerProtocolName.PHOTONICMEDIA);
573             putXpdrCepInTopologyContext(xpdr, spcXpdrNetwork, TapiStringConstants.PHTNC_MEDIA, TapiStringConstants.OTSI,
574                 netCep1);
575             ConnectionEndPoint netCep2 = createCepXpdr(spcXpdrNetwork, TapiStringConstants.E_OTSI,
576                 TapiStringConstants.OTSI, LayerProtocolName.PHOTONICMEDIA);
577             putXpdrCepInTopologyContext(xpdr, spcXpdrNetwork, TapiStringConstants.E_OTSI, TapiStringConstants.OTSI,
578                 netCep2);
579             ConnectionEndPoint netCep3 = createCepXpdr(spcXpdrNetwork, TapiStringConstants.I_OTSI,
580                 TapiStringConstants.OTSI, LayerProtocolName.PHOTONICMEDIA);
581             putXpdrCepInTopologyContext(xpdr, spcXpdrNetwork, TapiStringConstants.I_OTSI, TapiStringConstants.OTSI,
582                 netCep3);
583             cepMap.put(netCep1.key(), netCep1);
584             cepMap.put(netCep2.key(), netCep2);
585             cepMap.put(netCep3.key(), netCep3);
586
587             // Create x connection between I_OTSi and E_OTSi within xpdr
588             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
589                 connection = createXCBetweenCeps(netCep2, netCep3, spcXpdrNetwork, spcXpdrNetwork,
590                 TapiStringConstants.OTSI, LayerProtocolName.PHOTONICMEDIA);
591             this.connectionFullMap.put(connection.key(), connection);
592
593             // Create X connection that will be added to the service object
594             Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
595             connServMap.put(conn.key(), conn);
596         }
597         // OTSi top connection between edge I_OTSI Xpdr
598         String spcXpdr1 = xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist
599             .get(0))).findFirst().get();
600         String spcXpdr2 = xpdrNetworkTplist.stream().filter(adp -> adp.contains(xpdrNodelist
601             .get(xpdrNodelist.size() - 1))).findFirst().get();
602         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
603             connection = createTopConnection(spcXpdr1, spcXpdr2, cepMap, TapiStringConstants.I_OTSI,
604             LayerProtocolName.PHOTONICMEDIA);
605         this.connectionFullMap.put(connection.key(), connection);
606
607         // OTSi top connection that will be added to the service object
608         Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
609         connServMap.put(conn.key(), conn);
610
611
612         return connServMap;
613     }
614
615     private Map<ConnectionKey, Connection> createRoadmCepsAndConnections(List<String> rdmAddDropTplist,
616                                                                          List<String> rdmDegTplist,
617                                                                          List<String> rdmNodelist,
618                                                                          String edgeRoadm1, String edgeRoadm2) {
619         // TODO: will need to check if things exist already or not
620         Map<ConnectionKey, Connection> connServMap = new HashMap<>();
621         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey,
622             ConnectionEndPoint> cepMap = new HashMap<>();
623         // create ceps and x connections within roadm
624         for (String roadm : rdmNodelist) {
625             LOG.info("Creating ceps and xc for roadm {}", roadm);
626             String spcRdmAD = rdmAddDropTplist.stream().filter(adp -> adp.contains(roadm)).findFirst().get();
627             LOG.info("AD port of ROADm {} = {}", roadm, spcRdmAD);
628             // There should be only 1 AD and 1 DEG per roadm
629             // TODO photonic media model should be updated to have the corresponding CEPs. I will just create
630             //  3 different MC CEPs giving different IDs to show that they are different
631             // Create 3 CEPs for each AD and DEG and the corresponding cross connections, matching the NEPs
632             // created in the topology creation
633             // add CEPs to the topology to the corresponding ONEP
634             ConnectionEndPoint adCep1 = createCepRoadm(spcRdmAD, TapiStringConstants.PHTNC_MEDIA);
635             putRdmCepInTopologyContext(roadm, spcRdmAD, TapiStringConstants.PHTNC_MEDIA, adCep1);
636             ConnectionEndPoint adCep2 = createCepRoadm(spcRdmAD, TapiStringConstants.MC);
637             putRdmCepInTopologyContext(roadm, spcRdmAD, TapiStringConstants.MC, adCep2);
638             ConnectionEndPoint adCep3 = createCepRoadm(spcRdmAD, TapiStringConstants.OTSI_MC);
639             putRdmCepInTopologyContext(roadm, spcRdmAD, TapiStringConstants.OTSI_MC, adCep3);
640             cepMap.put(adCep1.key(), adCep1);
641             cepMap.put(adCep2.key(), adCep2);
642             cepMap.put(adCep3.key(), adCep3);
643
644             String spcRdmDEG = rdmDegTplist.stream().filter(adp -> adp.contains(roadm)).findFirst().get();
645             LOG.info("Degree port of ROADm {} = {}", roadm, spcRdmDEG);
646
647             ConnectionEndPoint degCep1 = createCepRoadm(spcRdmDEG, TapiStringConstants.PHTNC_MEDIA);
648             putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.PHTNC_MEDIA, degCep1);
649             ConnectionEndPoint degCep2 = createCepRoadm(spcRdmDEG, TapiStringConstants.MC);
650             putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.MC, degCep2);
651             ConnectionEndPoint degCep3 = createCepRoadm(spcRdmDEG, TapiStringConstants.OTSI_MC);
652             putRdmCepInTopologyContext(roadm, spcRdmDEG, TapiStringConstants.OTSI_MC, degCep3);
653             cepMap.put(degCep1.key(), degCep1);
654             cepMap.put(degCep2.key(), degCep2);
655             cepMap.put(degCep3.key(), degCep3);
656
657             LOG.info("Going to create cross connections for ROADM {}", roadm);
658             // Create X connections between MC and OTSi_MC for full map
659             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
660                 connection1 = createXCBetweenCeps(adCep2, degCep2, spcRdmAD, spcRdmDEG, TapiStringConstants.MC,
661                 LayerProtocolName.PHOTONICMEDIA);
662             LOG.info("Cross connection 1 created = {}", connection1);
663             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
664                 connection2 = createXCBetweenCeps(adCep3, degCep3, spcRdmAD, spcRdmDEG, TapiStringConstants.OTSI_MC,
665                 LayerProtocolName.PHOTONICMEDIA);
666             LOG.info("Cross connection 2 created = {}", connection2);
667             this.connectionFullMap.put(connection1.key(), connection1);
668             this.connectionFullMap.put(connection2.key(), connection2);
669
670             // Create X connections that will be added to the service object
671             Connection conn1 = new ConnectionBuilder().setConnectionUuid(connection1.getUuid()).build();
672             Connection conn2 = new ConnectionBuilder().setConnectionUuid(connection2.getUuid()).build();
673             connServMap.put(conn1.key(), conn1);
674             connServMap.put(conn2.key(), conn2);
675         }
676         LOG.info("Going to create top connections betwee roadms");
677         // create top connections between roadms: MC connections between AD MC CEPs of roadms
678         for (int i = 0; i < rdmNodelist.size(); i++) {
679             if (rdmNodelist.size() <= (i + 1)) {
680                 LOG.info("Reached last roadm. No more MC connections");
681                 break;
682             }
683             // Current roadm with roadm i + 1 --> MC
684             String roadm1 = rdmNodelist.get(i);
685             String spcRdmAD1 = rdmAddDropTplist.stream().filter(adp -> adp.contains(roadm1)).findFirst().get();
686             String roadm2 = rdmNodelist.get(i + 1);
687             String spcRdmAD2 = rdmAddDropTplist.stream().filter(adp -> adp.contains(roadm2)).findFirst().get();
688             LOG.info("Creating top connection from {} to {} between tps: {}-{}", roadm1, roadm2, spcRdmAD1, spcRdmAD2);
689
690             // Create top connections between MC for full map
691             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
692                 connection = createTopConnection(spcRdmAD1, spcRdmAD2, cepMap, TapiStringConstants.MC,
693                 LayerProtocolName.PHOTONICMEDIA);
694             this.connectionFullMap.put(connection.key(), connection);
695             LOG.info("Top connection created = {}", connection);
696
697             // Create top connections that will be added to the service object
698             Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
699             connServMap.put(conn.key(), conn);
700         }
701
702         // OTSiMC top connection between edge roadms
703         LOG.info("Going to created top connection between OTSiMC");
704         String spcRdmAD1 = rdmAddDropTplist.stream().filter(adp -> adp.contains(edgeRoadm1)).findFirst().get();
705         String spcRdmAD2 = rdmAddDropTplist.stream().filter(adp -> adp.contains(edgeRoadm2)).findFirst().get();
706         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
707             connection = createTopConnection(spcRdmAD1, spcRdmAD2, cepMap, TapiStringConstants.OTSI_MC,
708             LayerProtocolName.PHOTONICMEDIA);
709         this.connectionFullMap.put(connection.key(), connection);
710         LOG.info("Top connection created = {}", connection);
711
712         // OTSiMC top connections that will be added to the service object
713         Connection conn = new ConnectionBuilder().setConnectionUuid(connection.getUuid()).build();
714         connServMap.put(conn.key(), conn);
715         return connServMap;
716     }
717
718     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
719             createTopConnection(String tp1, String tp2,
720                         Map<org.opendaylight.yang.gen.v1.urn
721                             .onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey,
722                             ConnectionEndPoint> cepMap, String qual, LayerProtocolName topPortocol) {
723         // find cep for each AD MC of roadm 1 and 2
724         LOG.info("Top connection name = {}", String.join("+", "TOP", tp1, tp2, qual));
725         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.ConnectionEndPoint adCep1 =
726             cepMap.get(new org.opendaylight.yang.gen.v1.urn
727                 .onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey(
728                 new Uuid(UUID.nameUUIDFromBytes((String.join("+", "CEP", tp1.split("\\+")[0],
729                     qual, tp1.split("\\+")[1])).getBytes(Charset.forName("UTF-8")))
730                     .toString())));
731         LOG.info("ADCEP1 = {}", adCep1);
732         org.opendaylight.yang.gen.v1.urn
733             .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPoint cep1 =
734             new org.opendaylight.yang.gen.v1.urn
735                 .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPointBuilder()
736                 .setNodeEdgePointUuid(adCep1.getClientNodeEdgePoint()
737                     .values().stream().findFirst().get().getNodeEdgePointUuid())
738                 .setTopologyUuid(adCep1.getClientNodeEdgePoint()
739                     .values().stream().findFirst().get().getTopologyUuid())
740                 .setNodeUuid(adCep1.getClientNodeEdgePoint()
741                     .values().stream().findFirst().get().getNodeUuid())
742                 .setConnectionEndPointUuid(adCep1.getUuid())
743                 .build();
744         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.ConnectionEndPoint adCep2 =
745             cepMap.get(new org.opendaylight.yang.gen.v1.urn
746                 .onf.otcc.yang.tapi.connectivity.rev181210.cep.list.ConnectionEndPointKey(
747                 new Uuid(UUID.nameUUIDFromBytes((String.join("+", "CEP", tp2.split("\\+")[0],
748                     qual, tp2.split("\\+")[1])).getBytes(Charset.forName("UTF-8")))
749                     .toString())));
750         LOG.info("ADCEP2 = {}", adCep2);
751         org.opendaylight.yang.gen.v1.urn
752             .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPoint cep2 =
753             new org.opendaylight.yang.gen.v1.urn
754                 .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPointBuilder()
755                 .setNodeEdgePointUuid(adCep2.getClientNodeEdgePoint()
756                     .values().stream().findFirst().get().getNodeEdgePointUuid())
757                 .setTopologyUuid(adCep2.getClientNodeEdgePoint()
758                     .values().stream().findFirst().get().getTopologyUuid())
759                 .setNodeUuid(adCep2.getClientNodeEdgePoint()
760                     .values().stream().findFirst().get().getNodeUuid())
761                 .setConnectionEndPointUuid(adCep1.getUuid())
762                 .build();
763         Map<ConnectionEndPointKey, org.opendaylight.yang.gen.v1.urn
764             .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPoint> ceps = new HashMap<>();
765         ceps.put(cep1.key(), cep1);
766         ceps.put(cep2.key(), cep2);
767         Name connName = new NameBuilder()
768             .setValueName("Connection name")
769             .setValue(String.join("+", "TOP", tp1, tp2, qual))
770             .build();
771         // TODO: lower connection, supported link.......
772         return new org.opendaylight.yang.gen.v1.urn
773             .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionBuilder()
774             .setUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", "TOP", tp1, tp2, qual))
775                 .getBytes(Charset.forName("UTF-8"))).toString()))
776             .setName(Map.of(connName.key(), connName))
777             .setConnectionEndPoint(ceps)
778             .setOperationalState(OperationalState.ENABLED)
779             .setLayerProtocolName(topPortocol)
780             .setLifecycleState(LifecycleState.INSTALLED)
781             .setDirection(ForwardingDirection.BIDIRECTIONAL)
782             .build();
783     }
784
785     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection
786             createXCBetweenCeps(ConnectionEndPoint cep1, ConnectionEndPoint cep2, String tp1, String tp2, String qual,
787                         LayerProtocolName xcProtocol) {
788         LOG.info("Creation cross connection between: {} and {}", tp1, tp2);
789         LOG.info("Cross connection name = {}", String.join("+", "XC", tp1, tp2, qual));
790         LOG.info("CEP1 = {}", cep1.getClientNodeEdgePoint());
791         LOG.info("CEP2 = {}", cep2.getClientNodeEdgePoint());
792         org.opendaylight.yang.gen.v1.urn
793             .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPoint cepServ1 =
794             new org.opendaylight.yang.gen.v1.urn
795                 .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPointBuilder()
796                 .setNodeEdgePointUuid(cep1.getClientNodeEdgePoint()
797                     .values().stream().findFirst().get().getNodeEdgePointUuid())
798                 .setTopologyUuid(cep1.getClientNodeEdgePoint()
799                     .values().stream().findFirst().get().getTopologyUuid())
800                 .setNodeUuid(cep1.getClientNodeEdgePoint()
801                     .values().stream().findFirst().get().getNodeUuid())
802                 .setConnectionEndPointUuid(cep1.getUuid())
803                 .build();
804         org.opendaylight.yang.gen.v1.urn
805             .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPoint cepServ2 =
806             new org.opendaylight.yang.gen.v1.urn
807                 .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPointBuilder()
808                 .setNodeEdgePointUuid(cep2.getClientNodeEdgePoint()
809                     .values().stream().findFirst().get().getNodeEdgePointUuid())
810                 .setTopologyUuid(cep2.getClientNodeEdgePoint()
811                     .values().stream().findFirst().get().getTopologyUuid())
812                 .setNodeUuid(cep2.getClientNodeEdgePoint()
813                     .values().stream().findFirst().get().getNodeUuid())
814                 .setConnectionEndPointUuid(cep2.getUuid())
815                 .build();
816         Map<ConnectionEndPointKey, org.opendaylight.yang.gen.v1.urn
817             .onf.otcc.yang.tapi.connectivity.rev181210.connection.ConnectionEndPoint> ceps = new HashMap<>();
818         ceps.put(cepServ1.key(), cepServ1);
819         ceps.put(cepServ2.key(), cepServ2);
820         Name connName = new NameBuilder()
821             .setValueName("Connection name")
822             .setValue(String.join("+", "XC", tp1, tp2, qual))
823             .build();
824         // TODO: lower connection, supported link.......
825         return new org.opendaylight.yang.gen.v1.urn
826             .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionBuilder()
827             .setUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", "XC", tp1, tp2, qual))
828                 .getBytes(Charset.forName("UTF-8"))).toString()))
829             .setName(Map.of(connName.key(), connName))
830             .setConnectionEndPoint(ceps)
831             .setOperationalState(OperationalState.ENABLED)
832             .setLayerProtocolName(xcProtocol)
833             .setLifecycleState(LifecycleState.INSTALLED)
834             .setDirection(ForwardingDirection.BIDIRECTIONAL)
835             .build();
836     }
837
838     private ConnectionEndPoint createCepRoadm(String id, String qualifier) {
839         LOG.info("NEP = {}", String.join("+", id.split("\\+")[0], qualifier, id.split("\\+")[1]));
840         Name cepName = new NameBuilder()
841             .setValueName("ConnectionEndPoint name")
842             .setValue(String.join("+", id.split("\\+")[0], qualifier,
843                 id.split("\\+")[1]))
844             .build();
845         ClientNodeEdgePoint cnep = new ClientNodeEdgePointBuilder()
846             .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", id.split("\\+")[0],
847                 qualifier, id.split("\\+")[1])).getBytes(Charset.forName("UTF-8")))
848                 .toString()))
849             .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+",id.split("\\+")[0],
850                 qualifier)).getBytes(Charset.forName("UTF-8")))
851                 .toString()))
852             .setTopologyUuid(new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
853                 .getBytes(Charset.forName("UTF-8"))).toString()))
854             .build();
855         // TODO: add augmentation with the corresponding cep-spec (i.e. MC, OTSiMC...)
856         // TODO: add parent ONEP??
857         ConnectionEndPointBuilder cepBldr = new ConnectionEndPointBuilder()
858             .setUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", "CEP", id.split("\\+")[0],
859                 qualifier, id.split("\\+")[1])).getBytes(Charset.forName("UTF-8")))
860                 .toString()))
861             .setClientNodeEdgePoint(Map.of(cnep.key(), cnep))
862             .setName(Map.of(cepName.key(), cepName))
863             .setConnectionPortRole(PortRole.SYMMETRIC)
864             .setConnectionPortDirection(PortDirection.BIDIRECTIONAL)
865             .setOperationalState(OperationalState.ENABLED)
866             .setLifecycleState(LifecycleState.INSTALLED)
867             .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA);
868         return cepBldr.build();
869     }
870
871     private ConnectionEndPoint createCepXpdr(String id, String qualifier, String nodeLayer,
872                                              LayerProtocolName cepProtocol) {
873         Name cepName = new NameBuilder()
874             .setValueName("ConnectionEndPoint name")
875             .setValue(String.join("+", id.split("\\+")[0], qualifier,
876                 id.split("\\+")[1]))
877             .build();
878         ClientNodeEdgePoint cnep = new ClientNodeEdgePointBuilder()
879             .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", id.split("\\+")[0],
880                 qualifier, id.split("\\+")[1])).getBytes(Charset.forName("UTF-8")))
881                 .toString()))
882             .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+",id.split("\\+")[0],
883                 nodeLayer)).getBytes(Charset.forName("UTF-8")))
884                 .toString()))
885             .setTopologyUuid(new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
886                 .getBytes(Charset.forName("UTF-8"))).toString()))
887             .build();
888         // TODO: add augmentation with the corresponding cep-spec (i.e. MC, OTSiMC...)
889         // TODO: add parent ONEP??
890         ConnectionEndPointBuilder cepBldr = new ConnectionEndPointBuilder()
891             .setUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", "CEP", id.split("\\+")[0],
892                 qualifier, id.split("\\+")[1])).getBytes(Charset.forName("UTF-8")))
893                 .toString()))
894             .setClientNodeEdgePoint(Map.of(cnep.key(), cnep))
895             .setName(Map.of(cepName.key(), cepName))
896             .setConnectionPortRole(PortRole.SYMMETRIC)
897             .setConnectionPortDirection(PortDirection.BIDIRECTIONAL)
898             .setOperationalState(OperationalState.ENABLED)
899             .setLifecycleState(LifecycleState.INSTALLED)
900             .setLayerProtocolName(cepProtocol);
901         return cepBldr.build();
902     }
903
904     private EndPoint mapServiceZEndPoint(
905             org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceZEnd
906                 serviceZEnd, PathDescription pathDescription) {
907         EndPointBuilder endPointBuilder = new EndPointBuilder();
908         // 1. Service Format: ODU, OTU, ETH
909         ServiceFormat serviceFormat = serviceZEnd.getServiceFormat();
910         String serviceNodeId = serviceZEnd.getNodeId().getValue();
911         // Identify SIP name
912         Uuid sipUuid = getSipIdFromZend(pathDescription.getZToADirection().getZToA(), serviceNodeId, serviceFormat);
913         LOG.info("Uuid of z end {}", sipUuid);
914         LayerProtocolName layerProtocols = null;
915         // Layer protocol name
916         switch (serviceFormat) {
917             case Ethernet:
918                 layerProtocols = LayerProtocolName.DSR;
919                 break;
920             case OTU:
921             case OC:
922                 layerProtocols = LayerProtocolName.PHOTONICMEDIA;
923                 break;
924             case ODU:
925                 layerProtocols = LayerProtocolName.ODU;
926                 break;
927             default:
928                 LOG.error("Service Format not supported");
929         }
930         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.local._class.Name name =
931             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.local._class.NameBuilder()
932                 .setValueName("OpenROADM info")
933                 .setValue(String.join("-", serviceZEnd.getClli(),
934                     serviceZEnd.getTxDirection().getPort().getPortDeviceName(),
935                     serviceZEnd.getTxDirection().getPort().getPortName()))
936                 .build();
937         return endPointBuilder
938             .setServiceInterfacePoint(new ServiceInterfacePointBuilder()
939                 .setServiceInterfacePointUuid(sipUuid)
940                 .build())
941             .setName(Map.of(name.key(), name))
942             .setAdministrativeState(AdministrativeState.UNLOCKED)
943             .setDirection(PortDirection.BIDIRECTIONAL)
944             .setLifecycleState(LifecycleState.INSTALLED)
945             .setOperationalState(OperationalState.ENABLED)
946             .setLayerProtocolName(layerProtocols)
947             .setCapacity(new CapacityBuilder()
948                 .setTotalSize(new TotalSizeBuilder()
949                     .setValue(Uint64.valueOf(serviceZEnd.getServiceRate()))
950                     .setUnit(CapacityUnit.GBPS)
951                     .build())
952                 .setBandwidthProfile(new BandwidthProfileBuilder().build()) // TODO: implement bandwidth profile
953                 .build())
954             .setProtectionRole(ProtectionRole.WORK)
955             .setRole(PortRole.SYMMETRIC)
956             .setLocalId(serviceNodeId)
957             .build();
958     }
959
960     private EndPoint mapServiceAEndPoint(
961             org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEnd
962                 serviceAEnd, PathDescription pathDescription) {
963         EndPointBuilder endPointBuilder = new EndPointBuilder();
964         // 1. Service Format: ODU, OTU, ETH
965         ServiceFormat serviceFormat = serviceAEnd.getServiceFormat();
966         String serviceNodeId = serviceAEnd.getNodeId().getValue();
967         // Identify SIP name
968         Uuid sipUuid = getSipIdFromAend(pathDescription.getAToZDirection().getAToZ(), serviceNodeId, serviceFormat);
969         LOG.info("Uuid of a end {}", sipUuid);
970         LayerProtocolName layerProtocols = null;
971         // Layer protocol name
972         switch (serviceFormat) {
973             case Ethernet:
974                 layerProtocols = LayerProtocolName.DSR;
975                 break;
976             case OTU:
977             case OC:
978                 layerProtocols = LayerProtocolName.PHOTONICMEDIA;
979                 break;
980             case ODU:
981                 layerProtocols = LayerProtocolName.ODU;
982                 break;
983             default:
984                 LOG.error("Service Format not supported");
985         }
986         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.local._class.Name name =
987             new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.local._class.NameBuilder()
988                 .setValueName("OpenROADM info")
989                 .setValue(String.join("-", serviceAEnd.getClli(),
990                     serviceAEnd.getTxDirection().getPort().getPortDeviceName(),
991                     serviceAEnd.getTxDirection().getPort().getPortName()))
992                 .build();
993         return endPointBuilder
994             .setServiceInterfacePoint(new ServiceInterfacePointBuilder()
995                 .setServiceInterfacePointUuid(sipUuid)
996                 .build())
997             .setName(Map.of(name.key(), name))
998             .setAdministrativeState(AdministrativeState.UNLOCKED)
999             .setDirection(PortDirection.BIDIRECTIONAL)
1000             .setLifecycleState(LifecycleState.INSTALLED)
1001             .setOperationalState(OperationalState.ENABLED)
1002             .setLayerProtocolName(layerProtocols)
1003             .setCapacity(new CapacityBuilder()
1004                 .setTotalSize(new TotalSizeBuilder()
1005                     .setValue(Uint64.valueOf(serviceAEnd.getServiceRate()))
1006                     .setUnit(CapacityUnit.GBPS)
1007                     .build())
1008                 .setBandwidthProfile(new BandwidthProfileBuilder().build()) // TODO: implement bandwidth profile
1009                 .build())
1010             .setProtectionRole(ProtectionRole.WORK)
1011             .setRole(PortRole.SYMMETRIC)
1012             .setLocalId(serviceNodeId)
1013             .build();
1014     }
1015
1016     private Uuid getSipIdFromZend(Map<ZToAKey, ZToA> mapztoa, String serviceNodeId, ServiceFormat serviceFormat) {
1017         Uuid zendUuid = null;
1018         if (serviceNodeId.contains("ROADM")) {
1019             // Service from ROADM to ROADM
1020             // AddDrop-AddDrop ports --> MC layer SIPs
1021             ZToA firstElement = mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("0")).findFirst().get();
1022             TerminationPoint tp = (TerminationPoint) firstElement.getResource().getResource();
1023             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1024                 tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1025                 .toString());
1026             LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId()));
1027             for (ServiceInterfacePoint sip:this.sipMap.values()) {
1028                 if (!sip.getUuid().equals(sipUuid)) {
1029                     LOG.info("SIP {} doesn match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1030                     continue;
1031                 }
1032                 zendUuid = sip.getUuid();
1033                 break;
1034             }
1035         } else {
1036             // Service from XPDR to XPDR
1037             ZToA firstElement;
1038             TerminationPoint tp;
1039             Uuid sipUuid;
1040             switch (serviceFormat) {
1041                 case ODU:
1042                     firstElement = mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("2")).findFirst().get();
1043                     tp = (TerminationPoint) firstElement.getResource().getResource();
1044                     // Network-Network ports --> iODU layer SIPs TODO --> updated to E_ODU
1045                     sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1046                         tp.getTpNodeId(), TapiStringConstants.I_ODU, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1047                         .toString());
1048                     LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.I_ODU,
1049                         tp.getTpId()));
1050                     break;
1051                 case OTU:
1052                     firstElement = mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("2")).findFirst().get();
1053                     tp = (TerminationPoint) firstElement.getResource().getResource();
1054                     // Network-Network ports --> iOTSi layer SIPs
1055                     sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1056                         tp.getTpNodeId(), TapiStringConstants.I_OTSI, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1057                         .toString());
1058                     LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.I_OTSI,
1059                         tp.getTpId()));
1060                     break;
1061                 case Ethernet:
1062                     LOG.info("Elements ZA = {}", mapztoa.values().toString());
1063                     firstElement = mapztoa.values().stream().filter(ztoa -> ztoa.getId().equals("0")).findFirst().get();
1064                     tp = (TerminationPoint) firstElement.getResource().getResource();
1065                     // Client-client ports --> DSR layer SIPs
1066                     sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1067                         tp.getTpNodeId(), TapiStringConstants.DSR, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1068                         .toString());
1069                     LOG.info("SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.DSR,
1070                         tp.getTpId()));
1071                     break;
1072                 default:
1073                     sipUuid = null;
1074                     LOG.warn("Service format {} not supported (?)", serviceFormat.getName());
1075             }
1076             for (ServiceInterfacePoint sip:this.sipMap.values()) {
1077                 if (!sip.getUuid().equals(sipUuid)) {
1078                     LOG.info("SIP {} doesn match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1079                     continue;
1080                 }
1081                 zendUuid = sip.getUuid();
1082                 break;
1083             }
1084         }
1085         return zendUuid;
1086     }
1087
1088     private Uuid getSipIdFromAend(Map<AToZKey, AToZ> mapatoz, String serviceNodeId, ServiceFormat serviceFormat) {
1089         Uuid aendUuid = null;
1090         LOG.info("ServiceNode = {} and ServiceFormat = {}", serviceNodeId, serviceFormat.getName());
1091         LOG.info("Map a to z = {}", mapatoz);
1092         if (serviceNodeId.contains("ROADM")) {
1093             // Service from ROADM to ROADM
1094             // AddDrop-AddDrop ports --> MC layer SIPs
1095             AToZ firstElement = mapatoz.values().stream().filter(atoz -> atoz.getId().equals("0")).findFirst().get();
1096             LOG.info("First element of service path = {}", firstElement.getResource().getResource());
1097             TerminationPoint tp = (TerminationPoint) firstElement.getResource().getResource();
1098             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1099                 tp.getTpNodeId(), TapiStringConstants.MC, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1100                 .toString());
1101             LOG.info("ROADM SIP name = {}", String.join("+", tp.getTpNodeId(), TapiStringConstants.MC,
1102                 tp.getTpId()));
1103             for (ServiceInterfacePoint sip:this.sipMap.values()) {
1104                 if (!sip.getUuid().equals(sipUuid)) {
1105                     LOG.info("SIP {} doesn match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1106                     continue;
1107                 }
1108                 aendUuid = sip.getUuid();
1109                 break;
1110             }
1111         } else {
1112             // Service from XPDR to XPDR
1113             AToZ firstElement;
1114             TerminationPoint tp;
1115             Uuid sipUuid;
1116             switch (serviceFormat) {
1117                 case ODU:
1118                     firstElement = mapatoz.values().stream().filter(atoz -> atoz.getId().equals("2")).findFirst().get();
1119                     tp = (TerminationPoint) firstElement.getResource().getResource();
1120                     // Network-Network ports --> iODU layer SIPs. TODO -> updated to eODU
1121                     sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1122                         tp.getTpNodeId(), TapiStringConstants.I_ODU, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1123                         .toString());
1124                     LOG.info("ODU XPDR SIP name = {}", String.join("+", tp.getTpNodeId(),
1125                         TapiStringConstants.I_ODU, tp.getTpId()));
1126                     break;
1127                 case OTU:
1128                     firstElement = mapatoz.values().stream().filter(atoz -> atoz.getId().equals("2")).findFirst().get();
1129                     tp = (TerminationPoint) firstElement.getResource().getResource();
1130                     // Network-Network ports --> iOTSi layer SIPs
1131                     sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1132                         tp.getTpNodeId(), TapiStringConstants.I_OTSI, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1133                         .toString());
1134                     LOG.info("OTU XPDR SIP name = {}", String.join("+", tp.getTpNodeId(),
1135                         TapiStringConstants.I_OTSI, tp.getTpId()));
1136                     break;
1137                 case Ethernet:
1138                     LOG.info("Elements AZ = {}", mapatoz.values().toString());
1139                     firstElement = mapatoz.values().stream().filter(atoz -> atoz.getId().equals("0")).findFirst().get();
1140                     tp = (TerminationPoint) firstElement.getResource().getResource();
1141                     // Client-client ports --> DSR layer SIPs
1142                     sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP",
1143                         tp.getTpNodeId(), TapiStringConstants.DSR, tp.getTpId())).getBytes(Charset.forName("UTF-8")))
1144                         .toString());
1145                     LOG.info("DSR XPDR SIP name = {}", String.join("+", tp.getTpNodeId(),
1146                         TapiStringConstants.DSR, tp.getTpId()));
1147                     break;
1148                 default:
1149                     sipUuid = null;
1150                     LOG.warn("Service format {} not supported (?)", serviceFormat.getName());
1151             }
1152             for (ServiceInterfacePoint sip:this.sipMap.values()) {
1153                 if (!sip.getUuid().equals(sipUuid)) {
1154                     LOG.info("SIP {} doesn match sipname {}", sip.getUuid().getValue(), sipUuid.getValue());
1155                     continue;
1156                 }
1157                 aendUuid = sip.getUuid();
1158                 break;
1159             }
1160         }
1161         return aendUuid;
1162     }
1163
1164     private void putRdmCepInTopologyContext(String node, String spcRdmAD, String qual, ConnectionEndPoint cep) {
1165         LOG.info("NEP id before Merge = {}", String.join("+", node, qual, spcRdmAD.split("\\+")[1]));
1166         LOG.info("Node of NEP id before Merge = {}", String.join("+", node, TapiStringConstants.PHTNC_MEDIA));
1167         // Give uuids so that it is easier to look for things: topology uuid, node uuid, nep uuid, cep
1168         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
1169             .getBytes(Charset.forName("UTF-8"))).toString());
1170         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(String.join("+", node, TapiStringConstants.PHTNC_MEDIA)
1171             .getBytes(Charset.forName("UTF-8"))).toString());
1172         Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(String.join("+", node, qual, spcRdmAD.split("\\+")[1])
1173             .getBytes(Charset.forName("UTF-8"))).toString());
1174         this.tapiContext.updateTopologyWithCep(topoUuid, nodeUuid, nepUuid, cep);
1175     }
1176
1177     private void putXpdrCepInTopologyContext(String node, String spcXpdrNet, String qual, String nodeLayer,
1178                                              ConnectionEndPoint cep) {
1179         // Give uuids so that it is easier to look for things: topology uuid, node uuid, nep uuid, cep
1180         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
1181             .getBytes(Charset.forName("UTF-8"))).toString());
1182         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(String.join("+", node, nodeLayer)
1183             .getBytes(Charset.forName("UTF-8"))).toString());
1184         Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(String.join("+", node, qual, spcXpdrNet.split("\\+")[1])
1185             .getBytes(Charset.forName("UTF-8"))).toString());
1186         this.tapiContext.updateTopologyWithCep(topoUuid, nodeUuid, nepUuid, cep);
1187     }
1188
1189     public Map<org.opendaylight.yang.gen.v1.urn
1190             .onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey,
1191             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection>
1192             getConnectionFullMap() {
1193         return this.connectionFullMap;
1194     }
1195
1196     private String getIdBasedOnModelVersion(String nodeid) {
1197         return nodeid.matches("[A-Z]{5}-[A-Z0-9]{2}-.*") ? String.join("-", nodeid.split("-")[0],
1198             nodeid.split("-")[1]) : nodeid.split("-")[0];
1199     }
1200
1201     public ServiceCreateInput createORServiceInput(CreateConnectivityServiceInput input, Uuid serviceUuid) {
1202         // TODO: not taking into account all the constraints. Only using EndPoints and Connectivity Constraint.
1203         Map<org.opendaylight.yang.gen.v1.urn
1204             .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPointKey,
1205             org.opendaylight.yang.gen.v1.urn
1206                 .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint>
1207             endPointMap = input.getEndPoint();
1208         ConnectivityConstraint constraint = input.getConnectivityConstraint();
1209         ConnectionType connType = null;
1210         ServiceFormat serviceFormat = null;
1211         String nodeAid = String.join("+", endPointMap.values().stream().findFirst().get().getLocalId(),
1212             TapiStringConstants.DSR);
1213         String nodeZid = String.join("+", endPointMap.values().stream().skip(1).findFirst().get().getLocalId(),
1214             TapiStringConstants.DSR);
1215         LOG.debug("Node a = {}", nodeAid);
1216         LOG.debug("Node z = {}", nodeZid);
1217         switch (constraint.getServiceLayer().getIntValue()) {
1218             case 0:
1219                 LOG.info("ODU");
1220                 connType = ConnectionType.Infrastructure;
1221                 serviceFormat = ServiceFormat.ODU;
1222                 break;
1223             case 1:
1224                 LOG.info("ETH, no need to create OTU and ODU");
1225                 connType = ConnectionType.Service;
1226                 serviceFormat = ServiceFormat.Ethernet;
1227                 break;
1228             case 2:
1229                 LOG.info("DSR, need to create OTU and ODU");
1230                 connType = ConnectionType.Service;
1231                 serviceFormat = ServiceFormat.Ethernet;
1232                 break;
1233             case 3:
1234                 LOG.info("PHOTONIC");
1235                 connType = getConnectionTypePhtnc(endPointMap.values());
1236                 serviceFormat = getServiceFormatPhtnc(endPointMap.values());
1237                 if (serviceFormat.equals(ServiceFormat.OC)) {
1238                     nodeAid = String.join("+", endPointMap.values().stream().findFirst().get().getLocalId(),
1239                         TapiStringConstants.PHTNC_MEDIA);
1240                     nodeZid = String.join("+", endPointMap.values().stream().skip(1).findFirst().get().getLocalId(),
1241                         TapiStringConstants.PHTNC_MEDIA);
1242                 } else {
1243                     nodeAid = String.join("+", endPointMap.values().stream().findFirst().get().getLocalId(),
1244                         TapiStringConstants.OTSI);
1245                     nodeZid = String.join("+", endPointMap.values().stream().skip(1).findFirst().get().getLocalId(),
1246                         TapiStringConstants.OTSI);
1247                 }
1248                 LOG.debug("Node a photonic = {}", nodeAid);
1249                 LOG.debug("Node z photonic = {}", nodeZid);
1250                 break;
1251             default:
1252                 LOG.info("Service type {} not supported", constraint.getServiceLayer().getName());
1253         }
1254         // Requested Capacity for connectivity service
1255         Uint64 capacity = input.getConnectivityConstraint().getRequestedCapacity().getTotalSize().getValue();
1256         // map endpoints into service end points. Map the type of service from TAPI to OR
1257         ServiceAEnd serviceAEnd = tapiEndPointToServiceAPoint(endPointMap.values().stream().findFirst().get(),
1258             serviceFormat, nodeAid, capacity);
1259         ServiceZEnd serviceZEnd = tapiEndPointToServiceZPoint(endPointMap.values().stream().skip(1).findFirst().get(),
1260             serviceFormat, nodeZid, capacity);
1261         if (serviceAEnd == null || serviceZEnd == null) {
1262             LOG.error("Couldnt map endpoints to service end");
1263             return null;
1264         }
1265         LOG.info("Service a end = {}", serviceAEnd);
1266         LOG.info("Service z end = {}", serviceZEnd);
1267         return new ServiceCreateInputBuilder()
1268             .setServiceAEnd(serviceAEnd)
1269             .setServiceZEnd(serviceZEnd)
1270             .setConnectionType(connType)
1271             .setServiceName(serviceUuid.getValue())
1272             .setCommonId("common id")
1273             .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request-1")
1274                 .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url")
1275                 .setRequestSystemId("appname")
1276                 .build())
1277             .setCustomer("customer")
1278             .setDueDate(DateAndTime.getDefaultInstance("2018-06-15T00:00:01Z"))
1279             .setOperatorContact("pw1234")
1280             .build();
1281     }
1282
1283     private ServiceZEnd tapiEndPointToServiceZPoint(
1284         org.opendaylight.yang.gen.v1.urn
1285             .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint endPoint,
1286         ServiceFormat serviceFormat, String nodeZid, Uint64 capacity) {
1287         // TODO -> change way this is being created. The name includes only SPDR-SA1-XPDR1.
1288         //  Not the rest which is needed in the txPortDeviceName.
1289         //  It could be obtained from the SIP which has the NEP and includes all the OR name.
1290         Uuid sipUuid = endPoint.getServiceInterfacePoint().getServiceInterfacePointUuid();
1291         // Todo -> need to find the NEP associated to that SIP
1292         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeZid.getBytes(Charset.forName("UTF-8"))).toString());
1293         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node =
1294             this.tapiContext.getTapiNode(this.tapiTopoUuid, nodeUuid);
1295         if (node == null) {
1296             LOG.error("Node not found in datastore");
1297             return null;
1298         }
1299         // TODO -> in case of a DSR service, for some requests we need the NETWORK PORT and not the CLIENT although the
1300         //  connection is between 2 CLIENT ports. Otherwise it will not work...
1301         OwnedNodeEdgePoint nep = null;
1302         for (OwnedNodeEdgePoint onep : node.getOwnedNodeEdgePoint().values()) {
1303             if (onep.getMappedServiceInterfacePoint() == null) {
1304                 continue;
1305             }
1306             if (onep.getMappedServiceInterfacePoint().containsKey(new MappedServiceInterfacePointKey(sipUuid))) {
1307                 nep = onep;
1308                 break;
1309             }
1310         }
1311         if (nep == null) {
1312             LOG.error("Nep not found in datastore");
1313             return null;
1314         }
1315         String nodeName = endPoint.getName().values().stream().findFirst().get().getValue();
1316         String nodeid = String.join("-", nodeName.split("-")[0], nodeName.split("-")[1]);
1317         String nepName = nep.getName().values().stream().findFirst().get().getValue();
1318         String txPortDeviceName = nepName.split("\\+")[0];
1319         String txPortName = nepName.split("\\+")[2];
1320         String rxPortDeviceName = txPortDeviceName;
1321         String rxPortName = txPortName;
1322         LOG.debug("Node z id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1323         LOG.debug("Node z id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1324         if (serviceFormat.equals(ServiceFormat.ODU)) {
1325             // TODO --> populate network map
1326             populateNetworkMap(nodeid, txPortName);
1327         }
1328         if (serviceFormat.equals(ServiceFormat.Ethernet)) {
1329             // TODO --> choose from network Map un network port which hasnt been used yet by another service.
1330             //  Set boolean to true and update txportName and so on
1331             String updTxName = findFreeConfiguredNetworkPort(nodeid);
1332             if (updTxName != null) {
1333                 txPortName = updTxName;
1334                 rxPortName = txPortName;
1335             }
1336         }
1337         // TODO --> get clli from datastore?
1338         String clli = "NodeSC";
1339         LOG.info("Node z id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1340         LOG.info("Node z id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1341         ServiceZEndBuilder serviceZEndBuilder = new ServiceZEndBuilder()
1342             .setClli(clli)
1343             .setNodeId(new NodeIdType(nodeid))
1344             .setOpticType(OpticTypes.Gray)
1345             .setServiceFormat(serviceFormat)
1346             .setServiceRate(Uint32.valueOf(capacity))
1347             .setSubrateEthSla(new SubrateEthSlaBuilder().setSubrateEthSla(
1348                 new org.opendaylight.yang.gen.v1.http
1349                     .org.openroadm.common.service.types.rev190531.subrate.eth.sla.SubrateEthSlaBuilder()
1350                     .setCommittedBurstSize(Uint16.valueOf(64))
1351                     .setCommittedInfoRate(Uint32.valueOf(100000))
1352                     .build())
1353                 .build())
1354             .setTxDirection(new TxDirectionBuilder()
1355                 .setPort(new PortBuilder()
1356                     .setPortDeviceName(txPortDeviceName)
1357                     .setPortName(txPortName)
1358                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1359                     .setPortShelf("00")
1360                     .setPortType(TapiStringConstants.PORT_TYPE)
1361                     .build())
1362                 .setLgx(new LgxBuilder()
1363                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1364                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1365                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1366                     .setLgxPortShelf("00")
1367                     .build())
1368                 .build())
1369             .setRxDirection(new RxDirectionBuilder()
1370                 .setPort(new PortBuilder()
1371                     .setPortDeviceName(rxPortDeviceName)
1372                     .setPortName(rxPortName)
1373                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1374                     .setPortShelf("00")
1375                     .setPortType(TapiStringConstants.PORT_TYPE)
1376                     .build())
1377                 .setLgx(new LgxBuilder()
1378                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1379                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1380                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1381                     .setLgxPortShelf("00")
1382                     .build())
1383                 .build());
1384         if (serviceFormat.equals(ServiceFormat.ODU)) {
1385             serviceZEndBuilder.setOduServiceRate(ODU4.class);
1386         }
1387         if (serviceFormat.equals(ServiceFormat.OTU)) {
1388             serviceZEndBuilder.setOtuServiceRate(OTU4.class);
1389         }
1390         return serviceZEndBuilder.build();
1391     }
1392
1393     private ServiceAEnd tapiEndPointToServiceAPoint(
1394         org.opendaylight.yang.gen.v1.urn
1395             .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint endPoint,
1396         ServiceFormat serviceFormat, String nodeAid, Uint64 capacity) {
1397         // TODO -> change way this is being created. The name includes only SPDR-SA1-XPDR1.
1398         //  Not the rest which is needed in the txPortDeviceName.
1399         //  It could be obtained from the SIP which has the NEP and includes all the OR name.
1400         Uuid sipUuid = endPoint.getServiceInterfacePoint().getServiceInterfacePointUuid();
1401         // Todo -> need to find the NEP associated to that SIP
1402         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeAid.getBytes(Charset.forName("UTF-8"))).toString());
1403         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node =
1404             this.tapiContext.getTapiNode(this.tapiTopoUuid, nodeUuid);
1405         if (node == null) {
1406             LOG.error("Node not found in datastore");
1407             return null;
1408         }
1409         // TODO -> in case of a DSR service, for some requests we need the NETWORK PORT and not the CLIENT although the
1410         //  connection is between 2 CLIENT ports. Otherwise it will not work...
1411         OwnedNodeEdgePoint nep = null;
1412         for (OwnedNodeEdgePoint onep : node.getOwnedNodeEdgePoint().values()) {
1413             if (onep.getMappedServiceInterfacePoint() == null) {
1414                 continue;
1415             }
1416             if (onep.getMappedServiceInterfacePoint().containsKey(new MappedServiceInterfacePointKey(sipUuid))) {
1417                 nep = onep;
1418                 break;
1419             }
1420         }
1421         if (nep == null) {
1422             LOG.error("Nep not found in datastore");
1423             return null;
1424         }
1425         String nodeName = endPoint.getName().values().stream().findFirst().get().getValue();
1426         String nodeid = String.join("-", nodeName.split("-")[0], nodeName.split("-")[1]);
1427         String nepName = nep.getName().values().stream().findFirst().get().getValue();
1428         String txPortDeviceName = nepName.split("\\+")[0];
1429         String txPortName = nepName.split("\\+")[2];
1430         String rxPortDeviceName = txPortDeviceName;
1431         String rxPortName = txPortName;
1432         LOG.debug("Node a id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1433         LOG.debug("Node a id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1434         if (serviceFormat.equals(ServiceFormat.ODU)) {
1435             // TODO --> populate network map
1436             populateNetworkMap(nodeid, txPortName);
1437         }
1438         if (serviceFormat.equals(ServiceFormat.Ethernet)) {
1439             // TODO --> choose from network Map un network port which hasnt been used yet by another service.
1440             //  Set boolean to true and update txportName and so on
1441             String updTxName = findFreeConfiguredNetworkPort(nodeid);
1442             if (updTxName != null) {
1443                 txPortName = updTxName;
1444                 rxPortName = txPortName;
1445             }
1446         }
1447         // TODO --> get clli from datastore?
1448         String clli = "NodeSA";
1449         LOG.info("Node a id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
1450         LOG.info("Node a id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
1451         ServiceAEndBuilder serviceAEndBuilder = new ServiceAEndBuilder()
1452             .setClli(clli)
1453             .setNodeId(new NodeIdType(nodeid))
1454             .setOpticType(OpticTypes.Gray)
1455             .setServiceFormat(serviceFormat)
1456             .setServiceRate(Uint32.valueOf(capacity))
1457             .setSubrateEthSla(new SubrateEthSlaBuilder().setSubrateEthSla(
1458                 new org.opendaylight.yang.gen.v1.http
1459                     .org.openroadm.common.service.types.rev190531.subrate.eth.sla.SubrateEthSlaBuilder()
1460                     .setCommittedBurstSize(Uint16.valueOf(64))
1461                     .setCommittedInfoRate(Uint32.valueOf(100000))
1462                     .build())
1463                 .build())
1464             .setTxDirection(new TxDirectionBuilder()
1465                 .setPort(new PortBuilder()
1466                     .setPortDeviceName(txPortDeviceName)
1467                     .setPortName(txPortName)
1468                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1469                     .setPortShelf("00")
1470                     .setPortType(TapiStringConstants.PORT_TYPE)
1471                     .build())
1472                 .setLgx(new LgxBuilder()
1473                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1474                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1475                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1476                     .setLgxPortShelf("00")
1477                     .build())
1478                 .build())
1479             .setRxDirection(new RxDirectionBuilder()
1480                 .setPort(new PortBuilder()
1481                     .setPortDeviceName(rxPortDeviceName)
1482                     .setPortName(rxPortName)
1483                     .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
1484                     .setPortShelf("00")
1485                     .setPortType(TapiStringConstants.PORT_TYPE)
1486                     .build())
1487                 .setLgx(new LgxBuilder()
1488                     .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
1489                     .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
1490                     .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
1491                     .setLgxPortShelf("00")
1492                     .build())
1493                 .build());
1494         if (serviceFormat.equals(ServiceFormat.ODU)) {
1495             serviceAEndBuilder.setOduServiceRate(ODU4.class);
1496         }
1497         if (serviceFormat.equals(ServiceFormat.OTU)) {
1498             serviceAEndBuilder.setOtuServiceRate(OTU4.class);
1499         }
1500         return serviceAEndBuilder.build();
1501     }
1502
1503     private String findFreeConfiguredNetworkPort(String nodeid) {
1504         if (!this.networkMap.containsKey(nodeid)) {
1505             return null;
1506         }
1507         Map<String, Boolean> netMap = this.networkMap.get(nodeid);
1508         for (Map.Entry<String, Boolean> entry : netMap.entrySet()) {
1509             if (!entry.getValue()) {
1510                 this.networkMap.get(nodeid).put(entry.getKey(), true);
1511                 return entry.getKey();
1512             }
1513         }
1514         return null;
1515     }
1516
1517     private void populateNetworkMap(String nodeid, String txPortName) {
1518         Map<String, Boolean> netMap = new HashMap<>();
1519         netMap.put(txPortName, false);
1520         if (!this.networkMap.containsKey(nodeid)) {
1521             this.networkMap.put(nodeid, netMap);
1522         } else if (!this.networkMap.get(nodeid).containsKey(txPortName)) {
1523             this.networkMap.get(nodeid).putAll(netMap);
1524         }
1525     }
1526
1527     private ConnectionType getConnectionTypePhtnc(Collection<org.opendaylight.yang.gen.v1.urn
1528             .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint> endPoints) {
1529         if (endPoints.stream().anyMatch(ep -> ep.getName().values().stream()
1530                 .anyMatch(name -> name.getValue().contains("ROADM")))) {
1531             // EndPoints are ROADMs
1532             return ConnectionType.RoadmLine;
1533         }
1534         // EndPoints ar not ROADMs -> XPDR, MUXPDR, SWTICHPDR
1535         return ConnectionType.Infrastructure;
1536     }
1537
1538     private ServiceFormat getServiceFormatPhtnc(Collection<org.opendaylight.yang.gen.v1.urn
1539             .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint> endPoints) {
1540         if (endPoints.stream().anyMatch(ep -> ep.getName().values().stream()
1541                 .anyMatch(name -> name.getValue().contains("ROADM")))) {
1542             // EndPoints are ROADMs
1543             return ServiceFormat.OC;
1544         }
1545         // EndPoints ar not ROADMs -> XPDR, MUXPDR, SWTICHPDR
1546         return ServiceFormat.OTU;
1547     }
1548
1549     private ConnectionEndPoint getAssociatediODUCep(String spcXpdrNetwork) {
1550         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", spcXpdrNetwork.split("\\+")[0],
1551             TapiStringConstants.DSR).getBytes(Charset.forName("UTF-8")))).toString());
1552         Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", spcXpdrNetwork.split("\\+")[0],
1553                 TapiStringConstants.I_ODU, spcXpdrNetwork.split("\\+")[1]).getBytes(Charset.forName("UTF-8"))))
1554             .toString());
1555         Uuid cepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "CEP",
1556             spcXpdrNetwork.split("\\+")[0], TapiStringConstants.I_ODU, spcXpdrNetwork.split("\\+")[1]))
1557             .getBytes(Charset.forName("UTF-8"))).toString());
1558         return this.tapiContext.getTapiCEP(this.tapiTopoUuid, nodeUuid, nepUuid, cepUuid);
1559     }
1560
1561     private String getAssociatedNetworkPort(String spcXpdrClient, List<String> xpdrNetworkTplist) {
1562         for (String networkPort:xpdrNetworkTplist) {
1563             if (networkPort.split("\\+")[0].equals(spcXpdrClient.split("\\+")[0])) {
1564                 return networkPort;
1565             }
1566         }
1567         return null;
1568     }
1569 }