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