Update portmapping YANG model
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / util / OpenRoadmOtnTopology.java
index 101e52c2f85b0b1fbfe032f82f946f7b9c3f855c..3f1b5388a6a2c96475560a45608ace57ece6f6fa 100644 (file)
@@ -18,8 +18,8 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.networkmodel.dto.OtnTopoNode;
 import org.opendaylight.transportpce.networkmodel.dto.TopologyShard;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
@@ -37,6 +37,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.x
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODTU4TsAllocated;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU0;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU2;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU2e;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU4;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OduRateIdentity;
@@ -62,8 +63,10 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2e;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If1GE;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If1GEODU0;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If400GE;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCH;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOTUCnODUCn;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.SupportedIfCapability;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.switching.pool.types.rev191129.SwitchingPoolTypes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev200529.xpdr.otn.tp.attributes.OdtuTpnPool;
@@ -601,34 +604,39 @@ public final class OpenRoadmOtnTopology {
         for (Mapping mapping : mappings) {
             // openroadm-otn-topoology augmentation
             Map<SupportedInterfaceCapabilityKey, SupportedInterfaceCapability> supIfMap = new HashMap<>();
-            for (Class<? extends SupportedIfCapability> supInterCapa : mapping.getSupportedInterfaceCapability()) {
-                SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
-                    .withKey(new SupportedInterfaceCapabilityKey(convertSupIfCapa(supInterCapa)))
-                    .setIfCapType(convertSupIfCapa(supInterCapa))
+            TerminationPoint1Builder otnTp1Bldr = new TerminationPoint1Builder();
+            if (mapping.getSupportedInterfaceCapability() != null) {
+                XpdrTpPortConnectionAttributesBuilder xtpcaBldr = new XpdrTpPortConnectionAttributesBuilder();
+                for (Class<? extends SupportedIfCapability> supInterCapa : mapping.getSupportedInterfaceCapability()) {
+                    SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
+                        .withKey(new SupportedInterfaceCapabilityKey(convertSupIfCapa(supInterCapa)))
+                        .setIfCapType(convertSupIfCapa(supInterCapa))
+                        .build();
+                    supIfMap.put(supIfCapa.key(), supIfCapa);
+                }
+                TpSupportedInterfaces tpSupIf = new TpSupportedInterfacesBuilder()
+                    .setSupportedInterfaceCapability(supIfMap)
                     .build();
-                supIfMap.put(supIfCapa.key(), supIfCapa);
-            }
-            TpSupportedInterfaces tpSupIf = new TpSupportedInterfacesBuilder()
-                .setSupportedInterfaceCapability(supIfMap)
-                .build();
-            XpdrTpPortConnectionAttributesBuilder xtpcaBldr = new XpdrTpPortConnectionAttributesBuilder();
-            if (withRate) {
-                xtpcaBldr.setRate(fixRate(mapping.getSupportedInterfaceCapability().get(0)));
+                otnTp1Bldr.setTpSupportedInterfaces(tpSupIf);
+                if (withRate) {
+                    xtpcaBldr.setRate(fixRate(mapping.getSupportedInterfaceCapability().get(0)));
+                    otnTp1Bldr.setXpdrTpPortConnectionAttributes(xtpcaBldr.build());
+                }
+            } else {
+                LOG.warn("mapping {} of node {} has no if-cap-type", mapping.getLogicalConnectionPoint(),
+                    node.getNodeId());
             }
-            TerminationPoint1 otnTp1 = new TerminationPoint1Builder()
-                .setTpSupportedInterfaces(tpSupIf)
-                .setXpdrTpPortConnectionAttributes(xtpcaBldr.build())
-                .build();
             org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1Builder tpceTp1Bldr =
                 new org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1Builder();
             TpId tpId = new TpId(mapping.getLogicalConnectionPoint());
-            setclientNwTpAttr(tpMap, node, tpId, tpType, otnTp1, tpceTp1Bldr);
+            setclientNwTpAttr(tpMap, node, tpId, tpType, otnTp1Bldr.build(), tpceTp1Bldr, mapping);
         }
     }
 
     private static void setclientNwTpAttr(Map<TerminationPointKey, TerminationPoint> tpMap, OtnTopoNode node, TpId tpId,
             OpenroadmTpType tpType, TerminationPoint1 otnTp1,
-            org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1Builder tpceTp1Bldr) {
+            org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1Builder tpceTp1Bldr,
+            Mapping mapping) {
         switch (tpType) {
             case XPONDERNETWORK:
                 if (node.getXpdrNetConnectionMap().get(tpId.getValue()) != null) {
@@ -639,14 +647,15 @@ public final class OpenRoadmOtnTopology {
                     .setNodeRef(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
                     .setTpRef(tpId.getValue())
                     .build();
-                TerminationPoint ietfTpNw = buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, Map.of(stp.key(), stp));
+                TerminationPoint ietfTpNw = buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, Map.of(stp.key(), stp),
+                    mapping);
                 tpMap.put(ietfTpNw.key(),ietfTpNw);
                 break;
             case XPONDERCLIENT:
                 if (node.getXpdrCliConnectionMap().get(tpId.getValue()) != null) {
                     tpceTp1Bldr.setAssociatedConnectionMapPort(node.getXpdrCliConnectionMap().get(tpId.getValue()));
                 }
-                TerminationPoint ietfTpCl = buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, null);
+                TerminationPoint ietfTpCl = buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, null, mapping);
                 tpMap.put(ietfTpCl.key(),ietfTpCl);
                 break;
             default:
@@ -663,6 +672,8 @@ public final class OpenRoadmOtnTopology {
                 return ODU4.class;
             case "If1GEODU0":
                 return ODU0.class;
+            case "If10GEODU2":
+                return ODU2.class;
             case "If10GEODU2e":
                 return ODU2e.class;
             default:
@@ -673,24 +684,28 @@ public final class OpenRoadmOtnTopology {
     private static Class<? extends SupportedIfCapability> convertSupIfCapa(Class<? extends
             SupportedIfCapability> ifCapType) {
         switch (ifCapType.getSimpleName()) {
-            case "If100GEODU4":
-                return If100GEODU4.class;
+            case "IfOTUCnODUCn":
+                return IfOTUCnODUCn.class;
             case "IfOCHOTU4ODU4":
                 return IfOCHOTU4ODU4.class;
-            case "If1GEODU0":
-                return If1GEODU0.class;
+            case "IfOCH":
+                return IfOCH.class;
+            case "If100GEODU4":
+                return If100GEODU4.class;
             case "If10GEODU2e":
                 return If10GEODU2e.class;
             case "If10GEODU2":
                 return If10GEODU2.class;
+            case "If1GEODU0":
+                return If1GEODU0.class;
+            case "If400GE":
+                return If400GE.class;
             case "If100GE":
                 return If100GE.class;
             case "If10GE":
                 return If10GE.class;
             case "If1GE":
                 return If1GE.class;
-            case "IfOCH":
-                return IfOCH.class;
             default:
                 return null;
         }
@@ -725,7 +740,7 @@ public final class OpenRoadmOtnTopology {
     private static TerminationPoint buildIetfTp(
         org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1Builder tpceTp1Bldr,
         TerminationPoint1 otnTp1, OpenroadmTpType tpType, TpId tpId,
-        Map<SupportingTerminationPointKey, SupportingTerminationPoint> supportTpMap) {
+        Map<SupportingTerminationPointKey, SupportingTerminationPoint> supportTpMap, Mapping mapping) {
 
         TerminationPointBuilder ietfTpBldr = new TerminationPointBuilder();
         if (tpceTp1Bldr.getAssociatedConnectionMapPort() != null) {
@@ -737,8 +752,8 @@ public final class OpenRoadmOtnTopology {
         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1 ocnTp =
             new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1Builder()
                     .setTpType(tpType)
-                    .setAdministrativeState(AdminStates.InService)
-                    .setOperationalState(State.InService)
+                    .setAdministrativeState(TopologyUtils.setNetworkAdminState(mapping.getPortAdminState()))
+                    .setOperationalState(TopologyUtils.setNetworkOperState(mapping.getPortOperState()))
                     .build();
 
         ietfTpBldr.setTpId(tpId)