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