Update portmapping model
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / TapiNetworkModelServiceImpl.java
1 /*
2  * Copyright © 2021 Nokia, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.topology;
9
10 import java.nio.charset.Charset;
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.Collection;
14 import java.util.Comparator;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Optional;
19 import java.util.UUID;
20 import java.util.concurrent.ExecutionException;
21 import java.util.stream.Collectors;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
24 import org.opendaylight.transportpce.tapi.R2RTapiLinkDiscovery;
25 import org.opendaylight.transportpce.tapi.TapiStringConstants;
26 import org.opendaylight.transportpce.tapi.utils.TapiLink;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.Nodes;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.NodeTypes;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.OduSwitchingPools;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.OduSwitchingPoolsBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListKey;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityKey;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GE;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GEODU4;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GE;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2e;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If1GE;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If1GEODU0;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCH;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.SupportedIfCapability;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.switching.pool.types.rev191129.SwitchingPoolTypes;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ContextBuilder;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LAYERPROTOCOLQUALIFIER;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortDirection;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortRole;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationDirection;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationState;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.AvailableCapacityBuilder;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.TotalPotentialCapacityBuilder;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointBuilder;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.Connection;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionBuilder;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectionKey;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityService;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceBuilder;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceKey;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.EndPoint;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.service.EndPointKey;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.context.ConnectivityContext;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE100GigE;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE10GigELAN;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPEGigE;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU0;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2E;
90 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU4;
91 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROMS;
92 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROTSi;
93 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1;
94 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
95 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
96 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext;
97 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
98 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroupBuilder;
99 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroupKey;
100 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
101 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointBuilder;
102 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
103 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePoint;
104 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointBuilder;
105 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointKey;
106 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint;
107 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointBuilder;
108 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointKey;
109 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
110 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.RuleBuilder;
111 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.RuleKey;
112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.risk.parameter.pac.RiskCharacteristic;
113 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.risk.parameter.pac.RiskCharacteristicBuilder;
114 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
115 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
116 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
117 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
118 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
119 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology;
120 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyBuilder;
121 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
122 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.cost.pac.CostCharacteristic;
123 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.cost.pac.CostCharacteristicBuilder;
124 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.timing.pac.LatencyCharacteristic;
125 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.timing.pac.LatencyCharacteristicBuilder;
126 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
127 import org.opendaylight.yangtools.yang.common.Uint16;
128 import org.opendaylight.yangtools.yang.common.Uint32;
129 import org.slf4j.Logger;
130 import org.slf4j.LoggerFactory;
131
132 public class TapiNetworkModelServiceImpl implements TapiNetworkModelService {
133
134     private static final Logger LOG = LoggerFactory.getLogger(TapiNetworkModelServiceImpl.class);
135     private final Uuid tapiTopoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
136             .getBytes(Charset.forName("UTF-8"))).toString());
137     private final NetworkTransactionService networkTransactionService;
138     private Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap;
139     private final R2RTapiLinkDiscovery linkDiscovery;
140     private final TapiLink tapiLink;
141
142     public TapiNetworkModelServiceImpl(final R2RTapiLinkDiscovery linkDiscovery,
143                                        NetworkTransactionService networkTransactionService, TapiLink tapiLink) {
144         this.networkTransactionService = networkTransactionService;
145         this.sipMap = new HashMap<>();
146         this.linkDiscovery = linkDiscovery;
147         this.tapiLink = tapiLink;
148     }
149
150     @Override
151     public void createTapiNode(String orNodeId, int orNodeVersion, Nodes node) {
152         // TODO -> Implementation with PortMappingListener
153         // check if port mapping exists or not...
154         if (node.getMapping() == null) {
155             LOG.warn("Could not generate port mapping for {} skipping network model creation", orNodeId);
156             return;
157         }
158         this.sipMap.clear();
159         LOG.info("Mapping of node {}: {}", orNodeId, node.getMapping().values());
160
161         // check type of device, check version and create node mapping
162         if (NodeTypes.Rdm.getIntValue() == node.getNodeInfo().getNodeType().getIntValue()) {
163             // ROADM device
164             // transform flat mapping list to per degree and per srg mapping lists
165             Map<String, List<Mapping>> mapDeg = new HashMap<>();
166             Map<String, List<Mapping>> mapSrg = new HashMap<>();
167             List<Mapping> mappingList = new ArrayList<>(node.nonnullMapping().values());
168             mappingList.sort(Comparator.comparing(Mapping::getLogicalConnectionPoint));
169
170             List<String> nodeShardList = getRoadmNodelist(mappingList);
171
172             // populate degree and srg LCP map
173             for (String str : nodeShardList) {
174                 List<Mapping> interList = mappingList.stream().filter(x -> x.getLogicalConnectionPoint().contains(str))
175                         .collect(Collectors.toList());
176                 if (str.contains("DEG")) {
177                     mapDeg.put(str, interList);
178                 } else if (str.contains("SRG")) {
179                     mapSrg.put(str, interList);
180                 } else {
181                     LOG.error("unknown element");
182                 }
183             }
184             // Transform LCPs into ONEP
185             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap =
186                 new HashMap<>(transformDegToOnep(orNodeId, mapDeg));
187             onepMap.putAll(transformSrgToOnep(orNodeId, mapSrg));
188
189             // create tapi Node
190             Node roadmNode = createRoadmTapiNode(orNodeId, onepMap);
191             mergeNodeinTopology(Map.of(roadmNode.key(), roadmNode));
192             mergeSipsinContext(this.sipMap);
193             // TODO add states corresponding to device config -> based on mapping.
194             //  This should be possible after Gilles work is merged
195
196             // rdm to rdm link creation if neighbour roadm is mounted
197             LOG.info("checking if neighbor roadm exists");
198             Map<LinkKey, Link> rdm2rdmLinks = this.linkDiscovery.readLLDP(new NodeId(orNodeId), orNodeVersion,
199                 this.tapiTopoUuid);
200             if (!rdm2rdmLinks.isEmpty()) {
201                 mergeLinkinTopology(rdm2rdmLinks);
202             }
203             LOG.info("TAPI node for or node {} successfully merged", orNodeId);
204         } else if (NodeTypes.Xpdr.getIntValue() ==  node.getNodeInfo().getNodeType().getIntValue()) {
205             List<Mapping> networkMappings = node.nonnullMapping().values()
206                     .stream().filter(k -> k.getLogicalConnectionPoint()
207                             .contains("NETWORK")).collect(Collectors.toList());
208             Map<Integer, String> xpdrMap = new HashMap<>();
209             for (Mapping mapping : networkMappings) {
210                 Integer xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
211                 String nodeId = node.getNodeId() + TapiStringConstants.XPDR + xpdrNb;
212                 if (!xpdrMap.containsKey(xpdrNb)) {
213                     List<Mapping> xpdrNetMaps = node.nonnullMapping().values()
214                         .stream().filter(k -> k.getLogicalConnectionPoint()
215                             .contains("XPDR" + xpdrNb + TapiStringConstants.NETWORK)).collect(Collectors.toList());
216                     List<Mapping> xpdrClMaps = node.nonnullMapping().values()
217                         .stream().filter(k -> k.getLogicalConnectionPoint()
218                             .contains("XPDR" + xpdrNb + TapiStringConstants.CLIENT)).collect(Collectors.toList());
219                     xpdrMap.put(xpdrNb, node.getNodeId());
220
221                     // create switching pool
222                     OduSwitchingPools oorOduSwitchingPool = createSwitchPoolForXpdr(
223                         mapping.getXponderType().getIntValue(), xpdrClMaps, xpdrNetMaps, xpdrNb);
224
225                     // node transformation
226                     Map<NodeKey, Node> nodeMap = new HashMap<>(transformXpdrToTapiNode(
227                         nodeId, xpdrClMaps, xpdrNetMaps, mapping.getXponderType(), oorOduSwitchingPool));
228                     // add nodes and sips to tapi context
229                     mergeNodeinTopology(nodeMap);
230                     mergeSipsinContext(this.sipMap);
231                 }
232             }
233             LOG.info("TAPI node for or node {} successfully merged", orNodeId);
234         }
235         // Device not managed yet
236     }
237
238     private Map<NodeKey, Node> transformXpdrToTapiNode(String nodeId, List<Mapping> xpdrClMaps,
239                                                        List<Mapping> xpdrNetMaps, XpdrNodeTypes xponderType,
240                                                        OduSwitchingPools oorOduSwitchingPool) {
241         Map<NodeKey, Node> nodeMap = new HashMap<>();
242         LOG.info("creation of a DSR/ODU node for {}", nodeId);
243         Uuid nodeUuidDsr = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId, TapiStringConstants.DSR))
244             .getBytes(Charset.forName("UTF-8"))).toString());
245         Name nameDsr = new NameBuilder().setValueName("dsr/odu node name").setValue(
246             String.join("+", nodeId, TapiStringConstants.DSR)).build();
247         List<LayerProtocolName> dsrLayerProtocols = Arrays.asList(LayerProtocolName.DSR,
248             LayerProtocolName.ODU);
249         Node dsrNode = createTapiXpdrNode(Map.of(nameDsr.key(), nameDsr), dsrLayerProtocols,
250             nodeId, nodeUuidDsr, xpdrClMaps, xpdrNetMaps, xponderType, oorOduSwitchingPool);
251
252         nodeMap.put(dsrNode.key(), dsrNode);
253
254         // node creation [otsi]
255         LOG.info("creation of an OTSi node for {}", nodeId);
256         Uuid nodeUuidOtsi = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId, TapiStringConstants.OTSI))
257             .getBytes(Charset.forName("UTF-8"))).toString());
258         Name nameOtsi =  new NameBuilder().setValueName("otsi node name").setValue(
259             String.join("+", nodeId, TapiStringConstants.OTSI)).build();
260         List<LayerProtocolName> otsiLayerProtocols = Arrays.asList(LayerProtocolName.PHOTONICMEDIA);
261         Node otsiNode = createTapiXpdrNode(Map.of(nameOtsi.key(), nameOtsi), otsiLayerProtocols,
262             nodeId, nodeUuidOtsi, xpdrClMaps, xpdrNetMaps, xponderType, null);
263
264         nodeMap.put(otsiNode.key(), otsiNode);
265
266         // transitional link cration between network nep of DSR/ODU node and iNep of otsi node
267         LOG.info("creation of transitional links between DSR/ODU and OTSi nodes");
268         Map<LinkKey, Link> linkMap = createTapiTransitionalLinks(nodeId, xpdrNetMaps, nodeUuidDsr,
269             nodeUuidOtsi);
270         mergeLinkinTopology(linkMap);
271
272         return nodeMap;
273     }
274
275     private OduSwitchingPools createSwitchPoolForXpdr(int xpdrType, List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
276                                                       Integer xpdrNb) {
277         // todo: are switching pool correct here??
278         switch (xpdrType) {
279             case 1:
280                 // Tpdr
281                 return createTpdrSwitchPool();
282             case 2:
283                 // Mux
284                 return createMuxSwitchPool(xpdrClMaps, xpdrNetMaps, xpdrNb);
285             case 3:
286                 // Switch
287                 return createSwtchSwitchPool(xpdrClMaps, xpdrNetMaps, xpdrNb);
288             default:
289                 LOG.warn("Xpdr type {} not supported", xpdrType);
290         }
291         return null;
292     }
293
294     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> transformSrgToOnep(String orNodeId,
295                                                                               Map<String, List<Mapping>> mapSrg) {
296         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
297         for (Map.Entry<String, List<Mapping>> entry : mapSrg.entrySet()) {
298             // For each srg node. Loop through the LCPs and create neps and sips for PP
299             for (Mapping m:entry.getValue()) {
300                 if (!m.getLogicalConnectionPoint().contains("PP")) {
301                     LOG.info("LCP {} is not an external TP of SRG node", m.getLogicalConnectionPoint());
302                     continue;
303                 }
304                 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> srgNeps =
305                     createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), true,
306                             transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()));
307                 onepMap.putAll(srgNeps);
308             }
309         }
310         return onepMap;
311     }
312
313     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> transformDegToOnep(String orNodeId,
314                                                                               Map<String, List<Mapping>> mapDeg) {
315         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
316         for (Map.Entry<String, List<Mapping>> entry : mapDeg.entrySet()) {
317             // For each degree node. Loop through the LCPs and create neps and sips for TTP
318             for (Mapping m:entry.getValue()) {
319                 if (!m.getLogicalConnectionPoint().contains("TTP")) {
320                     LOG.info("LCP {} is not an external TP of DEGREE node", m.getLogicalConnectionPoint());
321                     continue;
322                 }
323                 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> degNeps =
324                     createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), false,
325                             transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()));
326                 onepMap.putAll(degNeps);
327             }
328         }
329         return onepMap;
330     }
331
332     private List<String> getRoadmNodelist(List<Mapping> mappingList) {
333         List<String> nodeShardList = new ArrayList<>();
334         for (Mapping mapping : mappingList) {
335             // TODO -> maybe we need to check the id based on the version
336             String str = mapping.getLogicalConnectionPoint().split("-")[0];
337             LOG.info("LCP = {}", str);
338             if (!nodeShardList.contains(str)) {
339                 nodeShardList.add(str);
340             }
341         }
342         return nodeShardList;
343     }
344
345     @Override
346     public void deleteTapinode(String nodeId) {
347         // TODO: check for null objects
348         // Check if it is ROADM or XPDR --> create the uuids of the node and delete from topology the node.
349         // This will delete NEPs. Then check for links that have this node and delete them.
350         // Then check SIPs and delete them. Then services and connections with SIPs and put them to another state.
351         LOG.info("Deleting node {} from TAPI topology", nodeId);
352         InstanceIdentifier<Topology> topologyIID = InstanceIdentifier.builder(Context.class)
353                 .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
354                         new TopologyKey(tapiTopoUuid)).build();
355         Topology topology = null;
356         try {
357             Optional<Topology> optTopology =
358                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, topologyIID).get();
359             if (!optTopology.isPresent()) {
360                 LOG.error("No topology object present. Error deleting node {}", nodeId);
361                 return;
362             }
363             topology = optTopology.get();
364         } catch (InterruptedException | ExecutionException e) {
365             LOG.error("Couldnt read tapi topology from datastore", e);
366         }
367         if (topology == null) {
368             LOG.error("Topology is null, nothing to delete");
369             return;
370         }
371         if (topology.getNode() == null) {
372             LOG.error("No nodes in topology");
373             return;
374         }
375         if (nodeId.contains("ROADM")) {
376             // Node is in photonic media layer and UUID can be built from nodeId + PHTN_MEDIA
377             Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
378                 TapiStringConstants.PHTNC_MEDIA)).getBytes(Charset.forName("UTF-8"))).toString());
379             deleteNodeFromTopo(nodeUuid);
380         }
381         if (nodeId.contains("XPDR") || nodeId.contains("SPDR") || nodeId.contains("MXPDR")) {
382             // Node is either XPDR, MXPDR or SPDR. Retrieve nodes from topology and check names
383             for (Node tapiNode:topology.getNode().values()) {
384                 if (tapiNode.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
385                     // Found node we need to delete
386                     deleteNodeFromTopo(tapiNode.getUuid());
387                 }
388             }
389         }
390         // Delete links of topology
391         Map<LinkKey, Link> linkMap = topology.getLink();
392         if (linkMap != null) {
393             for (Link link:linkMap.values()) {
394                 if (link.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
395                     deleteLinkFromTopo(link.getUuid());
396                 }
397             }
398         }
399         // Delete sips of sip map
400         InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
401         Context context = null;
402         try {
403             Optional<Context> optContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
404                     contextIID).get();
405             if (!optContext.isPresent()) {
406                 LOG.error("No context object present in datastore.");
407                 return;
408             }
409             context = optContext.get();
410         } catch (InterruptedException | ExecutionException e) {
411             LOG.error("Couldnt read tapi context from datastore", e);
412         }
413         if (context == null) {
414             LOG.error("Context is null, nothing to delete");
415             return;
416         }
417         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips = context.getServiceInterfacePoint();
418         if (sips != null) {
419             for (ServiceInterfacePoint sip:sips.values()) {
420                 if (sip.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
421                     // Update state of services that have this sip as an endpoint and also connections
422                     updateConnectivityServicesState(sip.getUuid(), nodeId);
423                     deleteSipFromTopo(sip.getUuid());
424                 }
425             }
426         }
427     }
428
429     private Node createTapiXpdrNode(Map<NameKey, Name> nameMap, List<LayerProtocolName> layerProtocols,
430                                     String nodeId, Uuid nodeUuid, List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
431                                     XpdrNodeTypes xponderType, OduSwitchingPools oorOduSwitchingPool) {
432         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
433         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList = new HashMap<>();
434         Map<RuleKey, Rule> ruleList = new HashMap<>();
435         Rule rule = new RuleBuilder()
436                 .setLocalId("forward")
437                 .setForwardingRule(ForwardingRule.MAYFORWARDACROSSGROUP)
438                 .setRuleType(RuleType.FORWARDING)
439                 .build();
440         ruleList.put(rule.key(), rule);
441         if (layerProtocols.contains(LayerProtocolName.DSR)) {
442             // neps for dsr/odu layer
443             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> dsroduNeps =
444                     createXpdrDsrOduNeps(nodeId, xpdrClMaps, xpdrNetMaps, xponderType);
445             onepl.putAll(dsroduNeps);
446             nodeRuleGroupList = createNodeRuleGroupForDsrNode(nodeId, oorOduSwitchingPool, ruleList, onepl);
447         } else if (layerProtocols.contains(LayerProtocolName.PHOTONICMEDIA)) {
448             // neps for photonic layer
449             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> phtmdNeps =
450                     createXpdrPhtnMdNeps(nodeId, xpdrNetMaps);
451             onepl.putAll(phtmdNeps);
452             nodeRuleGroupList = createNodeRuleGroupForOtsiNode(nodeId, xpdrNetMaps, ruleList);
453         } else {
454             LOG.error("Undefined LayerProtocolName for {} node {}", nameMap.get(nameMap.keySet().iterator().next())
455                     .getValueName(), nameMap.get(nameMap.keySet().iterator().next()).getValue());
456         }
457         // Empty random creation of mandatory fields for avoiding errors....
458         CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
459             .setCostAlgorithm("Restricted Shortest Path - RSP")
460             .setCostName("HOP_COUNT")
461             .setCostValue("12345678")
462             .build();
463         LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
464             .setFixedLatencyCharacteristic("12345678")
465             .setQueingLatencyCharacteristic("12345678")
466             .setJitterCharacteristic("12345678")
467             .setWanderCharacteristic("12345678")
468             .setTrafficPropertyName("FIXED_LATENCY")
469             .build();
470         return new NodeBuilder()
471             .setUuid(nodeUuid)
472             .setName(nameMap)
473             .setLayerProtocolName(layerProtocols)
474             .setAdministrativeState(AdministrativeState.UNLOCKED)
475             .setOperationalState(OperationalState.ENABLED)
476             .setLifecycleState(LifecycleState.INSTALLED)
477             .setOwnedNodeEdgePoint(onepl)
478             .setNodeRuleGroup(nodeRuleGroupList)
479             .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
480             .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
481             .setErrorCharacteristic("error")
482             .setLossCharacteristic("loss")
483             .setRepeatDeliveryCharacteristic("repeat delivery")
484             .setDeliveryOrderCharacteristic("delivery order")
485             .setUnavailableTimeCharacteristic("unavailable time")
486             .setServerIntegrityProcessCharacteristic("server integrity process")
487             .build();
488     }
489
490     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createXpdrPhtnMdNeps(String nodeId,
491                                                                                 List<Mapping> xpdrNetMaps) {
492         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
493
494         // iNep creation on otsi node
495         for (int i = 0; i < xpdrNetMaps.size(); i++) {
496             Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes(
497                 (String.join("+", nodeId, TapiStringConstants.I_OTSI,
498                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString());
499             Name onedName = new NameBuilder()
500                 .setValueName("iNodeEdgePoint")
501                 .setValue(String.join("+", nodeId, TapiStringConstants.I_OTSI,
502                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
503                 .build();
504
505             OwnedNodeEdgePoint onep = createNep(nepUuid1, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
506                 Map.of(onedName.key(), onedName), LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA,
507                 true, String.join("+", nodeId, TapiStringConstants.I_OTSI),
508                 xpdrNetMaps.get(i).getSupportedInterfaceCapability(),
509                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
510                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
511             onepl.put(onep.key(), onep);
512         }
513         // eNep creation on otsi node
514         for (int i = 0; i < xpdrNetMaps.size(); i++) {
515             Uuid nepUuid2 = new Uuid(UUID.nameUUIDFromBytes(
516                 (String.join("+", nodeId, TapiStringConstants.E_OTSI,
517                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString());
518             Name onedName = new NameBuilder()
519                 .setValueName("eNodeEdgePoint")
520                 .setValue(String.join("+", nodeId, TapiStringConstants.E_OTSI,
521                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
522                 .build();
523
524             OwnedNodeEdgePoint onep = createNep(nepUuid2, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
525                 Map.of(onedName.key(), onedName), LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA,
526                 false, String.join("+", nodeId, TapiStringConstants.E_OTSI),
527                 xpdrNetMaps.get(i).getSupportedInterfaceCapability(),
528                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
529                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
530             onepl.put(onep.key(), onep);
531         }
532         // Photonic Media Nep creation on otsi node
533         for (int i = 0; i < xpdrNetMaps.size(); i++) {
534             Uuid nepUuid3 = new Uuid(UUID.nameUUIDFromBytes(
535                 (String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA,
536                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString());
537             Name onedName = new NameBuilder()
538                 .setValueName("PhotMedNodeEdgePoint")
539                 .setValue(String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA,
540                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
541                 .build();
542
543             OwnedNodeEdgePoint onep = createNep(nepUuid3, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
544                 Map.of(onedName.key(), onedName), LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA,
545                 false, String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA),
546                 xpdrNetMaps.get(i).getSupportedInterfaceCapability(),
547                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
548                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
549             onepl.put(onep.key(), onep);
550         }
551         return onepl;
552     }
553
554     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createXpdrDsrOduNeps(String nodeId, List<Mapping> xpdrClMaps,
555                                                                                 List<Mapping> xpdrNetMaps,
556                                                                                 XpdrNodeTypes xponderType) {
557         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
558         // client nep creation on DSR node
559         for (int i = 0; i < xpdrClMaps.size(); i++) {
560             LOG.info("Client NEP = {}", String.join("+", nodeId, TapiStringConstants.DSR,
561                 xpdrClMaps.get(i).getLogicalConnectionPoint()));
562             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
563                 (String.join("+", nodeId, TapiStringConstants.DSR,
564                     xpdrClMaps.get(i).getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString());
565             NameBuilder nameBldr = new NameBuilder().setValue(String.join("+", nodeId,
566                 TapiStringConstants.DSR, xpdrClMaps.get(i).getLogicalConnectionPoint()));
567             Name name;
568             if (OpenroadmNodeType.TPDR.getName().equalsIgnoreCase(xponderType.getName())) {
569                 name = nameBldr.setValueName("100G-tpdr").build();
570             } else {
571                 name = nameBldr.setValueName("NodeEdgePoint_C").build();
572             }
573
574             OwnedNodeEdgePoint onep = createNep(nepUuid, xpdrClMaps.get(i).getLogicalConnectionPoint(),
575                 Map.of(name.key(), name), LayerProtocolName.DSR, LayerProtocolName.DSR, true,
576                 String.join("+", nodeId, TapiStringConstants.DSR),
577                 xpdrClMaps.get(i).getSupportedInterfaceCapability(),
578                 transformOperState(xpdrClMaps.get(i).getPortOperState()),
579                 transformAdminState(xpdrClMaps.get(i).getPortAdminState()));
580             onepl.put(onep.key(), onep);
581         }
582         // network nep creation on I_ODU node
583         for (int i = 0; i < xpdrNetMaps.size(); i++) {
584             LOG.info("iODU NEP = {}", String.join("+", nodeId, TapiStringConstants.I_ODU,
585                 xpdrNetMaps.get(i).getLogicalConnectionPoint()));
586             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
587                 (String.join("+", nodeId, TapiStringConstants.I_ODU,
588                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString());
589             Name onedName = new NameBuilder()
590                 .setValueName("iNodeEdgePoint_N")
591                 .setValue(String.join("+", nodeId, TapiStringConstants.I_ODU,
592                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
593                 .build();
594
595             OwnedNodeEdgePoint onep = createNep(nepUuid, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
596                 Map.of(onedName.key(), onedName),
597                 LayerProtocolName.ODU, LayerProtocolName.DSR, true,
598                 String.join("+", nodeId, TapiStringConstants.I_ODU),
599                 xpdrNetMaps.get(i).getSupportedInterfaceCapability(),
600                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
601                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
602             onepl.put(onep.key(), onep);
603         }
604         // network nep creation on E_ODU node
605         for (int i = 0; i < xpdrClMaps.size(); i++) {
606             LOG.info("eODU NEP = {}", String.join("+", nodeId, TapiStringConstants.E_ODU,
607                 xpdrClMaps.get(i).getLogicalConnectionPoint()));
608             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
609                 (String.join("+", nodeId, TapiStringConstants.E_ODU,
610                     xpdrClMaps.get(i).getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString());
611             Name onedName = new NameBuilder()
612                 .setValueName("eNodeEdgePoint_N")
613                 .setValue(String.join("+", nodeId, TapiStringConstants.E_ODU,
614                     xpdrClMaps.get(i).getLogicalConnectionPoint()))
615                 .build();
616
617             OwnedNodeEdgePoint onep = createNep(nepUuid, xpdrClMaps.get(i).getLogicalConnectionPoint(),
618                 Map.of(onedName.key(), onedName),
619                 LayerProtocolName.ODU, LayerProtocolName.DSR, false,
620                 String.join("+", nodeId, TapiStringConstants.E_ODU),
621                 xpdrClMaps.get(i).getSupportedInterfaceCapability(),
622                 transformOperState(xpdrClMaps.get(i).getPortOperState()),
623                 transformAdminState(xpdrClMaps.get(i).getPortAdminState()));
624             onepl.put(onep.key(), onep);
625         }
626         return onepl;
627     }
628
629     private OperationalState transformOperState(String operString) {
630         State operState = org.opendaylight.transportpce.networkmodel.util.TopologyUtils.setNetworkOperState(operString);
631         return operState.equals(State.InService) ? OperationalState.ENABLED : OperationalState.DISABLED;
632     }
633
634     private AdministrativeState transformAdminState(String adminString) {
635         AdminStates adminState = org.opendaylight.transportpce.networkmodel.util.TopologyUtils
636             .setNetworkAdminState(adminString);
637         return adminState.equals(AdminStates.InService) ? AdministrativeState.UNLOCKED : AdministrativeState.LOCKED;
638     }
639
640     private OwnedNodeEdgePoint createNep(Uuid nepUuid, String tpid, Map<NameKey, Name> nepNames,
641                                          LayerProtocolName nepProtocol, LayerProtocolName nodeProtocol, boolean withSip,
642                                          String keyword,
643                                          List<Class<? extends SupportedIfCapability>> supportedInterfaceCapability,
644                                          OperationalState operState, AdministrativeState adminState) {
645         OwnedNodeEdgePointBuilder onepBldr = new OwnedNodeEdgePointBuilder()
646                 .setUuid(nepUuid)
647                 .setLayerProtocolName(nepProtocol)
648                 .setName(nepNames);
649         if (withSip) {
650             onepBldr.setMappedServiceInterfacePoint(createMSIP(1, nepProtocol, tpid, keyword,
651                     supportedInterfaceCapability, operState, adminState));
652         }
653         LOG.debug("Node layer {}", nodeProtocol.getName());
654         onepBldr.setSupportedCepLayerProtocolQualifier(createSupportedLayerProtocolQualifier(
655                 supportedInterfaceCapability, nepProtocol));
656         onepBldr.setLinkPortDirection(PortDirection.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
657                 .setAdministrativeState(adminState).setOperationalState(operState)
658                 .setLifecycleState(LifecycleState.INSTALLED).setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
659                 .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL);
660         return onepBldr.build();
661     }
662
663     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createRoadmNeps(String orNodeId, String tpId,
664                                                                            boolean withSip, OperationalState operState,
665                                                                            AdministrativeState adminState) {
666         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
667         // PHOTONIC MEDIA nep
668         Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId,
669                 TapiStringConstants.PHTNC_MEDIA, tpId)).getBytes(Charset.forName("UTF-8"))).toString());
670         Name nepName = new NameBuilder()
671                 .setValueName(TapiStringConstants.PHTNC_MEDIA + "NodeEdgePoint")
672                 .setValue(String.join("+", orNodeId, TapiStringConstants.PHTNC_MEDIA, tpId))
673                 .build();
674         OwnedNodeEdgePoint onep = new OwnedNodeEdgePointBuilder()
675             .setUuid(nepUuid)
676             .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA)
677             .setName(Map.of(nepName.key(), nepName))
678             .setSupportedCepLayerProtocolQualifier(List.of(PHOTONICLAYERQUALIFIEROMS.class))
679             .setLinkPortDirection(PortDirection.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
680             .setAdministrativeState(adminState).setOperationalState(operState)
681             .setLifecycleState(LifecycleState.INSTALLED).setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
682             .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL)
683             .build();
684         onepMap.put(onep.key(), onep);
685
686         // MC nep
687         Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId,
688                 TapiStringConstants.MC, tpId)).getBytes(Charset.forName("UTF-8"))).toString());
689         Name nepName1 = new NameBuilder()
690                 .setValueName(TapiStringConstants.MC + "NodeEdgePoint")
691                 .setValue(String.join("+", orNodeId, TapiStringConstants.MC, tpId))
692                 .build();
693         OwnedNodeEdgePointBuilder onepBldr1 = new OwnedNodeEdgePointBuilder()
694                 .setUuid(nepUuid1)
695                 .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA)
696                 .setName(Map.of(nepName1.key(), nepName1))
697                 .setSupportedCepLayerProtocolQualifier(List.of(PHOTONICLAYERQUALIFIEROMS.class))
698                 .setLinkPortDirection(PortDirection.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
699                 .setAdministrativeState(adminState).setOperationalState(operState)
700                 .setLifecycleState(LifecycleState.INSTALLED).setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
701                 .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL);
702         if (withSip) {
703             onepBldr1.setMappedServiceInterfacePoint(createMSIP(1, LayerProtocolName.PHOTONICMEDIA,
704                 tpId, String.join("+", orNodeId, TapiStringConstants.MC), null,
705                 operState, adminState));
706         }
707         OwnedNodeEdgePoint onep1 = onepBldr1.build();
708         onepMap.put(onep1.key(), onep1);
709
710         // OTSiMC nep
711         Uuid nepUuid2 = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId, TapiStringConstants.OTSI_MC,
712                 tpId)).getBytes(Charset.forName("UTF-8"))).toString());
713         Name nepName2 = new NameBuilder()
714                 .setValueName(TapiStringConstants.OTSI_MC + "NodeEdgePoint")
715                 .setValue(String.join("+", orNodeId, TapiStringConstants.OTSI_MC, tpId))
716                 .build();
717
718         OwnedNodeEdgePoint onep2 = new OwnedNodeEdgePointBuilder()
719             .setUuid(nepUuid2)
720             .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA)
721             .setName(Map.of(nepName2.key(), nepName2))
722             .setSupportedCepLayerProtocolQualifier(List.of(PHOTONICLAYERQUALIFIEROMS.class))
723             .setLinkPortDirection(PortDirection.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
724             .setAdministrativeState(adminState).setOperationalState(operState)
725             .setLifecycleState(LifecycleState.INSTALLED).setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
726             .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL)
727             .build();
728         onepMap.put(onep2.key(), onep2);
729         return onepMap;
730     }
731
732     private Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint>
733             createMSIP(int nb, LayerProtocolName layerProtocol, String tpid, String nodeid,
734                    List<Class<? extends SupportedIfCapability>> supportedInterfaceCapability,
735                    OperationalState operState, AdministrativeState adminState) {
736         Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> msipl = new HashMap<>();
737         for (int i = 0; i < nb; i++) {
738             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP", nodeid,
739                     tpid)).getBytes(Charset.forName("UTF-8"))).toString());
740             MappedServiceInterfacePoint msip = new MappedServiceInterfacePointBuilder()
741                     .setServiceInterfacePointUuid(sipUuid).build();
742             ServiceInterfacePoint sip = createSIP(sipUuid, layerProtocol, tpid, nodeid, supportedInterfaceCapability,
743                 operState, adminState);
744             this.sipMap.put(sip.key(), sip);
745             LOG.info("SIP created {}", sip.getUuid());
746             // this.tapiSips.put(sip.key(), sip);
747             msipl.put(msip.key(), msip);
748         }
749         return msipl;
750     }
751
752     private ServiceInterfacePoint createSIP(Uuid sipUuid, LayerProtocolName layerProtocol, String tpid, String nodeid,
753                                             List<Class<? extends SupportedIfCapability>> supportedInterfaceCapability,
754                                             OperationalState operState, AdministrativeState adminState) {
755         // TODO: what value should be set in total capacity and available capacity
756         LOG.info("SIP name = {}", String.join("+", nodeid, tpid));
757         Name sipName = new NameBuilder()
758                 .setValueName("SIP name")
759                 .setValue(String.join("+", nodeid, tpid))
760                 .build();
761         return new ServiceInterfacePointBuilder()
762                 .setUuid(sipUuid)
763                 .setName(Map.of(sipName.key(), sipName))
764                 .setLayerProtocolName(layerProtocol)
765                 .setAdministrativeState(adminState)
766                 .setOperationalState(operState)
767                 .setLifecycleState(LifecycleState.INSTALLED)
768                 .setAvailableCapacity(new AvailableCapacityBuilder().build())
769                 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().build())
770                 .setSupportedLayerProtocolQualifier(createSupportedLayerProtocolQualifier(supportedInterfaceCapability,
771                         layerProtocol))
772                 .build();
773     }
774
775     private Node createRoadmTapiNode(String orNodeId, Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> oneplist) {
776         // UUID
777         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId,
778             TapiStringConstants.PHTNC_MEDIA)).getBytes(Charset.forName("UTF-8"))).toString());
779         // Names
780         Name nodeNames =  new NameBuilder().setValueName("roadm node name")
781             .setValue(String.join("+", orNodeId, TapiStringConstants.PHTNC_MEDIA)).build();
782         // Protocol Layer
783         List<LayerProtocolName> layerProtocols = Arrays.asList(LayerProtocolName.PHOTONICMEDIA);
784         // Empty random creation of mandatory fields for avoiding errors....
785         CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
786             .setCostAlgorithm("Restricted Shortest Path - RSP")
787             .setCostName("HOP_COUNT")
788             .setCostValue("12345678")
789             .build();
790         LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
791             .setFixedLatencyCharacteristic("12345678")
792             .setQueingLatencyCharacteristic("12345678")
793             .setJitterCharacteristic("12345678")
794             .setWanderCharacteristic("12345678")
795             .setTrafficPropertyName("FIXED_LATENCY")
796             .build();
797         return new NodeBuilder()
798             .setUuid(nodeUuid)
799             .setName(Map.of(nodeNames.key(), nodeNames))
800             .setLayerProtocolName(layerProtocols)
801             .setAdministrativeState(AdministrativeState.UNLOCKED)
802             .setOperationalState(OperationalState.ENABLED)
803             .setLifecycleState(LifecycleState.INSTALLED)
804             .setOwnedNodeEdgePoint(oneplist)
805             .setNodeRuleGroup(createNodeRuleGroupForRdmNode(orNodeId, nodeUuid, oneplist.values()))
806             .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
807             .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
808             .setErrorCharacteristic("error")
809             .setLossCharacteristic("loss")
810             .setRepeatDeliveryCharacteristic("repeat delivery")
811             .setDeliveryOrderCharacteristic("delivery order")
812             .setUnavailableTimeCharacteristic("unavailable time")
813             .setServerIntegrityProcessCharacteristic("server integrity process")
814             .build();
815     }
816
817     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForRdmNode(String orNodeId, Uuid nodeUuid,
818                                                                                Collection<OwnedNodeEdgePoint> onepl) {
819         Map<NodeEdgePointKey, NodeEdgePoint>
820                 nepMap = new HashMap<>();
821         for (OwnedNodeEdgePoint onep : onepl) {
822             NodeEdgePoint nep = new NodeEdgePointBuilder()
823                 .setTopologyUuid(this.tapiTopoUuid)
824                 .setNodeUuid(nodeUuid)
825                 .setNodeEdgePointUuid(onep.key().getUuid())
826                 .build();
827             nepMap.put(nep.key(), nep);
828         }
829         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
830         Map<RuleKey, Rule> ruleList = new HashMap<>();
831         Rule rule = new RuleBuilder()
832                 .setLocalId("forward")
833                 .setForwardingRule(ForwardingRule.MAYFORWARDACROSSGROUP)
834                 .setRuleType(RuleType.FORWARDING)
835                 .build();
836         ruleList.put(rule.key(), rule);
837         NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
838                 .setUuid(new Uuid(UUID.nameUUIDFromBytes((orNodeId + " node rule group")
839                         .getBytes(Charset.forName("UTF-8"))).toString()))
840                 .setRule(ruleList)
841                 .setNodeEdgePoint(nepMap)
842                 .build();
843         nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
844         return nodeRuleGroupMap;
845     }
846
847     private Map<LinkKey, Link> createTapiTransitionalLinks(String nodeId, List<Mapping> xpdrNetMaps, Uuid nodeUuidDsr,
848                                                            Uuid nodeUuidOtsi) {
849         Map<LinkKey, Link> linkMap = new HashMap<>();
850         for (Mapping mapping : xpdrNetMaps) {
851             Link transiLink = tapiLink.createTapiLink(nodeId, mapping.getLogicalConnectionPoint(), nodeId,
852                 mapping.getLogicalConnectionPoint(), TapiStringConstants.TRANSITIONAL_LINK, TapiStringConstants.DSR,
853                 TapiStringConstants.OTSI, TapiStringConstants.I_ODU, TapiStringConstants.I_OTSI,
854                 "inService", "inService", Arrays.asList(LayerProtocolName.ODU,
855                     LayerProtocolName.PHOTONICMEDIA),
856                 Arrays.asList(LayerProtocolName.ODU.getName(), LayerProtocolName.PHOTONICMEDIA.getName()),
857                 this.tapiTopoUuid);
858             linkMap.put(transiLink.key(), transiLink);
859         }
860         // return a map of links and then we can do merge the corresponding link map into the topology context
861         return linkMap;
862     }
863
864     private OduSwitchingPools createTpdrSwitchPool() {
865         return new OduSwitchingPoolsBuilder().build();
866     }
867
868     private OduSwitchingPools createSwtchSwitchPool(List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
869                                                     Integer xpdrNb) {
870         List<TpId> tpl = new ArrayList<>();
871         TpId tpId = null;
872         for (int i = 1; i <= xpdrClMaps.size(); i++) {
873             tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.CLIENT + i);
874             tpl.add(tpId);
875         }
876         for (int i = 1; i <= xpdrNetMaps.size(); i++) {
877             tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.NETWORK + i);
878             tpl.add(tpId);
879         }
880         Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
881         NonBlockingList nbl = new NonBlockingListBuilder()
882             .setNblNumber(Uint16.valueOf(1))
883             .setTpList(tpl)
884             .build();
885         nbMap.put(nbl.key(),nbl);
886
887         return new OduSwitchingPoolsBuilder()
888             .setSwitchingPoolNumber(Uint16.valueOf(1))
889             .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
890             .setNonBlockingList(nbMap)
891             .build();
892     }
893
894     private OduSwitchingPools createMuxSwitchPool(List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps, Integer xpdrNb) {
895         Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
896         for (int i = 1; i <= xpdrClMaps.size(); i++) {
897             List<TpId> tpList = new ArrayList<>();
898             TpId tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.CLIENT + i);
899             tpList.add(tpId);
900             tpId = new TpId("XPDR" + xpdrNb + "-NETWORK1");
901             tpList.add(tpId);
902             NonBlockingList nbl = new NonBlockingListBuilder()
903                 .setNblNumber(Uint16.valueOf(i))
904                 .setTpList(tpList)
905                 .setAvailableInterconnectBandwidth(Uint32.valueOf(xpdrNetMaps.size() * 10L))
906                 .setInterconnectBandwidthUnit(Uint32.valueOf(1000000000))
907                 .build();
908             nbMap.put(nbl.key(),nbl);
909         }
910         return new OduSwitchingPoolsBuilder()
911                 .setSwitchingPoolNumber(Uint16.valueOf(1))
912                 .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
913                 .setNonBlockingList(nbMap)
914                 .build();
915     }
916
917     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForOtsiNode(String nodeId,
918                                                                                 List<Mapping> xpdrNetMaps,
919                                                                                 Map<RuleKey, Rule> ruleList) {
920         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
921         // create NodeRuleGroup
922         int count = 1;
923         for (Mapping tpMapping : xpdrNetMaps) {
924             Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
925             NodeEdgePoint inep = new NodeEdgePointBuilder()
926                 .setTopologyUuid(this.tapiTopoUuid)
927                 .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
928                         TapiStringConstants.OTSI)).getBytes(Charset.forName("UTF-8"))).toString()))
929                 .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
930                     TapiStringConstants.I_OTSI, tpMapping.getLogicalConnectionPoint()))
931                     .getBytes(Charset.forName("UTF-8"))).toString()))
932                 .build();
933             NodeEdgePoint enep = new NodeEdgePointBuilder()
934                 .setTopologyUuid(this.tapiTopoUuid)
935                 .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
936                     TapiStringConstants.OTSI)).getBytes(Charset.forName("UTF-8"))).toString()))
937                 .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes(
938                     (String.join("+", nodeId, TapiStringConstants.E_OTSI,
939                         tpMapping.getLogicalConnectionPoint())).getBytes(Charset.forName("UTF-8"))).toString()))
940                 .build();
941             nepList.put(inep.key(), inep);
942             nepList.put(enep.key(), enep);
943             // Empty random creation of mandatory fields for avoiding errors....
944             CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
945                 .setCostAlgorithm("Restricted Shortest Path - RSP")
946                 .setCostName("HOP_COUNT")
947                 .setCostValue("12345678")
948                 .build();
949             LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
950                 .setFixedLatencyCharacteristic("12345678")
951                 .setQueingLatencyCharacteristic("12345678")
952                 .setJitterCharacteristic("12345678")
953                 .setWanderCharacteristic("12345678")
954                 .setTrafficPropertyName("FIXED_LATENCY")
955                 .build();
956             RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
957                 .setRiskCharacteristicName("risk characteristic")
958                 .setRiskIdentifierList(List.of("risk identifier1", "risk identifier2"))
959                 .build();
960             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
961                 .setUuid(new Uuid(
962                     UUID.nameUUIDFromBytes(("otsi node rule group " + count).getBytes(Charset.forName("UTF-8")))
963                         .toString()))
964                 .setRule(ruleList)
965                 .setNodeEdgePoint(nepList)
966                 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
967                 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
968                 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
969                 .build();
970             nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
971             count++;
972         }
973         return nodeRuleGroupMap;
974     }
975
976     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForDsrNode(String nodeId,
977                                                                                OduSwitchingPools oorOduSwitchingPool,
978                                                                                Map<RuleKey, Rule> ruleList,
979                                                                                Map<OwnedNodeEdgePointKey,
980                                                                                        OwnedNodeEdgePoint> onepl) {
981         // create NodeRuleGroup
982         if (oorOduSwitchingPool == null) {
983             LOG.info("TPDR node --> no switching pool");
984             return new HashMap<>();
985         }
986         LOG.info("ONEPL = {}", onepl.values());
987         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
988         int count = 1;
989         for (NonBlockingList nbl : oorOduSwitchingPool.nonnullNonBlockingList().values()) {
990             LOG.info("Non blocking list = {}", nbl);
991             Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
992             for (TpId tp : nbl.getTpList()) {
993                 LOG.info("EDOU TP = {}", String.join("+", nodeId, TapiStringConstants.E_ODU, tp.getValue()));
994                 LOG.info("DSR TP = {}", String.join("+", nodeId, TapiStringConstants.DSR, tp.getValue()));
995                 Uuid tpUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
996                     TapiStringConstants.E_ODU, tp.getValue())).getBytes(Charset.forName("UTF-8"))).toString());
997                 Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
998                     TapiStringConstants.DSR, tp.getValue())).getBytes(Charset.forName("UTF-8"))).toString());
999                 if (onepl.containsKey(new OwnedNodeEdgePointKey(tpUuid))
1000                         && onepl.containsKey(new OwnedNodeEdgePointKey(tp1Uuid))) {
1001                     NodeEdgePoint nep1 = new NodeEdgePointBuilder()
1002                         .setTopologyUuid(this.tapiTopoUuid)
1003                         .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1004                             (String.join("+", nodeId,TapiStringConstants. DSR))
1005                                 .getBytes(Charset.forName("UTF-8"))).toString()))
1006                         .setNodeEdgePointUuid(tp1Uuid)
1007                         .build();
1008                     NodeEdgePoint nep2 = new NodeEdgePointBuilder()
1009                         .setTopologyUuid(this.tapiTopoUuid)
1010                         .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1011                             (String.join("+", nodeId,TapiStringConstants. DSR))
1012                                 .getBytes(Charset.forName("UTF-8"))).toString()))
1013                         .setNodeEdgePointUuid(tpUuid)
1014                         .build();
1015                     nepList.put(nep1.key(), nep1);
1016                     nepList.put(nep2.key(), nep2);
1017                 }
1018             }
1019             // Empty random creation of mandatory fields for avoiding errors....
1020             CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
1021                 .setCostAlgorithm("Restricted Shortest Path - RSP")
1022                 .setCostName("HOP_COUNT")
1023                 .setCostValue("12345678")
1024                 .build();
1025             LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
1026                 .setFixedLatencyCharacteristic("12345678")
1027                 .setQueingLatencyCharacteristic("12345678")
1028                 .setJitterCharacteristic("12345678")
1029                 .setWanderCharacteristic("12345678")
1030                 .setTrafficPropertyName("FIXED_LATENCY")
1031                 .build();
1032             RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
1033                 .setRiskCharacteristicName("risk characteristic")
1034                 .setRiskIdentifierList(List.of("risk identifier1", "risk identifier2"))
1035                 .build();
1036             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
1037                 .setUuid(new Uuid(
1038                     UUID.nameUUIDFromBytes(("dsr node rule group " + count).getBytes(Charset.forName("UTF-8")))
1039                         .toString()))
1040                 .setRule(ruleList)
1041                 .setNodeEdgePoint(nepList)
1042                 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1043                 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1044                 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1045                 .build();
1046             nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1047             count++;
1048         }
1049         return nodeRuleGroupMap;
1050     }
1051
1052     private List<Class<? extends LAYERPROTOCOLQUALIFIER>> createSupportedLayerProtocolQualifier(
1053             List<Class<? extends SupportedIfCapability>> sicList, LayerProtocolName lpn) {
1054         if (sicList == null) {
1055             return List.of(PHOTONICLAYERQUALIFIEROMS.class);
1056         }
1057         Map<SupportedInterfaceCapabilityKey, SupportedInterfaceCapability> supIfMap = new HashMap<>();
1058         LOG.info("SIC list = {}", sicList);
1059         for (Class<? extends SupportedIfCapability> supInterCapa : sicList) {
1060             SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
1061                     .withKey(new SupportedInterfaceCapabilityKey(convertSupIfCapa(supInterCapa)))
1062                     .setIfCapType(convertSupIfCapa(supInterCapa))
1063                     .build();
1064             supIfMap.put(supIfCapa.key(), supIfCapa);
1065         }
1066         List<Class<? extends LAYERPROTOCOLQUALIFIER>> sclpqList = new ArrayList<>();
1067         for (SupportedInterfaceCapability sic : supIfMap.values()) {
1068             switch (lpn.getName()) {
1069                 case "DSR":
1070                     switch (sic.getIfCapType().getSimpleName()) {
1071                         // TODO: it may be needed to add more cases clauses if the interface capabilities of a
1072                         //  port are extended in the config file
1073                         case "If1GEODU0":
1074                             sclpqList.add(ODUTYPEODU0.class);
1075                             sclpqList.add(DIGITALSIGNALTYPEGigE.class);
1076                             break;
1077                         case "If10GEODU2e":
1078                             sclpqList.add(ODUTYPEODU2E.class);
1079                             sclpqList.add(DIGITALSIGNALTYPE10GigELAN.class);
1080                             break;
1081                         case "If10GEODU2":
1082                             sclpqList.add(ODUTYPEODU2.class);
1083                             sclpqList.add(DIGITALSIGNALTYPE10GigELAN.class);
1084                             break;
1085                         case "If10GE":
1086                             sclpqList.add(DIGITALSIGNALTYPE10GigELAN.class);
1087                             break;
1088                         case "If100GEODU4":
1089                             sclpqList.add(DIGITALSIGNALTYPE100GigE.class);
1090                             sclpqList.add(ODUTYPEODU4.class);
1091                             break;
1092                         case "If100GE":
1093                             sclpqList.add(DIGITALSIGNALTYPE100GigE.class);
1094                             break;
1095                         case "IfOCHOTU4ODU4":
1096                         case "IfOCH":
1097                             sclpqList.add(ODUTYPEODU4.class);
1098                             break;
1099                         default:
1100                             LOG.error("IfCapability type not managed");
1101                             break;
1102                     }
1103                     break;
1104                 case "ODU":
1105                     switch (sic.getIfCapType().getSimpleName()) {
1106                         // TODO: it may be needed to add more cases clauses if the interface capabilities of a
1107                         //  port are extended in the config file
1108                         case "If1GEODU0":
1109                             sclpqList.add(ODUTYPEODU0.class);
1110                             break;
1111                         case "If10GEODU2e":
1112                             sclpqList.add(ODUTYPEODU2E.class);
1113                             break;
1114                         case "If10GEODU2":
1115                         case "If10GE":
1116                             sclpqList.add(ODUTYPEODU2.class);
1117                             break;
1118                         case "If100GEODU4":
1119                         case "If100GE":
1120                         case "IfOCHOTU4ODU4":
1121                         case "IfOCH":
1122                             sclpqList.add(ODUTYPEODU4.class);
1123                             break;
1124                         default:
1125                             LOG.error("IfCapability type not managed");
1126                             break;
1127                     }
1128                     break;
1129                 case "PHOTONIC_MEDIA":
1130                     if (sic.getIfCapType().getSimpleName().equals("IfOCHOTU4ODU4")
1131                             || sic.getIfCapType().getSimpleName().equals("IfOCH")) {
1132                         sclpqList.add(PHOTONICLAYERQUALIFIEROTSi.class);
1133                         sclpqList.add(PHOTONICLAYERQUALIFIEROMS.class);
1134                     }
1135                     break;
1136                 default:
1137                     LOG.error("Layer Protocol Name is unknown {}", lpn.getName());
1138                     break;
1139             }
1140         }
1141         return sclpqList;
1142     }
1143
1144     private static Class<? extends SupportedIfCapability> convertSupIfCapa(Class<? extends
1145             SupportedIfCapability> ifCapType) {
1146         LOG.info("Interface Capability type = {}", ifCapType.getSimpleName());
1147         switch (ifCapType.getSimpleName()) {
1148             case "If100GEODU4":
1149                 return If100GEODU4.class;
1150             case "IfOCHOTU4ODU4":
1151                 return IfOCHOTU4ODU4.class;
1152             case "If1GEODU0":
1153                 return If1GEODU0.class;
1154             case "If10GEODU2e":
1155                 return If10GEODU2e.class;
1156             case "If10GEODU2":
1157                 return If10GEODU2.class;
1158             case "If100GE":
1159                 return If100GE.class;
1160             case "If10GE":
1161                 return If10GE.class;
1162             case "If1GE":
1163                 return If1GE.class;
1164             case "IfOCH":
1165                 return IfOCH.class;
1166             default:
1167                 return null;
1168         }
1169     }
1170
1171     private void mergeNodeinTopology(Map<NodeKey, Node> nodeMap) {
1172         // TODO is this merge correct? Should we just merge topology by changing the nodes map??
1173         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
1174         LOG.info("Creating tapi node in TAPI topology context");
1175         InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
1176             .augmentation(Context1.class).child(TopologyContext.class)
1177             .child(Topology.class, new TopologyKey(this.tapiTopoUuid))
1178             .build();
1179
1180         Topology topology = new TopologyBuilder().setUuid(this.tapiTopoUuid).setNode(nodeMap).build();
1181
1182         // merge in datastore
1183         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topoIID,
1184                 topology);
1185         try {
1186             this.networkTransactionService.commit().get();
1187         } catch (InterruptedException | ExecutionException e) {
1188             LOG.error("Error populating TAPI topology: ", e);
1189         }
1190         LOG.info("Node added succesfully.");
1191     }
1192
1193     private void mergeLinkinTopology(Map<LinkKey, Link> linkMap) {
1194         // TODO is this merge correct? Should we just merge topology by changing the nodes map??
1195         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
1196         LOG.info("Creating tapi node in TAPI topology context");
1197         InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
1198             .augmentation(Context1.class).child(TopologyContext.class)
1199             .child(Topology.class, new TopologyKey(this.tapiTopoUuid))
1200             .build();
1201
1202         Topology topology = new TopologyBuilder().setUuid(this.tapiTopoUuid).setLink(linkMap).build();
1203
1204         // merge in datastore
1205         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topoIID,
1206                 topology);
1207         try {
1208             this.networkTransactionService.commit().get();
1209         } catch (InterruptedException | ExecutionException e) {
1210             LOG.error("Error populating TAPI topology: ", e);
1211         }
1212         LOG.info("Roadm Link added succesfully.");
1213     }
1214
1215     private void mergeSipsinContext(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips) {
1216         // TODO is this merge correct? Should we just merge topology by changing the nodes map??
1217         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
1218         try {
1219             ContextBuilder contextBuilder = new ContextBuilder();
1220             contextBuilder.setServiceInterfacePoint(sips);
1221             InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
1222             // merge in datastore
1223             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, contextIID,
1224                     contextBuilder.build());
1225             this.networkTransactionService.commit().get();
1226             LOG.info("TAPI SIPs merged successfully.");
1227         } catch (InterruptedException | ExecutionException e) {
1228             LOG.error("Failed to merge TAPI Sips", e);
1229         }
1230     }
1231
1232     private void deleteLinkFromTopo(Uuid linkUuid) {
1233         // TODO: check if this IID is correct
1234         try {
1235             InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
1236                 .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
1237                     new TopologyKey(this.tapiTopoUuid)).child(Link.class, new LinkKey(linkUuid)).build();
1238             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, linkIID);
1239             this.networkTransactionService.commit().get();
1240             LOG.info("TAPI link deleted successfully.");
1241         } catch (InterruptedException | ExecutionException e) {
1242             LOG.error("Failed to delete TAPI link", e);
1243         }
1244     }
1245
1246     private void deleteNodeFromTopo(Uuid nodeUuid) {
1247         // TODO: check if this IID is correct
1248         try {
1249             InstanceIdentifier<Node> nodeIDD = InstanceIdentifier.builder(Context.class)
1250                 .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
1251                     new TopologyKey(this.tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid)).build();
1252             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, nodeIDD);
1253             this.networkTransactionService.commit().get();
1254             LOG.info("TAPI Node deleted successfully.");
1255         } catch (InterruptedException | ExecutionException e) {
1256             LOG.error("Failed to delete TAPI Node", e);
1257         }
1258     }
1259
1260     private void deleteSipFromTopo(Uuid sipUuid) {
1261         // TODO: check if this IID is correct
1262         try {
1263             InstanceIdentifier<ServiceInterfacePoint> sipIID = InstanceIdentifier.builder(Context.class)
1264                     .child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(sipUuid)).build();
1265             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, sipIID);
1266             this.networkTransactionService.commit().get();
1267             LOG.info("TAPI SIP deleted successfully.");
1268         } catch (InterruptedException | ExecutionException e) {
1269             LOG.error("Failed to delete TAPI SIP", e);
1270         }
1271     }
1272
1273     private void updateConnectivityServicesState(Uuid sipUuid, String nodeId) {
1274         // TODO: check if this IID is correct
1275         InstanceIdentifier<ConnectivityContext> connectivitycontextIID = InstanceIdentifier.builder(Context.class)
1276             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1.class)
1277             .child(ConnectivityContext.class)
1278             .build();
1279         ConnectivityContext connContext = null;
1280         try {
1281             Optional<ConnectivityContext> optConnContext =
1282                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivitycontextIID)
1283                             .get();
1284             if (!optConnContext.isPresent()) {
1285                 LOG.error("Couldnt retrieve connectivity context from datastore");
1286                 return;
1287             }
1288             connContext = optConnContext.get();
1289         } catch (InterruptedException | ExecutionException e) {
1290             LOG.error("Couldnt read connectivity context from datastore", e);
1291         }
1292         if (connContext == null) {
1293             LOG.error("Connectivity context is empty");
1294             return;
1295         }
1296         // Loop through services, check if the endpoint uuid is equal to the sip.
1297         // If so update state.
1298         Map<ConnectivityServiceKey, ConnectivityService> connServMap = connContext.getConnectivityService();
1299         Map<ConnectionKey, Connection> connMap = connContext.getConnection();
1300         if (connServMap != null) {
1301             for (ConnectivityService service:connServMap.values()) {
1302                 Map<EndPointKey, EndPoint> serviceEndPoints = service.getEndPoint();
1303                 if (serviceEndPoints.values().stream().anyMatch(endPoint -> endPoint.getServiceInterfacePoint()
1304                     .getServiceInterfacePointUuid().equals(sipUuid))) {
1305                     LOG.info("Service using SIP of node {} identified. Update state of service", nodeId);
1306                     ConnectivityService updService = new ConnectivityServiceBuilder(service)
1307                         .setAdministrativeState(AdministrativeState.LOCKED)
1308                         .setOperationalState(OperationalState.DISABLED)
1309                         .setLifecycleState(LifecycleState.PENDINGREMOVAL)
1310                         .build();
1311                     updateConnectivityService(updService);
1312                 }
1313             }
1314         }
1315         // Update state of connections
1316         if (connMap != null) {
1317             for (Connection connection:connMap.values()) {
1318                 if (connection.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
1319                     Connection updConn = new ConnectionBuilder(connection)
1320                         .setLifecycleState(LifecycleState.PENDINGREMOVAL)
1321                         .setOperationalState(OperationalState.DISABLED)
1322                         .build();
1323                     updateConnection(updConn);
1324                 }
1325             }
1326         }
1327     }
1328
1329     private void updateConnection(Connection updConn) {
1330         // TODO: check if this IID is correct
1331         InstanceIdentifier<Connection> connectionIID = InstanceIdentifier.builder(Context.class)
1332                 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1.class)
1333                 .child(ConnectivityContext.class).child(Connection.class,
1334                         new ConnectionKey(updConn.getUuid())).build();
1335         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectionIID, updConn);
1336         try {
1337             this.networkTransactionService.commit().get();
1338         } catch (InterruptedException | ExecutionException e) {
1339             LOG.error("Error committing into datastore", e);
1340         }
1341     }
1342
1343     private void updateConnectivityService(ConnectivityService updService) {
1344         // TODO: check if this IID is correct
1345         InstanceIdentifier<ConnectivityService> connectivityserviceIID = InstanceIdentifier.builder(Context.class)
1346                 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.Context1.class)
1347                 .child(ConnectivityContext.class).child(ConnectivityService.class,
1348                         new ConnectivityServiceKey(updService.getUuid())).build();
1349         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectivityserviceIID, updService);
1350         try {
1351             this.networkTransactionService.commit().get();
1352         } catch (InterruptedException | ExecutionException e) {
1353             LOG.error("Error committing into datastore", e);
1354         }
1355     }
1356
1357 }