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