d3827534b23ca205a7e1a4b60536cd335e4e27a2
[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.StandardCharsets;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.Comparator;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Objects;
20 import java.util.Optional;
21 import java.util.Set;
22 import java.util.UUID;
23 import java.util.concurrent.ExecutionException;
24 import java.util.stream.Collectors;
25 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
28 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
29 import org.opendaylight.transportpce.tapi.R2RTapiLinkDiscovery;
30 import org.opendaylight.transportpce.tapi.TapiStringConstants;
31 import org.opendaylight.transportpce.tapi.utils.TapiLink;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.NodeTypes;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.OduSwitchingPools;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.OduSwitchingPoolsBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListKey;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.SupportedIfCapability;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.switching.pool.types.rev191129.SwitchingPoolTypes;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.AdministrativeState;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.ContextBuilder;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Direction;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LifecycleState;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OBJECTTYPETAPICONTEXT;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OperationalState;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.PortRole;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.capacity.pac.AvailableCapacityBuilder;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.capacity.pac.TotalPotentialCapacityBuilder;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameKey;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointBuilder;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.OwnedNodeEdgePoint1;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.OwnedNodeEdgePoint1Builder;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.cep.list.ConnectionEndPoint;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.cep.list.ConnectionEndPointBuilder;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.cep.list.ConnectionEndPointKey;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.Connection;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectionBuilder;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectionKey;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityService;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityServiceBuilder;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityServiceKey;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPoint;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPointKey;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.context.ConnectivityContext;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.context.topology.context.topology.node.owned.node.edge.point.CepList;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.context.topology.context.topology.node.owned.node.edge.point.CepListBuilder;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU0;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU2;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU2E;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU4;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPE100GigE;
90 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPE10GigELAN;
91 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPEGigE;
92 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.NOTIFICATIONTYPEATTRIBUTEVALUECHANGE;
93 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.NotificationBuilder;
94 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.ChangedAttributes;
95 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.ChangedAttributesBuilder;
96 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.ChangedAttributesKey;
97 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROMS;
98 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTS;
99 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTSiMC;
100 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1;
101 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.FORWARDINGRULEMAYFORWARDACROSSGROUP;
102 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.NodeEdgePointRef;
103 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.RuleType;
104 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.context.TopologyContext;
105 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroup;
106 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupBuilder;
107 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupKey;
108 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
109 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointBuilder;
110 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointKey;
111 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePoint;
112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePointBuilder;
113 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePointKey;
114 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedCepLayerProtocolQualifierInstances;
115 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedCepLayerProtocolQualifierInstancesBuilder;
116 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint;
117 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePointBuilder;
118 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePointKey;
119 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.Rule;
120 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.RuleBuilder;
121 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.RuleKey;
122 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.risk.parameter.pac.RiskCharacteristic;
123 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.risk.parameter.pac.RiskCharacteristicBuilder;
124 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link;
125 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.LinkBuilder;
126 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.LinkKey;
127 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node;
128 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeBuilder;
129 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey;
130 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology;
131 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyBuilder;
132 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyKey;
133 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.cost.pac.CostCharacteristic;
134 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.cost.pac.CostCharacteristicBuilder;
135 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.timing.pac.LatencyCharacteristic;
136 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.timing.pac.LatencyCharacteristicBuilder;
137 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
138 import org.opendaylight.yangtools.yang.binding.Notification;
139 import org.opendaylight.yangtools.yang.common.Uint16;
140 import org.opendaylight.yangtools.yang.common.Uint32;
141 import org.opendaylight.yangtools.yang.common.Uint64;
142 import org.osgi.service.component.annotations.Activate;
143 import org.osgi.service.component.annotations.Component;
144 import org.osgi.service.component.annotations.Reference;
145 import org.slf4j.Logger;
146 import org.slf4j.LoggerFactory;
147
148
149 @Component
150 public class TapiNetworkModelServiceImpl implements TapiNetworkModelService {
151
152     private static final Logger LOG = LoggerFactory.getLogger(TapiNetworkModelServiceImpl.class);
153
154     private final Uuid tapiTopoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER
155             .getBytes(StandardCharsets.UTF_8)).toString());
156     private final NetworkTransactionService networkTransactionService;
157     private final R2RTapiLinkDiscovery linkDiscovery;
158     private final TapiLink tapiLink;
159     private final NotificationPublishService notificationPublishService;
160     private Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap = new HashMap<>();
161
162     @Activate
163     public TapiNetworkModelServiceImpl(@Reference NetworkTransactionService networkTransactionService,
164             @Reference DeviceTransactionManager deviceTransactionManager,
165             @Reference TapiLink tapiLink,
166             @Reference final NotificationPublishService notificationPublishService) {
167         this.networkTransactionService = networkTransactionService;
168         this.linkDiscovery = new R2RTapiLinkDiscovery(networkTransactionService, deviceTransactionManager, tapiLink);
169         this.tapiLink = tapiLink;
170         this.notificationPublishService = notificationPublishService;
171     }
172
173     @Override
174     public void createTapiNode(String orNodeId, int orNodeVersion, Nodes node) {
175         // TODO -> Implementation with PortMappingListener
176         // check if port mapping exists or not...
177         if (node.getMapping() == null) {
178             LOG.warn("Could not generate port mapping for {} skipping network model creation", orNodeId);
179             return;
180         }
181         this.sipMap.clear();
182         LOG.info("Mapping of node {}: {}", orNodeId, node.getMapping().values());
183
184         // check type of device, check version and create node mapping
185         if (NodeTypes.Rdm.getIntValue() == node.getNodeInfo().getNodeType().getIntValue()) {
186             // ROADM device
187             // transform flat mapping list to per degree and per srg mapping lists
188             Map<String, List<Mapping>> mapDeg = new HashMap<>();
189             Map<String, List<Mapping>> mapSrg = new HashMap<>();
190             List<Mapping> mappingList = new ArrayList<>(node.nonnullMapping().values());
191             mappingList.sort(Comparator.comparing(Mapping::getLogicalConnectionPoint));
192
193             List<String> nodeShardList = getRoadmNodelist(mappingList);
194
195             // populate degree and srg LCP map
196             for (String str : nodeShardList) {
197                 List<Mapping> interList = mappingList.stream().filter(x -> x.getLogicalConnectionPoint().contains(str))
198                         .collect(Collectors.toList());
199                 if (str.contains("DEG")) {
200                     mapDeg.put(str, interList);
201                 } else if (str.contains("SRG")) {
202                     mapSrg.put(str, interList);
203                 } else {
204                     LOG.error("unknown element");
205                 }
206             }
207             // Transform LCPs into ONEP
208             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap =
209                 new HashMap<>(transformDegToOnep(orNodeId, mapDeg));
210             onepMap.putAll(transformSrgToOnep(orNodeId, mapSrg));
211
212             // create tapi Node
213             Node roadmNode = createRoadmTapiNode(orNodeId, onepMap);
214             mergeNodeinTopology(Map.of(roadmNode.key(), roadmNode));
215             mergeSipsinContext(this.sipMap);
216             // TODO add states corresponding to device config -> based on mapping.
217             //  This should be possible after Gilles work is merged
218
219             // rdm to rdm link creation if neighbour roadm is mounted
220             LOG.info("checking if neighbor roadm exists");
221             Map<LinkKey, Link> rdm2rdmLinks = this.linkDiscovery.readLLDP(new NodeId(orNodeId), orNodeVersion,
222                 this.tapiTopoUuid);
223             if (!rdm2rdmLinks.isEmpty()) {
224                 mergeLinkinTopology(rdm2rdmLinks);
225             }
226             LOG.info("TAPI node for or node {} successfully merged", orNodeId);
227         } else if (NodeTypes.Xpdr.getIntValue() ==  node.getNodeInfo().getNodeType().getIntValue()) {
228             List<Mapping> networkMappings = node.nonnullMapping().values()
229                     .stream().filter(k -> k.getLogicalConnectionPoint()
230                             .contains("NETWORK")).collect(Collectors.toList());
231             Map<Integer, String> xpdrMap = new HashMap<>();
232             for (Mapping mapping : networkMappings) {
233                 Integer xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
234                 String nodeId = node.getNodeId() + TapiStringConstants.XPDR + xpdrNb;
235                 if (!xpdrMap.containsKey(xpdrNb)) {
236                     List<Mapping> xpdrNetMaps = node.nonnullMapping().values()
237                         .stream().filter(k -> k.getLogicalConnectionPoint()
238                             .contains("XPDR" + xpdrNb + TapiStringConstants.NETWORK)).collect(Collectors.toList());
239                     List<Mapping> xpdrClMaps = node.nonnullMapping().values()
240                         .stream().filter(k -> k.getLogicalConnectionPoint()
241                             .contains("XPDR" + xpdrNb + TapiStringConstants.CLIENT)).collect(Collectors.toList());
242                     xpdrMap.put(xpdrNb, node.getNodeId());
243
244                     // create switching pool
245                     OduSwitchingPools oorOduSwitchingPool = createSwitchPoolForXpdr(
246                         mapping.getXpdrType().getIntValue(), xpdrClMaps, xpdrNetMaps, xpdrNb);
247
248                     // node transformation
249                     Map<NodeKey, Node> nodeMap = new HashMap<>(transformXpdrToTapiNode(
250                         nodeId, xpdrClMaps, xpdrNetMaps, mapping.getXpdrType(), oorOduSwitchingPool));
251                     // add nodes and sips to tapi context
252                     mergeNodeinTopology(nodeMap);
253                     mergeSipsinContext(this.sipMap);
254                 }
255             }
256             LOG.info("TAPI node for or node {} successfully merged", orNodeId);
257         }
258         // Device not managed yet
259     }
260
261     @Override
262     public void updateTapiTopology(String nodeId, Mapping mapping) {
263         List<Uuid> uuids = getChangedNodeUuids(nodeId, mapping);
264
265         List<Uuid> changedOneps = updateNeps(mapping, uuids);
266         updateLinks(changedOneps, mapping);
267         sendNotification(changedOneps, mapping);
268
269         LOG.info("Updated TAPI topology successfully.");
270     }
271
272     @SuppressWarnings("rawtypes")
273     private void sendNotification(List<Uuid> changedOneps, Mapping mapping) {
274         Notification notification = new NotificationBuilder()
275             .setNotificationType(NOTIFICATIONTYPEATTRIBUTEVALUECHANGE.VALUE)
276 //            .setTargetObjectType(ObjectType.NODEEDGEPOINT)
277             //TODO: Change this : modification in Models 2.4 does not provide for Object type Node EdgePoint
278             .setTargetObjectType(OBJECTTYPETAPICONTEXT.VALUE)
279             .setChangedAttributes(getChangedAttributes(changedOneps, mapping))
280             .setUuid(tapiTopoUuid)
281             .build();
282         try {
283             notificationPublishService.putNotification(notification);
284         } catch (InterruptedException e) {
285             LOG.error("Could not send notification");
286         }
287     }
288
289     private Map<ChangedAttributesKey, ChangedAttributes> getChangedAttributes(List<Uuid> changedOneps,
290                                                                               Mapping mapping) {
291         Map<ChangedAttributesKey, ChangedAttributes> changedAttributes = new HashMap<>();
292         for (Uuid nep : changedOneps) {
293             changedAttributes.put(new ChangedAttributesKey(nep.getValue()),
294                 new ChangedAttributesBuilder().setValueName(nep.getValue())
295                     .setOldValue(mapping.getPortOperState().equals("InService") ? "OutOfService" : "InService")
296                     .setNewValue(mapping.getPortOperState())
297                     .build());
298         }
299         return changedAttributes;
300     }
301
302     private void updateLinks(List<Uuid> changedOneps, Mapping mapping) {
303         try {
304             InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
305                     .augmentation(Context1.class).child(TopologyContext.class)
306                     .child(Topology.class, new TopologyKey(tapiTopoUuid))
307                     .build();
308             Optional<Topology> optTopology = this.networkTransactionService
309                     .read(LogicalDatastoreType.OPERATIONAL, topoIID).get();
310             if (optTopology.isEmpty()) {
311                 LOG.error("Could not update TAPI links");
312                 return;
313             }
314             for (Link link : optTopology.orElseThrow().nonnullLink().values()) {
315                 List<Uuid> linkNeps = Objects.requireNonNull(link.getNodeEdgePoint()).values().stream()
316                         .map(NodeEdgePointRef::getNodeEdgePointUuid).collect(Collectors.toList());
317                 if (!Collections.disjoint(changedOneps, linkNeps)) {
318                     InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
319                             .augmentation(Context1.class).child(TopologyContext.class)
320                             .child(Topology.class, new TopologyKey(tapiTopoUuid))
321                             .child(Link.class, new LinkKey(link.getUuid())).build();
322                     Link linkblr = new LinkBuilder().setUuid(link.getUuid())
323                             .setAdministrativeState(transformAdminState(mapping.getPortAdminState()))
324                             .setOperationalState(transformOperState(mapping.getPortOperState())).build();
325                     this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, linkIID, linkblr);
326                 }
327             }
328             this.networkTransactionService.commit().get();
329         } catch (InterruptedException | ExecutionException e) {
330             LOG.error("Could not update TAPI links");
331         }
332     }
333
334     private List<Uuid> updateNeps(Mapping mapping, List<Uuid> uuids) {
335         List<Uuid> changedOneps = new ArrayList<>();
336         for (Uuid nodeUuid : uuids) {
337             try {
338                 InstanceIdentifier<Node> nodeIID = InstanceIdentifier.builder(Context.class)
339                         .augmentation(Context1.class).child(TopologyContext.class)
340                         .child(Topology.class, new TopologyKey(tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid))
341                         .build();
342                 Optional<Node> optionalNode = this.networkTransactionService.read(
343                         LogicalDatastoreType.OPERATIONAL, nodeIID).get();
344                 if (optionalNode.isPresent()) {
345                     Node node = optionalNode.orElseThrow();
346                     List<OwnedNodeEdgePoint> oneps = node.getOwnedNodeEdgePoint().values().stream()
347                             .filter(onep -> ((Name) onep.getName().values().toArray()[0]).getValue()
348                                     .contains(mapping.getLogicalConnectionPoint())).collect(Collectors.toList());
349                     for (OwnedNodeEdgePoint onep : oneps) {
350                         changedOneps.add(onep.getUuid());
351                         updateSips(mapping, onep);
352                         CepList cepList = getUpdatedCeps(mapping, onep);
353                         InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
354                                 .augmentation(Context1.class).child(TopologyContext.class)
355                                 .child(Topology.class, new TopologyKey(tapiTopoUuid))
356                                 .child(Node.class, new NodeKey(nodeUuid))
357                                 .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(onep.getUuid()))
358                                 .build();
359                         OwnedNodeEdgePoint onepblr = new OwnedNodeEdgePointBuilder().setUuid(onep.getUuid())
360                                 .addAugmentation(new OwnedNodeEdgePoint1Builder().setCepList(cepList).build())
361                                 .setAdministrativeState(transformAdminState(mapping.getPortAdminState()))
362                                 .setOperationalState(transformOperState(mapping.getPortOperState())).build();
363                         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, onepIID, onepblr);
364                     }
365                     this.networkTransactionService.commit().get();
366                 }
367             } catch (InterruptedException | ExecutionException e) {
368                 LOG.error("Could not update TAPI NEP");
369             }
370         }
371         return changedOneps;
372     }
373
374     private CepList getUpdatedCeps(Mapping mapping, OwnedNodeEdgePoint onep) {
375         OwnedNodeEdgePoint1 onep1 = onep.augmentation(OwnedNodeEdgePoint1.class);
376         Map<ConnectionEndPointKey, ConnectionEndPoint> cepMap = new HashMap<>();
377         if (onep1 != null && onep1.getCepList() != null && onep1.getCepList().getConnectionEndPoint() != null) {
378             for (Map.Entry<ConnectionEndPointKey, ConnectionEndPoint> entry : onep1.getCepList().getConnectionEndPoint()
379                     .entrySet()) {
380                 ConnectionEndPoint cep = new ConnectionEndPointBuilder(entry.getValue())
381                         .setOperationalState(transformOperState(mapping.getPortOperState())).build();
382                 cepMap.put(entry.getKey(), cep);
383             }
384         }
385         return new CepListBuilder().setConnectionEndPoint(cepMap).build();
386     }
387
388     private List<Uuid> getChangedNodeUuids(String nodeId, Mapping mapping) {
389         List<Uuid> uuids = new ArrayList<>();
390         if (nodeId.contains("ROADM")) {
391             uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA))
392                     .getBytes(StandardCharsets.UTF_8)).toString()));
393         } else if (nodeId.contains("PDR") && mapping.getLogicalConnectionPoint().contains("CLIENT")) {
394             int xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
395             String xpdrNodeId = nodeId + TapiStringConstants.XPDR + xpdrNb;
396             uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", xpdrNodeId, TapiStringConstants.DSR))
397                     .getBytes(StandardCharsets.UTF_8)).toString()));
398         } else if (nodeId.contains("PDR") && mapping.getLogicalConnectionPoint().contains("NETWORK")) {
399             int xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
400             String xpdrNodeId = nodeId + TapiStringConstants.XPDR + xpdrNb;
401             uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", xpdrNodeId, TapiStringConstants.DSR))
402                     .getBytes(StandardCharsets.UTF_8)).toString()));
403             uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", xpdrNodeId, TapiStringConstants.OTSI))
404                     .getBytes(StandardCharsets.UTF_8)).toString()));
405         } else {
406             LOG.error("Updating this device is currently not supported");
407             return uuids;
408         }
409         return uuids;
410     }
411
412     private void updateSips(Mapping mapping, OwnedNodeEdgePoint onep) {
413         if (onep.getMappedServiceInterfacePoint() == null
414                 || onep.getMappedServiceInterfacePoint().size() == 0) {
415             return;
416         }
417         for (MappedServiceInterfacePoint msip : onep.getMappedServiceInterfacePoint().values()) {
418             InstanceIdentifier<ServiceInterfacePoint> sipIID = InstanceIdentifier
419                     .builder(Context.class)
420                     .child(ServiceInterfacePoint.class,
421                             new ServiceInterfacePointKey(msip.getServiceInterfacePointUuid()))
422                     .build();
423             ServiceInterfacePoint sipblr = new ServiceInterfacePointBuilder()
424                     .setUuid(msip.getServiceInterfacePointUuid())
425                     .setAdministrativeState(transformAdminState(mapping.getPortAdminState()))
426                     .setOperationalState(transformOperState(mapping.getPortOperState())).build();
427             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, sipIID, sipblr);
428         }
429
430     }
431
432     private Map<NodeKey, Node> transformXpdrToTapiNode(String nodeId, List<Mapping> xpdrClMaps,
433                                                        List<Mapping> xpdrNetMaps, XpdrNodeTypes xponderType,
434                                                        OduSwitchingPools oorOduSwitchingPool) {
435         Map<NodeKey, Node> nodeMap = new HashMap<>();
436         LOG.info("creation of a DSR/ODU node for {}", nodeId);
437         Uuid nodeUuidDsr = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId, TapiStringConstants.DSR))
438             .getBytes(StandardCharsets.UTF_8)).toString());
439         Name nameDsr = new NameBuilder().setValueName("dsr/odu node name").setValue(
440             String.join("+", nodeId, TapiStringConstants.DSR)).build();
441         Name nameNodeType = new NameBuilder().setValueName("Node Type")
442             .setValue(getNodeType(xponderType)).build();
443         Set<LayerProtocolName> dsrLayerProtocols = Set.of(LayerProtocolName.DSR, LayerProtocolName.ODU);
444         Node dsrNode = createTapiXpdrNode(Map.of(nameDsr.key(), nameDsr, nameNodeType.key(), nameNodeType),
445             dsrLayerProtocols, nodeId, nodeUuidDsr, xpdrClMaps, xpdrNetMaps, xponderType, oorOduSwitchingPool);
446
447         nodeMap.put(dsrNode.key(), dsrNode);
448
449         // node creation [otsi]
450         LOG.info("creation of an OTSi node for {}", nodeId);
451         Uuid nodeUuidOtsi = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId, TapiStringConstants.OTSI))
452             .getBytes(StandardCharsets.UTF_8)).toString());
453         Name nameOtsi =  new NameBuilder().setValueName("otsi node name").setValue(
454             String.join("+", nodeId, TapiStringConstants.OTSI)).build();
455         Set<LayerProtocolName> otsiLayerProtocols = Set.of(LayerProtocolName.PHOTONICMEDIA);
456         Node otsiNode = createTapiXpdrNode(Map.of(nameOtsi.key(), nameOtsi, nameNodeType.key(), nameNodeType),
457             otsiLayerProtocols, nodeId, nodeUuidOtsi, xpdrClMaps, xpdrNetMaps, xponderType, null);
458
459         nodeMap.put(otsiNode.key(), otsiNode);
460
461         // transitional link cration between network nep of DSR/ODU node and iNep of otsi node
462         LOG.info("creation of transitional links between DSR/ODU and OTSi nodes");
463         Map<LinkKey, Link> linkMap = createTapiTransitionalLinks(nodeId, xpdrNetMaps);
464         mergeLinkinTopology(linkMap);
465
466         return nodeMap;
467     }
468
469     private OduSwitchingPools createSwitchPoolForXpdr(int xpdrType, List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
470                                                       Integer xpdrNb) {
471         // todo: are switching pool correct here??
472         switch (xpdrType) {
473             case 1:
474                 // Tpdr
475                 return createTpdrSwitchPool(xpdrNetMaps);
476             case 2:
477                 // Mux
478                 return createMuxSwitchPool(xpdrClMaps, xpdrNetMaps, xpdrNb);
479             case 3:
480                 // Switch
481                 return createSwtchSwitchPool(xpdrClMaps, xpdrNetMaps, xpdrNb);
482             default:
483                 LOG.warn("Xpdr type {} not supported", xpdrType);
484         }
485         return null;
486     }
487
488     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> transformSrgToOnep(String orNodeId,
489                                                                               Map<String, List<Mapping>> mapSrg) {
490         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
491         for (Map.Entry<String, List<Mapping>> entry : mapSrg.entrySet()) {
492             // For each srg node. Loop through the LCPs and create neps and sips for PP
493             for (Mapping m:entry.getValue()) {
494                 if (!m.getLogicalConnectionPoint().contains("PP")) {
495                     LOG.info("LCP {} is not an external TP of SRG node", m.getLogicalConnectionPoint());
496                     continue;
497                 }
498                 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> srgNeps =
499                     createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), true,
500                             transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()),
501                             TapiStringConstants.PHTNC_MEDIA_OTS);
502                 onepMap.putAll(srgNeps);
503             }
504         }
505         return onepMap;
506     }
507
508     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> transformDegToOnep(String orNodeId,
509                                                                               Map<String, List<Mapping>> mapDeg) {
510         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
511         for (Map.Entry<String, List<Mapping>> entry : mapDeg.entrySet()) {
512             // For each degree node. Loop through the LCPs and create neps and sips for TTP
513             for (Mapping m:entry.getValue()) {
514                 if (!m.getLogicalConnectionPoint().contains("TTP")) {
515                     LOG.info("LCP {} is not an external TP of DEGREE node", m.getLogicalConnectionPoint());
516                     continue;
517                 }
518                 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> degNeps =
519                     createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), false,
520                             transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()),
521                             TapiStringConstants.PHTNC_MEDIA_OTS);
522                 degNeps.putAll(createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), false,
523                         transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()),
524                         TapiStringConstants.PHTNC_MEDIA_OMS));
525                 onepMap.putAll(degNeps);
526             }
527         }
528         return onepMap;
529     }
530
531     private List<String> getRoadmNodelist(List<Mapping> mappingList) {
532         List<String> nodeShardList = new ArrayList<>();
533         for (Mapping mapping : mappingList) {
534             // TODO -> maybe we need to check the id based on the version
535             String str = mapping.getLogicalConnectionPoint().split("-")[0];
536             LOG.info("LCP = {}", str);
537             if (!nodeShardList.contains(str)) {
538                 nodeShardList.add(str);
539             }
540         }
541         return nodeShardList;
542     }
543
544     @Override
545     public void deleteTapinode(String nodeId) {
546         // TODO: check for null objects
547         // Check if it is ROADM or XPDR --> create the uuids of the node and delete from topology the node.
548         // This will delete NEPs. Then check for links that have this node and delete them.
549         // Then check SIPs and delete them. Then services and connections with SIPs and put them to another state.
550         LOG.info("Deleting node {} from TAPI topology", nodeId);
551         InstanceIdentifier<Topology> topologyIID = InstanceIdentifier.builder(Context.class)
552                 .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
553                         new TopologyKey(tapiTopoUuid)).build();
554         Topology topology = null;
555         try {
556             Optional<Topology> optTopology =
557                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, topologyIID).get();
558             if (!optTopology.isPresent()) {
559                 LOG.error("No topology object present. Error deleting node {}", nodeId);
560                 return;
561             }
562             topology = optTopology.orElseThrow();
563         } catch (InterruptedException | ExecutionException e) {
564             LOG.error("Couldnt read tapi topology from datastore", e);
565         }
566         if (topology == null) {
567             LOG.error("Topology is null, nothing to delete");
568             return;
569         }
570         if (topology.getNode() == null) {
571             LOG.error("No nodes in topology");
572             return;
573         }
574         if (nodeId.contains("ROADM")) {
575             // Node is in photonic media layer and UUID can be built from nodeId + PHTN_MEDIA
576             Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
577                 TapiStringConstants.PHTNC_MEDIA)).getBytes(StandardCharsets.UTF_8)).toString());
578             deleteNodeFromTopo(nodeUuid);
579         }
580         if (nodeId.contains("XPDR") || nodeId.contains("SPDR") || nodeId.contains("MXPDR")) {
581             // Node is either XPDR, MXPDR or SPDR. Retrieve nodes from topology and check names
582             for (Node tapiNode:topology.getNode().values()) {
583                 if (tapiNode.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
584                     // Found node we need to delete
585                     deleteNodeFromTopo(tapiNode.getUuid());
586                 }
587             }
588         }
589         // Delete links of topology
590         Map<LinkKey, Link> linkMap = topology.getLink();
591         if (linkMap != null) {
592             for (Link link:linkMap.values()) {
593                 if (link.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
594                     deleteLinkFromTopo(link.getUuid());
595                 }
596             }
597         }
598         // Delete sips of sip map
599         InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
600         Context context = null;
601         try {
602             Optional<Context> optContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
603                     contextIID).get();
604             if (!optContext.isPresent()) {
605                 LOG.error("No context object present in datastore.");
606                 return;
607             }
608             context = optContext.orElseThrow();
609         } catch (InterruptedException | ExecutionException e) {
610             LOG.error("Couldnt read tapi context from datastore", e);
611         }
612         if (context == null) {
613             LOG.error("Context is null, nothing to delete");
614             return;
615         }
616         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips = context.getServiceInterfacePoint();
617         if (sips != null) {
618             for (ServiceInterfacePoint sip:sips.values()) {
619                 if (sip.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
620                     // Update state of services that have this sip as an endpoint and also connections
621                     updateConnectivityServicesState(sip.getUuid(), nodeId);
622                     deleteSipFromTopo(sip.getUuid());
623                 }
624             }
625         }
626     }
627
628     private Node createTapiXpdrNode(Map<NameKey, Name> nameMap, Set<LayerProtocolName> layerProtocols,
629                                     String nodeId, Uuid nodeUuid, List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
630                                     XpdrNodeTypes xponderType, OduSwitchingPools oorOduSwitchingPool) {
631         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
632         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList = new HashMap<>();
633         Map<RuleKey, Rule> ruleList = new HashMap<>();
634         Set<RuleType> ruleTypes = new HashSet<>();
635         ruleTypes.add(RuleType.FORWARDING);
636         Rule rule = new RuleBuilder()
637                 .setLocalId("forward")
638                 .setForwardingRule(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE)
639                 .setRuleType(ruleTypes)
640                 .build();
641         ruleList.put(rule.key(), rule);
642         if (layerProtocols.contains(LayerProtocolName.DSR)) {
643             // neps for dsr/odu layer
644             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> dsroduNeps =
645                     createXpdrDsrOduNeps(nodeId, xpdrClMaps, xpdrNetMaps, xponderType);
646             onepl.putAll(dsroduNeps);
647             nodeRuleGroupList = createNodeRuleGroupForDsrNode(nodeId, oorOduSwitchingPool, ruleList, onepl);
648         } else if (layerProtocols.contains(LayerProtocolName.PHOTONICMEDIA)) {
649             // neps for photonic layer
650             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> phtmdNeps =
651                     createXpdrPhtnMdNeps(nodeId, xpdrNetMaps);
652             onepl.putAll(phtmdNeps);
653             nodeRuleGroupList = createNodeRuleGroupForOtsiNode(nodeId, xpdrNetMaps, ruleList);
654         } else {
655             LOG.error("Undefined LayerProtocolName for {} node {}", nameMap.get(nameMap.keySet().iterator().next())
656                     .getValueName(), nameMap.get(nameMap.keySet().iterator().next()).getValue());
657         }
658         // Empty random creation of mandatory fields for avoiding errors....
659         CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
660             .setCostAlgorithm("Restricted Shortest Path - RSP")
661             .setCostName("HOP_COUNT")
662             .setCostValue(TapiStringConstants.COST_HOP_VALUE)
663             .build();
664         LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
665             .setFixedLatencyCharacteristic(TapiStringConstants.FIXED_LATENCY_VALUE)
666             .setQueuingLatencyCharacteristic(TapiStringConstants.QUEING_LATENCY_VALUE)
667             .setJitterCharacteristic(TapiStringConstants.JITTER_VALUE)
668             .setWanderCharacteristic(TapiStringConstants.WANDER_VALUE)
669             .setTrafficPropertyName("FIXED_LATENCY")
670             .build();
671         return new NodeBuilder()
672             .setUuid(nodeUuid)
673             .setName(nameMap)
674             .setLayerProtocolName(layerProtocols)
675             .setAdministrativeState(AdministrativeState.UNLOCKED)
676             .setOperationalState(OperationalState.ENABLED)
677             .setLifecycleState(LifecycleState.INSTALLED)
678             .setOwnedNodeEdgePoint(onepl)
679             .setNodeRuleGroup(nodeRuleGroupList)
680             .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
681             .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
682             .setErrorCharacteristic("error")
683             .setLossCharacteristic("loss")
684             .setRepeatDeliveryCharacteristic("repeat delivery")
685             .setDeliveryOrderCharacteristic("delivery order")
686             .setUnavailableTimeCharacteristic("unavailable time")
687             .setServerIntegrityProcessCharacteristic("server integrity process")
688             .build();
689     }
690
691     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createXpdrPhtnMdNeps(String nodeId,
692                                                                                 List<Mapping> xpdrNetMaps) {
693         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
694
695         // iNep creation on otsi node
696         for (int i = 0; i < xpdrNetMaps.size(); i++) {
697             Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes(
698                 (String.join("+", nodeId, TapiStringConstants.I_OTSI,
699                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString());
700             Name onedName = new NameBuilder()
701                 .setValueName("iNodeEdgePoint")
702                 .setValue(String.join("+", nodeId, TapiStringConstants.I_OTSI,
703                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
704                 .build();
705
706             List<SupportedIfCapability> newSupIfCapList =
707                     new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
708
709             OwnedNodeEdgePoint onep = createNep(nepUuid1, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
710                 Map.of(onedName.key(), onedName), LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA,
711                 true, String.join("+", nodeId, TapiStringConstants.I_OTSI), newSupIfCapList,
712                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
713                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
714             onepl.put(onep.key(), onep);
715         }
716         // eNep creation on otsi node
717         for (int i = 0; i < xpdrNetMaps.size(); i++) {
718             Uuid nepUuid2 = new Uuid(UUID.nameUUIDFromBytes(
719                 (String.join("+", nodeId, TapiStringConstants.E_OTSI,
720                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString());
721             Name onedName = new NameBuilder()
722                 .setValueName("eNodeEdgePoint")
723                 .setValue(String.join("+", nodeId, TapiStringConstants.E_OTSI,
724                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
725                 .build();
726
727             List<SupportedIfCapability> newSupIfCapList =
728                     new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
729
730             OwnedNodeEdgePoint onep = createNep(nepUuid2, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
731                 Map.of(onedName.key(), onedName), LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA,
732                 false, String.join("+", nodeId, TapiStringConstants.E_OTSI), newSupIfCapList,
733                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
734                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
735             onepl.put(onep.key(), onep);
736         }
737         // Photonic Media Nep creation on otsi node
738         for (int i = 0; i < xpdrNetMaps.size(); i++) {
739             Uuid nepUuid3 = new Uuid(UUID.nameUUIDFromBytes(
740                 (String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA,
741                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString());
742             Name onedName = new NameBuilder()
743                 .setValueName("PhotMedNodeEdgePoint")
744                 .setValue(String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA,
745                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
746                 .build();
747
748             List<SupportedIfCapability> newSupIfCapList =
749                     new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
750
751             OwnedNodeEdgePoint onep = createNep(nepUuid3, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
752                 Map.of(onedName.key(), onedName), LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA,
753                 false, String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA), newSupIfCapList,
754                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
755                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
756             onepl.put(onep.key(), onep);
757         }
758         return onepl;
759     }
760
761     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createXpdrDsrOduNeps(String nodeId, List<Mapping> xpdrClMaps,
762                                                                                 List<Mapping> xpdrNetMaps,
763                                                                                 XpdrNodeTypes xponderType) {
764         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
765         // client nep creation on DSR node
766         for (int i = 0; i < xpdrClMaps.size(); i++) {
767             LOG.info("Client NEP = {}", String.join("+", nodeId, TapiStringConstants.DSR,
768                 xpdrClMaps.get(i).getLogicalConnectionPoint()));
769             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
770                 (String.join("+", nodeId, TapiStringConstants.DSR,
771                     xpdrClMaps.get(i).getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString());
772             NameBuilder nameBldr = new NameBuilder().setValue(String.join("+", nodeId,
773                 TapiStringConstants.DSR, xpdrClMaps.get(i).getLogicalConnectionPoint()));
774             Name name;
775             if (OpenroadmNodeType.TPDR.getName().equalsIgnoreCase(xponderType.getName())) {
776                 name = nameBldr.setValueName("100G-tpdr").build();
777             } else {
778                 name = nameBldr.setValueName("NodeEdgePoint_C").build();
779             }
780
781             List<SupportedIfCapability> newSupIfCapList =
782                     new ArrayList<>(xpdrClMaps.get(i).getSupportedInterfaceCapability());
783
784             OwnedNodeEdgePoint onep = createNep(nepUuid, xpdrClMaps.get(i).getLogicalConnectionPoint(),
785                 Map.of(name.key(), name), LayerProtocolName.DSR, LayerProtocolName.DSR, true,
786                 String.join("+", nodeId, TapiStringConstants.DSR), newSupIfCapList,
787                 transformOperState(xpdrClMaps.get(i).getPortOperState()),
788                 transformAdminState(xpdrClMaps.get(i).getPortAdminState()));
789             onepl.put(onep.key(), onep);
790         }
791         // network nep creation on I_ODU node
792         for (int i = 0; i < xpdrNetMaps.size(); i++) {
793             LOG.info("iODU NEP = {}", String.join("+", nodeId, TapiStringConstants.I_ODU,
794                 xpdrNetMaps.get(i).getLogicalConnectionPoint()));
795             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
796                 (String.join("+", nodeId, TapiStringConstants.I_ODU,
797                     xpdrNetMaps.get(i).getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString());
798             Name onedName = new NameBuilder()
799                 .setValueName("iNodeEdgePoint_N")
800                 .setValue(String.join("+", nodeId, TapiStringConstants.I_ODU,
801                     xpdrNetMaps.get(i).getLogicalConnectionPoint()))
802                 .build();
803
804             List<SupportedIfCapability> newSupIfCapList =
805                     new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
806
807             OwnedNodeEdgePoint onep = createNep(nepUuid, xpdrNetMaps.get(i).getLogicalConnectionPoint(),
808                 Map.of(onedName.key(), onedName),
809                 LayerProtocolName.ODU, LayerProtocolName.DSR, true,
810                 String.join("+", nodeId, TapiStringConstants.I_ODU), newSupIfCapList,
811                 transformOperState(xpdrNetMaps.get(i).getPortOperState()),
812                 transformAdminState(xpdrNetMaps.get(i).getPortAdminState()));
813             onepl.put(onep.key(), onep);
814         }
815         // network nep creation on E_ODU node
816         for (int i = 0; i < xpdrClMaps.size(); i++) {
817             LOG.info("eODU NEP = {}", String.join("+", nodeId, TapiStringConstants.E_ODU,
818                 xpdrClMaps.get(i).getLogicalConnectionPoint()));
819             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
820                 (String.join("+", nodeId, TapiStringConstants.E_ODU,
821                     xpdrClMaps.get(i).getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString());
822             Name onedName = new NameBuilder()
823                 .setValueName("eNodeEdgePoint_N")
824                 .setValue(String.join("+", nodeId, TapiStringConstants.E_ODU,
825                     xpdrClMaps.get(i).getLogicalConnectionPoint()))
826                 .build();
827
828             List<SupportedIfCapability> newSupIfCapList =
829                     new ArrayList<>(xpdrClMaps.get(i).getSupportedInterfaceCapability());
830
831             OwnedNodeEdgePoint onep = createNep(nepUuid, xpdrClMaps.get(i).getLogicalConnectionPoint(),
832                 Map.of(onedName.key(), onedName),
833                 LayerProtocolName.ODU, LayerProtocolName.DSR, false,
834                 String.join("+", nodeId, TapiStringConstants.E_ODU), newSupIfCapList,
835                 transformOperState(xpdrClMaps.get(i).getPortOperState()),
836                 transformAdminState(xpdrClMaps.get(i).getPortAdminState()));
837             onepl.put(onep.key(), onep);
838         }
839         return onepl;
840     }
841
842     private OperationalState transformOperState(String operString) {
843         State operState = org.opendaylight.transportpce.networkmodel.util.TopologyUtils.setNetworkOperState(operString);
844         return operState.equals(State.InService) ? OperationalState.ENABLED : OperationalState.DISABLED;
845     }
846
847     private AdministrativeState transformAdminState(String adminString) {
848         AdminStates adminState = org.opendaylight.transportpce.networkmodel.util.TopologyUtils
849             .setNetworkAdminState(adminString);
850         return adminState.equals(AdminStates.InService) ? AdministrativeState.UNLOCKED : AdministrativeState.LOCKED;
851     }
852
853     private OwnedNodeEdgePoint createNep(Uuid nepUuid, String tpid, Map<NameKey, Name> nepNames,
854                                          LayerProtocolName nepProtocol, LayerProtocolName nodeProtocol, boolean withSip,
855                                          String keyword,
856                                          List<SupportedIfCapability> supportedInterfaceCapability,
857                                          OperationalState operState, AdministrativeState adminState) {
858         OwnedNodeEdgePointBuilder onepBldr = new OwnedNodeEdgePointBuilder()
859                 .setUuid(nepUuid)
860                 .setLayerProtocolName(nepProtocol)
861                 .setName(nepNames);
862         if (withSip) {
863             onepBldr.setMappedServiceInterfacePoint(createMSIP(1, nepProtocol, tpid, keyword,
864                     supportedInterfaceCapability, operState, adminState));
865         }
866         LOG.debug("Node layer {}", nodeProtocol.getName());
867         onepBldr.setSupportedCepLayerProtocolQualifierInstances(createSupportedLayerProtocolQualifier(
868                 supportedInterfaceCapability, nepProtocol));
869         onepBldr.setDirection(Direction.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
870                 .setAdministrativeState(adminState).setOperationalState(operState)
871                 .setLifecycleState(LifecycleState.INSTALLED);
872 //                .setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
873 //                .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL);
874         return onepBldr.build();
875     }
876
877     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createRoadmNeps(String orNodeId, String tpId,
878             boolean withSip, OperationalState operState, AdministrativeState adminState, String nepPhotonicSublayer) {
879         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
880         // PHOTONIC MEDIA nep
881         Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId,
882                 TapiStringConstants.PHTNC_MEDIA, tpId)).getBytes(StandardCharsets.UTF_8)).toString());
883         Name nepName = new NameBuilder()
884                 .setValueName(TapiStringConstants.PHTNC_MEDIA + "NodeEdgePoint")
885                 .setValue(String.join("+", orNodeId, TapiStringConstants.PHTNC_MEDIA, tpId))
886                 .build();
887         List<SupportedCepLayerProtocolQualifierInstances> sclpqiList = new ArrayList<>();
888         sclpqiList.add(
889             new SupportedCepLayerProtocolQualifierInstancesBuilder()
890                 .setLayerProtocolQualifier(
891                     TapiStringConstants.PHTNC_MEDIA_OMS.equals(nepPhotonicSublayer)
892                         ? PHOTONICLAYERQUALIFIEROMS.VALUE
893                         : PHOTONICLAYERQUALIFIEROTS.VALUE)
894                 .setNumberOfCepInstances(Uint64.valueOf(1))
895                 .build());
896         OwnedNodeEdgePoint onep = new OwnedNodeEdgePointBuilder()
897             .setUuid(nepUuid)
898             .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA)
899             .setName(Map.of(nepName.key(), nepName))
900             .setSupportedCepLayerProtocolQualifierInstances(sclpqiList)
901             .setDirection(Direction.BIDIRECTIONAL)
902             .setLinkPortRole(PortRole.SYMMETRIC)
903             .setAdministrativeState(adminState).setOperationalState(operState)
904             .setLifecycleState(LifecycleState.INSTALLED)
905 //            .setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
906 //            .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL)
907             .build();
908         onepMap.put(onep.key(), onep);
909         return onepMap;
910     }
911
912     private Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint>
913             createMSIP(int nb, LayerProtocolName layerProtocol, String tpid, String nodeid,
914                    List<SupportedIfCapability> supportedInterfaceCapability,
915                    OperationalState operState, AdministrativeState adminState) {
916         Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> msipl = new HashMap<>();
917         for (int i = 0; i < nb; i++) {
918             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP", nodeid,
919                     tpid)).getBytes(StandardCharsets.UTF_8)).toString());
920             MappedServiceInterfacePoint msip = new MappedServiceInterfacePointBuilder()
921                     .setServiceInterfacePointUuid(sipUuid).build();
922             ServiceInterfacePoint sip = createSIP(sipUuid, layerProtocol, tpid, nodeid, supportedInterfaceCapability,
923                 operState, adminState);
924             this.sipMap.put(sip.key(), sip);
925             LOG.info("SIP created {}", sip.getUuid());
926             // this.tapiSips.put(sip.key(), sip);
927             msipl.put(msip.key(), msip);
928         }
929         return msipl;
930     }
931
932     private ServiceInterfacePoint createSIP(Uuid sipUuid, LayerProtocolName layerProtocol, String tpid, String nodeid,
933                                             List<SupportedIfCapability> supportedInterfaceCapability,
934                                             OperationalState operState, AdministrativeState adminState) {
935         // TODO: what value should be set in total capacity and available capacity
936         LOG.info("SIP name = {}", String.join("+", nodeid, tpid));
937         Name sipName = new NameBuilder()
938                 .setValueName("SIP name")
939                 .setValue(String.join("+", nodeid, tpid))
940                 .build();
941         return new ServiceInterfacePointBuilder()
942                 .setUuid(sipUuid)
943                 .setName(Map.of(sipName.key(), sipName))
944                 .setLayerProtocolName(layerProtocol)
945                 .setAdministrativeState(adminState)
946                 .setOperationalState(operState)
947                 .setLifecycleState(LifecycleState.INSTALLED)
948                 .setAvailableCapacity(new AvailableCapacityBuilder().build())
949                 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().build())
950                 .setSupportedCepLayerProtocolQualifierInstances(createSipSupportedLayerProtocolQualifier(
951                         supportedInterfaceCapability, layerProtocol))
952                 .build();
953     }
954
955     private Node createRoadmTapiNode(String orNodeId, Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> oneplist) {
956         // UUID
957         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId,
958             TapiStringConstants.PHTNC_MEDIA)).getBytes(StandardCharsets.UTF_8)).toString());
959         // Names
960         Name nodeNames =  new NameBuilder().setValueName("roadm node name")
961             .setValue(String.join("+", orNodeId, TapiStringConstants.PHTNC_MEDIA)).build();
962         Name nameNodeType = new NameBuilder().setValueName("Node Type")
963             .setValue(OpenroadmNodeType.ROADM.getName()).build();
964         // Protocol Layer
965         Set<LayerProtocolName> layerProtocols = Set.of(LayerProtocolName.PHOTONICMEDIA);
966         // Empty random creation of mandatory fields for avoiding errors....
967         CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
968             .setCostAlgorithm("Restricted Shortest Path - RSP")
969             .setCostName("HOP_COUNT")
970             .setCostValue(TapiStringConstants.COST_HOP_VALUE)
971             .build();
972         LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
973             .setFixedLatencyCharacteristic(TapiStringConstants.COST_HOP_VALUE)
974             .setQueuingLatencyCharacteristic(TapiStringConstants.QUEING_LATENCY_VALUE)
975             .setJitterCharacteristic(TapiStringConstants.JITTER_VALUE)
976             .setWanderCharacteristic(TapiStringConstants.WANDER_VALUE)
977             .setTrafficPropertyName("FIXED_LATENCY")
978             .build();
979         return new NodeBuilder()
980             .setUuid(nodeUuid)
981             .setName(Map.of(nodeNames.key(), nodeNames, nameNodeType.key(), nameNodeType))
982             .setLayerProtocolName(layerProtocols)
983             .setAdministrativeState(AdministrativeState.UNLOCKED)
984             .setOperationalState(OperationalState.ENABLED)
985             .setLifecycleState(LifecycleState.INSTALLED)
986             .setOwnedNodeEdgePoint(oneplist)
987             .setNodeRuleGroup(createNodeRuleGroupForRdmNode(orNodeId, nodeUuid, oneplist.values()))
988             .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
989             .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
990             .setErrorCharacteristic("error")
991             .setLossCharacteristic("loss")
992             .setRepeatDeliveryCharacteristic("repeat delivery")
993             .setDeliveryOrderCharacteristic("delivery order")
994             .setUnavailableTimeCharacteristic("unavailable time")
995             .setServerIntegrityProcessCharacteristic("server integrity process")
996             .build();
997     }
998
999     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForRdmNode(String orNodeId, Uuid nodeUuid,
1000                                                                                Collection<OwnedNodeEdgePoint> onepl) {
1001         Map<NodeEdgePointKey, NodeEdgePoint>
1002                 nepMap = new HashMap<>();
1003         for (OwnedNodeEdgePoint onep : onepl) {
1004             NodeEdgePoint nep = new NodeEdgePointBuilder()
1005                 .setTopologyUuid(this.tapiTopoUuid)
1006                 .setNodeUuid(nodeUuid)
1007                 .setNodeEdgePointUuid(onep.key().getUuid())
1008                 .build();
1009             nepMap.put(nep.key(), nep);
1010         }
1011         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
1012         Map<RuleKey, Rule> ruleList = new HashMap<>();
1013         Set<RuleType> ruleTypes = new HashSet<>();
1014         ruleTypes.add(RuleType.FORWARDING);
1015         Rule rule = new RuleBuilder()
1016                 .setLocalId("forward")
1017                 .setForwardingRule(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE)
1018                 .setRuleType(ruleTypes)
1019                 .build();
1020         ruleList.put(rule.key(), rule);
1021         NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
1022                 .setUuid(new Uuid(UUID.nameUUIDFromBytes((orNodeId + " node rule group")
1023                         .getBytes(StandardCharsets.UTF_8)).toString()))
1024                 .setRule(ruleList)
1025                 .setNodeEdgePoint(nepMap)
1026                 .build();
1027         nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1028         return nodeRuleGroupMap;
1029     }
1030
1031     private Map<LinkKey, Link> createTapiTransitionalLinks(String nodeId, List<Mapping> xpdrNetMaps) {
1032         Map<LinkKey, Link> linkMap = new HashMap<>();
1033         for (Mapping mapping : xpdrNetMaps) {
1034             Link transiLink = tapiLink.createTapiLink(nodeId, mapping.getLogicalConnectionPoint(), nodeId,
1035                 mapping.getLogicalConnectionPoint(), TapiStringConstants.TRANSITIONAL_LINK, TapiStringConstants.DSR,
1036                 TapiStringConstants.OTSI, TapiStringConstants.I_ODU, TapiStringConstants.I_OTSI,
1037                 "inService", "inService", Set.of(LayerProtocolName.ODU, LayerProtocolName.PHOTONICMEDIA),
1038                 Set.of(LayerProtocolName.ODU.getName(), LayerProtocolName.PHOTONICMEDIA.getName()),
1039                 this.tapiTopoUuid);
1040             linkMap.put(transiLink.key(), transiLink);
1041         }
1042         // return a map of links and then we can do merge the corresponding link map into the topology context
1043         return linkMap;
1044     }
1045
1046     private OduSwitchingPools createTpdrSwitchPool(List<Mapping> xpdrNetMaps) {
1047         Map<NonBlockingListKey, NonBlockingList> nblMap = new HashMap<>();
1048         int count = 1;
1049         for (int i = 1; i <= xpdrNetMaps.size(); i++) {
1050             LOG.info("XPDr net LCP = {}", xpdrNetMaps.get(i - 1).getLogicalConnectionPoint());
1051             LOG.info("XPDr net associated LCP = {}", xpdrNetMaps.get(i - 1).getConnectionMapLcp());
1052             TpId tpid1 = new TpId(xpdrNetMaps.get(i - 1).getLogicalConnectionPoint());
1053             TpId tpid2 = new TpId(xpdrNetMaps.get(i - 1).getConnectionMapLcp());
1054             Set<TpId> tpList = new HashSet<>();
1055             tpList.add(tpid1);
1056             tpList.add(tpid2);
1057             NonBlockingList nbl = new NonBlockingListBuilder()
1058                 .setNblNumber(Uint16.valueOf(count))
1059                 .setTpList(tpList)
1060                 .build();
1061             nblMap.put(nbl.key(), nbl);
1062             count++;
1063         }
1064         return new OduSwitchingPoolsBuilder()
1065             .setNonBlockingList(nblMap)
1066             .setSwitchingPoolNumber(Uint16.valueOf(1))
1067             .build();
1068     }
1069
1070     private OduSwitchingPools createSwtchSwitchPool(List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
1071                                                     Integer xpdrNb) {
1072         Set<TpId> tpl = new HashSet<>();
1073         TpId tpId = null;
1074         for (int i = 1; i <= xpdrClMaps.size(); i++) {
1075             tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.CLIENT + i);
1076             tpl.add(tpId);
1077         }
1078         for (int i = 1; i <= xpdrNetMaps.size(); i++) {
1079             tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.NETWORK + i);
1080             tpl.add(tpId);
1081         }
1082         Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
1083         NonBlockingList nbl = new NonBlockingListBuilder()
1084             .setNblNumber(Uint16.valueOf(1))
1085             .setTpList(tpl)
1086             .build();
1087         nbMap.put(nbl.key(),nbl);
1088
1089         return new OduSwitchingPoolsBuilder()
1090             .setSwitchingPoolNumber(Uint16.valueOf(1))
1091             .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
1092             .setNonBlockingList(nbMap)
1093             .build();
1094     }
1095
1096     private OduSwitchingPools createMuxSwitchPool(List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps, Integer xpdrNb) {
1097         Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
1098         for (int i = 1; i <= xpdrClMaps.size(); i++) {
1099             Set<TpId> tpList = new HashSet<>();
1100             TpId tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.CLIENT + i);
1101             tpList.add(tpId);
1102             tpId = new TpId("XPDR" + xpdrNb + "-NETWORK1");
1103             tpList.add(tpId);
1104             NonBlockingList nbl = new NonBlockingListBuilder()
1105                 .setNblNumber(Uint16.valueOf(i))
1106                 .setTpList(tpList)
1107                 .setAvailableInterconnectBandwidth(Uint32.valueOf(xpdrNetMaps.size() * 10L))
1108                 .setInterconnectBandwidthUnit(Uint32.valueOf(1000000000))
1109                 .build();
1110             nbMap.put(nbl.key(),nbl);
1111         }
1112         return new OduSwitchingPoolsBuilder()
1113                 .setSwitchingPoolNumber(Uint16.valueOf(1))
1114                 .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
1115                 .setNonBlockingList(nbMap)
1116                 .build();
1117     }
1118
1119     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForOtsiNode(String nodeId,
1120                                                                                 List<Mapping> xpdrNetMaps,
1121                                                                                 Map<RuleKey, Rule> ruleList) {
1122         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
1123         // create NodeRuleGroup
1124         int count = 1;
1125         for (Mapping tpMapping : xpdrNetMaps) {
1126             Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
1127             NodeEdgePoint inep = new NodeEdgePointBuilder()
1128                 .setTopologyUuid(this.tapiTopoUuid)
1129                 .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
1130                         TapiStringConstants.OTSI)).getBytes(StandardCharsets.UTF_8)).toString()))
1131                 .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
1132                     TapiStringConstants.I_OTSI, tpMapping.getLogicalConnectionPoint()))
1133                     .getBytes(StandardCharsets.UTF_8)).toString()))
1134                 .build();
1135             NodeEdgePoint enep = new NodeEdgePointBuilder()
1136                 .setTopologyUuid(this.tapiTopoUuid)
1137                 .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
1138                     TapiStringConstants.OTSI)).getBytes(StandardCharsets.UTF_8)).toString()))
1139                 .setNodeEdgePointUuid(new Uuid(UUID.nameUUIDFromBytes(
1140                     (String.join("+", nodeId, TapiStringConstants.E_OTSI,
1141                         tpMapping.getLogicalConnectionPoint())).getBytes(StandardCharsets.UTF_8)).toString()))
1142                 .build();
1143             nepList.put(inep.key(), inep);
1144             nepList.put(enep.key(), enep);
1145             // Empty random creation of mandatory fields for avoiding errors....
1146             CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
1147                 .setCostAlgorithm("Restricted Shortest Path - RSP")
1148                 .setCostName("HOP_COUNT")
1149                 .setCostValue(TapiStringConstants.COST_HOP_VALUE)
1150                 .build();
1151             LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
1152                 .setFixedLatencyCharacteristic(TapiStringConstants.FIXED_LATENCY_VALUE)
1153                 .setQueuingLatencyCharacteristic(TapiStringConstants.QUEING_LATENCY_VALUE)
1154                 .setJitterCharacteristic(TapiStringConstants.JITTER_VALUE)
1155                 .setWanderCharacteristic(TapiStringConstants.WANDER_VALUE)
1156                 .setTrafficPropertyName("FIXED_LATENCY")
1157                 .build();
1158             RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
1159                 .setRiskCharacteristicName("risk characteristic")
1160                 .setRiskIdentifierList(Set.of("risk identifier1", "risk identifier2"))
1161                 .build();
1162             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
1163                 .setUuid(new Uuid(
1164                     UUID.nameUUIDFromBytes(("otsi node rule group " + count).getBytes(StandardCharsets.UTF_8))
1165                         .toString()))
1166                 .setRule(ruleList)
1167                 .setNodeEdgePoint(nepList)
1168                 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1169                 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1170                 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1171                 .build();
1172             nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1173             count++;
1174         }
1175         return nodeRuleGroupMap;
1176     }
1177
1178     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForDsrNode(String nodeId,
1179                                                                                OduSwitchingPools oorOduSwitchingPool,
1180                                                                                Map<RuleKey, Rule> ruleList,
1181                                                                                Map<OwnedNodeEdgePointKey,
1182                                                                                        OwnedNodeEdgePoint> onepl) {
1183         // create NodeRuleGroup
1184         if (oorOduSwitchingPool == null) {
1185             LOG.info("No switching pool created for node = {}", nodeId);
1186             return new HashMap<>();
1187         }
1188         LOG.info("ONEPL = {}", onepl.values());
1189         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
1190         int count = 1;
1191         for (NonBlockingList nbl : oorOduSwitchingPool.nonnullNonBlockingList().values()) {
1192             LOG.info("Non blocking list = {}", nbl);
1193             Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
1194             for (TpId tp : nbl.getTpList()) {
1195                 LOG.info("EDOU TP = {}", String.join("+", nodeId, TapiStringConstants.E_ODU, tp.getValue()));
1196                 LOG.info("DSR TP = {}", String.join("+", nodeId, TapiStringConstants.DSR, tp.getValue()));
1197                 Uuid tpUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
1198                     TapiStringConstants.E_ODU, tp.getValue())).getBytes(StandardCharsets.UTF_8)).toString());
1199                 Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId,
1200                     TapiStringConstants.DSR, tp.getValue())).getBytes(StandardCharsets.UTF_8)).toString());
1201                 if (onepl.containsKey(new OwnedNodeEdgePointKey(tpUuid))
1202                         && onepl.containsKey(new OwnedNodeEdgePointKey(tp1Uuid))) {
1203                     NodeEdgePoint nep1 = new NodeEdgePointBuilder()
1204                         .setTopologyUuid(this.tapiTopoUuid)
1205                         .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1206                             (String.join("+", nodeId,TapiStringConstants. DSR))
1207                                 .getBytes(StandardCharsets.UTF_8)).toString()))
1208                         .setNodeEdgePointUuid(tp1Uuid)
1209                         .build();
1210                     NodeEdgePoint nep2 = new NodeEdgePointBuilder()
1211                         .setTopologyUuid(this.tapiTopoUuid)
1212                         .setNodeUuid(new Uuid(UUID.nameUUIDFromBytes(
1213                             (String.join("+", nodeId,TapiStringConstants. DSR))
1214                                 .getBytes(StandardCharsets.UTF_8)).toString()))
1215                         .setNodeEdgePointUuid(tpUuid)
1216                         .build();
1217                     nepList.put(nep1.key(), nep1);
1218                     nepList.put(nep2.key(), nep2);
1219                 }
1220             }
1221             // Empty random creation of mandatory fields for avoiding errors....
1222             CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
1223                 .setCostAlgorithm("Restricted Shortest Path - RSP")
1224                 .setCostName("HOP_COUNT")
1225                 .setCostValue(TapiStringConstants.COST_HOP_VALUE)
1226                 .build();
1227             LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
1228                 .setFixedLatencyCharacteristic(TapiStringConstants.FIXED_LATENCY_VALUE)
1229                 .setQueuingLatencyCharacteristic(TapiStringConstants.QUEING_LATENCY_VALUE)
1230                 .setJitterCharacteristic(TapiStringConstants.JITTER_VALUE)
1231                 .setWanderCharacteristic(TapiStringConstants.WANDER_VALUE)
1232                 .setTrafficPropertyName("FIXED_LATENCY")
1233                 .build();
1234             RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
1235                 .setRiskCharacteristicName("risk characteristic")
1236                 .setRiskIdentifierList(Set.of("risk identifier1", "risk identifier2"))
1237                 .build();
1238             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
1239                 .setUuid(new Uuid(
1240                     UUID.nameUUIDFromBytes(("dsr node rule group " + count).getBytes(StandardCharsets.UTF_8))
1241                         .toString()))
1242                 .setRule(ruleList)
1243                 .setNodeEdgePoint(nepList)
1244                 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1245                 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1246                 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1247                 .build();
1248             nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1249             count++;
1250         }
1251         return nodeRuleGroupMap;
1252     }
1253
1254     private List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1255             .service._interface.point.SupportedCepLayerProtocolQualifierInstances>
1256             createSipSupportedLayerProtocolQualifier(List<SupportedIfCapability> sicList, LayerProtocolName lpn) {
1257         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1258                 .service._interface.point.SupportedCepLayerProtocolQualifierInstances> sclpqiList = new ArrayList<>();
1259         if (sicList == null) {
1260             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1261                     .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1262                 .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROMS.VALUE)
1263                 .setNumberOfCepInstances(Uint64.valueOf(1))
1264                 .build());
1265             return sclpqiList;
1266         }
1267         Map<SupportedInterfaceCapabilityKey, SupportedInterfaceCapability> supIfMap = new HashMap<>();
1268         LOG.info("SIC list = {}", sicList);
1269         for (SupportedIfCapability supInterCapa : sicList) {
1270             SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
1271                     .withKey(new SupportedInterfaceCapabilityKey(supInterCapa))
1272                     .setIfCapType(supInterCapa)
1273                     .build();
1274             supIfMap.put(supIfCapa.key(), supIfCapa);
1275         }
1276         for (SupportedInterfaceCapability sic : supIfMap.values()) {
1277             String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
1278             switch (lpn.getName()) {
1279                 case "DSR":
1280                     switch (ifCapType) {
1281                         // TODO: it may be needed to add more cases clauses if the interface capabilities of a
1282                         //  port are extended in the config file
1283                         case "If1GEODU0":
1284                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1285                                     .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1286                                 .setLayerProtocolQualifier(ODUTYPEODU0.VALUE)
1287                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1288                                 .build());
1289                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1290                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1291                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPEGigE.VALUE)
1292                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1293                                 .build());
1294                             break;
1295                         case "If10GEODU2e":
1296                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1297                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1298                                 .setLayerProtocolQualifier(ODUTYPEODU2E.VALUE)
1299                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1300                                 .build());
1301                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1302                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1303                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE10GigELAN.VALUE)
1304                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1305                                 .build());
1306                             break;
1307                         case "If10GEODU2":
1308                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1309                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1310                                 .setLayerProtocolQualifier(ODUTYPEODU2.VALUE)
1311                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1312                                 .build());
1313                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1314                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1315                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE10GigELAN.VALUE)
1316                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1317                                 .build());
1318                             break;
1319                         case "If10GE":
1320                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1321                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1322                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE10GigELAN.VALUE)
1323                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1324                                 .build());
1325                             break;
1326                         case "If100GEODU4":
1327                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1328                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1329                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE100GigE.VALUE)
1330                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1331                                 .build());
1332                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1333                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1334                                 .setLayerProtocolQualifier(ODUTYPEODU4.VALUE)
1335                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1336                                 .build());
1337                             break;
1338                         case "If100GE":
1339                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1340                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1341                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE100GigE.VALUE)
1342                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1343                                 .build());
1344                             break;
1345                         case "IfOCHOTU4ODU4":
1346                         case "IfOCH":
1347                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1348                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1349                                 .setLayerProtocolQualifier(ODUTYPEODU4.VALUE)
1350                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1351                                 .build());
1352                             break;
1353                         default:
1354                             LOG.error("IfCapability type not managed");
1355                             break;
1356                     }
1357                     break;
1358                 case "ODU":
1359                     switch (ifCapType) {
1360                         // TODO: it may be needed to add more cases clauses if the interface capabilities of a
1361                         //  port are extended in the config file
1362                         case "If1GEODU0":
1363                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1364                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1365                                 .setLayerProtocolQualifier(ODUTYPEODU0.VALUE)
1366                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1367                                 .build());
1368                             break;
1369                         case "If10GEODU2e":
1370                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1371                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1372                                 .setLayerProtocolQualifier(ODUTYPEODU2E.VALUE)
1373                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1374                                 .build());
1375                             break;
1376                         case "If10GEODU2":
1377                         case "If10GE":
1378                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1379                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1380                                 .setLayerProtocolQualifier(ODUTYPEODU2.VALUE)
1381                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1382                                 .build());
1383                             break;
1384                         case "If100GEODU4":
1385                         case "If100GE":
1386                         case "IfOCHOTU4ODU4":
1387                         case "IfOCH":
1388                             sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1389                                 .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1390                                 .setLayerProtocolQualifier(ODUTYPEODU4.VALUE)
1391                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1392                                 .build());
1393                             break;
1394                         default:
1395                             LOG.error("IfCapability type not managed");
1396                             break;
1397                     }
1398                     break;
1399                 case "PHOTONIC_MEDIA":
1400                     if (ifCapType.equals("IfOCHOTU4ODU4") || ifCapType.equals("IfOCH")) {
1401                         sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1402                             .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1403                             .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROTSiMC.VALUE)
1404                             .setNumberOfCepInstances(Uint64.valueOf(0))
1405                             .build());
1406                         sclpqiList.add(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1407                             .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1408                             .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROMS.VALUE)
1409                             .setNumberOfCepInstances(Uint64.valueOf(0))
1410                             .build());
1411                     }
1412                     break;
1413                 default:
1414                     LOG.error("Layer Protocol Name is unknown {}", lpn.getName());
1415                     break;
1416             }
1417         }
1418         return sclpqiList;
1419     }
1420
1421     private List<SupportedCepLayerProtocolQualifierInstances> createSupportedLayerProtocolQualifier(
1422             List<SupportedIfCapability> sicList, LayerProtocolName lpn) {
1423         List<SupportedCepLayerProtocolQualifierInstances> sclpqiList = new ArrayList<>();
1424         if (sicList == null) {
1425             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1426                 .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROMS.VALUE)
1427                 .setNumberOfCepInstances(Uint64.valueOf(1))
1428                 .build());
1429             return sclpqiList;
1430         }
1431         Map<SupportedInterfaceCapabilityKey, SupportedInterfaceCapability> supIfMap = new HashMap<>();
1432         LOG.info("SIC list = {}", sicList);
1433         for (SupportedIfCapability supInterCapa : sicList) {
1434             SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
1435                     .withKey(new SupportedInterfaceCapabilityKey(supInterCapa))
1436                     .setIfCapType(supInterCapa)
1437                     .build();
1438             supIfMap.put(supIfCapa.key(), supIfCapa);
1439         }
1440         for (SupportedInterfaceCapability sic : supIfMap.values()) {
1441             String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
1442             switch (lpn.getName()) {
1443                 case "DSR":
1444                     switch (ifCapType) {
1445                         // TODO: it may be needed to add more cases clauses if the interface capabilities of a
1446                         //  port are extended in the config file
1447                         case "If1GEODU0":
1448                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1449                                 .setLayerProtocolQualifier(ODUTYPEODU0.VALUE)
1450                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1451                                 .build());
1452                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1453                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPEGigE.VALUE)
1454                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1455                                 .build());
1456                             break;
1457                         case "If10GEODU2e":
1458                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1459                                 .setLayerProtocolQualifier(ODUTYPEODU2E.VALUE)
1460                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1461                                 .build());
1462                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1463                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE10GigELAN.VALUE)
1464                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1465                                 .build());
1466                             break;
1467                         case "If10GEODU2":
1468                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1469                                 .setLayerProtocolQualifier(ODUTYPEODU2.VALUE)
1470                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1471                                 .build());
1472                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1473                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE10GigELAN.VALUE)
1474                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1475                                 .build());
1476                             break;
1477                         case "If10GE":
1478                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1479                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE10GigELAN.VALUE)
1480                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1481                                 .build());
1482                             break;
1483                         case "If100GEODU4":
1484                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1485                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE100GigE.VALUE)
1486                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1487                                 .build());
1488                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1489                                 .setLayerProtocolQualifier(ODUTYPEODU4.VALUE)
1490                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1491                                 .build());
1492                             break;
1493                         case "If100GE":
1494                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1495                                 .setLayerProtocolQualifier(DIGITALSIGNALTYPE100GigE.VALUE)
1496                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1497                                 .build());
1498                             break;
1499                         case "IfOCHOTU4ODU4":
1500                         case "IfOCH":
1501                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1502                                 .setLayerProtocolQualifier(ODUTYPEODU4.VALUE)
1503                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1504                                 .build());
1505                             break;
1506                         default:
1507                             LOG.error("IfCapability type not managed");
1508                             break;
1509                     }
1510                     break;
1511                 case "ODU":
1512                     switch (ifCapType) {
1513                         // TODO: it may be needed to add more cases clauses if the interface capabilities of a
1514                         //  port are extended in the config file
1515                         case "If1GEODU0":
1516                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1517                                 .setLayerProtocolQualifier(ODUTYPEODU0.VALUE)
1518                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1519                                 .build());
1520                             break;
1521                         case "If10GEODU2e":
1522                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1523                                 .setLayerProtocolQualifier(ODUTYPEODU2E.VALUE)
1524                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1525                                 .build());
1526                             break;
1527                         case "If10GEODU2":
1528                         case "If10GE":
1529                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1530                                 .setLayerProtocolQualifier(ODUTYPEODU2.VALUE)
1531                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1532                                 .build());
1533                             break;
1534                         case "If100GEODU4":
1535                         case "If100GE":
1536                         case "IfOCHOTU4ODU4":
1537                         case "IfOCH":
1538                             sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1539                                 .setLayerProtocolQualifier(ODUTYPEODU4.VALUE)
1540                                 .setNumberOfCepInstances(Uint64.valueOf(0))
1541                                 .build());
1542                             break;
1543                         default:
1544                             LOG.error("IfCapability type not managed");
1545                             break;
1546                     }
1547                     break;
1548                 case "PHOTONIC_MEDIA":
1549                     if (ifCapType.equals("IfOCHOTU4ODU4") || ifCapType.equals("IfOCH")) {
1550                         sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1551                             .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROTSiMC.VALUE)
1552                             .setNumberOfCepInstances(Uint64.valueOf(0))
1553                             .build());
1554                         sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
1555                             .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROMS.VALUE)
1556                             .setNumberOfCepInstances(Uint64.valueOf(0))
1557                             .build());
1558                     }
1559                     break;
1560                 default:
1561                     LOG.error("Layer Protocol Name is unknown {}", lpn.getName());
1562                     break;
1563             }
1564         }
1565         return sclpqiList;
1566     }
1567
1568     private String getNodeType(XpdrNodeTypes xponderType) {
1569         switch (xponderType.getIntValue()) {
1570             case 1:
1571                 return OpenroadmNodeType.TPDR.getName();
1572             case 2:
1573                 return OpenroadmNodeType.MUXPDR.getName();
1574             case 3:
1575                 return OpenroadmNodeType.SWITCH.getName();
1576             default:
1577                 LOG.info("XpdrType {} not supported", xponderType);
1578                 break;
1579         }
1580         return null;
1581     }
1582
1583     private void mergeNodeinTopology(Map<NodeKey, Node> nodeMap) {
1584         // TODO is this merge correct? Should we just merge topology by changing the nodes map??
1585         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
1586         LOG.info("Creating tapi node in TAPI topology context");
1587         InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
1588             .augmentation(Context1.class).child(TopologyContext.class)
1589             .child(Topology.class, new TopologyKey(this.tapiTopoUuid))
1590             .build();
1591
1592         Topology topology = new TopologyBuilder().setUuid(this.tapiTopoUuid).setNode(nodeMap).build();
1593
1594         // merge in datastore
1595         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topoIID,
1596                 topology);
1597         try {
1598             this.networkTransactionService.commit().get();
1599         } catch (InterruptedException | ExecutionException e) {
1600             LOG.error("Error populating TAPI topology: ", e);
1601         }
1602         LOG.info("Node added succesfully.");
1603     }
1604
1605     private void mergeLinkinTopology(Map<LinkKey, Link> linkMap) {
1606         // TODO is this merge correct? Should we just merge topology by changing the nodes map??
1607         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
1608         LOG.info("Creating tapi node in TAPI topology context");
1609         InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
1610             .augmentation(Context1.class).child(TopologyContext.class)
1611             .child(Topology.class, new TopologyKey(this.tapiTopoUuid))
1612             .build();
1613
1614         Topology topology = new TopologyBuilder().setUuid(this.tapiTopoUuid).setLink(linkMap).build();
1615
1616         // merge in datastore
1617         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topoIID,
1618                 topology);
1619         try {
1620             this.networkTransactionService.commit().get();
1621         } catch (InterruptedException | ExecutionException e) {
1622             LOG.error("Error populating TAPI topology: ", e);
1623         }
1624         LOG.info("Roadm Link added succesfully.");
1625     }
1626
1627     private void mergeSipsinContext(Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips) {
1628         // TODO is this merge correct? Should we just merge topology by changing the nodes map??
1629         // TODO: verify this is correct. Should we identify the context IID with the context UUID??
1630         try {
1631             ContextBuilder contextBuilder = new ContextBuilder();
1632             contextBuilder.setServiceInterfacePoint(sips);
1633             InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
1634             // merge in datastore
1635             this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, contextIID,
1636                     contextBuilder.build());
1637             this.networkTransactionService.commit().get();
1638             LOG.info("TAPI SIPs merged successfully.");
1639         } catch (InterruptedException | ExecutionException e) {
1640             LOG.error("Failed to merge TAPI Sips", e);
1641         }
1642     }
1643
1644     private void deleteLinkFromTopo(Uuid linkUuid) {
1645         // TODO: check if this IID is correct
1646         try {
1647             InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
1648                 .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
1649                     new TopologyKey(this.tapiTopoUuid)).child(Link.class, new LinkKey(linkUuid)).build();
1650             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, linkIID);
1651             this.networkTransactionService.commit().get();
1652             LOG.info("TAPI link deleted successfully.");
1653         } catch (InterruptedException | ExecutionException e) {
1654             LOG.error("Failed to delete TAPI link", e);
1655         }
1656     }
1657
1658     private void deleteNodeFromTopo(Uuid nodeUuid) {
1659         // TODO: check if this IID is correct
1660         try {
1661             InstanceIdentifier<Node> nodeIDD = InstanceIdentifier.builder(Context.class)
1662                 .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
1663                     new TopologyKey(this.tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid)).build();
1664             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, nodeIDD);
1665             this.networkTransactionService.commit().get();
1666             LOG.info("TAPI Node deleted successfully.");
1667         } catch (InterruptedException | ExecutionException e) {
1668             LOG.error("Failed to delete TAPI Node", e);
1669         }
1670     }
1671
1672     private void deleteSipFromTopo(Uuid sipUuid) {
1673         // TODO: check if this IID is correct
1674         try {
1675             InstanceIdentifier<ServiceInterfacePoint> sipIID = InstanceIdentifier.builder(Context.class)
1676                     .child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(sipUuid)).build();
1677             this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, sipIID);
1678             this.networkTransactionService.commit().get();
1679             LOG.info("TAPI SIP deleted successfully.");
1680         } catch (InterruptedException | ExecutionException e) {
1681             LOG.error("Failed to delete TAPI SIP", e);
1682         }
1683     }
1684
1685     private void updateConnectivityServicesState(Uuid sipUuid, String nodeId) {
1686         // TODO: check if this IID is correct
1687         InstanceIdentifier<ConnectivityContext> connectivitycontextIID = InstanceIdentifier.builder(Context.class)
1688             .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.Context1.class)
1689             .child(ConnectivityContext.class)
1690             .build();
1691         ConnectivityContext connContext = null;
1692         try {
1693             Optional<ConnectivityContext> optConnContext =
1694                     this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivitycontextIID)
1695                             .get();
1696             if (!optConnContext.isPresent()) {
1697                 LOG.error("Couldnt retrieve connectivity context from datastore");
1698                 return;
1699             }
1700             connContext = optConnContext.orElseThrow();
1701         } catch (InterruptedException | ExecutionException e) {
1702             LOG.error("Couldnt read connectivity context from datastore", e);
1703         }
1704         if (connContext == null) {
1705             LOG.error("Connectivity context is empty");
1706             return;
1707         }
1708         // Loop through services, check if the endpoint uuid is equal to the sip.
1709         // If so update state.
1710         Map<ConnectivityServiceKey, ConnectivityService> connServMap = connContext.getConnectivityService();
1711         Map<ConnectionKey, Connection> connMap = connContext.getConnection();
1712         if (connServMap != null) {
1713             for (ConnectivityService service:connServMap.values()) {
1714                 Map<EndPointKey, EndPoint> serviceEndPoints = service.getEndPoint();
1715                 if (serviceEndPoints.values().stream().anyMatch(endPoint -> endPoint.getServiceInterfacePoint()
1716                     .getServiceInterfacePointUuid().equals(sipUuid))) {
1717                     LOG.info("Service using SIP of node {} identified. Update state of service", nodeId);
1718                     ConnectivityService updService = new ConnectivityServiceBuilder(service)
1719                         .setAdministrativeState(AdministrativeState.LOCKED)
1720                         .setOperationalState(OperationalState.DISABLED)
1721                         .setLifecycleState(LifecycleState.PENDINGREMOVAL)
1722                         .build();
1723                     updateConnectivityService(updService);
1724                 }
1725             }
1726         }
1727         // Update state of connections
1728         if (connMap != null) {
1729             for (Connection connection:connMap.values()) {
1730                 if (connection.getName().values().stream().anyMatch(name -> name.getValue().contains(nodeId))) {
1731                     Connection updConn = new ConnectionBuilder(connection)
1732                         .setLifecycleState(LifecycleState.PENDINGREMOVAL)
1733                         .setOperationalState(OperationalState.DISABLED)
1734                         .build();
1735                     updateConnection(updConn);
1736                 }
1737             }
1738         }
1739     }
1740
1741     private void updateConnection(Connection updConn) {
1742         // TODO: check if this IID is correct
1743         InstanceIdentifier<Connection> connectionIID = InstanceIdentifier.builder(Context.class)
1744                 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.Context1.class)
1745                 .child(ConnectivityContext.class).child(Connection.class,
1746                         new ConnectionKey(updConn.getUuid())).build();
1747         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectionIID, updConn);
1748         try {
1749             this.networkTransactionService.commit().get();
1750         } catch (InterruptedException | ExecutionException e) {
1751             LOG.error("Error committing into datastore", e);
1752         }
1753     }
1754
1755     private void updateConnectivityService(ConnectivityService updService) {
1756         // TODO: check if this IID is correct
1757         InstanceIdentifier<ConnectivityService> connectivityserviceIID = InstanceIdentifier.builder(Context.class)
1758                 .augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.Context1.class)
1759                 .child(ConnectivityContext.class).child(ConnectivityService.class,
1760                         new ConnectivityServiceKey(updService.getUuid())).build();
1761         this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, connectivityserviceIID, updService);
1762         try {
1763             this.networkTransactionService.commit().get();
1764         } catch (InterruptedException | ExecutionException e) {
1765             LOG.error("Error committing into datastore", e);
1766         }
1767     }
1768 }