2 * Copyright © 2021 Nokia, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.tapi.topology;
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;
19 import java.util.Objects;
20 import java.util.Optional;
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;
149 public class TapiNetworkModelServiceImpl implements TapiNetworkModelService {
151 private static final Logger LOG = LoggerFactory.getLogger(TapiNetworkModelServiceImpl.class);
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<>();
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;
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);
181 LOG.info("Mapping of node {}: {}", orNodeId, node.getMapping().values());
183 // check type of device, check version and create node mapping
184 if (NodeTypes.Rdm.getIntValue() == node.getNodeInfo().getNodeType().getIntValue()) {
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));
192 List<String> nodeShardList = getRoadmNodelist(mappingList);
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);
203 LOG.error("unknown element");
206 // Transform LCPs into ONEP
207 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap =
208 new HashMap<>(transformDegToOnep(orNodeId, mapDeg));
209 onepMap.putAll(transformSrgToOnep(orNodeId, mapSrg));
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
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,
222 if (!rdm2rdmLinks.isEmpty()) {
223 mergeLinkinTopology(rdm2rdmLinks);
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());
243 // create switching pool
244 OduSwitchingPools oorOduSwitchingPool = createSwitchPoolForXpdr(
245 mapping.getXpdrType().getIntValue(), xpdrClMaps, xpdrNetMaps, xpdrNb);
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);
255 LOG.info("TAPI node for or node {} successfully merged", orNodeId);
257 // Device not managed yet
261 public void updateTapiTopology(String nodeId, Mapping mapping) {
262 List<Uuid> uuids = getChangedNodeUuids(nodeId, mapping);
264 List<Uuid> changedOneps = updateNeps(mapping, uuids);
265 updateLinks(changedOneps, mapping);
266 sendNotification(changedOneps, mapping);
268 LOG.info("Updated TAPI topology successfully.");
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)
280 notificationPublishService.putNotification(notification);
281 } catch (InterruptedException e) {
282 LOG.error("Could not send notification");
286 private Map<ChangedAttributesKey, ChangedAttributes> getChangedAttributes(List<Uuid> changedOneps,
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())
296 return changedAttributes;
299 private void updateLinks(List<Uuid> changedOneps, Mapping mapping) {
301 InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
302 .augmentation(Context1.class).child(TopologyContext.class)
303 .child(Topology.class, new TopologyKey(tapiTopoUuid))
305 Optional<Topology> optTopology = this.networkTransactionService
306 .read(LogicalDatastoreType.OPERATIONAL, topoIID).get();
307 if (optTopology.isEmpty()) {
308 LOG.error("Could not update TAPI links");
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);
325 this.networkTransactionService.commit().get();
326 } catch (InterruptedException | ExecutionException e) {
327 LOG.error("Could not update TAPI links");
331 private List<Uuid> updateNeps(Mapping mapping, List<Uuid> uuids) {
332 List<Uuid> changedOneps = new ArrayList<>();
333 for (Uuid nodeUuid : uuids) {
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))
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()))
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);
362 this.networkTransactionService.commit().get();
364 } catch (InterruptedException | ExecutionException e) {
365 LOG.error("Could not update TAPI NEP");
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()
377 ConnectionEndPoint cep = new ConnectionEndPointBuilder(entry.getValue())
378 .setOperationalState(transformOperState(mapping.getPortOperState())).build();
379 cepMap.put(entry.getKey(), cep);
382 return new CepListBuilder().setConnectionEndPoint(cepMap).build();
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()));
403 LOG.error("Updating this device is currently not supported");
409 private void updateSips(Mapping mapping, OwnedNodeEdgePoint onep) {
410 if (onep.getMappedServiceInterfacePoint() == null
411 || onep.getMappedServiceInterfacePoint().size() == 0) {
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()))
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);
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);
444 nodeMap.put(dsrNode.key(), dsrNode);
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);
456 nodeMap.put(otsiNode.key(), otsiNode);
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);
466 private OduSwitchingPools createSwitchPoolForXpdr(int xpdrType, List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
468 // todo: are switching pool correct here??
472 return createTpdrSwitchPool(xpdrNetMaps);
475 return createMuxSwitchPool(xpdrClMaps, xpdrNetMaps, xpdrNb);
478 return createSwtchSwitchPool(xpdrClMaps, xpdrNetMaps, xpdrNb);
480 LOG.warn("Xpdr type {} not supported", xpdrType);
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());
495 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> srgNeps =
496 createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), true,
497 transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()));
498 onepMap.putAll(srgNeps);
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());
514 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> degNeps =
515 createRoadmNeps(orNodeId, m.getLogicalConnectionPoint(), false,
516 transformOperState(m.getPortOperState()), transformAdminState(m.getPortAdminState()));
517 onepMap.putAll(degNeps);
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);
533 return nodeShardList;
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;
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);
554 topology = optTopology.orElseThrow();
555 } catch (InterruptedException | ExecutionException e) {
556 LOG.error("Couldnt read tapi topology from datastore", e);
558 if (topology == null) {
559 LOG.error("Topology is null, nothing to delete");
562 if (topology.getNode() == null) {
563 LOG.error("No nodes in topology");
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);
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());
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());
590 // Delete sips of sip map
591 InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
592 Context context = null;
594 Optional<Context> optContext = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL,
596 if (!optContext.isPresent()) {
597 LOG.error("No context object present in datastore.");
600 context = optContext.orElseThrow();
601 } catch (InterruptedException | ExecutionException e) {
602 LOG.error("Couldnt read tapi context from datastore", e);
604 if (context == null) {
605 LOG.error("Context is null, nothing to delete");
608 Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips = context.getServiceInterfacePoint();
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());
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)
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);
645 LOG.error("Undefined LayerProtocolName for {} node {}", nameMap.get(nameMap.keySet().iterator().next())
646 .getValueName(), nameMap.get(nameMap.keySet().iterator().next()).getValue());
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)
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")
661 return new NodeBuilder()
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")
681 private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createXpdrPhtnMdNeps(String nodeId,
682 List<Mapping> xpdrNetMaps) {
683 Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
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()))
696 List<SupportedIfCapability> newSupIfCapList =
697 new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
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);
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()))
717 List<SupportedIfCapability> newSupIfCapList =
718 new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
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);
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()))
738 List<SupportedIfCapability> newSupIfCapList =
739 new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
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);
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()));
765 if (OpenroadmNodeType.TPDR.getName().equalsIgnoreCase(xponderType.getName())) {
766 name = nameBldr.setValueName("100G-tpdr").build();
768 name = nameBldr.setValueName("NodeEdgePoint_C").build();
771 List<SupportedIfCapability> newSupIfCapList =
772 new ArrayList<>(xpdrClMaps.get(i).getSupportedInterfaceCapability());
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);
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()))
794 List<SupportedIfCapability> newSupIfCapList =
795 new ArrayList<>(xpdrNetMaps.get(i).getSupportedInterfaceCapability());
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);
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()))
818 List<SupportedIfCapability> newSupIfCapList =
819 new ArrayList<>(xpdrClMaps.get(i).getSupportedInterfaceCapability());
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);
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;
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;
843 private OwnedNodeEdgePoint createNep(Uuid nepUuid, String tpid, Map<NameKey, Name> nepNames,
844 LayerProtocolName nepProtocol, LayerProtocolName nodeProtocol, boolean withSip,
846 List<SupportedIfCapability> supportedInterfaceCapability,
847 OperationalState operState, AdministrativeState adminState) {
848 OwnedNodeEdgePointBuilder onepBldr = new OwnedNodeEdgePointBuilder()
850 .setLayerProtocolName(nepProtocol)
853 onepBldr.setMappedServiceInterfacePoint(createMSIP(1, nepProtocol, tpid, keyword,
854 supportedInterfaceCapability, operState, adminState));
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();
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))
877 OwnedNodeEdgePoint onep = new OwnedNodeEdgePointBuilder()
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)
887 onepMap.put(onep.key(), onep);
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))
896 OwnedNodeEdgePointBuilder onepBldr1 = new OwnedNodeEdgePointBuilder()
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);
906 onepBldr1.setMappedServiceInterfacePoint(createMSIP(1, LayerProtocolName.PHOTONICMEDIA,
907 tpId, String.join("+", orNodeId, TapiStringConstants.MC), null,
908 operState, adminState));
910 OwnedNodeEdgePoint onep1 = onepBldr1.build();
911 onepMap.put(onep1.key(), onep1);
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))
921 OwnedNodeEdgePoint onep2 = new OwnedNodeEdgePointBuilder()
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)
931 onepMap.put(onep2.key(), onep2);
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);
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))
964 return new ServiceInterfacePointBuilder()
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,
978 private Node createRoadmTapiNode(String orNodeId, Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> oneplist) {
980 Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", orNodeId,
981 TapiStringConstants.PHTNC_MEDIA)).getBytes(StandardCharsets.UTF_8)).toString());
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();
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)
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")
1002 return new NodeBuilder()
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")
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())
1032 nepMap.put(nep.key(), nep);
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)
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()))
1046 .setNodeEdgePoint(nepMap)
1048 nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1049 return nodeRuleGroupMap;
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()),
1061 linkMap.put(transiLink.key(), transiLink);
1063 // return a map of links and then we can do merge the corresponding link map into the topology context
1067 private OduSwitchingPools createTpdrSwitchPool(List<Mapping> xpdrNetMaps) {
1068 Map<NonBlockingListKey, NonBlockingList> nblMap = new HashMap<>();
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<>();
1078 NonBlockingList nbl = new NonBlockingListBuilder()
1079 .setNblNumber(Uint16.valueOf(count))
1082 nblMap.put(nbl.key(), nbl);
1085 return new OduSwitchingPoolsBuilder()
1086 .setNonBlockingList(nblMap)
1087 .setSwitchingPoolNumber(Uint16.valueOf(1))
1091 private OduSwitchingPools createSwtchSwitchPool(List<Mapping> xpdrClMaps, List<Mapping> xpdrNetMaps,
1093 Set<TpId> tpl = new HashSet<>();
1095 for (int i = 1; i <= xpdrClMaps.size(); i++) {
1096 tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.CLIENT + i);
1099 for (int i = 1; i <= xpdrNetMaps.size(); i++) {
1100 tpId = new TpId("XPDR" + xpdrNb + TapiStringConstants.NETWORK + i);
1103 Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
1104 NonBlockingList nbl = new NonBlockingListBuilder()
1105 .setNblNumber(Uint16.valueOf(1))
1108 nbMap.put(nbl.key(),nbl);
1110 return new OduSwitchingPoolsBuilder()
1111 .setSwitchingPoolNumber(Uint16.valueOf(1))
1112 .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
1113 .setNonBlockingList(nbMap)
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);
1123 tpId = new TpId("XPDR" + xpdrNb + "-NETWORK1");
1125 NonBlockingList nbl = new NonBlockingListBuilder()
1126 .setNblNumber(Uint16.valueOf(i))
1128 .setAvailableInterconnectBandwidth(Uint32.valueOf(xpdrNetMaps.size() * 10L))
1129 .setInterconnectBandwidthUnit(Uint32.valueOf(1000000000))
1131 nbMap.put(nbl.key(),nbl);
1133 return new OduSwitchingPoolsBuilder()
1134 .setSwitchingPoolNumber(Uint16.valueOf(1))
1135 .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
1136 .setNonBlockingList(nbMap)
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
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()))
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()))
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)
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")
1179 RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
1180 .setRiskCharacteristicName("risk characteristic")
1181 .setRiskIdentifierList(Set.of("risk identifier1", "risk identifier2"))
1183 NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
1185 UUID.nameUUIDFromBytes(("otsi node rule group " + count).getBytes(StandardCharsets.UTF_8))
1188 .setNodeEdgePoint(nepList)
1189 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1190 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1191 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1193 nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1196 return nodeRuleGroupMap;
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<>();
1209 LOG.info("ONEPL = {}", onepl.values());
1210 Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
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)
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)
1238 nepList.put(nep1.key(), nep1);
1239 nepList.put(nep2.key(), nep2);
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)
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")
1255 RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
1256 .setRiskCharacteristicName("risk characteristic")
1257 .setRiskIdentifierList(Set.of("risk identifier1", "risk identifier2"))
1259 NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
1261 UUID.nameUUIDFromBytes(("dsr node rule group " + count).getBytes(StandardCharsets.UTF_8))
1264 .setNodeEdgePoint(nepList)
1265 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1266 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1267 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1269 nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
1272 return nodeRuleGroupMap;
1275 private Set<LAYERPROTOCOLQUALIFIER> createSupportedLayerProtocolQualifier(
1276 List<SupportedIfCapability> sicList, LayerProtocolName lpn) {
1277 if (sicList == null) {
1278 return Set.of(PHOTONICLAYERQUALIFIEROMS.VALUE);
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)
1287 supIfMap.put(supIfCapa.key(), supIfCapa);
1289 Set<LAYERPROTOCOLQUALIFIER> sclpqList = new HashSet<>();
1290 for (SupportedInterfaceCapability sic : supIfMap.values()) {
1291 String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
1292 switch (lpn.getName()) {
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
1298 sclpqList.add(ODUTYPEODU0.VALUE);
1299 sclpqList.add(DIGITALSIGNALTYPEGigE.VALUE);
1302 sclpqList.add(ODUTYPEODU2E.VALUE);
1303 sclpqList.add(DIGITALSIGNALTYPE10GigELAN.VALUE);
1306 sclpqList.add(ODUTYPEODU2.VALUE);
1307 sclpqList.add(DIGITALSIGNALTYPE10GigELAN.VALUE);
1310 sclpqList.add(DIGITALSIGNALTYPE10GigELAN.VALUE);
1313 sclpqList.add(DIGITALSIGNALTYPE100GigE.VALUE);
1314 sclpqList.add(ODUTYPEODU4.VALUE);
1317 sclpqList.add(DIGITALSIGNALTYPE100GigE.VALUE);
1319 case "IfOCHOTU4ODU4":
1321 sclpqList.add(ODUTYPEODU4.VALUE);
1324 LOG.error("IfCapability type not managed");
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
1333 sclpqList.add(ODUTYPEODU0.VALUE);
1336 sclpqList.add(ODUTYPEODU2E.VALUE);
1340 sclpqList.add(ODUTYPEODU2.VALUE);
1344 case "IfOCHOTU4ODU4":
1346 sclpqList.add(ODUTYPEODU4.VALUE);
1349 LOG.error("IfCapability type not managed");
1353 case "PHOTONIC_MEDIA":
1354 if (ifCapType.equals("IfOCHOTU4ODU4") || ifCapType.equals("IfOCH")) {
1355 sclpqList.add(PHOTONICLAYERQUALIFIEROTSi.VALUE);
1356 sclpqList.add(PHOTONICLAYERQUALIFIEROMS.VALUE);
1360 LOG.error("Layer Protocol Name is unknown {}", lpn.getName());
1367 private String getNodeType(XpdrNodeTypes xponderType) {
1368 switch (xponderType.getIntValue()) {
1370 return OpenroadmNodeType.TPDR.getName();
1372 return OpenroadmNodeType.MUXPDR.getName();
1374 return OpenroadmNodeType.SWITCH.getName();
1376 LOG.info("XpdrType {} not supported", xponderType);
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))
1391 Topology topology = new TopologyBuilder().setUuid(this.tapiTopoUuid).setNode(nodeMap).build();
1393 // merge in datastore
1394 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topoIID,
1397 this.networkTransactionService.commit().get();
1398 } catch (InterruptedException | ExecutionException e) {
1399 LOG.error("Error populating TAPI topology: ", e);
1401 LOG.info("Node added succesfully.");
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))
1413 Topology topology = new TopologyBuilder().setUuid(this.tapiTopoUuid).setLink(linkMap).build();
1415 // merge in datastore
1416 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, topoIID,
1419 this.networkTransactionService.commit().get();
1420 } catch (InterruptedException | ExecutionException e) {
1421 LOG.error("Error populating TAPI topology: ", e);
1423 LOG.info("Roadm Link added succesfully.");
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??
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);
1443 private void deleteLinkFromTopo(Uuid linkUuid) {
1444 // TODO: check if this IID is correct
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);
1457 private void deleteNodeFromTopo(Uuid nodeUuid) {
1458 // TODO: check if this IID is correct
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);
1471 private void deleteSipFromTopo(Uuid sipUuid) {
1472 // TODO: check if this IID is correct
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);
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)
1490 ConnectivityContext connContext = null;
1492 Optional<ConnectivityContext> optConnContext =
1493 this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, connectivitycontextIID)
1495 if (!optConnContext.isPresent()) {
1496 LOG.error("Couldnt retrieve connectivity context from datastore");
1499 connContext = optConnContext.orElseThrow();
1500 } catch (InterruptedException | ExecutionException e) {
1501 LOG.error("Couldnt read connectivity context from datastore", e);
1503 if (connContext == null) {
1504 LOG.error("Connectivity context is empty");
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)
1522 updateConnectivityService(updService);
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)
1534 updateConnection(updConn);
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);
1548 this.networkTransactionService.commit().get();
1549 } catch (InterruptedException | ExecutionException e) {
1550 LOG.error("Error committing into datastore", e);
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);
1562 this.networkTransactionService.commit().get();
1563 } catch (InterruptedException | ExecutionException e) {
1564 LOG.error("Error committing into datastore", e);