Fix few code issues
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / gnpy / GnpyTopoImpl.java
index 3bcdc327ba3e99f3b9c1d82f583677af62c18d3e..abdcb703801eff7f0d6571f09edd7c4cf663dddd 100644 (file)
@@ -10,48 +10,48 @@ package org.opendaylight.transportpce.pce.gnpy;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.IntStream;
-
-import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Coordinate;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Km;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.edfa.params.Operational;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.edfa.params.OperationalBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.Edfa;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.EdfaBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.FiberRoadmBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.Transceiver;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.TransceiverBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.Params;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.ParamsBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.Fiber;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.FiberBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.Roadm;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.RoadmBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.location.attributes.Location;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.location.attributes.LocationBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Connections;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.ConnectionsBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Elements;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.ElementsBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.elements.Metadata;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.elements.MetadataBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.AmplifiedLink;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.amplified.link.section.element.section.element.Span;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.amplified.link.section.element.section.element.ila.Ila;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.rev181130.Node1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.OMSAttributes;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.Coordinate;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.Km;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.edfa.params.Operational;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.edfa.params.OperationalBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.Edfa;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.EdfaBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.FiberRoadmBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.Transceiver;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.TransceiverBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.fiberroadm.Params;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.fiberroadm.ParamsBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.fiberroadm.params.fiberroadmfused.Fiber;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.fiberroadm.params.fiberroadmfused.FiberBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.fiberroadm.params.fiberroadmfused.Roadm;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.element.type.choice.element.type.fiberroadm.params.fiberroadmfused.RoadmBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.location.attributes.Location;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.location.attributes.LocationBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.Connections;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.ConnectionsBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.Elements;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.ElementsBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.ElementsKey;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.elements.Metadata;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.elements.MetadataBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev211210.SpanAttributes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev211210.amplified.link.attributes.AmplifiedLink;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev211210.amplified.link.attributes.amplified.link.section.element.section.element.Span;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev211210.amplified.link.attributes.amplified.link.section.element.section.element.ila.Ila;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.rev211210.Node1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.link.OMSAttributes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.link.concatenation.LinkConcatenation;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
@@ -74,49 +74,37 @@ import org.slf4j.LoggerFactory;
 public class GnpyTopoImpl {
     private static final Logger LOG = LoggerFactory.getLogger(GnpyTopoImpl.class);
     private final NetworkTransactionService networkTransactionService;
-    private List<Elements> elements = new ArrayList<>();
+    //List of elements
+    private Map<ElementsKey, Elements> elements = new HashMap<>();
     private List<Connections> connections = new ArrayList<>();
+    private List<String> elementsList = new ArrayList<>();
     //Mapping elements
     //Mapping between the ord-topo and ord-ntw node
-    private Map<String, String> mapDisgNodeRefNode = new HashMap<String, String>();
-    //Mapping between the ord-ntw and node ip
-    private Map<String, IpAddress> mapNodeRefIp = new HashMap<String, IpAddress>();
-    //Mapping between link id and clfi
-    private Map<String, String> mapLinkFiber = new HashMap<String, String>();
-    //Mapping between fiber clfi and ipAddress
-    private Map<String, IpAddress> mapFiberIp = new HashMap<String, IpAddress>();
-    private static int convertKmM = 1000;
+    private Map<String, String> mapDisgNodeRefNode = new HashMap<>();
+    //Mapping between the ROADM-ROADM linkId/secElement and the linkId
+    private Map<String, List<String>> mapLinkFiber = new HashMap<>();
+    //List of Xponders
+    private List<String> trxList = new ArrayList<>();
+    private static final double LATITUDE = 0;
+    private static final double LONGITUTE = 0;
+    private static final String REGION = "N/A";
+    private static final String CITY = "N/A";
+    private static final int CONVERT_KM_M = 1000;
+    private static final double TARGET_PCH_OUT_DB = -20;
 
     /*
      * Construct the ExtractTopoDataStoreImpl.
      */
-    @SuppressWarnings("unchecked")
-    public GnpyTopoImpl(final NetworkTransactionService networkTransactionService) {
+    public GnpyTopoImpl(final NetworkTransactionService networkTransactionService) throws GnpyException {
         this.networkTransactionService = networkTransactionService;
-        Map<String, List<?>> map = extractTopo();
-        if (map.containsKey("Elements")) {
-            elements = (List<Elements>) map.get("Elements");
-        } else {
-            elements = null;
-        }
-        if (map.containsKey("Connections")) {
-            connections = (List<Connections>) map.get("Connections");
-        } else {
-            connections = null;
-        }
+        extractTopo();
     }
 
     /*
-     * extract the topology: all the elements have ipAddress as uid and maintain
-     * a mapping structure to map between the nodeId and the ipAddress (uid)
+     * extract the topology
      *
      */
-    public Map<String, List<?>> extractTopo() {
-        Map<String, List<?>> map = new HashMap<String, List<?>>();
-        // Define the elements
-        List<Elements> topoElements = new ArrayList<>();
-        // Define the connections
-        List<Connections> topoConnections = new ArrayList<>();
+    private void extractTopo() throws GnpyException {
         // Define the instance identifier of the OpenRoadm topology
         InstanceIdentifier<Network> insIdOpenRoadmTopo = InstanceIdentifier
                 .builder(Networks.class)
@@ -127,262 +115,252 @@ public class GnpyTopoImpl {
                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))).build();
         try {
             // Initialize the reading of the networkTransactionService
-            // read the configuration part of the data broker that concerns
-            // the openRoadm topology and get all the nodes
+            // read the configuration part of the data broker that concerns the openRoadm topology and get all the nodes
             java.util.Optional<Network> openRoadmTopo = this.networkTransactionService
                     .read(LogicalDatastoreType.CONFIGURATION, insIdOpenRoadmTopo).get();
             java.util.Optional<Network> openRoadmNet = this.networkTransactionService
                     .read(LogicalDatastoreType.CONFIGURATION, insIdrOpenRoadmNet).get();
-            if (openRoadmNet.isPresent()) {
-                List<Node> openRoadmNetNodeList = openRoadmNet.get().getNode();
-                if (openRoadmTopo.isPresent()) {
-                    List<Node> openRoadmTopoNodeList = openRoadmTopo.get().getNode();
-                    List<String> nodesList = new ArrayList<>();
-                    // Create the list of nodes
-                    if (!openRoadmTopoNodeList.isEmpty()) {
-                        // Create elements
-                        for (Node openRoadmTopoNode : openRoadmTopoNodeList) {
-                            // Retrieve the supporting node and the type of the
-                            // node in openRoadm network
-                            List<SupportingNode> supportingNodeList = openRoadmTopoNode.getSupportingNode();
-                            for (SupportingNode supportingNode : supportingNodeList) {
-                                String nodeRef = supportingNode.getNodeRef().getValue();
-                                IpAddress ipAddress = null;
-                                // Retrieve the mapping between the openRoadm
-                                // topology and openRoadm network
-                                mapDisgNodeRefNode.put(openRoadmTopoNode.getNodeId().getValue(), nodeRef);
-                                Node1 openRoadmNetNode1 = null;
-                                org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
-                                    .Node1 commonNetworkNode1 = null;
-                                for (Node openRoadmNetNode : openRoadmNetNodeList) {
-                                    if (openRoadmNetNode.getNodeId().getValue().equals(nodeRef)) {
-                                        openRoadmNetNode1 = openRoadmNetNode.augmentation(Node1.class);
-                                        commonNetworkNode1 = openRoadmNetNode.augmentation(org.opendaylight.yang.gen.v1
-                                            .http.org.openroadm.common.network.rev181130.Node1.class);
-                                        ipAddress = openRoadmNetNode1.getIp();
-                                        mapNodeRefIp.put(nodeRef, ipAddress);
-                                        break;
-                                    }
-                                }
-                                if (commonNetworkNode1.getNodeType().getName().equals("ROADM")) {
-                                //if (((org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Node1)
-                                //            openRoadmNetNode1).getNodeType().getName().equals("ROADM")) {
-                                    if (!nodesList.contains(nodeRef)) {
-                                        Elements element = addElementsRoadm(2, 0, nodeRef, openRoadmNetNode1.getShelf(),
-                                                -20, ipAddress.getIpv4Address().getValue().toString());
-                                        topoElements.add(element);
-                                        nodesList.add(nodeRef);
-                                    }
-                                } else if (commonNetworkNode1.getNodeType().getName().equals("XPONDER")) {
-                                //} else if (((org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
-                                //            .Node1) openRoadmNetNode1).getNodeType().getName().equals("XPONDER")) {
-                                    if (!nodesList.contains(nodeRef)) {
-                                        Elements element = addElementsTransceiver(2, 0, nodeRef,
-                                                openRoadmNetNode1.getShelf(),
-                                                ipAddress.getIpv4Address().getValue().toString());
-                                        topoElements.add(element);
-                                        nodesList.add(nodeRef);
-                                    }
-                                } else {
-                                    LOG.warn("the type is not implemented");
-                                }
-                            }
-                        }
-                    } else {
-                        LOG.warn("no nodes in the network");
-                    }
+            if (openRoadmNet.isPresent() && openRoadmTopo.isPresent()) {
+                extractElements(openRoadmTopo,openRoadmNet);
+                extractConnections(openRoadmTopo);
+                LOG.debug("In GnpyTopoImpl : elements and connections are well extracted");
+            }
+            else {
+                throw new GnpyException(
+                    "In GnpyTopoImpl : openroadm topology network or openroadm network are not well mounted ...");
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            this.networkTransactionService.close();
+            throw new GnpyException("In gnpyTopoImpl: error in reading the topology", e);
+        }
+        this.networkTransactionService.close();
+    }
+
+    private void extractElements(java.util.Optional<Network> openRoadmTopo,
+            java.util.Optional<Network> openRoadmNet) throws GnpyException {
+        if ((!openRoadmNet.isPresent()) || (!openRoadmTopo.isPresent())) {
+            throw new GnpyException("In gnpyTopoImpl: openRoadmNet or openRoadmTopo is not present");
+        }
+        // Create the list of nodes
+        Collection<Node> openRoadmNetNodeList = openRoadmNet.get().nonnullNode().values();
+        Collection<Node> openRoadmTopoNodeList = openRoadmTopo.get().nonnullNode().values();
 
-                    // Create the list of connections
-                    Network1 nw1 = openRoadmTopo.get().augmentation(Network1.class);
-                    List<Link> linksList = nw1.getLink();
-                    // 1:EXPRESS-LINK    2:ADD-LINK       3:DROP-LINK
-                    // 4:ROADM-To-ROADM  5:XPONDER-INPUT  6:XPONDER-OUTPUT
-                    int[] externalLink = {4,5,6};
-                    int idFiber = 0;
-                    int nbEDFA = 0;
-                    if (!linksList.isEmpty()) {
-                        LOG.debug("The link list is not empty");
-                        for (Link link : linksList) {
-                            Link1 link1 = link.augmentation(Link1.class);
-                            org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
-                                .Link1 openroadmNetworkLink1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org
-                                .openroadm.network.topology.rev181130.Link1.class);
-                            int linkType = link1.getLinkType().getIntValue();
-                            // the previous line generates a warning
-                            //  but the following cast in comment makes the gnpy tox test fail
-                            // ((org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1) link1)
-                            if (IntStream.of(externalLink).anyMatch(x -> x == linkType)) {
-                                // Verify if the node is a ROADM
-                                String srcId = mapDisgNodeRefNode.get(link.getSource().getSourceNode().getValue());
-                                IpAddress srcIp = mapNodeRefIp.get(srcId);
-                                String clfi = link1.getClfi();
-                                String destId = null;
-                                IpAddress destIp = null;
-                                // Add the links between amplifiers
-                                OMSAttributes omsAttributes = null;
-                                if (linkType == 4) {
-                                    omsAttributes = openroadmNetworkLink1.getOMSAttributes();
-                                }
-                                if (omsAttributes != null) {
-                                    if (omsAttributes.getAmplifiedLink() != null) {
-                                        List<AmplifiedLink> amplifiedLinkList = omsAttributes.getAmplifiedLink()
-                                                .getAmplifiedLink();
-                                        if (!amplifiedLinkList.isEmpty()) {
-                                            for (AmplifiedLink amplifiedLink : amplifiedLinkList) {
-                                                Elements element1 = null;
-                                                if (amplifiedLink.getSectionElement()
-                                                        .getSectionElement() instanceof Ila) {
-                                                    Ila ila = (Ila) amplifiedLink.getSectionElement()
-                                                            .getSectionElement();
-                                                    String nodeId = ila.getNodeId().getValue();
-                                                    IpAddress ipEdfa = new IpAddress(
-                                                            new Ipv4Address("1.1.1." + nbEDFA));
-                                                    nbEDFA++;
-                                                    mapDisgNodeRefNode.put(nodeId, nodeId);
-                                                    mapNodeRefIp.put(nodeId, ipEdfa);
-                                                    element1 = addElementsEdfa(2, 0, "RLD", "Lannion_CAS",
-                                                            ila.getGain().getValue(), ila.getTilt().getValue(),
-                                                            ila.getOutVoaAtt().getValue(), "std_medium_gain",
-                                                            ipEdfa.getIpv4Address().getValue().toString());
-                                                } else if (amplifiedLink.getSectionElement()
-                                                        .getSectionElement() instanceof Span) {
-                                                    // Create the location
-                                                    IpAddress ipFiber = new IpAddress(
-                                                            new Ipv4Address("2.2.2." + idFiber));
-                                                    mapLinkFiber.put(link.getLinkId().getValue(), clfi);
-                                                    mapFiberIp.put(clfi, ipFiber);
-                                                    idFiber++;
-                                                    element1 = addElementsFiber(2, 0, "RLD", "Lannion_CAS",
-                                                            ipFiber.getIpv4Address().getValue(), 20, 0, 0.2, 0, 0,
-                                                            "SSMF");
-                                                }
-                                                if (element1 != null) {
-                                                    topoElements.add(element1);
-                                                    destId = element1.getUid();
-                                                    destIp = null;
-                                                    // Create a new link
-                                                    if (srcId != destId) {
-                                                        Connections connection = createNewConnection(srcId, srcIp,
-                                                                destId, destIp);
-                                                        topoConnections.add(connection);
-                                                        srcId = destId;
-                                                        srcIp = destIp;
-                                                    }
-                                                }
-                                            }
-                                        }
-                                    } else if (omsAttributes.getSpan() != null) {
-                                        IpAddress ipFiber = new IpAddress(new Ipv4Address("2.2.2." + idFiber));
-                                        mapLinkFiber.put(link.getLinkId().getValue(), clfi);
-                                        mapFiberIp.put(clfi, ipFiber);
-                                        idFiber++;
-                                        double attIn = 0;
-                                        double connIn = 0;
-                                        double connOut = 0;
-                                        String typeVariety = "SSMF";
-                                        double length = 0;
-                                        // Compute the length of the link
-                                        org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
-                                            .networks.network.link.oms.attributes.@Nullable Span span =
-                                            omsAttributes.getSpan();
-                                        List<LinkConcatenation> linkConcatenationList = span.getLinkConcatenation();
-                                        for (LinkConcatenation linkConcatenation : linkConcatenationList) {
-                                            double srlgLength = linkConcatenation.getSRLGLength();
-                                            //convert to kilometer
-                                            length += srlgLength / convertKmM;
-                                        }
-                                        double lossCoef = span.getSpanlossCurrent().getValue().doubleValue() / length;
-                                        Elements element1 = addElementsFiber(2, 0, "RLD", "Lannion_CAS",
-                                                ipFiber.getIpv4Address().getValue(), length, attIn, lossCoef, connIn,
-                                                connOut, typeVariety);
-                                        topoElements.add(element1);
-                                        // Create a new link
-                                        destId = element1.getUid();
-                                        destIp = null;
-                                        if (srcId != destId) {
-                                            Connections connection = createNewConnection(srcId, srcIp, destId, destIp);
-                                            topoConnections.add(connection);
-                                            srcId = destId;
-                                            srcIp = destIp;
-                                        }
-                                    } else {
-                                        // Add a fiber
-                                        clfi = "Fiber" + idFiber;
-                                        IpAddress ipFiber = new IpAddress(new Ipv4Address("2.2.2." + idFiber));
-                                        mapLinkFiber.put(link.getLinkId().getValue(), clfi);
-                                        mapFiberIp.put(clfi, ipFiber);
-                                        idFiber++;
-                                        // Create a new element
-                                        Elements element1 = addElementsFiber(2, 0, "RLD", "Lannion_CAS",
-                                                ipFiber.getIpv4Address().getValue(), 20, 0, 0.2, 0, 0, "SSMF");
-                                        topoElements.add(element1);
-                                        // Create a new link
-                                        destId = element1.getUid();
-                                        destIp = null;
-                                        if (srcId != destId) {
-                                            Connections connection = createNewConnection(srcId, srcIp, destId, destIp);
-                                            topoConnections.add(connection);
-                                            srcId = destId;
-                                            srcIp = destIp;
-                                        }
-                                    }
-                                } else {
-                                    LOG.warn("The oms attributes is null {} !",link1.getLinkType().getName());
-                                }
-                                // Create a new link
-                                destId = mapDisgNodeRefNode.get(link.getDestination().getDestNode().getValue());
-                                destIp = mapNodeRefIp.get(destId);
-                                Connections connection = createNewConnection(srcId, srcIp, destId, destIp);
-                                topoConnections.add(connection);
-                            }
-                        }
-                    } else {
-                        LOG.warn("no links in the network");
+        if (openRoadmTopoNodeList.isEmpty() || openRoadmNetNodeList.isEmpty()) {
+            throw new GnpyException("In gnpyTopoImpl: no nodes in the openradm topology or openroadm network");
+        }
+        // Create elements
+        for (Node openRoadmTopoNode : openRoadmTopoNodeList) {
+            // Retrieve the supporting node and the type of the node in openRoadm network
+            Collection<SupportingNode> supportingNodeList = openRoadmTopoNode.nonnullSupportingNode().values();
+
+            for (SupportingNode supportingNode : supportingNodeList) {
+                if (!supportingNode.getNetworkRef().getValue().equals("openroadm-network")) {
+                    continue;
+                }
+                String nodeRef = supportingNode.getNodeRef().getValue();
+                if (nodeRef == null) {
+                    throw new GnpyException("In gnpyTopoImpl: nodeRef is null");
+                }
+                // Retrieve the mapping between the openRoadm topology and openRoadm network
+                mapDisgNodeRefNode.put(openRoadmTopoNode.getNodeId().getValue(), nodeRef);
+                Node1 openRoadmNetNode1 = null;
+                org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210
+                    .Node1 commonNetworkNode1 = null;
+                for (Node openRoadmNetNode : openRoadmNetNodeList) {
+                    if (openRoadmNetNode.getNodeId().getValue().equals(nodeRef)) {
+                        openRoadmNetNode1 = openRoadmNetNode.augmentation(Node1.class);
+                        commonNetworkNode1 = openRoadmNetNode.augmentation(org.opendaylight.yang.gen.v1
+                            .http.org.openroadm.common.network.rev211210.Node1.class);
+                        break;
+                    }
+                }
+                if (commonNetworkNode1 == null) {
+                    throw new GnpyException(String.format("In gnpyTopoImpl: the node type of %s is null",nodeRef));
+                }
+                if (commonNetworkNode1.getNodeType().getName().equals("ROADM")) {
+                    if (!elementsList.contains(nodeRef)) {
+                        Elements element = createElementsRoadm(LATITUDE, LONGITUTE, nodeRef,
+                                openRoadmNetNode1.getShelf(),TARGET_PCH_OUT_DB, nodeRef);
+                        this.elements.put(element.key(),element);
+                        elementsList.add(nodeRef);
+                    }
+                } else if (commonNetworkNode1.getNodeType().getName().equals("XPONDER")) {
+                    if (!elementsList.contains(nodeRef)) {
+                        Elements element = createElementsTransceiver(LATITUDE, LONGITUTE, nodeRef,
+                                openRoadmNetNode1.getShelf(), nodeRef);
+                        this.elements.put(element.key(),element);
+                        elementsList.add(nodeRef);
+                        trxList.add(nodeRef);
                     }
                 } else {
-                    LOG.warn("No nodes in the selected network ...");
+                    throw new GnpyException("In gnpyTopoImpl: the type is not implemented");
                 }
             }
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error reading the topology", e);
-            this.networkTransactionService.close();
         }
-        this.networkTransactionService.close();
-        map.put("Elements", topoElements);
-        map.put("Connections", topoConnections);
-        return map;
+    }
+
+    private void extractConnections(java.util.Optional<Network> openRoadmTopo) throws GnpyException {
+        // Create the list of connections
+        if (!openRoadmTopo.isPresent()) {
+            throw new GnpyException("In gnpyTopoImpl: openroadmTopo is not present");
+        }
+        Network1 nw1 = openRoadmTopo.get().augmentation(Network1.class);
+        Collection<Link> linksList = nw1.nonnullLink().values();
+        // 1:EXPRESS-LINK    2:ADD-LINK       3:DROP-LINK
+        // 4:ROADM-To-ROADM  5:XPONDER-INPUT  6:XPONDER-OUTPUT
+        int[] externalLink = {OpenroadmLinkType.ROADMTOROADM.getIntValue(),OpenroadmLinkType.XPONDERINPUT.getIntValue(),
+            OpenroadmLinkType.XPONDEROUTPUT.getIntValue()};
+
+        if (linksList.isEmpty()) {
+            throw new GnpyException("In gnpyTopoImpl: no links in the network");
+        }
+
+        for (Link link : linksList) {
+            Link1 link1 = link.augmentation(Link1.class);
+            org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
+                .Link1 openroadmNetworkLink1 = link.augmentation(org.opendaylight.yang.gen.v1.http
+                        .org.openroadm.network.topology.rev211210.Link1.class);
+            if (link1.getLinkType() == null) {
+                throw new GnpyException("In gnpyTopoImpl: the link type is null");
+            }
+            int linkType = link1.getLinkType().getIntValue();
+            if (! IntStream.of(externalLink).anyMatch(x -> x == linkType)) {
+                continue;
+            }
+
+            String srcId = mapDisgNodeRefNode.get(link.getSource().getSourceNode().getValue());
+            String linkId = link.getLinkId().getValue();
+            String destId = null;
+            if (linkType == OpenroadmLinkType.ROADMTOROADM.getIntValue()) {
+                OMSAttributes omsAttributes = openroadmNetworkLink1.getOMSAttributes();
+                if (omsAttributes == null) {
+                    throw new GnpyException(String.format(
+                        "In gnpyTopoImpl: OMS attributes do not exit for ROADM to ROADM link: %s",linkId));
+                }
+                //Case of amplified link
+                if (omsAttributes.getAmplifiedLink() != null) {
+                    srcId = extractAmplifiedLink(omsAttributes, linkId, srcId);
+                }
+                //Case of one span link
+                if (omsAttributes.getSpan() != null) {
+                    srcId = extractSpanLink(omsAttributes, linkId, srcId);
+                }
+            }
+            // Create a new link
+            destId = mapDisgNodeRefNode.get(link.getDestination().getDestNode().getValue());
+            createNewConnection(srcId,destId);
+        }
+    }
+
+    private String extractAmplifiedLink(OMSAttributes omsAttributes, String linkId, String srcId)
+        throws GnpyException {
+
+        List<AmplifiedLink> amplifiedLinkList = new ArrayList<>(omsAttributes.getAmplifiedLink()
+            .nonnullAmplifiedLink().values());
+        String destId = null;
+        if (!amplifiedLinkList.isEmpty()) {
+            for (AmplifiedLink amplifiedLink: amplifiedLinkList) {
+                String secElt = amplifiedLink .getSectionEltNumber().toString();
+                //Case of ILA
+                if (amplifiedLink.getSectionElement().getSectionElement() instanceof Ila) {
+                    Ila ila = (Ila) amplifiedLink.getSectionElement().getSectionElement();
+                    destId = extractILAFromAmpLink(ila);
+                }
+                //Case of Span
+                if (amplifiedLink.getSectionElement().getSectionElement() instanceof Span) {
+                    Span span = (Span) amplifiedLink.getSectionElement().getSectionElement();
+                    destId = extractSpan(span.getSpan(), linkId, secElt);
+                }
+                // Create a new link
+                if (createNewConnection(srcId,destId)) {
+                    srcId = destId;
+                }
+            }
+        }
+        return srcId;
+    }
+
+    private String extractSpanLink(OMSAttributes omsAttributes, String linkId, String srcId)
+        throws GnpyException {
+
+        SpanAttributes span = omsAttributes.getSpan();
+        String destId = extractSpan(span, linkId, linkId);
+        if (createNewConnection(srcId, destId)) {
+            return destId;
+        }
+        return srcId;
+    }
+
+    private String extractILAFromAmpLink(Ila ila) throws GnpyException {
+        String nodeId = ila.getNodeId().getValue();
+        mapDisgNodeRefNode.put(nodeId, nodeId);
+        Elements element = createElementsEdfa(LATITUDE, LONGITUTE, REGION, CITY,
+                ila.getGain().getValue(), ila.getTilt().getValue(),
+                ila.getOutVoaAtt().getValue(), "std_medium_gain",
+                nodeId);
+        this.elements.put(element.key(),element);
+        return nodeId;
+    }
+
+    private String extractSpan(SpanAttributes span, String linkId, String subLinkId) throws GnpyException {
+        if (!mapLinkFiber.containsKey(linkId)) {
+            mapLinkFiber.put(linkId, new ArrayList<>());
+        }
+        mapLinkFiber.get(linkId).add(subLinkId);
+        //mapFiberIp.put(subLinkId, ipFiber);
+        //fiberId = incrementIdentifier(fiberId);
+        double attIn = 0;
+        double connIn = 0;
+        double connOut = 0;
+        String typeVariety = "SSMF";
+        double length = 0;
+        // Compute the length of the link
+        for (LinkConcatenation linkConcatenation : span.nonnullLinkConcatenation().values()) {
+            double srlgLength = linkConcatenation.getSRLGLength().doubleValue();
+            //convert to kilometer
+            length += srlgLength / CONVERT_KM_M;
+        }
+        if (length == 0) {
+            throw new GnpyException(String.format(
+                "In gnpyTopoImpl: length of the link %s is equal to zero",linkId));
+        }
+        double lossCoef = span.getSpanlossCurrent().getValue().doubleValue() / length;
+        Elements element = createElementsFiber(LATITUDE, LONGITUTE, REGION, CITY,
+                subLinkId, length, attIn, lossCoef, connIn, connOut, typeVariety);
+        this.elements.put(element.key(),element);
+        return subLinkId;
     }
 
     /*
-     * Method to add Fiber
+     * Method to create Fiber
      */
-    private Elements addElementsFiber(double latitude, double longitude, String region, String city, String clfi,
+    private Elements createElementsFiber(double latitude, double longitude, String region, String city, String uidFiber,
             double length, double attIn, double lossCoef, double connIn, double connOut, String typeVariety) {
-        // Create an amplifier after the roadm
-        Coordinate c1 = new Coordinate(new BigDecimal(latitude));
-        Coordinate c2 = new Coordinate(new BigDecimal(longitude));
+        // Create an amplifier after the ROADM
+        Coordinate c1 = new Coordinate(BigDecimal.valueOf(latitude));
+        Coordinate c2 = new Coordinate(BigDecimal.valueOf(longitude));
         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
                 .build();
         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
-        Fiber fiber = new FiberBuilder().setLength(new BigDecimal(length)).setLengthUnits(Km.class)
-                .setAttIn(new BigDecimal(attIn)).setLossCoef(new BigDecimal(lossCoef)).setConIn(new BigDecimal(connIn))
-                .setConOut(new BigDecimal(connOut)).build();
-        Params params1 = new ParamsBuilder().setFiberroadm(fiber).build();
-        Elements element1 = new ElementsBuilder().setUid(clfi)
-                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Fiber.class)
+        Fiber fiber = new FiberBuilder().setLength(BigDecimal.valueOf(length)).setLengthUnits(Km.class)
+                .setAttIn(BigDecimal.valueOf(attIn)).setLossCoef(BigDecimal.valueOf(lossCoef))
+                .setConIn(BigDecimal.valueOf(connIn))
+                .setConOut(BigDecimal.valueOf(connOut)).build();
+        Params params1 = new ParamsBuilder().setFiberroadmfused(fiber).build();
+        return new ElementsBuilder().setUid(uidFiber)
+                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.Fiber.class)
                 .setTypeVariety(typeVariety).setMetadata(metadata1)
                 .setElementType(new FiberRoadmBuilder().setParams(params1).build()).build();
-        return element1;
     }
 
     /*
-     * Method to add Edfa
+     * Method to create EDFA
      */
-    private Elements addElementsEdfa(double latitude, double longitude, String region, String city,
+    private Elements createElementsEdfa(double latitude, double longitude, String region, String city,
             BigDecimal gainTarget, BigDecimal tiltTarget, BigDecimal outVoa, String typeVariety, String uidEdfa) {
-        // Create an amplifier after the roadm
-        Coordinate c1 = new Coordinate(new BigDecimal(latitude));
-        Coordinate c2 = new Coordinate(new BigDecimal(longitude));
+        // Create an amplifier after the ROADM
+        Coordinate c1 = new Coordinate(BigDecimal.valueOf(latitude));
+        Coordinate c2 = new Coordinate(BigDecimal.valueOf(longitude));
         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
                 .build();
         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
@@ -390,68 +368,64 @@ public class GnpyTopoImpl {
                 .setOutVoa(outVoa).build();
         Edfa edfa = new EdfaBuilder()
                 .setOperational(operational).build();
-        Elements element1 = new ElementsBuilder().setUid(uidEdfa)
-                // Choose an ip address
-                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Edfa.class)
+        return new ElementsBuilder().setUid(uidEdfa)
+                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.Edfa.class)
                 .setMetadata(metadata1).setElementType(edfa).setTypeVariety(typeVariety).build();
-        return element1;
     }
 
     /*
-     * Method to add ROADM
+     * Method to create ROADM
      */
-    private Elements addElementsRoadm(double latitude, double longitude, String region, String city,
+    private Elements createElementsRoadm(double latitude, double longitude, String region, String city,
             double targetPchOutDb, String uidRoadm) {
-
-        Coordinate c1 = new Coordinate(new BigDecimal(latitude));
-        Coordinate c2 = new Coordinate(new BigDecimal(longitude));
+        Coordinate c1 = new Coordinate(BigDecimal.valueOf(latitude));
+        Coordinate c2 = new Coordinate(BigDecimal.valueOf(longitude));
         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
                 .build();
         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
-        // Create the roadm
-        Roadm roadm = new RoadmBuilder().setTargetPchOutDb(new BigDecimal(targetPchOutDb)).build();
-        Params params1 = new ParamsBuilder().setFiberroadm(roadm).build();
-        Elements element1 = new ElementsBuilder().setUid(uidRoadm)
-                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Roadm.class)
+        Roadm roadm = new RoadmBuilder().setTargetPchOutDb(BigDecimal.valueOf(targetPchOutDb)).build();
+        Params params1 = new ParamsBuilder().setFiberroadmfused(roadm).build();
+        return new ElementsBuilder().setUid(uidRoadm)
+                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.Roadm.class)
                 .setMetadata(metadata1).setElementType(new FiberRoadmBuilder().setParams(params1).build()).build();
-        return element1;
     }
 
     /*
-     * Method to add Transceiver
+     * Method to create Transceiver
      */
-    private Elements addElementsTransceiver(double latitude, double longitude, String region, String city,
+    private Elements createElementsTransceiver(double latitude, double longitude, String region, String city,
             String uidTrans) {
-        Coordinate c1 = new Coordinate(new BigDecimal(latitude));
-        Coordinate c2 = new Coordinate(new BigDecimal(longitude));
+        Coordinate c1 = new Coordinate(BigDecimal.valueOf(latitude));
+        Coordinate c2 = new Coordinate(BigDecimal.valueOf(longitude));
         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
                 .build();
         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
         Transceiver transceiver = new TransceiverBuilder().build();
-        Elements element1 = new ElementsBuilder().setUid(uidTrans)
-                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Transceiver.class)
+        return new ElementsBuilder().setUid(uidTrans)
+                .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.Transceiver.class)
                 .setMetadata(metadata1).setElementType(transceiver).build();
-        return element1;
     }
 
-    private Connections createNewConnection(String srcId, IpAddress srcIp, String destId, IpAddress destIp) {
-        String fromNode = srcId;
-        String toNode = destId;
-        if (srcIp != null) {
-            fromNode = srcIp.getIpv4Address().getValue().toString();
+    /*
+     * Method to create Connection
+     */
+    private boolean createNewConnection(String fromNode, String toNode) throws GnpyException {
+        if (fromNode == null || toNode == null) {
+            throw new GnpyException("create new connection : null node IpAddress");
         }
-        if (destIp != null) {
-            toNode = destIp.getIpv4Address().getValue().toString();
+        if (fromNode.equals(toNode)) {
+            return false;
         }
-        Connections connection1 = new ConnectionsBuilder().setFromNode(fromNode).setToNode(toNode).build();
-        return (connection1);
+        Connections connection = new ConnectionsBuilder().setFromNode(fromNode).setToNode(toNode).build();
+        this.connections.add(connection);
+        return true;
     }
 
-    public List<Elements> getElements() {
+    public Map<ElementsKey, Elements> getElements() {
         return elements;
     }
 
-    public void setElements(List<Elements> elements) {
+    public void setElements(Map<ElementsKey, Elements> elements) {
         this.elements = elements;
     }
 
@@ -463,35 +437,35 @@ public class GnpyTopoImpl {
         this.connections = connections;
     }
 
-    public Map<String, String> getMapDisgNodeRefNode() {
-        return mapDisgNodeRefNode;
+    public List<String> getElementsList() {
+        return elementsList;
     }
 
-    public void setMapDisgNodeRefNode(Map<String, String> mapDisgNodeRefNode) {
-        this.mapDisgNodeRefNode = mapDisgNodeRefNode;
+    public void setElementsList(List<String> elementsList) {
+        this.elementsList = elementsList;
     }
 
-    public Map<String, IpAddress> getMapNodeRefIp() {
-        return mapNodeRefIp;
+    public Map<String, String> getMapDisgNodeRefNode() {
+        return mapDisgNodeRefNode;
     }
 
-    public void setMapNodeRefIp(Map<String, IpAddress> mapNodeRefIp) {
-        this.mapNodeRefIp = mapNodeRefIp;
+    public void setMapDisgNodeRefNode(Map<String, String> mapDisgNodeRefNode) {
+        this.mapDisgNodeRefNode = mapDisgNodeRefNode;
     }
 
-    public Map<String, String> getMapLinkFiber() {
+    public Map<String, List<String>> getMapLinkFiber() {
         return mapLinkFiber;
     }
 
-    public void setMapLinkFiber(Map<String, String> mapLinkFiber) {
+    public void setMapLinkFiber(Map<String, List<String>> mapLinkFiber) {
         this.mapLinkFiber = mapLinkFiber;
     }
 
-    public Map<String, IpAddress> getMapFiberIp() {
-        return mapFiberIp;
+    public List<String> getTrxList() {
+        return trxList;
     }
 
-    public void setMapFiberIp(Map<String, IpAddress> mapFiberIp) {
-        this.mapFiberIp = mapFiberIp;
+    public void setTrxList(List<String> trxList) {
+        this.trxList = trxList;
     }
 }