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