package org.opendaylight.transportpce.pce.gnpy;
import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class GnpyServiceImpl {
private static final Logger LOG = LoggerFactory.getLogger(GnpyServiceImpl.class);
- private static final double FIX_CH = 0.05; //Fix-grid channel width (THz)
- private static final int NB_SLOT_BW = 4; //Number of slot in 50GHz channel (THz)
- private static final double SLOT_BW = 0.00625; //Nominal central frequency granularity (THz)
- private static final double MAX_CENTRAL_FREQ = 196.1; //Minimum channel center frequency (openRoadm spec) (THz)
- private static final double FLEX_CENTRAL_FREQ = 193.1; //Flex-grid reference channel frequency (THz)
- private static final double CONVERT_TH_HZ = 1e12; //Convert THz to Hz
+ //Fix-grid channel width (THz)
+ private static final double FIX_CH = 0.05;
+ //Number of slot in 50GHz channel (THz)
+ private static final int NB_SLOT_BW = 4;
+ //Nominal central frequency granularity (THz)
+ private static final double SLOT_BW = 0.00625;
+ //Minimum channel center frequency (openRoadm spec) (THz)
+ private static final double MAX_CENTRAL_FREQ = 196.1;
+ //Flex-grid reference channel frequency (THz)
+ private static final double FLEX_CENTRAL_FREQ = 193.1;
+ //Convert THz to Hz
+ private static final double CONVERT_TH_HZ = 1e12;
private List<PathRequest> pathRequest = new ArrayList<>();
private List<Synchronization> synchronization = new ArrayList<>();
- private Map<String, String> mapDisgNodeRefNode = new HashMap<String, String>();
- private Map<String, IpAddress> mapNodeRefIp = new HashMap<String, IpAddress>();
- private Map<String, List<String>> mapLinkFiber = new HashMap<String, List<String>>();
- private Map<String, IpAddress> mapFiberIp = new HashMap<String, IpAddress>();
+ private Map<String, String> mapDisgNodeRefNode = new HashMap<>();
+ private Map<String, IpAddress> mapNodeRefIp = new HashMap<>();
+ private Map<String, List<String>> mapLinkFiber = new HashMap<>();
+ private Map<String, IpAddress> mapFiberIp = new HashMap<>();
private List<String> trxList = new ArrayList<>();
private List<Elements> elements = new ArrayList<>();
private List<RouteObjectIncludeExclude> routeObjectIncludeExcludes = new ArrayList<>();
- private Long index = (long) 0; //index of the element in the path
private IpAddress currentNodeIpAddress = null;
/*
List<PathRequest> pathRequestList = new ArrayList<>();
PathRequest pathRequestEl = new PathRequestBuilder().setRequestId(requestId)
.setSource(this.mapNodeRefIp.get(sourceNode)).setDestination(this.mapNodeRefIp.get(destNode))
- .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes())
+ .setSrcTpId("srcTpId".getBytes(StandardCharsets.UTF_8))
+ .setDstTpId("dstTpId".getBytes(StandardCharsets.UTF_8))
.setBidirectional(false).setPathConstraints(pathConstraints).setPathConstraints(pathConstraints)
.setExplicitRouteObjects(explicitRouteObjects).build();
pathRequestList.add(pathRequestEl);
List<PathRequest> pathRequestList = new ArrayList<>();
PathRequest pathRequestEl = new PathRequestBuilder().setRequestId(requestId)
.setSource(this.mapNodeRefIp.get(sourceNode)).setDestination(this.mapNodeRefIp.get(destNode))
- .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes())
+ .setSrcTpId("srcTpId".getBytes(StandardCharsets.UTF_8))
+ .setDstTpId("dstTpId".getBytes(StandardCharsets.UTF_8))
.setBidirectional(false).setPathConstraints(pathConstraints)
.setExplicitRouteObjects(explicitRouteObjects).build();
pathRequestList.add(pathRequestEl);
//Extract RouteObjectIncludeExclude list in the case of pre-computed path A-to-Z
private void extractRouteObjectIcludeAtoZ(List<AToZ> listAtoZ) throws GnpyException {
+ Long index = 0L;
for (int i = 0; i < listAtoZ.size(); i++) {
- createResource(listAtoZ.get(i).getResource().getResource());
+ index = createResource(listAtoZ.get(i).getResource().getResource(),index);
}
}
//Extract RouteObjectIncludeExclude list in the case of pre-computed path Z-to-A
private void extractRouteObjectIcludeZtoA(List<ZToA> listZtoA) throws GnpyException {
+ Long index = 0L;
for (int i = 0; i < listZtoA.size(); i++) {
- createResource(listZtoA.get(i).getResource().getResource());
+ index = createResource(listZtoA.get(i).getResource().getResource(),index);
}
}
//Create a new resource node or link
- private void createResource(@Nullable Resource resource) throws GnpyException {
+ private Long createResource(@Nullable Resource resource, Long index) throws GnpyException {
+ Long idx = index;
if (resource
instanceof
org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
if (node.getNodeId() == null) {
throw new GnpyException("In gnpyServiceImpl: nodeId is null");
}
- addNodeToRouteObject(this.mapDisgNodeRefNode.get(node.getNodeId()));
- return;
+ idx = addNodeToRouteObject(this.mapDisgNodeRefNode.get(node.getNodeId()),idx);
}
if (resource
.pce.resource.resource.resource.Link link =
(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
.pce.resource.resource.resource.Link) resource;
- addLinkToRouteObject(link.getLinkId());
- return;
+ idx = addLinkToRouteObject(link.getLinkId(),idx);
}
+ return idx;
}
//Create RouteObjectIncludeExclude list in the case of hard constraint
private void extractHardConstraints(PceConstraints pceHardConstraints) throws GnpyException {
List<String> listNodeToInclude = getListToInclude(pceHardConstraints);
- if (listNodeToInclude != null) {
+ if (!listNodeToInclude.isEmpty()) {
+ Long index = 0L;
for (int i = 0; i < listNodeToInclude.size(); i++) {
String nodeId = listNodeToInclude.get(i);
- addNodeToRouteObject(nodeId);
+ index = addNodeToRouteObject(nodeId, index);
}
}
}
}
//Add a node to the route object
- private void addNodeToRouteObject(String nodeRef) throws GnpyException {
- boolean found = false;
+ private Long addNodeToRouteObject(String nodeRef, Long index) throws GnpyException {
+ Long idx = index;
IpAddress ipAddress = this.mapNodeRefIp.get(nodeRef);
if (ipAddress == null) {
throw new GnpyException(String.format("In gnpyServiceImpl : NodeRef %s does not exist", nodeRef));
for (Elements element : this.elements) {
if (element.getUid().contains(ipAddress.getIpv4Address().getValue())) {
- if ((this.currentNodeIpAddress == null) || (this.currentNodeIpAddress != ipAddress)) {
+ if ((this.currentNodeIpAddress == null) || (!this.currentNodeIpAddress.equals(ipAddress))) {
this.currentNodeIpAddress = ipAddress;
RouteObjectIncludeExclude routeObjectIncludeExclude =
- addRouteObjectIncludeExclude(ipAddress, Uint32.valueOf(1));
+ addRouteObjectIncludeExclude(ipAddress, Uint32.valueOf(1),idx);
routeObjectIncludeExcludes.add(routeObjectIncludeExclude);
- index++;
- found = true;
+ idx += 1;
}
- return;
+ return idx;
}
}
- if (!found) {
- throw new GnpyException(String.format("In gnpyServiceImpl : NodeRef %s does not exist",nodeRef));
- }
+ throw new GnpyException(String.format("In gnpyServiceImpl : NodeRef %s does not exist",nodeRef));
}
//Add a link to the route object
- private void addLinkToRouteObject(String linkId) throws GnpyException {
+ private Long addLinkToRouteObject(String linkId, Long index) throws GnpyException {
+ Long idx = index;
if (linkId == null) {
- throw new GnpyException(String.format("In GnpyServiceImpl: the linkId does not exist"));
+ throw new GnpyException("In GnpyServiceImpl: the linkId is null");
}
//Only the ROADM-to-ROADM link are included in the route object
if (!mapLinkFiber.containsKey(linkId)) {
- return;
+ return idx;
}
List<String> listSubLink = this.mapLinkFiber.get(linkId);
if (listSubLink == null) {
subLink));
}
RouteObjectIncludeExclude routeObjectIncludeExclude =
- addRouteObjectIncludeExclude(fiberIp, Uint32.valueOf(1));
+ addRouteObjectIncludeExclude(fiberIp, Uint32.valueOf(1),idx);
routeObjectIncludeExcludes.add(routeObjectIncludeExclude);
- index++;
+ idx += 1;
}
+ return idx;
}
// Add routeObjectIncludeExclude
- private RouteObjectIncludeExclude addRouteObjectIncludeExclude(IpAddress ipAddress, Uint32 teTpValue) {
+ private RouteObjectIncludeExclude addRouteObjectIncludeExclude(IpAddress ipAddress, Uint32 teTpValue, Long index) {
TeNodeId teNodeId = new TeNodeId(ipAddress);
TeTpId teTpId = new TeTpId(teTpValue);
NumUnnumHop numUnnumHop = new org.opendaylight.yang.gen.v1.gnpy.path.rev200202.explicit.route.hop.type.num
.setHopType(TeHopType.STRICT).build();
Type type1 = new NumUnnumHopBuilder().setNumUnnumHop(numUnnumHop).build();
// Create routeObjectIncludeExclude element
- RouteObjectIncludeExclude routeObjectIncludeExclude = new RouteObjectIncludeExcludeBuilder()
- .setIndex(this.index).setExplicitRouteUsage(RouteIncludeEro.class).setType(type1).build();
- return routeObjectIncludeExclude;
+ return new RouteObjectIncludeExcludeBuilder()
+ .setIndex(index).setExplicitRouteUsage(RouteIncludeEro.class).setType(type1).build();
}
//Create the path constraints
TeBandwidth teBandwidth = new TeBandwidthBuilder().setPathBandwidth(new BigDecimal(rate))
.setTechnology("flexi-grid").setTrxType("openroadm-beta1")
.setTrxMode("W100G").setEffectiveFreqSlot(effectiveFreqSlot)
- .setSpacing(new BigDecimal(FIX_CH * CONVERT_TH_HZ)).build();
- PathConstraints pathConstraints = new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
- return pathConstraints;
+ .setSpacing(BigDecimal.valueOf(FIX_CH * CONVERT_TH_HZ)).build();
+ return new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
}
//Create the synchronization