X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgnpy%2FGnpyTopoImpl.java;h=94049b975d73923a85ae957ae592ee68e628b766;hb=f5a8fe61d265bce36b2fca393d82685a22ac326a;hp=5560ea7ddcecb8a5bfad708dd39f1121d519c25a;hpb=38da8caec743f447c641ce0f414c242a5ece363b;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java index 5560ea7dd..94049b975 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java @@ -16,7 +16,6 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.regex.Pattern; import java.util.stream.IntStream; - import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.NetworkUtils; import org.opendaylight.transportpce.common.network.NetworkTransactionService; @@ -81,13 +80,13 @@ public class GnpyTopoImpl { private List connections = new ArrayList<>(); //Mapping elements //Mapping between the ord-topo and ord-ntw node - private Map mapDisgNodeRefNode = new HashMap(); + private Map mapDisgNodeRefNode = new HashMap<>(); //Mapping between the ord-ntw and node ip - private Map mapNodeRefIp = new HashMap(); + private Map mapNodeRefIp = new HashMap<>(); //Mapping between the ROADM-ROADM linkId/secElement and the linkId - private Map> mapLinkFiber = new HashMap>(); + private Map> mapLinkFiber = new HashMap<>(); //Mapping between the ROADM-ROADM linkId/secElement and ipAddress - private Map mapFiberIp = new HashMap(); + private Map mapFiberIp = new HashMap<>(); //List of Xponders private List trxList = new ArrayList<>(); //Initialize the 32 bit identifiers for the edfa and the fiber. @@ -141,7 +140,7 @@ public class GnpyTopoImpl { .read(LogicalDatastoreType.CONFIGURATION, insIdrOpenRoadmNet).get(); if (openRoadmNet.isPresent() && openRoadmTopo.isPresent()) { extractElements(openRoadmTopo,openRoadmNet); - extractConnections(openRoadmTopo,openRoadmNet); + extractConnections(openRoadmTopo); LOG.debug("In GnpyTopoImpl : elements and connections are well extracted"); } else { @@ -157,6 +156,9 @@ public class GnpyTopoImpl { private void extractElements(java.util.Optional openRoadmTopo, java.util.Optional openRoadmNet) throws GnpyException { + if ((!openRoadmNet.isPresent()) || (!openRoadmTopo.isPresent())) { + throw new GnpyException("In gnpyTopoImpl: openRoadmNet or openRoadmTopo is not present"); + } // Create the list of nodes List openRoadmNetNodeList = openRoadmNet.get().getNode(); List openRoadmTopoNodeList = openRoadmTopo.get().getNode(); @@ -169,9 +171,16 @@ public class GnpyTopoImpl { for (Node openRoadmTopoNode : openRoadmTopoNodeList) { // Retrieve the supporting node and the type of the node in openRoadm network List supportingNodeList = openRoadmTopoNode.getSupportingNode(); + for (SupportingNode supportingNode : supportingNodeList) { + if (!supportingNode.getNetworkRef().getValue().equals("openroadm-network")) { + continue; + } IpAddress ipAddress = null; 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; @@ -183,10 +192,17 @@ public class GnpyTopoImpl { commonNetworkNode1 = openRoadmNetNode.augmentation(org.opendaylight.yang.gen.v1 .http.org.openroadm.common.network.rev181130.Node1.class); ipAddress = openRoadmNetNode1.getIp(); + if (ipAddress == null) { + throw new GnpyException(String.format( + "In gnpyTopoImpl: ipAddress of node %s is null",nodeRef)); + } mapNodeRefIp.put(nodeRef, ipAddress); 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 (!nodesList.contains(nodeRef)) { Elements element = createElementsRoadm(LATITUDE, LONGITUTE, nodeRef, @@ -209,9 +225,11 @@ public class GnpyTopoImpl { } } - private void extractConnections(java.util.Optional openRoadmTopo, - java.util.Optional openRoadmNet) throws GnpyException { + private void extractConnections(java.util.Optional 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); List linksList = nw1.getLink(); // 1:EXPRESS-LINK 2:ADD-LINK 3:DROP-LINK @@ -228,6 +246,9 @@ public class GnpyTopoImpl { 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); + 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; @@ -277,7 +298,7 @@ public class GnpyTopoImpl { //Case of Span if (amplifiedLink.getSectionElement().getSectionElement() instanceof Span) { Span span = (Span) amplifiedLink.getSectionElement().getSectionElement(); - destIp = extractSpan((SpanAttributes) span.getSpan(), linkId, secElt); + destIp = extractSpan(span.getSpan(), linkId, secElt); } // Create a new link if (createNewConnection(srcIp,destIp)) { @@ -292,7 +313,7 @@ public class GnpyTopoImpl { throws GnpyException { SpanAttributes span = omsAttributes.getSpan(); - IpAddress destIp = extractSpan((SpanAttributes) span, linkId, linkId); + IpAddress destIp = extractSpan(span, linkId, linkId); if (createNewConnection(srcIp, destIp)) { return destIp; } @@ -330,10 +351,14 @@ public class GnpyTopoImpl { // Compute the length of the link List linkConcatenationList = span.getLinkConcatenation(); for (LinkConcatenation linkConcatenation : linkConcatenationList) { - double srlgLength = linkConcatenation.getSRLGLength(); + double srlgLength = linkConcatenation.getSRLGLength().toJava(); //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, ipFiber.getIpv4Address().getValue(), length, attIn, lossCoef, connIn, connOut, typeVariety); @@ -348,20 +373,20 @@ public class GnpyTopoImpl { 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)); + 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(); + 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().setFiberroadm(fiber).build(); - Elements element1 = new ElementsBuilder().setUid(uidFiber) + return new ElementsBuilder().setUid(uidFiber) .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Fiber.class) .setTypeVariety(typeVariety).setMetadata(metadata1) .setElementType(new FiberRoadmBuilder().setParams(params1).build()).build(); - return element1; } /* @@ -370,8 +395,8 @@ public class GnpyTopoImpl { 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)); + 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(); @@ -379,10 +404,9 @@ public class GnpyTopoImpl { .setOutVoa(outVoa).build(); Edfa edfa = new EdfaBuilder() .setOperational(operational).build(); - Elements element1 = new ElementsBuilder().setUid(uidEdfa) + return new ElementsBuilder().setUid(uidEdfa) .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Edfa.class) .setMetadata(metadata1).setElementType(edfa).setTypeVariety(typeVariety).build(); - return element1; } /* @@ -391,17 +415,16 @@ public class GnpyTopoImpl { 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(); - Roadm roadm = new RoadmBuilder().setTargetPchOutDb(new BigDecimal(targetPchOutDb)).build(); + Roadm roadm = new RoadmBuilder().setTargetPchOutDb(BigDecimal.valueOf(targetPchOutDb)).build(); Params params1 = new ParamsBuilder().setFiberroadm(roadm).build(); - Elements element1 = new ElementsBuilder().setUid(uidRoadm) + return new ElementsBuilder().setUid(uidRoadm) .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Roadm.class) .setMetadata(metadata1).setElementType(new FiberRoadmBuilder().setParams(params1).build()).build(); - return element1; } /* @@ -409,16 +432,15 @@ public class GnpyTopoImpl { */ 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) + return new ElementsBuilder().setUid(uidTrans) .setType(org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.Transceiver.class) .setMetadata(metadata1).setElementType(transceiver).build(); - return element1; } /* @@ -430,7 +452,7 @@ public class GnpyTopoImpl { } String fromNode = srcIp.getIpv4Address().getValue(); String toNode = destIp.getIpv4Address().getValue(); - if (fromNode == toNode) { + if (fromNode.equals(toNode)) { return false; } Connections connection = new ConnectionsBuilder().setFromNode(fromNode).setToNode(toNode).build(); @@ -467,8 +489,7 @@ public class GnpyTopoImpl { } fields[3] = Integer.toString(intF3); String nidString = fields[0] + "." + fields[1] + "." + fields[2] + "." + fields[3]; - Ipv4Address nid = new Ipv4Address(nidString); - return nid; + return new Ipv4Address(nidString); } public List getElements() {