2 * Copyright © 2020 Orange. 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
9 package org.opendaylight.transportpce.networkmodel.util;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.AbstractMap;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
17 import java.util.stream.Collectors;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.transportpce.common.NetworkUtils;
20 import org.opendaylight.transportpce.networkmodel.dto.OtnTopoNode;
21 import org.opendaylight.transportpce.networkmodel.dto.TopologyShard;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mapping.Mapping;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.network.Nodes;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.OduSwitchingPools;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.OduSwitchingPoolsBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.OduSwitchingPoolsKey;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListKey;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmTpType;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityKey;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODTU4TsAllocated;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODTUCnTs;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU0;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU2;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU2e;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU4;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OdtuTypeIdentity;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OduRateIdentity;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Link1;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Link1Builder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Node1Builder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.TerminationPoint1;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.TerminationPoint1Builder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.SwitchingPoolsBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.TpBandwidthSharingBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.XpdrAttributesBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.termination.point.TpSupportedInterfacesBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.termination.point.XpdrTpPortConnectionAttributesBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If100GE;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If100GEODU4;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GE;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GEODU2;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GEODU2e;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If1GE;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If1GEODU0;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If400GE;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCH;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOTUCnODUCn;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOtsiOtsigroup;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.SupportedIfCapability;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.switching.pool.types.rev191129.SwitchingPoolTypes;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev211210.xpdr.otn.tp.attributes.OdtuTpnPool;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev211210.xpdr.otn.tp.attributes.OdtuTpnPoolBuilder;
73 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.OtnLinkType;
74 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
75 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
76 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
77 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeBuilder;
78 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
79 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
80 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNodeBuilder;
81 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNodeKey;
82 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkBuilder;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
86 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointBuilder;
87 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointKey;
88 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.termination.point.SupportingTerminationPoint;
89 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.termination.point.SupportingTerminationPointBuilder;
90 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.termination.point.SupportingTerminationPointKey;
91 import org.opendaylight.yangtools.yang.common.Uint16;
92 import org.opendaylight.yangtools.yang.common.Uint32;
93 import org.slf4j.Logger;
94 import org.slf4j.LoggerFactory;
96 public final class OpenRoadmOtnTopology {
98 private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmOtnTopology.class);
99 private static final String CLIENT = "-CLIENT";
100 private static final String NETWORK = "-NETWORK";
101 private static final String XPDR = "-XPDR";
102 private static final String OTN_PARAMS_ERROR = "Error with otn parameters of supported link {}";
103 private static final int NB_TRIB_PORTS = 80;
104 private static final int NB_TRIB_SLOTS = 80;
106 private static final Map<String, Class<? extends OduRateIdentity>> RATE_MAP = Map.of(
107 "If100GEODU4", ODU4.class,
108 "IfOCHOTU4ODU4", ODU4.class,
109 "If1GEODU0", ODU0.class,
110 "If10GEODU2", ODU2.class,
111 "If10GEODU2e", ODU2e.class);
112 private static final Map<OtnLinkType, Long> OTNLINKTYPE_BW_MAP = Map.of(
113 OtnLinkType.ODTU4, 100000L,
114 OtnLinkType.ODUC4, 400000L,
115 OtnLinkType.ODUC3, 300000L,
116 OtnLinkType.ODUC2, 200000L);
117 private static final Map<OtnLinkType, Long> OTNLINKTYPE_OTU_BW_MAP = Map.of(
118 OtnLinkType.OTU4, 100000L,
119 OtnLinkType.OTUC4, 400000L);
120 private static final Map<Uint32, Long> SERVICERATE_BWINCR_MAP = Map.of(
121 Uint32.valueOf(1), 1000L,
122 Uint32.valueOf(10), 10000L,
123 Uint32.valueOf(100), 100000L);
124 private static final Map<Uint32, Class<? extends OdtuTypeIdentity>> SERVICERATE_ODTUTYPECLASS_MAP = Map.of(
125 Uint32.valueOf(1), ODTU4TsAllocated.class,
126 Uint32.valueOf(10), ODTU4TsAllocated.class,
127 Uint32.valueOf(100), ODTUCnTs.class);
129 private static Map<String, Class<? extends SupportedIfCapability>> supIfCapaMap = Map.ofEntries(
130 new AbstractMap.SimpleEntry<>("IfOtsiOtsigroup", IfOtsiOtsigroup.class),
131 new AbstractMap.SimpleEntry<>("IfOTUCnODUCn", IfOTUCnODUCn.class),
132 new AbstractMap.SimpleEntry<>("IfOCHOTU4ODU4", IfOCHOTU4ODU4.class),
133 new AbstractMap.SimpleEntry<>("IfOCH", IfOCH.class),
134 new AbstractMap.SimpleEntry<>("If100GEODU4", If100GEODU4.class),
135 new AbstractMap.SimpleEntry<>("If10GEODU2e", If10GEODU2e.class),
136 new AbstractMap.SimpleEntry<>("If10GEODU2", If10GEODU2.class),
137 new AbstractMap.SimpleEntry<>("If1GEODU0", If1GEODU0.class),
138 new AbstractMap.SimpleEntry<>("If400GE", If400GE.class),
139 new AbstractMap.SimpleEntry<>("If100GE", If100GE.class),
140 new AbstractMap.SimpleEntry<>("If10GE", If10GE.class),
141 new AbstractMap.SimpleEntry<>("If1GE", If1GE.class));
143 private OpenRoadmOtnTopology() {
146 public static TopologyShard createTopologyShard(Nodes mappingNode) {
147 List<Node> nodes = new ArrayList<>();
148 List<Link> links = new ArrayList<>();
149 Map<Integer, OtnTopoNode> xpdrMap = convertPortMappingToOtnNodeList(mappingNode);
150 for (OtnTopoNode node : xpdrMap.values()) {
151 switch (node.getNodeType()) {
153 nodes.add(createTpdr(node));
156 nodes.add(createMuxpdr(node));
159 nodes.add(createSwitch(node));
162 LOG.error("unknown otn node type {}", node.getNodeType().getName());
166 return new TopologyShard(nodes, links);
169 public static TopologyShard createOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ,
170 OtnLinkType linkType) {
172 return new TopologyShard(
174 OTNLINKTYPE_OTU_BW_MAP.containsKey(linkType)
175 ? initialiseOtnLinks(nodeA, tpA, nodeZ, tpZ, linkType)
179 public static TopologyShard createOtnLinks(
180 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp
182 OtnLinkType linkType) {
184 return new TopologyShard(
186 initialiseOtnLinks(notifLink.getATermination().getNodeId(),
187 notifLink.getATermination().getTpId(),
188 notifLink.getZTermination().getNodeId(),
189 notifLink.getZTermination().getTpId(),
193 public static TopologyShard createOtnLinks(
194 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp
196 List<Link> supportedOtu4links, List<TerminationPoint> supportedTPs, OtnLinkType linkType) {
198 if (OTNLINKTYPE_OTU_BW_MAP.containsKey(linkType)) {
199 return new TopologyShard(
202 notifLink.getATermination().getNodeId(), notifLink.getATermination().getTpId(),
203 notifLink.getZTermination().getNodeId(), notifLink.getZTermination().getTpId(), linkType));
204 } else if (OTNLINKTYPE_BW_MAP.containsKey(linkType)) {
205 List<Link> links = initialiseOtnLinks(
206 notifLink.getATermination().getNodeId(), notifLink.getATermination().getTpId(),
207 notifLink.getZTermination().getNodeId(), notifLink.getZTermination().getTpId(), linkType);
208 links.addAll(updateOtnLinkBwParameters(supportedOtu4links, linkType));
209 List<TerminationPoint> updatedTPs = new ArrayList<>();
210 for (TerminationPoint tp : supportedTPs) {
211 updatedTPs.add(updateTp(tp, true, linkType));
213 return new TopologyShard(null, links, updatedTPs);
219 public static TopologyShard createOtnLinks(List<Link> suppOtuLinks, List<TerminationPoint> oldTps,
220 OtnLinkType linkType) {
222 List<Link> links = new ArrayList<>();
223 for (Link link : suppOtuLinks) {
224 if (link.augmentation(Link1.class) == null) {
225 LOG.error("Error with OTN parameters of supported link {}", link.getLinkId().getValue());
228 if (!OTNLINKTYPE_BW_MAP.containsKey(linkType)) {
229 LOG.error("Error with link {} : unsupported OTN link type", link.getLinkId().getValue());
232 if (link.augmentation(Link1.class).getAvailableBandwidth().longValue() < OTNLINKTYPE_BW_MAP.get(linkType)) {
233 LOG.error("Error with link {} : unsufficient available bandwith", link.getLinkId().getValue());
236 links.add(updateOtnLinkBwParameters(link, 0L, OTNLINKTYPE_BW_MAP.get(linkType)));
238 if (links.size() == 2) {
239 links.addAll(initialiseOtnLinks(suppOtuLinks.get(0).getSource().getSourceNode().getValue(),
240 suppOtuLinks.get(0).getSource().getSourceTp().getValue(),
241 suppOtuLinks.get(0).getDestination().getDestNode().getValue(),
242 suppOtuLinks.get(0).getDestination().getDestTp().getValue(),
245 List<TerminationPoint> tps = new ArrayList<>();
246 for (TerminationPoint tp : oldTps) {
247 tps.add(updateTp(tp, true, linkType));
249 return links.size() == 4 && tps.size() == 2
250 ? new TopologyShard(null, links, tps)
251 : new TopologyShard(null, null, null);
254 public static TopologyShard updateOtnLinks(List<Link> suppOduLinks, List<TerminationPoint> oldTps,
255 Uint32 serviceRate, Short tribPortNb, Short minTribSlotNb, Short maxTribSlotNb, boolean isDeletion) {
257 List<Link> links = new ArrayList<>();
258 if (!SERVICERATE_BWINCR_MAP.containsKey(serviceRate)) {
259 LOG.warn("Error with not managed service rate {}", serviceRate.toString());
260 return new TopologyShard(null, null, null);
262 Long bwIncr = SERVICERATE_BWINCR_MAP.get(serviceRate);
263 for (Link link : suppOduLinks) {
264 if (link.augmentation(Link1.class) == null
265 || link.augmentation(Link1.class).getAvailableBandwidth() == null
266 || link.augmentation(Link1.class).getUsedBandwidth() == null) {
267 LOG.error(OTN_PARAMS_ERROR, link.getLinkId().getValue());
269 Uint32 avlBw = link.augmentation(Link1.class).getAvailableBandwidth();
270 Uint32 usedBw = link.augmentation(Link1.class).getUsedBandwidth();
271 if (avlBw.toJava() < bwIncr) {
276 ? updateOtnLinkBwParameters(link, avlBw.toJava() + bwIncr, usedBw.toJava() - bwIncr)
277 : updateOtnLinkBwParameters(link, avlBw.toJava() - bwIncr, usedBw.toJava() + bwIncr)
281 List<TerminationPoint> tps = new ArrayList<>();
282 for (TerminationPoint tp : oldTps) {
284 tps.add(updateNodeTpTsPool(tp, serviceRate, tribPortNb, minTribSlotNb, maxTribSlotNb, isDeletion));
287 if (links.isEmpty() || tps.isEmpty()) {
288 LOG.error("unable to update otn links");
289 return new TopologyShard(null, null, null);
291 return new TopologyShard(null, links, tps);
295 public static TopologyShard updateOtnLinks(List<Link> suppOtuLinks, boolean isDeletion) {
297 List<Link> links = new ArrayList<>();
298 for (Link link : suppOtuLinks) {
299 if (link.augmentation(Link1.class) == null
300 || link.augmentation(Link1.class).getAvailableBandwidth() == null
301 || link.augmentation(Link1.class).getUsedBandwidth() == null) {
302 LOG.error(OTN_PARAMS_ERROR, link.getLinkId().getValue());
306 ? updateOtnLinkBwParameters(link, Long.valueOf(100000), Long.valueOf(0))
307 : updateOtnLinkBwParameters(link, Long.valueOf(0), Long.valueOf(100000))
311 if (links.isEmpty()) {
312 LOG.error("unable to update otn links");
313 return new TopologyShard(null, null, null);
315 return new TopologyShard(null, links, null);
319 public static TopologyShard deleteOtnLinks(List<Link> suppOtuLinks, List<TerminationPoint> oldTps,
320 OtnLinkType linkType) {
322 List<Link> links = new ArrayList<>();
323 for (Link link : suppOtuLinks) {
324 if (link.augmentation(Link1.class) == null
325 || link.augmentation(
326 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.Link1.class) == null) {
327 LOG.error(OTN_PARAMS_ERROR, link.getLinkId().getValue());
328 return new TopologyShard(null, null, null);
330 OtnLinkType otnLinkType = link.augmentation(
331 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.Link1.class).getOtnLinkType();
332 if (!OTNLINKTYPE_OTU_BW_MAP.containsKey(otnLinkType)) {
333 //TODO shouldn't other link type listed in OTNLINKTYPE_BW_MAP be handled too ?
334 LOG.warn("Unexpected otn-link-type {} for link {}", otnLinkType, link.getLinkId());
337 links.add(updateOtnLinkBwParameters(link, OTNLINKTYPE_OTU_BW_MAP.get(otnLinkType) , 0L));
339 List<TerminationPoint> tps = new ArrayList<>();
340 for (TerminationPoint tp : oldTps) {
341 tps.add(updateTp(tp, false, linkType));
344 links.isEmpty() || tps.isEmpty()
345 ? new TopologyShard(null, null, null)
346 : new TopologyShard(null, links, tps);
349 private static List<Link> initialiseOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ,
350 OtnLinkType linkType) {
352 List<Link> links = new ArrayList<>();
353 String nodeATopo = formatNodeName(nodeA, tpA);
354 String nodeZTopo = formatNodeName(nodeZ, tpZ);
355 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.Link1 tpceLink1
356 = new org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.Link1Builder()
357 .setOtnLinkType(linkType).build();
358 Link1Builder otnLink1Bldr = new Link1Builder()
359 .setUsedBandwidth(Uint32.valueOf(0));
360 if (OTNLINKTYPE_OTU_BW_MAP.containsKey(linkType)) {
361 otnLink1Bldr.setAvailableBandwidth(Uint32.valueOf(OTNLINKTYPE_OTU_BW_MAP.get(linkType)));
362 } else if (OTNLINKTYPE_BW_MAP.containsKey(linkType)) {
363 otnLink1Bldr.setAvailableBandwidth(Uint32.valueOf(OTNLINKTYPE_BW_MAP.get(linkType)));
365 LOG.error("unable to set available bandwidth to unknown link type");
368 LinkBuilder ietfLinkAZBldr = TopologyUtils.createLink(nodeATopo, nodeZTopo, tpA, tpZ, linkType.getName());
369 links.add(ietfLinkAZBldr
370 .addAugmentation(tpceLink1)
371 .addAugmentation(otnLink1Bldr.build())
373 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1Builder(
374 ietfLinkAZBldr.augmentation(
375 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1.class))
376 .setLinkType(OpenroadmLinkType.OTNLINK)
377 .setOperationalState(State.InService)
378 .setAdministrativeState(AdminStates.InService)
382 LinkBuilder ietfLinkZABldr = TopologyUtils.createLink(nodeZTopo, nodeATopo, tpZ, tpA, linkType.getName());
383 links.add(ietfLinkZABldr
384 .addAugmentation(tpceLink1)
385 .addAugmentation(otnLink1Bldr.build())
387 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1Builder(
388 ietfLinkZABldr.augmentation(
389 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1.class))
390 .setLinkType(OpenroadmLinkType.OTNLINK)
391 .setOperationalState(State.InService)
392 .setAdministrativeState(AdminStates.InService)
398 private static Link updateOtnLinkBwParameters(Link link, Long availBw, Long usedBw) {
400 LOG.debug("in updateOtnLinkBwParameters with availBw = {}, usedBw = {}", availBw, usedBw);
401 return new LinkBuilder(link)
403 new Link1Builder(link.augmentation(Link1.class))
404 .setAvailableBandwidth(Uint32.valueOf(availBw))
405 .setUsedBandwidth(Uint32.valueOf(usedBw))
410 private static List<Link> updateOtnLinkBwParameters(List<Link> supportedLinks, OtnLinkType linkType) {
412 LOG.debug("in updateOtnLinkBwParameters with supportedLinks = {}, linkType = {}", supportedLinks, linkType);
413 List<Link> updatedlinks = new ArrayList<>();
414 for (Link link : supportedLinks) {
416 new LinkBuilder(link)
417 .addAugmentation(new Link1Builder(link.augmentation(Link1.class))
418 .setAvailableBandwidth(Uint32.valueOf(0))
420 OTNLINKTYPE_BW_MAP.containsKey(linkType)
421 ? Uint32.valueOf(OTNLINKTYPE_BW_MAP.get(linkType))
429 private static TerminationPoint updateTp(TerminationPoint originalTp, boolean addingTsTpnPoolTermination,
430 OtnLinkType linkType) {
432 LOG.debug("in updateTp");
433 TerminationPointBuilder tpBldr = new TerminationPointBuilder(originalTp);
434 TerminationPoint1Builder otnTp1Bldr =
435 new TerminationPoint1Builder(tpBldr.augmentation(TerminationPoint1.class));
436 XpdrTpPortConnectionAttributesBuilder xtpcaBldr =
437 new XpdrTpPortConnectionAttributesBuilder(otnTp1Bldr.getXpdrTpPortConnectionAttributes());
438 if (addingTsTpnPoolTermination) {
439 List<Uint16> tsPool = new ArrayList<>();
440 for (int i = 1; i <= NB_TRIB_SLOTS; i++) {
441 tsPool.add(Uint16.valueOf(i));
443 xtpcaBldr.setTsPool(tsPool);
444 List<Uint16> tpnPool = new ArrayList<>();
445 int nbTribPort = NB_TRIB_PORTS;
446 if (OtnLinkType.ODUC4.equals(linkType)) {
449 for (int i = 1; i <= nbTribPort; i++) {
450 tpnPool.add(Uint16.valueOf(i));
452 OdtuTpnPool oduTpnPool = new OdtuTpnPoolBuilder()
453 .setOdtuType(ODTU4TsAllocated.class)
456 xtpcaBldr.setOdtuTpnPool(ImmutableMap.of(oduTpnPool.key(),oduTpnPool));
458 xtpcaBldr.setTsPool(null);
459 xtpcaBldr.setOdtuTpnPool(ImmutableMap.of());
461 return tpBldr.addAugmentation(otnTp1Bldr.setXpdrTpPortConnectionAttributes(xtpcaBldr.build()).build()).build();
464 private static TerminationPoint updateNodeTpTsPool(TerminationPoint tp, Uint32 serviceRate, Short tribPortNb,
465 Short minTribSlotNb, Short maxTribSlotNb, boolean isDeletion) {
467 LOG.debug("in updateNodeTpTsPool");
468 TerminationPointBuilder tpBldr = new TerminationPointBuilder(tp);
470 XpdrTpPortConnectionAttributesBuilder xtpcaBldr =
471 new XpdrTpPortConnectionAttributesBuilder(
472 tpBldr.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes());
473 List<Uint16> tsPool = new ArrayList<>(xtpcaBldr.getTsPool());
475 for (int i = minTribSlotNb; i <= maxTribSlotNb; i++) {
476 tsPool.add(Uint16.valueOf(i));
479 for (int i = minTribSlotNb; i <= maxTribSlotNb; i++) {
480 tsPool.remove(Uint16.valueOf(i));
483 xtpcaBldr.setTsPool(tsPool);
484 List<Uint16> tpnPool;
485 List<OdtuTpnPool> odtuTpnPoolValues = new ArrayList<>(xtpcaBldr.getOdtuTpnPool().values());
486 if (odtuTpnPoolValues.get(0).getTpnPool() == null) {
487 tpnPool = new ArrayList<>();
489 tpnPool = new ArrayList<>(odtuTpnPoolValues.get(0).getTpnPool());
491 tpnPool.add(Uint16.valueOf(tribPortNb));
493 tpnPool.remove(Uint16.valueOf(tribPortNb));
496 Class<? extends OdtuTypeIdentity> odtuType;
497 if (SERVICERATE_ODTUTYPECLASS_MAP.containsKey(serviceRate)) {
498 odtuType = SERVICERATE_ODTUTYPECLASS_MAP.get(serviceRate);
501 LOG.warn("Unable to set the odtu-type");
503 OdtuTpnPool odtuTpnPool = new OdtuTpnPoolBuilder()
504 .setOdtuType(odtuType)
509 new TerminationPoint1Builder(tp.augmentation(TerminationPoint1.class))
510 .setXpdrTpPortConnectionAttributes(
512 .setOdtuTpnPool(ImmutableMap.of(odtuTpnPool.key(),odtuTpnPool))
518 private static Map<Integer, OtnTopoNode> convertPortMappingToOtnNodeList(Nodes mappingNode) {
520 List<Mapping> networkMappings =
521 mappingNode.nonnullMapping().values().stream()
522 .filter(k -> k.getLogicalConnectionPoint().contains("NETWORK"))
523 .collect(Collectors.toList());
524 Map<Integer, OtnTopoNode> xpdrMap = new HashMap<>();
525 for (Mapping mapping : networkMappings) {
526 Integer xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
527 if (!xpdrMap.containsKey(xpdrNb)) {
528 List<Mapping> xpdrNetMaps =
529 mappingNode.nonnullMapping().values().stream()
530 .filter(k -> k.getLogicalConnectionPoint().contains("XPDR" + xpdrNb + NETWORK))
531 .collect(Collectors.toList());
532 List<Mapping> xpdrClMaps =
533 mappingNode.nonnullMapping().values().stream()
534 .filter(k -> k.getLogicalConnectionPoint().contains("XPDR" + xpdrNb + CLIENT))
535 .collect(Collectors.toList());
539 mappingNode.getNodeId(),
540 mappingNode.getNodeInfo().getNodeClli(),
542 mapping.getXponderType() == null
544 : mapping.getXponderType(),
545 fillConnectionMapLcp(xpdrNetMaps),
546 fillConnectionMapLcp(xpdrClMaps),
552 LOG.debug("there are {} xpdr to build", xpdrMap.size());
553 xpdrMap.forEach((k, v) -> LOG.debug("xpdr {} = {} - {} - {} - {}",
554 k, v.getNodeId(), v.getNodeType(), v.getNbTpClient(), v.getNbTpNetwork()));
558 private static Map<String, String> fillConnectionMapLcp(List<Mapping> mappingList) {
560 Map<String, String> xpdrConnectionMap = new HashMap<>();
561 for (Mapping map : mappingList) {
562 xpdrConnectionMap.put(map.getLogicalConnectionPoint(), map.getConnectionMapLcp());
564 return xpdrConnectionMap;
567 private static Node createTpdr(OtnTopoNode node) {
568 Map<TerminationPointKey,TerminationPoint> tpMap = new HashMap<>();
569 createTP(tpMap, node, OpenroadmTpType.XPONDERCLIENT, false);
570 createTP(tpMap, node, OpenroadmTpType.XPONDERNETWORK, true);
572 return new NodeBuilder()
573 .setNodeId(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
574 .withKey(new NodeKey(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb())))
575 .setSupportingNode(createSupportingNodes(node))
579 new XpdrAttributesBuilder()
580 .setXpdrNumber(Uint16.valueOf(node.getXpdrNb()))
584 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1Builder()
585 .setNodeType(OpenroadmNodeType.TPDR)
586 .setOperationalState(State.InService)
587 .setAdministrativeState(AdminStates.InService)
590 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
592 .setTerminationPoint(tpMap)
597 private static Node createMuxpdr(OtnTopoNode node) {
599 // prepare otn-topology node augmentation
600 // TODO: will need to be completed
601 Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
602 for (int i = 1; i <= node.getNbTpClient(); i++) {
603 List<TpId> tpList = new ArrayList<>();
604 tpList.add(new TpId("XPDR" + node.getXpdrNb() + CLIENT + i));
605 tpList.add(new TpId("XPDR" + node.getXpdrNb() + "-NETWORK1"));
606 NonBlockingList nbl = new NonBlockingListBuilder()
607 .setNblNumber(Uint16.valueOf(i))
609 .setAvailableInterconnectBandwidth(Uint32.valueOf(node.getNbTpNetwork() * 10L))
610 .setInterconnectBandwidthUnit(Uint32.valueOf(1000000000))
612 nbMap.put(nbl.key(),nbl);
614 OduSwitchingPools oduSwitchPool = new OduSwitchingPoolsBuilder()
615 .setSwitchingPoolNumber(Uint16.valueOf(1))
616 .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
617 .setNonBlockingList(nbMap)
619 Map<TerminationPointKey, TerminationPoint> tpMap = new HashMap<>();
620 createTP(tpMap, node, OpenroadmTpType.XPONDERCLIENT, true);
621 createTP(tpMap, node, OpenroadmTpType.XPONDERNETWORK, true);
623 return new NodeBuilder()
624 .setNodeId(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
625 .withKey(new NodeKey(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb())))
626 .setSupportingNode(createSupportingNodes(node))
629 .setTpBandwidthSharing(new TpBandwidthSharingBuilder().build())
631 new XpdrAttributesBuilder()
632 .setXpdrNumber(Uint16.valueOf(node.getXpdrNb()))
635 new SwitchingPoolsBuilder()
636 .setOduSwitchingPools(Map.of(oduSwitchPool.key(),oduSwitchPool))
640 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1Builder()
641 .setNodeType(OpenroadmNodeType.MUXPDR)
642 .setAdministrativeState(AdminStates.InService)
643 .setOperationalState(State.InService)
646 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
648 .setTerminationPoint(tpMap)
653 private static Node createSwitch(OtnTopoNode node) {
655 List<TpId> tpl = new ArrayList<>();
656 for (int i = 1; i <= node.getNbTpClient(); i++) {
657 tpl.add(new TpId("XPDR" + node.getXpdrNb() + CLIENT + i));
659 for (int i = 1; i <= node.getNbTpNetwork(); i++) {
660 tpl.add(new TpId("XPDR" + node.getXpdrNb() + NETWORK + i));
662 Map<NonBlockingListKey, NonBlockingList> nbMap = new HashMap<>();
663 NonBlockingList nbl = new NonBlockingListBuilder()
664 .setNblNumber(Uint16.valueOf(1))
667 nbMap.put(nbl.key(),nbl);
668 OduSwitchingPools oduSwitchPool = new OduSwitchingPoolsBuilder()
669 .setSwitchingPoolNumber(Uint16.valueOf(1))
670 .setSwitchingPoolType(SwitchingPoolTypes.NonBlocking)
671 .setNonBlockingList(nbMap)
673 Map<OduSwitchingPoolsKey, OduSwitchingPools> oduSwitchPoolList = new HashMap<>();
674 oduSwitchPoolList.put(oduSwitchPool.key(),oduSwitchPool);
675 Map<TerminationPointKey, TerminationPoint> tpMap = new HashMap<>();
676 createTP(tpMap, node, OpenroadmTpType.XPONDERCLIENT, true);
677 createTP(tpMap, node, OpenroadmTpType.XPONDERNETWORK, true);
679 return new NodeBuilder()
680 .setNodeId(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
681 .withKey(new NodeKey(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb())))
682 .setSupportingNode(createSupportingNodes(node))
685 .setTpBandwidthSharing(new TpBandwidthSharingBuilder().build())
687 new XpdrAttributesBuilder()
688 .setXpdrNumber(Uint16.valueOf(node.getXpdrNb()))
691 new SwitchingPoolsBuilder()
692 .setOduSwitchingPools(oduSwitchPoolList)
696 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1Builder()
697 .setNodeType(OpenroadmNodeType.SWITCH)
698 .setOperationalState(State.InService)
699 .setAdministrativeState(AdminStates.InService)
702 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
704 .setTerminationPoint(tpMap)
709 private static void createTP(Map<TerminationPointKey, TerminationPoint> tpMap,
710 OtnTopoNode node, OpenroadmTpType tpType, boolean withRate) {
712 List<Mapping> mappings = null;
715 mappings = node.getXpdrNetMappings();
718 mappings = node.getXpdrClMappings();
721 LOG.error("Error with Termination Point type {}", tpType);
724 fillTpMap(tpMap, node, tpType, withRate, mappings);
727 private static void fillTpMap(Map<TerminationPointKey, TerminationPoint> tpMap, OtnTopoNode node,
728 OpenroadmTpType tpType, boolean withRate, List<Mapping> mappings) {
730 for (Mapping mapping : mappings) {
731 // openroadm-otn-topoology augmentation
732 Map<SupportedInterfaceCapabilityKey, SupportedInterfaceCapability> supIfMap = new HashMap<>();
733 TerminationPoint1Builder otnTp1Bldr = new TerminationPoint1Builder();
734 if (mapping.getSupportedInterfaceCapability() == null) {
735 LOG.warn("mapping {} of node {} has no if-cap-type",
736 mapping.getLogicalConnectionPoint(), node.getNodeId());
738 XpdrTpPortConnectionAttributesBuilder xtpcaBldr = new XpdrTpPortConnectionAttributesBuilder();
739 for (Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
740 .SupportedIfCapability> supInterCapa : mapping.getSupportedInterfaceCapability()) {
741 SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
742 .withKey(new SupportedInterfaceCapabilityKey(convertSupIfCapa(supInterCapa.getSimpleName())))
743 .setIfCapType(convertSupIfCapa(supInterCapa.getSimpleName()))
745 supIfMap.put(supIfCapa.key(), supIfCapa);
747 otnTp1Bldr.setTpSupportedInterfaces(
748 new TpSupportedInterfacesBuilder()
749 .setSupportedInterfaceCapability(supIfMap)
752 //TODO: It is not logical to assign a priori one of the possible rate to the TP.
753 //Would be worth assigning per default "unallocated" at the tp creation step,
754 //and updating it with correct rate when it supports a specific service.
756 otnTp1Bldr.setXpdrTpPortConnectionAttributes(
757 xtpcaBldr.setRate(fixRate(mapping.getSupportedInterfaceCapability())).build());
763 new TpId(mapping.getLogicalConnectionPoint()),
766 new org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.TerminationPoint1Builder(),
771 private static void setclientNwTpAttr(Map<TerminationPointKey, TerminationPoint> tpMap, OtnTopoNode node, TpId tpId,
772 OpenroadmTpType tpType, TerminationPoint1 otnTp1,
773 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.TerminationPoint1Builder tpceTp1Bldr,
778 if (node.getXpdrNetConnectionMap().get(tpId.getValue()) != null) {
779 tpceTp1Bldr.setAssociatedConnectionMapPort(node.getXpdrNetConnectionMap().get(tpId.getValue()));
781 SupportingTerminationPoint stp = new SupportingTerminationPointBuilder()
782 .setNetworkRef(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))
783 .setNodeRef(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
786 TerminationPoint ietfTpNw =
787 buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, Map.of(stp.key(), stp), mapping);
788 tpMap.put(ietfTpNw.key(),ietfTpNw);
791 if (node.getXpdrCliConnectionMap().get(tpId.getValue()) != null) {
792 tpceTp1Bldr.setAssociatedConnectionMapPort(node.getXpdrCliConnectionMap().get(tpId.getValue()));
794 TerminationPoint ietfTpCl = buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, null, mapping);
795 tpMap.put(ietfTpCl.key(),ietfTpCl);
798 LOG.error("Undefined tpType for Termination point {} of {}", tpId.getValue(), node.getNodeId());
803 private static Class<? extends OduRateIdentity> fixRate(List<Class<? extends
804 org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.SupportedIfCapability>> list) {
806 for (Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.SupportedIfCapability>
808 if (RATE_MAP.containsKey(class1.getSimpleName())) {
809 return RATE_MAP.get(class1.getSimpleName());
815 private static Map<SupportingNodeKey,SupportingNode> createSupportingNodes(OtnTopoNode node) {
817 SupportingNode suppNode1 = new SupportingNodeBuilder()
818 .setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
819 .setNodeRef(new NodeId(node.getNodeId()))
821 new SupportingNodeKey(
822 new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID),
823 new NodeId(node.getNodeId())))
825 SupportingNode suppNode2 = new SupportingNodeBuilder()
826 .setNetworkRef(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))
827 .setNodeRef(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
829 new SupportingNodeKey(
830 new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID),
831 new NodeId(node.getNodeId() + XPDR + node.getXpdrNb())))
833 SupportingNode suppNode3 = new SupportingNodeBuilder()
834 .setNetworkRef(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))
835 .setNodeRef(new NodeId(node.getClli()))
837 new SupportingNodeKey(
838 new NetworkId(NetworkUtils.CLLI_NETWORK_ID),
839 new NodeId(node.getClli())))
841 Map<SupportingNodeKey,SupportingNode> suppNodeMap = new HashMap<>();
842 suppNodeMap.put(suppNode1.key(),suppNode1);
843 suppNodeMap.put(suppNode2.key(),suppNode2);
844 suppNodeMap.put(suppNode3.key(),suppNode3);
848 private static TerminationPoint buildIetfTp(
849 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.TerminationPoint1Builder tpceTp1Bldr,
850 TerminationPoint1 otnTp1, OpenroadmTpType tpType, TpId tpId,
851 Map<SupportingTerminationPointKey, SupportingTerminationPoint> supportTpMap, Mapping mapping) {
853 TerminationPointBuilder ietfTpBldr = new TerminationPointBuilder();
854 if (tpceTp1Bldr.getAssociatedConnectionMapPort() != null) {
855 ietfTpBldr.addAugmentation(tpceTp1Bldr.build());
857 if (supportTpMap != null) {
858 ietfTpBldr.setSupportingTerminationPoint(supportTpMap);
862 .withKey(new TerminationPointKey(tpId))
863 .addAugmentation(otnTp1)
865 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder()
867 .setAdministrativeState(TopologyUtils.setNetworkAdminState(mapping.getPortAdminState()))
868 .setOperationalState(TopologyUtils.setNetworkOperState(mapping.getPortOperState()))
873 private static String formatNodeName(String nodeName, String tpName) {
875 return nodeName.contains(XPDR)
877 : new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
880 private static Class<? extends SupportedIfCapability> convertSupIfCapa(String ifCapType) {
881 if (!supIfCapaMap.containsKey(ifCapType)) {
884 return supIfCapaMap.get(ifCapType);