Consolidation of the GNPy module
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / gnpy / GnpyTopoImpl.java
1 /*
2  * Copyright © 2019 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.pce.gnpy;
10
11 import java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.concurrent.ExecutionException;
17 import java.util.regex.Pattern;
18 import java.util.stream.IntStream;
19
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.transportpce.common.NetworkUtils;
22 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
23 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Coordinate;
24 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Km;
25 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.edfa.params.Operational;
26 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.edfa.params.OperationalBuilder;
27 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.Edfa;
28 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.EdfaBuilder;
29 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.FiberRoadmBuilder;
30 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.Transceiver;
31 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.TransceiverBuilder;
32 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.Params;
33 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.ParamsBuilder;
34 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.Fiber;
35 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.FiberBuilder;
36 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.Roadm;
37 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.element.type.choice.element.type.fiberroadm.params.fiberroadm.RoadmBuilder;
38 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.location.attributes.Location;
39 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.location.attributes.LocationBuilder;
40 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Connections;
41 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.ConnectionsBuilder;
42 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Elements;
43 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.ElementsBuilder;
44 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.elements.Metadata;
45 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.elements.MetadataBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.SpanAttributes;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.AmplifiedLink;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.amplified.link.section.element.section.element.Span;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.amplified.link.section.element.section.element.ila.Ila;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.rev181130.Node1;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.OMSAttributes;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
68
69 /**
70  * Class to create the topology corresponding to GNPy requirements.
71  *
72  * @author Ahmed Triki ( ahmed.triki@orange.com )
73  *
74  */
75
76 public class GnpyTopoImpl {
77     private static final Logger LOG = LoggerFactory.getLogger(GnpyTopoImpl.class);
78     private final NetworkTransactionService networkTransactionService;
79     //List of elements
80     private List<Elements> elements = new ArrayList<>();
81     private List<Connections> connections = new ArrayList<>();
82     //Mapping elements
83     //Mapping between the ord-topo and ord-ntw node
84     private Map<String, String> mapDisgNodeRefNode = new HashMap<String, String>();
85     //Mapping between the ord-ntw and node ip
86     private Map<String, IpAddress> mapNodeRefIp = new HashMap<String, IpAddress>();
87     //Mapping between the ROADM-ROADM linkId/secElement and the linkId
88     private Map<String, List<String>> mapLinkFiber = new HashMap<String, List<String>>();
89     //Mapping between the ROADM-ROADM linkId/secElement and ipAddress
90     private Map<String, IpAddress> mapFiberIp = new HashMap<String, IpAddress>();
91     //List of Xponders
92     private List<String> trxList = new ArrayList<>();
93     //Initialize the 32 bit identifiers for the edfa and the fiber.
94     //These 32-bit identifiers are not ipv4 addresses (despite having ipv4Adresses format, dotted-decimal notation).
95     //They are imposed by the GNPy yang model to identify network elements and not used for any routing purposes.
96     private Ipv4Address edfaId;
97     private Ipv4Address fiberId;
98     private static final double LATITUDE = 0;
99     private static final double LONGITUTE = 0;
100     private static final String REGION = "N/A";
101     private static final String CITY = "N/A";
102     private static final int CONVERT_KM_M = 1000;
103     private static final double TARGET_PCH_OUT_DB = -20;
104
105     /*
106      * Construct the ExtractTopoDataStoreImpl.
107      */
108     public GnpyTopoImpl(final NetworkTransactionService networkTransactionService) throws GnpyException {
109         this.networkTransactionService = networkTransactionService;
110         //32-bit identifier for the fiber. The dotted decimal notation has the format 243.x.x.x (0<=x<=255)
111         fiberId = new Ipv4Address("243.0.0.1");
112         //32-bit identifier for the edfa. The dotted decimal notation has the format 244.x.x.x (0<=x<=255)
113         edfaId = new Ipv4Address("244.0.0.1");
114         try {
115             extractTopo();
116         } catch (NullPointerException e) {
117             throw new GnpyException("In GnpyTopoImpl: one of the elements is null",e);
118         }
119     }
120
121     /*
122      * extract the topology: all the elements have ipAddress as uid and maintain
123      * a mapping structure to map between the nodeId and the ipAddress (uid)
124      *
125      */
126     private void extractTopo() throws GnpyException {
127         // Define the instance identifier of the OpenRoadm topology
128         InstanceIdentifier<Network> insIdOpenRoadmTopo = InstanceIdentifier
129                 .builder(Networks.class)
130                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
131         // Define the instance identifier of the OpenRoadm network
132         InstanceIdentifier<Network> insIdrOpenRoadmNet = InstanceIdentifier
133                 .builder(Networks.class)
134                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))).build();
135         try {
136             // Initialize the reading of the networkTransactionService
137             // read the configuration part of the data broker that concerns the openRoadm topology and get all the nodes
138             java.util.Optional<Network> openRoadmTopo = this.networkTransactionService
139                     .read(LogicalDatastoreType.CONFIGURATION, insIdOpenRoadmTopo).get();
140             java.util.Optional<Network> openRoadmNet = this.networkTransactionService
141                     .read(LogicalDatastoreType.CONFIGURATION, insIdrOpenRoadmNet).get();
142             if (openRoadmNet.isPresent() && openRoadmTopo.isPresent()) {
143                 extractElements(openRoadmTopo,openRoadmNet);
144                 extractConnections(openRoadmTopo,openRoadmNet);
145                 LOG.debug("In GnpyTopoImpl : elements and connections are well extracted");
146             }
147             else {
148                 throw new GnpyException(
149                     "In GnpyTopoImpl : openroadm topology network or openroadm network are not well mounted ...");
150             }
151         } catch (InterruptedException | ExecutionException e) {
152             this.networkTransactionService.close();
153             throw new GnpyException("In gnpyTopoImpl: error in reading the topology", e);
154         }
155         this.networkTransactionService.close();
156     }
157
158     private void extractElements(java.util.Optional<Network> openRoadmTopo,
159             java.util.Optional<Network> openRoadmNet) throws GnpyException {
160         // Create the list of nodes
161         List<Node> openRoadmNetNodeList = openRoadmNet.get().getNode();
162         List<Node> openRoadmTopoNodeList = openRoadmTopo.get().getNode();
163         List<String> nodesList = new ArrayList<>();
164
165         if (openRoadmTopoNodeList.isEmpty() || openRoadmNetNodeList.isEmpty()) {
166             throw new GnpyException("In gnpyTopoImpl: no nodes in the openradm topology or openroadm network");
167         }
168         // Create elements
169         for (Node openRoadmTopoNode : openRoadmTopoNodeList) {
170             // Retrieve the supporting node and the type of the node in openRoadm network
171             List<SupportingNode> supportingNodeList = openRoadmTopoNode.getSupportingNode();
172             for (SupportingNode supportingNode : supportingNodeList) {
173                 IpAddress ipAddress = null;
174                 String nodeRef = supportingNode.getNodeRef().getValue();
175                 // Retrieve the mapping between the openRoadm topology and openRoadm network
176                 mapDisgNodeRefNode.put(openRoadmTopoNode.getNodeId().getValue(), nodeRef);
177                 Node1 openRoadmNetNode1 = null;
178                 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
179                     .Node1 commonNetworkNode1 = null;
180                 for (Node openRoadmNetNode : openRoadmNetNodeList) {
181                     if (openRoadmNetNode.getNodeId().getValue().equals(nodeRef)) {
182                         openRoadmNetNode1 = openRoadmNetNode.augmentation(Node1.class);
183                         commonNetworkNode1 = openRoadmNetNode.augmentation(org.opendaylight.yang.gen.v1
184                             .http.org.openroadm.common.network.rev181130.Node1.class);
185                         ipAddress = openRoadmNetNode1.getIp();
186                         mapNodeRefIp.put(nodeRef, ipAddress);
187                         break;
188                     }
189                 }
190                 if (commonNetworkNode1.getNodeType().getName().equals("ROADM")) {
191                     if (!nodesList.contains(nodeRef)) {
192                         Elements element = createElementsRoadm(LATITUDE, LONGITUTE, nodeRef,
193                                 openRoadmNetNode1.getShelf(),TARGET_PCH_OUT_DB, ipAddress.getIpv4Address().getValue()
194                                 .toString());
195                         this.elements.add(element);
196                         nodesList.add(nodeRef);
197                     }
198                 } else if (commonNetworkNode1.getNodeType().getName().equals("XPONDER")) {
199                     if (!nodesList.contains(nodeRef)) {
200                         Elements element = createElementsTransceiver(LATITUDE, LONGITUTE, nodeRef,
201                                 openRoadmNetNode1.getShelf(),ipAddress.getIpv4Address().getValue().toString());
202                         this.elements.add(element);
203                         nodesList.add(nodeRef);
204                         trxList.add(nodeRef);
205                     }
206                 } else {
207                     throw new GnpyException("In gnpyTopoImpl: the type is not implemented");
208                 }
209             }
210         }
211     }
212
213     private void extractConnections(java.util.Optional<Network> openRoadmTopo,
214             java.util.Optional<Network> openRoadmNet) throws GnpyException {
215         // Create the list of connections
216         Network1 nw1 = openRoadmTopo.get().augmentation(Network1.class);
217         List<Link> linksList = nw1.getLink();
218         // 1:EXPRESS-LINK    2:ADD-LINK       3:DROP-LINK
219         // 4:ROADM-To-ROADM  5:XPONDER-INPUT  6:XPONDER-OUTPUT
220         int[] externalLink = {OpenroadmLinkType.ROADMTOROADM.getIntValue(),OpenroadmLinkType.XPONDERINPUT.getIntValue(),
221             OpenroadmLinkType.XPONDEROUTPUT.getIntValue()};
222
223         if (linksList.isEmpty()) {
224             throw new GnpyException("In gnpyTopoImpl: no links in the network");
225         }
226
227         for (Link link : linksList) {
228             Link1 link1 = link.augmentation(Link1.class);
229             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
230                 .Link1 openroadmNetworkLink1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org
231                 .openroadm.network.topology.rev181130.Link1.class);
232             int linkType = link1.getLinkType().getIntValue();
233             if (! IntStream.of(externalLink).anyMatch(x -> x == linkType)) {
234                 continue;
235             }
236
237             String srcId = mapDisgNodeRefNode.get(link.getSource().getSourceNode().getValue());
238             IpAddress srcIp = mapNodeRefIp.get(srcId);
239             String linkId = link.getLinkId().getValue();
240             String destId = null;
241             IpAddress destIp = null;
242             if (linkType == OpenroadmLinkType.ROADMTOROADM.getIntValue()) {
243                 OMSAttributes omsAttributes = openroadmNetworkLink1.getOMSAttributes();
244                 if (omsAttributes == null) {
245                     throw new GnpyException(String.format(
246                         "In gnpyTopoImpl: OMS attributes do not exit for ROADM to ROADM link: %s",linkId));
247                 }
248                 //Case of amplified link
249                 if (omsAttributes.getAmplifiedLink() != null) {
250                     srcIp = extractAmplifiedLink(omsAttributes, linkId, srcIp);
251                 }
252                 //Case of one span link
253                 if (omsAttributes.getSpan() != null) {
254                     srcIp = extractSpanLink(omsAttributes, linkId, srcIp);
255                 }
256             }
257             // Create a new link
258             destId = mapDisgNodeRefNode.get(link.getDestination().getDestNode().getValue());
259             destIp = mapNodeRefIp.get(destId);
260             createNewConnection(srcIp,destIp);
261         }
262     }
263
264     private IpAddress extractAmplifiedLink(OMSAttributes omsAttributes, String linkId, IpAddress srcIp)
265         throws GnpyException {
266
267         List<AmplifiedLink> amplifiedLinkList = omsAttributes.getAmplifiedLink()
268             .getAmplifiedLink();
269         IpAddress destIp = null;
270         if (!amplifiedLinkList.isEmpty()) {
271             for (AmplifiedLink amplifiedLink : amplifiedLinkList) {
272                 String secElt = amplifiedLink.getSectionEltNumber().toString();
273                 //Case of ILA
274                 if (amplifiedLink.getSectionElement().getSectionElement() instanceof Ila) {
275                     Ila ila = (Ila) amplifiedLink.getSectionElement().getSectionElement();
276                     destIp = extractILAFromAmpLink(ila);
277                 }
278                 //Case of Span
279                 if (amplifiedLink.getSectionElement().getSectionElement() instanceof Span) {
280                     Span span = (Span) amplifiedLink.getSectionElement().getSectionElement();
281                     destIp = extractSpan((SpanAttributes) span.getSpan(), linkId, secElt);
282                 }
283                 // Create a new link
284                 if (createNewConnection(srcIp,destIp)) {
285                     srcIp = destIp;
286                 }
287             }
288         }
289         return srcIp;
290     }
291
292     private IpAddress extractSpanLink(OMSAttributes omsAttributes, String linkId, IpAddress srcIp)
293         throws GnpyException {
294
295         SpanAttributes span = omsAttributes.getSpan();
296         IpAddress destIp = extractSpan((SpanAttributes) span, linkId, linkId);
297         if (createNewConnection(srcIp, destIp)) {
298             return destIp;
299         }
300         return srcIp;
301     }
302
303     private IpAddress extractILAFromAmpLink(Ila ila) throws GnpyException {
304         String nodeId = ila.getNodeId().getValue();
305         IpAddress ipEdfa = new IpAddress(edfaId);
306         edfaId = incrementIdentifier(edfaId);
307         mapDisgNodeRefNode.put(nodeId, nodeId);
308         mapNodeRefIp.put(nodeId, ipEdfa);
309         Elements element = createElementsEdfa(LATITUDE, LONGITUTE, REGION, CITY,
310                 ila.getGain().getValue(), ila.getTilt().getValue(),
311                 ila.getOutVoaAtt().getValue(), "std_medium_gain",
312                 ipEdfa.getIpv4Address().getValue().toString());
313         this.elements.add(element);
314         return ipEdfa;
315     }
316
317     private IpAddress extractSpan(SpanAttributes span, String linkId, String subLinkId) throws GnpyException {
318         IpAddress ipFiber = new IpAddress(fiberId);
319
320         if (!mapLinkFiber.containsKey(linkId)) {
321             mapLinkFiber.put(linkId, new ArrayList<String>());
322         }
323         mapLinkFiber.get(linkId).add(subLinkId);
324         mapFiberIp.put(subLinkId, ipFiber);
325         fiberId = incrementIdentifier(fiberId);
326         double attIn = 0;
327         double connIn = 0;
328         double connOut = 0;
329         String typeVariety = "SSMF";
330         double length = 0;
331         // Compute the length of the link
332         List<LinkConcatenation> linkConcatenationList = span.getLinkConcatenation();
333         for (LinkConcatenation linkConcatenation : linkConcatenationList) {
334             double srlgLength = linkConcatenation.getSRLGLength();
335             //convert to kilometer
336             length += srlgLength / CONVERT_KM_M;
337         }
338         double lossCoef = span.getSpanlossCurrent().getValue().doubleValue() / length;
339         Elements element = createElementsFiber(LATITUDE, LONGITUTE, REGION, CITY,
340             ipFiber.getIpv4Address().getValue(), length, attIn, lossCoef, connIn, connOut, typeVariety);
341         this.elements.add(element);
342         return ipFiber;
343
344     }
345
346     /*
347      * Method to create Fiber
348      */
349     private Elements createElementsFiber(double latitude, double longitude, String region, String city, String uidFiber,
350             double length, double attIn, double lossCoef, double connIn, double connOut, String typeVariety) {
351         // Create an amplifier after the ROADM
352         Coordinate c1 = new Coordinate(new BigDecimal(latitude));
353         Coordinate c2 = new Coordinate(new BigDecimal(longitude));
354         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
355                 .build();
356         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
357         Fiber fiber = new FiberBuilder().setLength(new BigDecimal(length)).setLengthUnits(Km.class)
358                 .setAttIn(new BigDecimal(attIn)).setLossCoef(new BigDecimal(lossCoef)).setConIn(new BigDecimal(connIn))
359                 .setConOut(new BigDecimal(connOut)).build();
360         Params params1 = new ParamsBuilder().setFiberroadm(fiber).build();
361         Elements element1 = new ElementsBuilder().setUid(uidFiber)
362                 .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Fiber.class)
363                 .setTypeVariety(typeVariety).setMetadata(metadata1)
364                 .setElementType(new FiberRoadmBuilder().setParams(params1).build()).build();
365         return element1;
366     }
367
368     /*
369      * Method to create EDFA
370      */
371     private Elements createElementsEdfa(double latitude, double longitude, String region, String city,
372             BigDecimal gainTarget, BigDecimal tiltTarget, BigDecimal outVoa, String typeVariety, String uidEdfa) {
373         // Create an amplifier after the ROADM
374         Coordinate c1 = new Coordinate(new BigDecimal(latitude));
375         Coordinate c2 = new Coordinate(new BigDecimal(longitude));
376         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
377                 .build();
378         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
379         Operational operational = new OperationalBuilder().setGainTarget(gainTarget).setTiltTarget(tiltTarget)
380                 .setOutVoa(outVoa).build();
381         Edfa edfa = new EdfaBuilder()
382                 .setOperational(operational).build();
383         Elements element1 = new ElementsBuilder().setUid(uidEdfa)
384                 .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Edfa.class)
385                 .setMetadata(metadata1).setElementType(edfa).setTypeVariety(typeVariety).build();
386         return element1;
387     }
388
389     /*
390      * Method to create ROADM
391      */
392     private Elements createElementsRoadm(double latitude, double longitude, String region, String city,
393             double targetPchOutDb, String uidRoadm) {
394
395         Coordinate c1 = new Coordinate(new BigDecimal(latitude));
396         Coordinate c2 = new Coordinate(new BigDecimal(longitude));
397         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
398                 .build();
399         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
400         Roadm roadm = new RoadmBuilder().setTargetPchOutDb(new BigDecimal(targetPchOutDb)).build();
401         Params params1 = new ParamsBuilder().setFiberroadm(roadm).build();
402         Elements element1 = new ElementsBuilder().setUid(uidRoadm)
403                 .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Roadm.class)
404                 .setMetadata(metadata1).setElementType(new FiberRoadmBuilder().setParams(params1).build()).build();
405         return element1;
406     }
407
408     /*
409      * Method to create Transceiver
410      */
411     private Elements createElementsTransceiver(double latitude, double longitude, String region, String city,
412             String uidTrans) {
413         Coordinate c1 = new Coordinate(new BigDecimal(latitude));
414         Coordinate c2 = new Coordinate(new BigDecimal(longitude));
415         Location location1 = new LocationBuilder().setRegion(region).setCity(city).setLatitude(c1).setLongitude(c2)
416                 .build();
417         Metadata metadata1 = new MetadataBuilder().setLocation(location1).build();
418         Transceiver transceiver = new TransceiverBuilder().build();
419         Elements element1 = new ElementsBuilder().setUid(uidTrans)
420                 .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Transceiver.class)
421                 .setMetadata(metadata1).setElementType(transceiver).build();
422         return element1;
423     }
424
425     /*
426      * Method to create Connection
427      */
428     private boolean createNewConnection(IpAddress srcIp, IpAddress destIp) throws GnpyException {
429         if (srcIp == null || destIp == null) {
430             throw new GnpyException("create new connection : null node IpAddress");
431         }
432         String fromNode = srcIp.getIpv4Address().getValue();
433         String toNode = destIp.getIpv4Address().getValue();
434         if (fromNode == toNode) {
435             return false;
436         }
437         Connections connection = new ConnectionsBuilder().setFromNode(fromNode).setToNode(toNode).build();
438         this.connections.add(connection);
439         return true;
440     }
441
442     /*
443      * Increment 32-bit identifier
444      */
445     private Ipv4Address incrementIdentifier(Ipv4Address id)  throws GnpyException {
446         String ips = id.getValue();
447         String [] fields = ips.split(Pattern.quote("."));
448         int intF1 = Integer.parseInt(fields[1]);
449         int intF2 = Integer.parseInt(fields[2]);
450         int intF3 = Integer.parseInt(fields[3]);
451         if (intF3 < 255) {
452             intF3++;
453         } else {
454             if (intF2 < 255) {
455                 intF2++;
456                 intF3 = 0;
457             } else {
458                 if (intF1 < 255) {
459                     intF1++;
460                     intF2 = 0;
461                     intF3 = 0;
462                 } else {
463                     throw new GnpyException("GnpyTopoImpl : the topology is not supported by gnpy");
464                 }
465                 fields[1] = Integer.toString(intF1);
466             }
467             fields[2] = Integer.toString(intF2);
468         }
469         fields[3] = Integer.toString(intF3);
470         String nidString = fields[0] + "." + fields[1] + "." + fields[2] + "." + fields[3];
471         Ipv4Address nid = new Ipv4Address(nidString);
472         return nid;
473     }
474
475     public List<Elements> getElements() {
476         return elements;
477     }
478
479     public void setElements(List<Elements> elements) {
480         this.elements = elements;
481     }
482
483     public List<Connections> getConnections() {
484         return connections;
485     }
486
487     public void setConnections(List<Connections> connections) {
488         this.connections = connections;
489     }
490
491     public Map<String, String> getMapDisgNodeRefNode() {
492         return mapDisgNodeRefNode;
493     }
494
495     public void setMapDisgNodeRefNode(Map<String, String> mapDisgNodeRefNode) {
496         this.mapDisgNodeRefNode = mapDisgNodeRefNode;
497     }
498
499     public Map<String, IpAddress> getMapNodeRefIp() {
500         return mapNodeRefIp;
501     }
502
503     public void setMapNodeRefIp(Map<String, IpAddress> mapNodeRefIp) {
504         this.mapNodeRefIp = mapNodeRefIp;
505     }
506
507     public Map<String, List<String>> getMapLinkFiber() {
508         return mapLinkFiber;
509     }
510
511     public void setMapLinkFiber(Map<String, List<String>> mapLinkFiber) {
512         this.mapLinkFiber = mapLinkFiber;
513     }
514
515     public Map<String, IpAddress> getMapFiberIp() {
516         return mapFiberIp;
517     }
518
519     public void setMapFiberIp(Map<String, IpAddress> mapFiberIp) {
520         this.mapFiberIp = mapFiberIp;
521     }
522
523     public List<String> getTrxList() {
524         return trxList;
525     }
526
527     public void setTrxList(List<String> trxList) {
528         this.trxList = trxList;
529     }
530 }