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