Optical topology provider for UC1
Change-Id: I1b25c9412b5180f9dce167f8700eb84baba70486
diff --git a/apps/optical/pom.xml b/apps/optical/pom.xml
new file mode 100644
index 0000000..0264f8a
--- /dev/null
+++ b/apps/optical/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-apps</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-app-optical</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS application for packet/optical deployments</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-cli</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalConfigProvider.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalConfigProvider.java
new file mode 100644
index 0000000..86c1c0b
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalConfigProvider.java
@@ -0,0 +1,338 @@
+package org.onlab.onos.optical.cfg;
+
+import static org.onlab.onos.net.DeviceId.deviceId;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.DefaultAnnotations;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.PortNumber;
+import org.onlab.onos.net.device.DefaultDeviceDescription;
+import org.onlab.onos.net.device.DeviceDescription;
+import org.onlab.onos.net.device.DeviceProvider;
+import org.onlab.onos.net.device.DeviceProviderRegistry;
+import org.onlab.onos.net.device.DeviceProviderService;
+import org.onlab.onos.net.link.DefaultLinkDescription;
+import org.onlab.onos.net.link.LinkProvider;
+import org.onlab.onos.net.link.LinkProviderRegistry;
+import org.onlab.onos.net.link.LinkProviderService;
+import org.onlab.onos.net.provider.AbstractProvider;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.packet.ChassisId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * OpticalConfigProvider emulates the SB network provider for optical switches,
+ * optical links and any other state that needs to be configured for correct network
+ * operations.
+ *
+ */
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Component(immediate = true)
+public class OpticalConfigProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(OpticalConfigProvider.class);
+
+ // TODO: fix hard coded file path later.
+ private static final String DEFAULT_CONFIG_FILE =
+ "/opt/onos/config/demo-3-roadm-2-ps.json";
+ private String configFileName = DEFAULT_CONFIG_FILE;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkProviderRegistry linkProviderRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceProviderRegistry deviceProviderRegistry;
+
+ private static final String OPTICAL_ANNOTATION = "optical.";
+
+ private LinkProviderService linkProviderService;
+ private DeviceProviderService deviceProviderService;
+
+ private static final List<Roadm> RAW_ROADMS = new ArrayList<>();
+ private static final List<WdmLink> RAW_WDMLINKS = new ArrayList<>();
+ private static final List<PktOptLink> RAW_PKTOPTLINKS = new ArrayList<>();
+
+ private static final String ROADM = "Roadm";
+ private static final String WDM_LINK = "wdmLink";
+ private static final String PKT_OPT_LINK = "pktOptLink";
+
+ protected OpticalNetworkConfig opticalNetworkConfig;
+
+ public OpticalConfigProvider() {
+ super(new ProviderId("of", "org.onlab.onos.provider.opticalConfig", true));
+ }
+
+ @Activate
+ protected void activate() {
+ linkProviderService = linkProviderRegistry.register(this);
+ deviceProviderService = deviceProviderRegistry.register(this);
+ log.info("Starting optical network configuration process...");
+ log.info("Optical config file set to {}", configFileName);
+
+ loadOpticalConfig();
+ parseOpticalConfig();
+ publishOpticalConfig();
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ linkProviderRegistry.unregister(this);
+ linkProviderService = null;
+ deviceProviderRegistry.unregister(this);
+ deviceProviderService = null;
+ RAW_ROADMS.clear();
+ RAW_WDMLINKS.clear();
+ RAW_PKTOPTLINKS.clear();
+ log.info("Stopped");
+ }
+
+ private void loadOpticalConfig() {
+ ObjectMapper mapper = new ObjectMapper();
+ opticalNetworkConfig = new OpticalNetworkConfig();
+ try {
+ opticalNetworkConfig = mapper.readValue(new File(configFileName), OpticalNetworkConfig.class);
+ } catch (JsonParseException e) {
+ String err = String.format("JsonParseException while loading network "
+ + "config from file: %s: %s", configFileName, e.getMessage());
+ log.error(err, e);
+ } catch (JsonMappingException e) {
+ String err = String.format(
+ "JsonMappingException while loading network config "
+ + "from file: %s: %s", configFileName, e.getMessage());
+ log.error(err, e);
+ } catch (IOException e) {
+ String err = String.format("IOException while loading network config "
+ + "from file: %s %s", configFileName, e.getMessage());
+ log.error(err, e);
+ }
+ }
+
+ private void parseOpticalConfig() {
+ List<OpticalSwitchDescription> swList = opticalNetworkConfig.getOpticalSwitches();
+ List<OpticalLinkDescription> lkList = opticalNetworkConfig.getOpticalLinks();
+
+ for (OpticalSwitchDescription sw : swList) {
+ String swtype = sw.getType();
+ boolean allow = sw.isAllowed();
+ if (swtype.equals(ROADM) && allow) {
+ int regNum = 0;
+ Set<Map.Entry<String, JsonNode>> m = sw.params.entrySet();
+ for (Map.Entry<String, JsonNode> e : m) {
+ String key = e.getKey();
+ JsonNode j = e.getValue();
+ if (key.equals("numRegen")) {
+ regNum = j.asInt();
+ }
+ }
+
+ Roadm newRoadm = new Roadm();
+ newRoadm.setName(sw.name);
+ newRoadm.setNodeId(sw.nodeDpid);
+ newRoadm.setLongtitude(sw.longitude);
+ newRoadm.setLatitude(sw.latitude);
+ newRoadm.setRegenNum(regNum);
+
+ RAW_ROADMS.add(newRoadm);
+ log.info(newRoadm.toString());
+ }
+ }
+
+ for (OpticalLinkDescription lk : lkList) {
+ String lktype = lk.getType();
+ switch (lktype) {
+ case WDM_LINK:
+ WdmLink newWdmLink = new WdmLink();
+ newWdmLink.setSrcNodeId(lk.getNodeDpid1());
+ newWdmLink.setSnkNodeId(lk.getNodeDpid2());
+ newWdmLink.setAdminWeight(1000); // default weight for each WDM link.
+ Set<Map.Entry<String, JsonNode>> m = lk.params.entrySet();
+ for (Map.Entry<String, JsonNode> e : m) {
+ String key = e.getKey();
+ JsonNode j = e.getValue();
+ if (key.equals("nodeName1")) {
+ newWdmLink.setSrcNodeName(j.asText());
+ } else if (key.equals("nodeName2")) {
+ newWdmLink.setSnkNodeName(j.asText());
+ } else if (key.equals("port1")) {
+ newWdmLink.setSrcPort(j.asInt());
+ } else if (key.equals("port2")) {
+ newWdmLink.setSnkPort(j.asInt());
+ } else if (key.equals("distKms")) {
+ newWdmLink.setDistance(j.asDouble());
+ } else if (key.equals("numWaves")) {
+ newWdmLink.setWavelengthNumber(j.asInt());
+ } else {
+ log.error("error found");
+ // TODO add exception processing;
+ }
+ }
+ RAW_WDMLINKS.add(newWdmLink);
+ log.info(newWdmLink.toString());
+
+ break;
+
+ case PKT_OPT_LINK:
+ PktOptLink newPktOptLink = new PktOptLink();
+ newPktOptLink.setSrcNodeId(lk.getNodeDpid1());
+ newPktOptLink.setSnkNodeId(lk.getNodeDpid2());
+ newPktOptLink.setAdminWeight(10); // default weight for each packet-optical link.
+ Set<Map.Entry<String, JsonNode>> ptm = lk.params.entrySet();
+ for (Map.Entry<String, JsonNode> e : ptm) {
+ String key = e.getKey();
+ JsonNode j = e.getValue();
+ if (key.equals("nodeName1")) {
+ newPktOptLink.setSrcNodeName(j.asText());
+ } else if (key.equals("nodeName2")) {
+ newPktOptLink.setSnkNodeName(j.asText());
+ } else if (key.equals("port1")) {
+ newPktOptLink.setSrcPort(j.asInt());
+ } else if (key.equals("port2")) {
+ newPktOptLink.setSnkPort(j.asInt());
+ } else if (key.equals("bandWidth")) {
+ newPktOptLink.setBandwdith(j.asDouble());
+ } else {
+ log.error("error found");
+ // TODO add exception processing;
+ }
+ }
+
+ RAW_PKTOPTLINKS.add(newPktOptLink);
+ log.info(newPktOptLink.toString());
+ break;
+ default:
+ }
+ }
+ }
+
+ private void publishOpticalConfig() {
+ if (deviceProviderService == null || linkProviderService == null) {
+ return;
+ }
+
+ // Discover the optical ROADM objects
+ Iterator<Roadm> iterWdmNode = RAW_ROADMS.iterator();
+ while (iterWdmNode.hasNext()) {
+ Roadm value = iterWdmNode.next();
+ DeviceId did = deviceId("of:" + value.getNodeId().replace(":", ""));
+ ChassisId cid = new ChassisId(value.getNodeId());
+ DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
+ .set(OPTICAL_ANNOTATION + "switchType", "ROADM")
+ .set(OPTICAL_ANNOTATION + "switchName", value.getName())
+ .set(OPTICAL_ANNOTATION + "latitude", Double.toString(value.getLatitude()))
+ .set(OPTICAL_ANNOTATION + "longtitude", Double.toString(value.getLongtitude()))
+ .set(OPTICAL_ANNOTATION + "regNum", Integer.toString(value.getRegenNum()))
+ .build();
+
+ DeviceDescription description =
+ new DefaultDeviceDescription(did.uri(),
+ Device.Type.SWITCH,
+ "",
+ "",
+ "",
+ "",
+ cid,
+ extendedAttributes);
+ deviceProviderService.deviceConnected(did, description);
+ }
+
+ // Discover the optical WDM link objects
+ Iterator<WdmLink> iterWdmlink = RAW_WDMLINKS.iterator();
+ while (iterWdmlink.hasNext()) {
+ WdmLink value = iterWdmlink.next();
+
+ DeviceId srcNodeId = deviceId("of:" + value.getSrcNodeId().replace(":", ""));
+ DeviceId snkNodeId = deviceId("of:" + value.getSnkNodeId().replace(":", ""));
+
+ PortNumber srcPort = PortNumber.portNumber(value.getSrcPort());
+ PortNumber snkPort = PortNumber.portNumber(value.getSnkPort());
+
+ ConnectPoint srcPoint = new ConnectPoint(srcNodeId, srcPort);
+ ConnectPoint snkPoint = new ConnectPoint(snkNodeId, snkPort);
+
+ DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
+ .set(OPTICAL_ANNOTATION + "linkType", "WDM")
+ .set(OPTICAL_ANNOTATION + "distance", Double.toString(value.getDistance()))
+ .set(OPTICAL_ANNOTATION + "cost", Double.toString(value.getDistance()))
+ .set(OPTICAL_ANNOTATION + "adminWeight", Double.toString(value.getAdminWeight()))
+ .set(OPTICAL_ANNOTATION + "wavelengthNum", Integer.toString(value.getWavelengthNumber()))
+ .build();
+
+ DefaultLinkDescription linkDescription =
+ new DefaultLinkDescription(srcPoint,
+ snkPoint,
+ Link.Type.DIRECT,
+ extendedAttributes);
+
+ linkProviderService.linkDetected(linkDescription);
+ log.info(String.format("WDM link: %s : %s",
+ linkDescription.src().toString(), linkDescription.dst().toString()));
+ }
+
+ // Discover the packet optical link objects
+ Iterator<PktOptLink> iterPktOptlink = RAW_PKTOPTLINKS.iterator();
+ while (iterPktOptlink.hasNext()) {
+ PktOptLink value = iterPktOptlink.next();
+ DeviceId srcNodeId = deviceId("of:" + value.getSrcNodeId().replace(":", ""));
+ DeviceId snkNodeId = deviceId("of:" + value.getSnkNodeId().replace(":", ""));
+
+ PortNumber srcPort = PortNumber.portNumber(value.getSrcPort());
+ PortNumber snkPort = PortNumber.portNumber(value.getSnkPort());
+
+ ConnectPoint srcPoint = new ConnectPoint(srcNodeId, srcPort);
+ ConnectPoint snkPoint = new ConnectPoint(snkNodeId, snkPort);
+
+ DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
+ .set(OPTICAL_ANNOTATION + "linkType", "PktOptLink")
+ .set(OPTICAL_ANNOTATION + "bandwidth", Double.toString(value.getBandwidth()))
+ .set(OPTICAL_ANNOTATION + "cost", Double.toString(value.getBandwidth()))
+ .set(OPTICAL_ANNOTATION + "adminWeight", Double.toString(value.getAdminWeight()))
+ .build();
+
+ DefaultLinkDescription linkDescription =
+ new DefaultLinkDescription(srcPoint,
+ snkPoint,
+ Link.Type.DIRECT,
+ extendedAttributes);
+
+ linkProviderService.linkDetected(linkDescription);
+ log.info(String.format("Packet-optical link: %s : %s",
+ linkDescription.src().toString(), linkDescription.dst().toString()));
+ }
+
+ }
+
+ @Override
+ public void triggerProbe(Device device) {
+ // TODO We may want to consider re-reading config files and publishing them based on this event.
+ }
+
+ @Override
+ public void roleChanged(Device device, MastershipRole newRole) {
+ // TODO Auto-generated method stub.
+ }
+
+}
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalLinkDescription.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalLinkDescription.java
new file mode 100644
index 0000000..af616ef
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalLinkDescription.java
@@ -0,0 +1,89 @@
+package org.onlab.onos.optical.cfg;
+
+import java.util.Map;
+import org.codehaus.jackson.JsonNode;
+import org.onlab.util.HexString;
+
+/**
+ * Public class corresponding to JSON described data model.
+ */
+public class OpticalLinkDescription {
+ protected String type;
+ protected Boolean allowed;
+ protected long dpid1;
+ protected long dpid2;
+ protected String nodeDpid1;
+ protected String nodeDpid2;
+ protected Map<String, JsonNode> params;
+ protected Map<String, String> publishAttributes;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Boolean isAllowed() {
+ return allowed;
+ }
+
+ public void setAllowed(Boolean allowed) {
+ this.allowed = allowed;
+ }
+
+ public String getNodeDpid1() {
+ return nodeDpid1;
+ }
+
+ public void setNodeDpid1(String nodeDpid1) {
+ this.nodeDpid1 = nodeDpid1;
+ this.dpid1 = HexString.toLong(nodeDpid1);
+ }
+
+ public String getNodeDpid2() {
+ return nodeDpid2;
+ }
+
+ public void setNodeDpid2(String nodeDpid2) {
+ this.nodeDpid2 = nodeDpid2;
+ this.dpid2 = HexString.toLong(nodeDpid2);
+ }
+
+ public long getDpid1() {
+ return dpid1;
+ }
+
+ public void setDpid1(long dpid1) {
+ this.dpid1 = dpid1;
+ this.nodeDpid1 = HexString.toHexString(dpid1);
+ }
+
+ public long getDpid2() {
+ return dpid2;
+ }
+
+ public void setDpid2(long dpid2) {
+ this.dpid2 = dpid2;
+ this.nodeDpid2 = HexString.toHexString(dpid2);
+ }
+
+ public Map<String, JsonNode> getParams() {
+ return params;
+ }
+
+ public void setParams(Map<String, JsonNode> params) {
+ this.params = params;
+ }
+
+ public Map<String, String> getPublishAttributes() {
+ return publishAttributes;
+ }
+
+ public void setPublishAttributes(Map<String, String> publishAttributes) {
+ this.publishAttributes = publishAttributes;
+ }
+
+}
+
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalNetworkConfig.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalNetworkConfig.java
new file mode 100644
index 0000000..a34f843
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalNetworkConfig.java
@@ -0,0 +1,40 @@
+package org.onlab.onos.optical.cfg;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Public class corresponding to JSON described data model.
+ */
+public class OpticalNetworkConfig {
+ protected static final Logger log = LoggerFactory.getLogger(OpticalNetworkConfig.class);
+
+ private List<OpticalSwitchDescription> opticalSwitches;
+ private List<OpticalLinkDescription> opticalLinks;
+
+ public OpticalNetworkConfig() {
+ opticalSwitches = new ArrayList<OpticalSwitchDescription>();
+ opticalLinks = new ArrayList<OpticalLinkDescription>();
+ }
+
+ public List<OpticalSwitchDescription> getOpticalSwitches() {
+ return opticalSwitches;
+ }
+
+ public void setOpticalSwitches(List<OpticalSwitchDescription> switches) {
+ this.opticalSwitches = switches;
+ }
+
+ public List<OpticalLinkDescription> getOpticalLinks() {
+ return opticalLinks;
+ }
+
+ public void setOpticalLinks(List<OpticalLinkDescription> links) {
+ this.opticalLinks = links;
+ }
+
+}
+
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalSwitchDescription.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalSwitchDescription.java
new file mode 100644
index 0000000..18a3982
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/OpticalSwitchDescription.java
@@ -0,0 +1,100 @@
+package org.onlab.onos.optical.cfg;
+
+import java.util.Map;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.onlab.util.HexString;
+
+/**
+ * Public class corresponding to JSON described data model.
+ */
+public class OpticalSwitchDescription {
+ protected String name;
+ protected long dpid;
+ protected String nodeDpid;
+ protected String type;
+ protected double latitude;
+ protected double longitude;
+ protected boolean allowed;
+ protected Map<String, JsonNode> params;
+ protected Map<String, String> publishAttributes;
+
+ public String getName() {
+ return name;
+ }
+ @JsonProperty("name")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getDpid() {
+ return dpid;
+ }
+ @JsonProperty("dpid")
+ public void setDpid(long dpid) {
+ this.dpid = dpid;
+ this.nodeDpid = HexString.toHexString(dpid);
+ }
+
+ public String getNodeDpid() {
+ return nodeDpid;
+ }
+
+ public String getHexDpid() {
+ return nodeDpid;
+ }
+
+ public void setNodeDpid(String nodeDpid) {
+ this.nodeDpid = nodeDpid;
+ this.dpid = HexString.toLong(nodeDpid);
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public boolean isAllowed() {
+ return allowed;
+ }
+
+ public void setAllowed(boolean allowed) {
+ this.allowed = allowed;
+ }
+
+ public Map<String, JsonNode> getParams() {
+ return params;
+ }
+
+ public void setParams(Map<String, JsonNode> params) {
+ this.params = params;
+ }
+
+ public Map<String, String> getPublishAttributes() {
+ return publishAttributes;
+ }
+
+ public void setPublishAttributes(Map<String, String> publishAttributes) {
+ this.publishAttributes = publishAttributes;
+ }
+
+}
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/PktOptLink.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/PktOptLink.java
new file mode 100644
index 0000000..206109f
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/PktOptLink.java
@@ -0,0 +1,110 @@
+package org.onlab.onos.optical.cfg;
+
+/**
+ * Packet-optical link Java data object.
+ */
+class PktOptLink {
+ private String srcNodeName;
+ private String snkNodeName;
+ private String srcNodeId;
+ private String snkNodeId;
+ private int srcPort;
+ private int snkPort;
+ private double bandwidth;
+ private double cost;
+ private long adminWeight;
+
+ public PktOptLink(String srcName, String snkName) {
+ this.srcNodeName = srcName;
+ this.snkNodeName = snkName;
+ }
+
+ public PktOptLink() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public void setSrcNodeName(String name) {
+ this.srcNodeName = name;
+ }
+
+ public String getSrcNodeName() {
+ return this.srcNodeName;
+ }
+
+ public void setSnkNodeName(String name) {
+ this.snkNodeName = name;
+ }
+
+ public String getSnkNodeName() {
+ return this.snkNodeName;
+ }
+
+ public void setSrcNodeId(String nodeId) {
+ this.srcNodeId = nodeId;
+ }
+
+ public String getSrcNodeId() {
+ return this.srcNodeId;
+ }
+
+ public void setSnkNodeId(String nodeId) {
+ this.snkNodeId = nodeId;
+ }
+
+ public String getSnkNodeId() {
+ return this.snkNodeId;
+ }
+
+ public void setSrcPort(int port) {
+ this.srcPort = port;
+ }
+
+ public int getSrcPort() {
+ return this.srcPort;
+ }
+
+ public void setSnkPort(int port) {
+ this.snkPort = port;
+ }
+
+ public int getSnkPort() {
+ return this.snkPort;
+ }
+
+ public void setBandwdith(double x) {
+ this.bandwidth = x;
+ }
+
+ public double getBandwidth() {
+ return this.bandwidth;
+ }
+
+ public void setCost(double x) {
+ this.cost = x;
+ }
+
+ public double getCost() {
+ return this.cost;
+ }
+
+ public void setAdminWeight(long x) {
+ this.adminWeight = x;
+ }
+
+ public long getAdminWeight() {
+ return this.adminWeight;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder(" srcNodeName: ").append(this.srcNodeName)
+ .append(" snkNodeName: ").append(this.snkNodeName)
+ .append(" srcNodeId: ").append(this.srcNodeId)
+ .append(" snkNodeId: ").append(this.snkNodeId)
+ .append(" srcPort: ").append(this.srcPort)
+ .append(" snkPort: ").append(this.snkPort)
+ .append(" bandwidth: ").append(this.bandwidth)
+ .append(" cost: ").append(this.cost)
+ .append(" adminWeight: ").append(this.adminWeight).toString();
+ }
+}
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/Roadm.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/Roadm.java
new file mode 100644
index 0000000..beca5af
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/Roadm.java
@@ -0,0 +1,106 @@
+package org.onlab.onos.optical.cfg;
+
+/**
+ * ROADM java data object converted from a JSON file.
+ */
+class Roadm {
+ private String name;
+ private String nodeID;
+ private double longtitude;
+ private double latitude;
+ private int regenNum;
+
+ //TODO use the following attributes when needed for configurations
+ private int tPort10G;
+ private int tPort40G;
+ private int tPort100G;
+ private int wPort;
+
+ public Roadm() {
+ }
+
+ public Roadm(String name) {
+ this.name = name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setNodeId(String nameId) {
+ this.nodeID = nameId;
+ }
+
+ public String getNodeId() {
+ return this.nodeID;
+ }
+
+ public void setLongtitude(double x) {
+ this.longtitude = x;
+ }
+
+ public double getLongtitude() {
+ return this.longtitude;
+ }
+
+ public void setLatitude(double y) {
+ this.latitude = y;
+ }
+
+ public double getLatitude() {
+ return this.latitude;
+ }
+
+ public void setRegenNum(int num) {
+ this.regenNum = num;
+ }
+ public int getRegenNum() {
+ return this.regenNum;
+ }
+
+ public void setTport10GNum(int num) {
+ this.tPort10G = num;
+ }
+ public int getTport10GNum() {
+ return this.tPort10G;
+ }
+
+ public void setTport40GNum(int num) {
+ this.tPort40G = num;
+ }
+ public int getTport40GNum() {
+ return this.tPort40G;
+ }
+
+ public void setTport100GNum(int num) {
+ this.tPort100G = num;
+ }
+ public int getTport100GNum() {
+ return this.tPort100G;
+ }
+
+ public void setWportNum(int num) {
+ this.wPort = num;
+ }
+ public int getWportNum() {
+ return this.wPort;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder(" ROADM Name: ").append(this.name)
+ .append(" nodeID: ").append(this.nodeID)
+ .append(" longtitude: ").append(this.longtitude)
+ .append(" latitude: ").append(this.latitude)
+ .append(" regenNum: ").append(this.regenNum)
+ .append(" 10GTportNum: ").append(this.tPort10G)
+ .append(" 40GTportNum: ").append(this.tPort40G)
+ .append(" 100GTportNum: ").append(this.tPort100G)
+ .append(" WportNum: ").append(this.wPort).toString();
+ }
+}
+
diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/cfg/WdmLink.java b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/WdmLink.java
new file mode 100644
index 0000000..5e7b468
--- /dev/null
+++ b/apps/optical/src/main/java/org/onlab/onos/optical/cfg/WdmLink.java
@@ -0,0 +1,121 @@
+package org.onlab.onos.optical.cfg;
+
+/**
+ * WDM Link Java data object converted from a JSON file.
+ */
+class WdmLink {
+ private String srcNodeName;
+ private String snkNodeName;
+ private String srcNodeId;
+ private String snkNodeId;
+ private int srcPort;
+ private int snkPort;
+ private double distance;
+ private double cost;
+ private int wavelengthNumber;
+ private long adminWeight;
+
+ public WdmLink(String name1, String name2) {
+ this.srcNodeName = name1;
+ this.snkNodeName = name2;
+ }
+
+ public WdmLink() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public void setSrcNodeName(String name) {
+ this.srcNodeName = name;
+ }
+
+ public String getSrcNodeName() {
+ return this.srcNodeName;
+ }
+
+ public void setSnkNodeName(String name) {
+ this.snkNodeName = name;
+ }
+
+ public String getSnkNodeName() {
+ return this.snkNodeName;
+ }
+
+ public void setSrcNodeId(String nodeId) {
+ this.srcNodeId = nodeId;
+ }
+
+ public String getSrcNodeId() {
+ return this.srcNodeId;
+ }
+
+ public void setSnkNodeId(String nodeId) {
+ this.snkNodeId = nodeId;
+ }
+
+ public String getSnkNodeId() {
+ return this.snkNodeId;
+ }
+
+ public void setSrcPort(int port) {
+ this.srcPort = port;
+ }
+
+ public int getSrcPort() {
+ return this.srcPort;
+ }
+
+ public void setSnkPort(int port) {
+ this.snkPort = port;
+ }
+
+ public int getSnkPort() {
+ return this.snkPort;
+ }
+
+ public void setDistance(double x) {
+ this.distance = x;
+ }
+
+ public double getDistance() {
+ return this.distance;
+ }
+
+ public void setCost(double x) {
+ this.cost = x;
+ }
+
+ public double getCost() {
+ return this.cost;
+ }
+
+ public void setWavelengthNumber(int x) {
+ this.wavelengthNumber = x;
+ }
+
+ public int getWavelengthNumber() {
+ return this.wavelengthNumber;
+ }
+
+ public void setAdminWeight(long x) {
+ this.adminWeight = x;
+ }
+
+ public long getAdminWeight() {
+ return this.adminWeight;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder(" srcNodeName: ").append(this.srcNodeName)
+ .append(" snkNodeName: ").append(this.snkNodeName)
+ .append(" srcNodeId: ").append(this.srcNodeId)
+ .append(" snkNodeId: ").append(this.snkNodeId)
+ .append(" srcPort: ").append(this.srcPort)
+ .append(" snkPort: ").append(this.snkPort)
+ .append(" distance: ").append(this.distance)
+ .append(" cost: ").append(this.cost)
+ .append(" wavelengthNumber: ").append(this.wavelengthNumber)
+ .append(" adminWeight: ").append(this.adminWeight).toString();
+ }
+}
+
diff --git a/apps/optical/src/main/resources/demo-10-roadm-6-ps.json b/apps/optical/src/main/resources/demo-10-roadm-6-ps.json
new file mode 100644
index 0000000..e4e1122
--- /dev/null
+++ b/apps/optical/src/main/resources/demo-10-roadm-6-ps.json
@@ -0,0 +1,391 @@
+{
+ "opticalSwitches": [
+ {
+ "allowed": true,
+ "latitude": 37.6,
+ "longitude": 122.3,
+ "name": "SFO-W10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:01",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 37.3,
+ "longitude": 121.9,
+ "name": "SJC-W10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:02",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 33.9,
+ "longitude": 118.4
+ "name": "LAX-W10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:03",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 32.8,
+ "longitude": 117.1,
+ "name": "SDG-W10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:04",
+ "params": {
+ "numRegen": 3
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 44.8,
+ "longitude": 93.1,
+ "name": "MSP-M10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:05",
+ "params": {
+ "numRegen": 3
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 32.8,
+ "longitude": 97.1,
+ "name": "DFW-M10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:06",
+ "params": {
+ "numRegen": 3
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 41.8,
+ "longitude": 120.1,
+ "name": "CHG-N10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:07",
+ "params": {
+ "numRegen": 3
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 38.8,
+ "longitude": 77.1,
+ "name": "IAD-M10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:08",
+ "params": {
+ "numRegen": 3
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 40.8,
+ "longitude": 73.1,
+ "name": "JFK-E10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:09",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+
+ },
+
+ {
+ "allowed": true,
+ "latitude": 33.8,
+ "longitude": 84.1,
+ "name": "ATL-S10",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:0A",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+ }
+
+ ],
+
+ "opticalLinks": [
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:01",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:02",
+ "params": {
+ "distKms": 1000,
+ "nodeName1": "SFO-W10",
+ "nodeName2": "SJC-W10",
+ "numWaves": 80,
+ "port1": 10,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:02",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:03",
+ "params": {
+ "distKms": 1000,
+ "nodeName1": "SJC-W10",
+ "nodeName2": "LAX-W10",
+ "numWaves": 80,
+ "port1": 20,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:03",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:04",
+ "params": {
+ "distKms": 1000,
+ "nodeName1": "LAX-W10",
+ "nodeName2": "SDG-W10",
+ "numWaves": 80,
+ "port1": 30,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:02",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:05",
+ "params": {
+ "distKms": 4000,
+ "nodeName1": "SJC-W10",
+ "nodeName2": "MSP-M10",
+ "numWaves": 80,
+ "port1": 20,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:03",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:06",
+ "params": {
+ "distKms": 5000,
+ "nodeName1": "LAX-W10",
+ "nodeName2": "DFW-M10",
+ "numWaves": 80,
+ "port1": 20,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:05",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:06",
+ "params": {
+ "distKms": 3000,
+ "nodeName1": "MSP-M10",
+ "nodeName2": "DFW-M10",
+ "numWaves": 80,
+ "port1": 30,
+ "port2": 20
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:05",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:07",
+ "params": {
+ "distKms": 3000,
+ "nodeName1": "MSP-M10",
+ "nodeName2": "CHG-N10",
+ "numWaves": 80,
+ "port1": 20,
+ "port2": 21
+ },
+ "type": "wdmLink"
+ },
+
+ {
+
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:06",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:08",
+ "params": {
+ "distKms": 4000,
+ "nodeName1": "DFW-M10",
+ "nodeName2": "IAD-M10",
+ "numWaves": 80,
+ "port1": 30,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:07",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:08",
+ "params": {
+ "distKms": 4000,
+ "nodeName1": "CHG-M10",
+ "nodeName2": "IAD-M10",
+ "numWaves": 80,
+ "port1": 30,
+ "port2": 20
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:07",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:09",
+ "params": {
+ "distKms": 5000,
+ "nodeName1": "CHG-M10",
+ "nodeName2": "JFK-E10",
+ "numWaves": 80,
+ "port1": 20,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:08",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:0A",
+ "params": {
+ "distKms": 3000,
+ "nodeName1": "IAD-M10",
+ "nodeName2": "ATL-S10",
+ "numWaves": 80,
+ "port1": 30,
+ "port2": 10
+ },
+ "type": "wdmLink"
+ },
+
+ {
+
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:09",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:0A",
+ "params": {
+ "distKms": 4000,
+ "nodeName1": "JFK-E10",
+ "nodeName2": "ATL-S10",
+ "numWaves": 80,
+ "port1": 20,
+ "port2": 20
+ },
+ "type": "wdmLink"
+ },
+
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:01",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:01",
+ "params": {
+ "nodeName1": "SFO-R10",
+ "nodeName2": "SFO-W10",
+ "port1": 10,
+ "port2": 1
+ },
+ "type": "pktOptLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:03",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:03",
+ "params": {
+ "nodeName1": "LAX-R10",
+ "nodeName2": "LAX-W10",
+ "port1": 10,
+ "port2": 1
+ },
+ "type": "pktOptLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:04",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:04",
+ "params": {
+ "nodeName1": "SDG-R10",
+ "nodeName2": "SDG-W10",
+ "port1": 10,
+ "port2": 1
+ },
+ "type": "pktOptLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:07",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:07",
+ "params": {
+ "nodeName1": "CHG-R10",
+ "nodeName2": "CHG-W10",
+ "port1": 10,
+ "port2": 1
+ },
+ "type": "pktOptLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:09",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:09",
+ "params": {
+ "nodeName1": "JFK-R10",
+ "nodeName2": "JFK-W10",
+ "port1": 10,
+ "port2": 1
+ },
+ "type": "pktOptLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:0A",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:0A",
+ "params": {
+ "nodeName1": "ATL-R10",
+ "nodeName2": "ATL-W10",
+ "port1": 10,
+ "port2": 1
+ },
+ "type": "pktOptLink"
+ },
+
+ ]
+}
diff --git a/apps/optical/src/main/resources/demo-3-roadm-2-ps.json b/apps/optical/src/main/resources/demo-3-roadm-2-ps.json
new file mode 100644
index 0000000..6f2c2f5
--- /dev/null
+++ b/apps/optical/src/main/resources/demo-3-roadm-2-ps.json
@@ -0,0 +1,101 @@
+{
+ "opticalSwitches": [
+ {
+ "allowed": true,
+ "latitude": 37.6,
+ "longitude": 122.3,
+ "name": "ROADM1",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:01",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 37.3,
+ "longitude": 121.9,
+ "name": "ROADM2",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:02",
+ "params": {
+ "numRegen": 0
+ },
+ "type": "Roadm"
+ },
+
+ {
+ "allowed": true,
+ "latitude": 33.9,
+ "longitude": 118.4,
+ "name": "ROADM3",
+ "nodeDpid": "00:00:ff:ff:ff:ff:ff:03",
+ "params": {
+ "numRegen": 2
+ },
+ "type": "Roadm"
+ }
+ ],
+
+ "opticalLinks": [
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:01",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:03",
+ "params": {
+ "distKms": 1000,
+ "nodeName1": "ROADM1",
+ "nodeName2": "ROADM3",
+ "numWaves": 80,
+ "port1": 10,
+ "port2": 30
+ },
+ "type": "wdmLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:ff:03",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:02",
+ "params": {
+ "distKms": 2000,
+ "nodeName1": "ROADM3",
+ "nodeName2": "ROADM2",
+ "numWaves": 80,
+ "port1": 31,
+ "port2": 20
+ },
+ "type": "wdmLink"
+ },
+
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:01",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:01",
+ "params": {
+ "nodeName1": "ROUTER1",
+ "nodeName2": "ROADM1",
+ "bandWidth": 100000,
+ "port1": 10,
+ "port2": 11
+ },
+ "type": "pktOptLink"
+ },
+
+ {
+ "allowed": true,
+ "nodeDpid1": "00:00:ff:ff:ff:ff:00:02",
+ "nodeDpid2": "00:00:ff:ff:ff:ff:ff:02",
+ "params": {
+ "nodeName1": "ROUTER2",
+ "nodeName2": "ROADM2",
+ "bandWidth": 100000,
+ "port1": 10,
+ "port2": 21
+ },
+ "type": "pktOptLink"
+ }
+
+ ]
+}
diff --git a/apps/pom.xml b/apps/pom.xml
index e9870ea..e812c47 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -26,6 +26,7 @@
<module>config</module>
<module>sdnip</module>
<module>calendar</module>
+ <module>optical</module>
</modules>
<properties>
diff --git a/features/features.xml b/features/features.xml
index 03c1814..9636643 100644
--- a/features/features.xml
+++ b/features/features.xml
@@ -155,6 +155,13 @@
<feature>onos-api</feature>
<bundle>mvn:org.onlab.onos/onos-app-config/1.0.0-SNAPSHOT</bundle>
</feature>
+
+ <feature name="onos-app-optical" version="1.0.0"
+ description="ONOS optical network config">
+ <feature>onos-api</feature>
+ <bundle>mvn:org.onlab.onos/onos-app-optical/1.0.0-SNAPSHOT</bundle>
+ </feature>
+
<feature name="onos-app-sdnip" version="1.0.0"
description="SDN-IP peering application">
diff --git a/tools/test/cells/single_optical b/tools/test/cells/single_optical
new file mode 100644
index 0000000..61b0d24
--- /dev/null
+++ b/tools/test/cells/single_optical
@@ -0,0 +1,7 @@
+# Local VirtualBox-based single ONOS instance & ONOS mininet box
+
+export ONOS_NIC=192.168.56.*
+export OC1="192.168.56.101"
+export OCN="192.168.56.103"
+
+export ONOS_FEATURES=webconsole,onos-api,onos-core-trivial,onos-cli,onos-openflow,onos-app-fwd,onos-app-mobility,onos-app-tvue,onos-app-optical
diff --git a/utils/misc/src/main/java/org/onlab/util/HexString.java b/utils/misc/src/main/java/org/onlab/util/HexString.java
new file mode 100644
index 0000000..db12aa3
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/util/HexString.java
@@ -0,0 +1,94 @@
+package org.onlab.util;
+
+public final class HexString {
+
+ private HexString() {
+
+ }
+
+ /**
+ * Convert a string of bytes to a ':' separated hex string.
+ *
+ * @param bytes
+ * @return "0f:ca:fe:de:ad:be:ef"
+ */
+ public static String toHexString(final byte[] bytes) {
+ int i;
+ StringBuilder ret = new StringBuilder();
+ String tmp;
+ for (i = 0; i < bytes.length; i++) {
+ if (i > 0) {
+ ret.append(':');
+ }
+ tmp = Integer.toHexString((bytes[i] & 0xff));
+ if (tmp.length() == 1) {
+ ret.append('0');
+ }
+ ret.append(tmp);
+ }
+ return ret.toString();
+ }
+
+ public static String toHexString(final long val, final int padTo) {
+ char[] arr = Long.toHexString(val).toCharArray();
+ String ret = "";
+ // prepend the right number of leading zeros
+ int i = 0;
+ for (; i < (padTo * 2 - arr.length); i++) {
+ ret += "0";
+ if ((i % 2) != 0) {
+ ret += ":";
+ }
+ }
+ for (int j = 0; j < arr.length; j++) {
+ ret += arr[j];
+ if ((((i + j) % 2) != 0) && (j < (arr.length - 1))) {
+ ret += ":";
+ }
+ }
+ return ret;
+ }
+
+ public static String toHexString(final long val) {
+ return toHexString(val, 8);
+ }
+
+ /**
+ * Convert a string of hex values into a string of bytes.
+ *
+ * @param values
+ * "0f:ca:fe:de:ad:be:ef"
+ * @return [15, 5 ,2, 5, 17]
+ * @throws NumberFormatException
+ * If the string can not be parsed
+ */
+ public static byte[] fromHexString(final String values) {
+ String[] octets = values.split(":");
+ byte[] ret = new byte[octets.length];
+
+ for (int i = 0; i < octets.length; i++) {
+ if (octets[i].length() > 2) {
+ throw new NumberFormatException("Invalid octet length");
+ }
+ ret[i] = Integer.valueOf(octets[i], 16).byteValue();
+ }
+ return ret;
+ }
+
+ public static long toLong(String value) {
+ String[] octets = value.split(":");
+ if (octets.length > 8) {
+ throw new NumberFormatException("Input string is too big to fit in long: " + value);
+ }
+ long l = 0;
+ for (String octet: octets) {
+ if (octet.length() > 2) {
+ throw new NumberFormatException(
+ "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value);
+ }
+ short s = Short.parseShort(octet, 16);
+ l = (l << 8) + s;
+ }
+ return l;
+ }
+}
diff --git a/utils/misc/src/test/java/org/onlab/util/HexStringTest.java b/utils/misc/src/test/java/org/onlab/util/HexStringTest.java
new file mode 100644
index 0000000..c20238f
--- /dev/null
+++ b/utils/misc/src/test/java/org/onlab/util/HexStringTest.java
@@ -0,0 +1,70 @@
+package org.onlab.util;
+
+import org.junit.Test;
+
+import com.esotericsoftware.minlog.Log;
+
+import junit.framework.TestCase;
+
+/**
+ * Test of the Hexstring.
+ *
+ */
+
+public class HexStringTest extends TestCase {
+
+ @Test
+ public void testMarshalling() throws Exception {
+ String dpidStr = "00:00:00:23:20:2d:16:71";
+ long dpid = HexString.toLong(dpidStr);
+ String testStr = HexString.toHexString(dpid);
+ TestCase.assertEquals(dpidStr, testStr);
+ }
+
+ @Test
+ public void testToLong() {
+ String dpidStr = "3e:1f:01:fc:72:8c:63:31";
+ long valid = 0x3e1f01fc728c6331L;
+ long testLong = HexString.toLong(dpidStr);
+ TestCase.assertEquals(valid, testLong);
+ }
+
+ @Test
+ public void testToLongMSB() {
+ String dpidStr = "ca:7c:5e:d1:64:7a:95:9b";
+ long valid = -3856102927509056101L;
+ long testLong = HexString.toLong(dpidStr);
+ TestCase.assertEquals(valid, testLong);
+ }
+
+ @Test
+ public void testToLongError() {
+ String dpidStr = "09:08:07:06:05:04:03:02:01";
+ try {
+ HexString.toLong(dpidStr);
+ fail("HexString.toLong() should have thrown a NumberFormatException");
+ } catch (NumberFormatException expected) {
+ Log.info("HexString.toLong() have thrown a NumberFormatException");
+ }
+ }
+
+ @Test
+ public void testToStringBytes() {
+ byte[] dpid = {0, 0, 0, 0, 0, 0, 0, -1 };
+ String valid = "00:00:00:00:00:00:00:ff";
+ String testString = HexString.toHexString(dpid);
+ TestCase.assertEquals(valid, testString);
+ }
+
+ @Test
+ public void testFromHexStringError() {
+ String invalidStr = "00:00:00:00:00:00:ffff";
+ try {
+ HexString.fromHexString(invalidStr);
+ fail("HexString.fromHexString() should have thrown a NumberFormatException");
+ } catch (NumberFormatException expected) {
+ Log.info("HexString.toLong() have thrown a NumberFormatException");
+ }
+ }
+}
+