X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=networkmodel%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnetworkmodel%2FR2RLinkDiscovery.java;h=39f26e2c4ef814956dedb18d87e860e13f80ac7e;hb=268165cb2822b6ce4c55f00cac63eed2bb222ec7;hp=7673e653fa1de61e326b02ef43a657b1d78ab605;hpb=c8c92c9ac1c175fe200dd347081a8395820798c8;p=transportpce.git diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/R2RLinkDiscovery.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/R2RLinkDiscovery.java index 7673e653f..39f26e2c4 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/R2RLinkDiscovery.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/R2RLinkDiscovery.java @@ -9,6 +9,7 @@ package org.opendaylight.transportpce.networkmodel; import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_1_2_1; import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_2_2_1; +import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_7_1; import java.util.Collection; import java.util.Optional; @@ -25,11 +26,11 @@ import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.networkmodel.util.TopologyUtils; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev170818.InitRoadmNodesInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.Network; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.Nodes; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.NodesKey; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.nodes.CpToDegree; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.nodes.Mapping; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.cp.to.degree.CpToDegree; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesKey; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev170929.Direction; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols; @@ -58,93 +59,107 @@ public class R2RLinkDiscovery { } public boolean readLLDP(NodeId nodeId, String nodeVersion) { - - if (nodeVersion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) { - InstanceIdentifier protocolsIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) + switch (nodeVersion) { + case OPENROADM_DEVICE_VERSION_1_2_1: + InstanceIdentifier protocols121IID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(Protocols.class); - Optional protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), - LogicalDatastoreType.OPERATIONAL, protocolsIID, Timeouts.DEVICE_READ_TIMEOUT, - Timeouts.DEVICE_READ_TIMEOUT_UNIT); - if (!protocolObject.isPresent() || (protocolObject.get().augmentation(Protocols1.class) == null)) { - LOG.warn("LLDP subtree is missing : isolated openroadm device"); + Optional protocol121Object = this.deviceTransactionManager.getDataFromDevice( + nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocols121IID, Timeouts.DEVICE_READ_TIMEOUT, + Timeouts.DEVICE_READ_TIMEOUT_UNIT); + if (!protocol121Object.isPresent() + || (protocol121Object.get().augmentation(Protocols1.class) == null)) { + LOG.warn("LLDP subtree is missing : isolated openroadm device"); + return false; + } + // get neighbor list + NbrList nbr121List = protocol121Object.get().augmentation(Protocols1.class).getLldp().getNbrList(); + LOG.info("LLDP subtree is present. Device has {} neighbours", nbr121List.getIfName().size()); + // try to create rdm2rdm link + return rdm2rdmLinkCreatedv121(nodeId, nbr121List); + case OPENROADM_DEVICE_VERSION_2_2_1: + InstanceIdentifier protocols221IID = + InstanceIdentifier.create(org.opendaylight.yang.gen.v1.http + .org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice.class) + .child(org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019 + .org.openroadm.device.container.org.openroadm.device.Protocols.class); + Optional protocol221Object = this.deviceTransactionManager + .getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocols221IID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + if (!protocol221Object.isPresent() || (protocol221Object.get().augmentation( + org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class) == null)) { + LOG.warn("LLDP subtree is missing : isolated openroadm device"); + return false; + } + org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.@Nullable NbrList + nbr221List = protocol221Object.get().augmentation(org.opendaylight.yang.gen.v1.http + .org.openroadm.lldp.rev181019.Protocols1.class).getLldp().getNbrList(); + LOG.info("LLDP subtree is present. Device has {} neighbours", nbr221List.getIfName().size()); + return rdm2rdmLinkCreatedv221(nodeId, nbr221List); + case OPENROADM_DEVICE_VERSION_7_1: + LOG.info("Not yet implemented?"); return false; - } - NbrList nbrList = protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList(); - LOG.info("LLDP subtree is present. Device has {} neighbours", nbrList.getIfName().size()); - boolean success = true; - for (IfName ifName : nbrList.nonnullIfName().values()) { - if (ifName.getRemoteSysName() == null) { - LOG.warn("LLDP subtree neighbour is empty for nodeId: {}, ifName: {}", - nodeId.getValue(),ifName.getIfName()); + default: + LOG.error("Unable to read LLDP data for unmanaged openroadm device version"); + return false; + } + } + + private boolean rdm2rdmLinkCreatedv221(NodeId nodeId, + org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.NbrList nbrList) { + boolean success = true; + for (org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.nbr.list.IfName + ifName : nbrList.nonnullIfName().values()) { + if (ifName.getRemoteSysName() == null) { + LOG.warn("LLDP subtree neighbour is empty for nodeId: {}, ifName: {}", + nodeId.getValue(),ifName.getIfName()); + } else { + Optional mps = this.deviceTransactionManager.getDeviceMountPoint(ifName + .getRemoteSysName()); + if (!mps.isPresent()) { + LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName()); + // The controller raises a warning rather than an error because the first node to + // mount cannot see its neighbors yet. The link will be detected when processing + // the neighbor node. } else { - Optional mps = this.deviceTransactionManager.getDeviceMountPoint(ifName - .getRemoteSysName()); - if (!mps.isPresent()) { - LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName()); - // The controller raises a warning rather than an error because the first node to - // mount cannot see its neighbors yet. The link will be detected when processing - // the neighbor node. - } else { - if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(), - ifName.getRemotePortId())) { - LOG.error("Link Creation failed between {} and {} nodes.", nodeId.getValue(), - ifName.getRemoteSysName()); - success = false; - } + if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(), + ifName.getRemotePortId())) { + LOG.error("Link Creation failed between {} and {} nodes.", nodeId, ifName + .getRemoteSysName()); + success = false; } } } - return success; } - else if (nodeVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) { - InstanceIdentifier protocolsIID = InstanceIdentifier.create(org.opendaylight - .yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container - .OrgOpenroadmDevice.class).child(org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019 - .org.openroadm.device.container.org.openroadm.device.Protocols.class); - Optional protocolObject = this.deviceTransactionManager - .getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocolsIID, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - if (!protocolObject.isPresent() || (protocolObject.get().augmentation(org.opendaylight.yang.gen.v1.http.org - .openroadm.lldp.rev181019.Protocols1.class) == null)) { - LOG.warn("LLDP subtree is missing : isolated openroadm device"); - return false; - } - org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.@Nullable NbrList nbrList - = protocolObject.get().augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019 - .Protocols1.class).getLldp().getNbrList(); - LOG.info("LLDP subtree is present. Device has {} neighbours", nbrList.getIfName().size()); - boolean success = true; - for (org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.nbr.list.IfName - ifName : nbrList.nonnullIfName().values()) { - if (ifName.getRemoteSysName() == null) { - LOG.warn("LLDP subtree neighbour is empty for nodeId: {}, ifName: {}", - nodeId.getValue(),ifName.getIfName()); + return success; + } + + private boolean rdm2rdmLinkCreatedv121(NodeId nodeId, NbrList nbrList) { + boolean success = true; + for (IfName ifName : nbrList.nonnullIfName().values()) { + if (ifName.getRemoteSysName() == null) { + LOG.warn("LLDP subtree neighbour is empty for nodeId: {}, ifName: {}", + nodeId.getValue(),ifName.getIfName()); + } else { + Optional mps = this.deviceTransactionManager.getDeviceMountPoint(ifName + .getRemoteSysName()); + if (!mps.isPresent()) { + LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName()); + // The controller raises a warning rather than an error because the first node to + // mount cannot see its neighbors yet. The link will be detected when processing + // the neighbor node. } else { - Optional mps = this.deviceTransactionManager.getDeviceMountPoint(ifName - .getRemoteSysName()); - if (!mps.isPresent()) { - LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName()); - // The controller raises a warning rather than an error because the first node to - // mount cannot see its neighbors yet. The link will be detected when processing - // the neighbor node. - } else { - if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(), - ifName.getRemotePortId())) { - LOG.error("Link Creation failed between {} and {} nodes.", nodeId, ifName - .getRemoteSysName()); - success = false; - } + if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(), + ifName.getRemotePortId())) { + LOG.error("Link Creation failed between {} and {} nodes.", nodeId.getValue(), + ifName.getRemoteSysName()); + success = false; } } } - return success; - } - else { - LOG.error("Unable to read LLDP data for unmanaged openroadm device version"); - return false; } + return success; } public Direction getDegreeDirection(Integer degreeCounter, NodeId nodeId) {