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