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