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