weibit

Optical topology provider for UC1

Change-Id: I1b25c9412b5180f9dce167f8700eb84baba70486
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5 + <modelVersion>4.0.0</modelVersion>
6 +
7 + <parent>
8 + <groupId>org.onlab.onos</groupId>
9 + <artifactId>onos-apps</artifactId>
10 + <version>1.0.0-SNAPSHOT</version>
11 + <relativePath>../pom.xml</relativePath>
12 + </parent>
13 +
14 + <artifactId>onos-app-optical</artifactId>
15 + <packaging>bundle</packaging>
16 +
17 + <description>ONOS application for packet/optical deployments</description>
18 +
19 + <dependencies>
20 +
21 + <dependency>
22 + <groupId>org.onlab.onos</groupId>
23 + <artifactId>onos-cli</artifactId>
24 + <version>${project.version}</version>
25 + </dependency>
26 + <dependency>
27 + <groupId>org.apache.karaf.shell</groupId>
28 + <artifactId>org.apache.karaf.shell.console</artifactId>
29 + </dependency>
30 +
31 + <dependency>
32 + <groupId>org.codehaus.jackson</groupId>
33 + <artifactId>jackson-core-asl</artifactId>
34 + </dependency>
35 + <dependency>
36 + <groupId>org.codehaus.jackson</groupId>
37 + <artifactId>jackson-mapper-asl</artifactId>
38 + </dependency>
39 + <dependency>
40 + <groupId>com.fasterxml.jackson.core</groupId>
41 + <artifactId>jackson-annotations</artifactId>
42 + <scope>provided</scope>
43 + </dependency>
44 +
45 + </dependencies>
46 +
47 +</project>
1 +package org.onlab.onos.optical.cfg;
2 +
3 +import static org.onlab.onos.net.DeviceId.deviceId;
4 +
5 +import java.io.File;
6 +import java.io.IOException;
7 +import java.util.ArrayList;
8 +import java.util.Iterator;
9 +import java.util.List;
10 +import java.util.Map;
11 +import java.util.Set;
12 +
13 +import org.apache.felix.scr.annotations.Activate;
14 +import org.apache.felix.scr.annotations.Component;
15 +import org.apache.felix.scr.annotations.Deactivate;
16 +import org.apache.felix.scr.annotations.Reference;
17 +import org.apache.felix.scr.annotations.ReferenceCardinality;
18 +import org.codehaus.jackson.JsonNode;
19 +import org.codehaus.jackson.JsonParseException;
20 +import org.codehaus.jackson.annotate.JsonIgnoreProperties;
21 +import org.codehaus.jackson.map.JsonMappingException;
22 +import org.codehaus.jackson.map.ObjectMapper;
23 +import org.onlab.onos.net.ConnectPoint;
24 +import org.onlab.onos.net.DefaultAnnotations;
25 +import org.onlab.onos.net.Device;
26 +import org.onlab.onos.net.DeviceId;
27 +import org.onlab.onos.net.Link;
28 +import org.onlab.onos.net.MastershipRole;
29 +import org.onlab.onos.net.PortNumber;
30 +import org.onlab.onos.net.device.DefaultDeviceDescription;
31 +import org.onlab.onos.net.device.DeviceDescription;
32 +import org.onlab.onos.net.device.DeviceProvider;
33 +import org.onlab.onos.net.device.DeviceProviderRegistry;
34 +import org.onlab.onos.net.device.DeviceProviderService;
35 +import org.onlab.onos.net.link.DefaultLinkDescription;
36 +import org.onlab.onos.net.link.LinkProvider;
37 +import org.onlab.onos.net.link.LinkProviderRegistry;
38 +import org.onlab.onos.net.link.LinkProviderService;
39 +import org.onlab.onos.net.provider.AbstractProvider;
40 +import org.onlab.onos.net.provider.ProviderId;
41 +import org.onlab.packet.ChassisId;
42 +import org.slf4j.Logger;
43 +import org.slf4j.LoggerFactory;
44 +
45 +/**
46 + * OpticalConfigProvider emulates the SB network provider for optical switches,
47 + * optical links and any other state that needs to be configured for correct network
48 + * operations.
49 + *
50 + */
51 +
52 +@JsonIgnoreProperties(ignoreUnknown = true)
53 +@Component(immediate = true)
54 +public class OpticalConfigProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
55 +
56 + protected static final Logger log = LoggerFactory
57 + .getLogger(OpticalConfigProvider.class);
58 +
59 + // TODO: fix hard coded file path later.
60 + private static final String DEFAULT_CONFIG_FILE =
61 + "/opt/onos/config/demo-3-roadm-2-ps.json";
62 + private String configFileName = DEFAULT_CONFIG_FILE;
63 +
64 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 + protected LinkProviderRegistry linkProviderRegistry;
66 +
67 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 + protected DeviceProviderRegistry deviceProviderRegistry;
69 +
70 + private static final String OPTICAL_ANNOTATION = "optical.";
71 +
72 + private LinkProviderService linkProviderService;
73 + private DeviceProviderService deviceProviderService;
74 +
75 + private static final List<Roadm> RAW_ROADMS = new ArrayList<>();
76 + private static final List<WdmLink> RAW_WDMLINKS = new ArrayList<>();
77 + private static final List<PktOptLink> RAW_PKTOPTLINKS = new ArrayList<>();
78 +
79 + private static final String ROADM = "Roadm";
80 + private static final String WDM_LINK = "wdmLink";
81 + private static final String PKT_OPT_LINK = "pktOptLink";
82 +
83 + protected OpticalNetworkConfig opticalNetworkConfig;
84 +
85 + public OpticalConfigProvider() {
86 + super(new ProviderId("of", "org.onlab.onos.provider.opticalConfig", true));
87 + }
88 +
89 + @Activate
90 + protected void activate() {
91 + linkProviderService = linkProviderRegistry.register(this);
92 + deviceProviderService = deviceProviderRegistry.register(this);
93 + log.info("Starting optical network configuration process...");
94 + log.info("Optical config file set to {}", configFileName);
95 +
96 + loadOpticalConfig();
97 + parseOpticalConfig();
98 + publishOpticalConfig();
99 + }
100 +
101 + @Deactivate
102 + protected void deactivate() {
103 + linkProviderRegistry.unregister(this);
104 + linkProviderService = null;
105 + deviceProviderRegistry.unregister(this);
106 + deviceProviderService = null;
107 + RAW_ROADMS.clear();
108 + RAW_WDMLINKS.clear();
109 + RAW_PKTOPTLINKS.clear();
110 + log.info("Stopped");
111 + }
112 +
113 + private void loadOpticalConfig() {
114 + ObjectMapper mapper = new ObjectMapper();
115 + opticalNetworkConfig = new OpticalNetworkConfig();
116 + try {
117 + opticalNetworkConfig = mapper.readValue(new File(configFileName), OpticalNetworkConfig.class);
118 + } catch (JsonParseException e) {
119 + String err = String.format("JsonParseException while loading network "
120 + + "config from file: %s: %s", configFileName, e.getMessage());
121 + log.error(err, e);
122 + } catch (JsonMappingException e) {
123 + String err = String.format(
124 + "JsonMappingException while loading network config "
125 + + "from file: %s: %s", configFileName, e.getMessage());
126 + log.error(err, e);
127 + } catch (IOException e) {
128 + String err = String.format("IOException while loading network config "
129 + + "from file: %s %s", configFileName, e.getMessage());
130 + log.error(err, e);
131 + }
132 + }
133 +
134 + private void parseOpticalConfig() {
135 + List<OpticalSwitchDescription> swList = opticalNetworkConfig.getOpticalSwitches();
136 + List<OpticalLinkDescription> lkList = opticalNetworkConfig.getOpticalLinks();
137 +
138 + for (OpticalSwitchDescription sw : swList) {
139 + String swtype = sw.getType();
140 + boolean allow = sw.isAllowed();
141 + if (swtype.equals(ROADM) && allow) {
142 + int regNum = 0;
143 + Set<Map.Entry<String, JsonNode>> m = sw.params.entrySet();
144 + for (Map.Entry<String, JsonNode> e : m) {
145 + String key = e.getKey();
146 + JsonNode j = e.getValue();
147 + if (key.equals("numRegen")) {
148 + regNum = j.asInt();
149 + }
150 + }
151 +
152 + Roadm newRoadm = new Roadm();
153 + newRoadm.setName(sw.name);
154 + newRoadm.setNodeId(sw.nodeDpid);
155 + newRoadm.setLongtitude(sw.longitude);
156 + newRoadm.setLatitude(sw.latitude);
157 + newRoadm.setRegenNum(regNum);
158 +
159 + RAW_ROADMS.add(newRoadm);
160 + log.info(newRoadm.toString());
161 + }
162 + }
163 +
164 + for (OpticalLinkDescription lk : lkList) {
165 + String lktype = lk.getType();
166 + switch (lktype) {
167 + case WDM_LINK:
168 + WdmLink newWdmLink = new WdmLink();
169 + newWdmLink.setSrcNodeId(lk.getNodeDpid1());
170 + newWdmLink.setSnkNodeId(lk.getNodeDpid2());
171 + newWdmLink.setAdminWeight(1000); // default weight for each WDM link.
172 + Set<Map.Entry<String, JsonNode>> m = lk.params.entrySet();
173 + for (Map.Entry<String, JsonNode> e : m) {
174 + String key = e.getKey();
175 + JsonNode j = e.getValue();
176 + if (key.equals("nodeName1")) {
177 + newWdmLink.setSrcNodeName(j.asText());
178 + } else if (key.equals("nodeName2")) {
179 + newWdmLink.setSnkNodeName(j.asText());
180 + } else if (key.equals("port1")) {
181 + newWdmLink.setSrcPort(j.asInt());
182 + } else if (key.equals("port2")) {
183 + newWdmLink.setSnkPort(j.asInt());
184 + } else if (key.equals("distKms")) {
185 + newWdmLink.setDistance(j.asDouble());
186 + } else if (key.equals("numWaves")) {
187 + newWdmLink.setWavelengthNumber(j.asInt());
188 + } else {
189 + log.error("error found");
190 + // TODO add exception processing;
191 + }
192 + }
193 + RAW_WDMLINKS.add(newWdmLink);
194 + log.info(newWdmLink.toString());
195 +
196 + break;
197 +
198 + case PKT_OPT_LINK:
199 + PktOptLink newPktOptLink = new PktOptLink();
200 + newPktOptLink.setSrcNodeId(lk.getNodeDpid1());
201 + newPktOptLink.setSnkNodeId(lk.getNodeDpid2());
202 + newPktOptLink.setAdminWeight(10); // default weight for each packet-optical link.
203 + Set<Map.Entry<String, JsonNode>> ptm = lk.params.entrySet();
204 + for (Map.Entry<String, JsonNode> e : ptm) {
205 + String key = e.getKey();
206 + JsonNode j = e.getValue();
207 + if (key.equals("nodeName1")) {
208 + newPktOptLink.setSrcNodeName(j.asText());
209 + } else if (key.equals("nodeName2")) {
210 + newPktOptLink.setSnkNodeName(j.asText());
211 + } else if (key.equals("port1")) {
212 + newPktOptLink.setSrcPort(j.asInt());
213 + } else if (key.equals("port2")) {
214 + newPktOptLink.setSnkPort(j.asInt());
215 + } else if (key.equals("bandWidth")) {
216 + newPktOptLink.setBandwdith(j.asDouble());
217 + } else {
218 + log.error("error found");
219 + // TODO add exception processing;
220 + }
221 + }
222 +
223 + RAW_PKTOPTLINKS.add(newPktOptLink);
224 + log.info(newPktOptLink.toString());
225 + break;
226 + default:
227 + }
228 + }
229 + }
230 +
231 + private void publishOpticalConfig() {
232 + if (deviceProviderService == null || linkProviderService == null) {
233 + return;
234 + }
235 +
236 + // Discover the optical ROADM objects
237 + Iterator<Roadm> iterWdmNode = RAW_ROADMS.iterator();
238 + while (iterWdmNode.hasNext()) {
239 + Roadm value = iterWdmNode.next();
240 + DeviceId did = deviceId("of:" + value.getNodeId().replace(":", ""));
241 + ChassisId cid = new ChassisId(value.getNodeId());
242 + DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
243 + .set(OPTICAL_ANNOTATION + "switchType", "ROADM")
244 + .set(OPTICAL_ANNOTATION + "switchName", value.getName())
245 + .set(OPTICAL_ANNOTATION + "latitude", Double.toString(value.getLatitude()))
246 + .set(OPTICAL_ANNOTATION + "longtitude", Double.toString(value.getLongtitude()))
247 + .set(OPTICAL_ANNOTATION + "regNum", Integer.toString(value.getRegenNum()))
248 + .build();
249 +
250 + DeviceDescription description =
251 + new DefaultDeviceDescription(did.uri(),
252 + Device.Type.SWITCH,
253 + "",
254 + "",
255 + "",
256 + "",
257 + cid,
258 + extendedAttributes);
259 + deviceProviderService.deviceConnected(did, description);
260 + }
261 +
262 + // Discover the optical WDM link objects
263 + Iterator<WdmLink> iterWdmlink = RAW_WDMLINKS.iterator();
264 + while (iterWdmlink.hasNext()) {
265 + WdmLink value = iterWdmlink.next();
266 +
267 + DeviceId srcNodeId = deviceId("of:" + value.getSrcNodeId().replace(":", ""));
268 + DeviceId snkNodeId = deviceId("of:" + value.getSnkNodeId().replace(":", ""));
269 +
270 + PortNumber srcPort = PortNumber.portNumber(value.getSrcPort());
271 + PortNumber snkPort = PortNumber.portNumber(value.getSnkPort());
272 +
273 + ConnectPoint srcPoint = new ConnectPoint(srcNodeId, srcPort);
274 + ConnectPoint snkPoint = new ConnectPoint(snkNodeId, snkPort);
275 +
276 + DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
277 + .set(OPTICAL_ANNOTATION + "linkType", "WDM")
278 + .set(OPTICAL_ANNOTATION + "distance", Double.toString(value.getDistance()))
279 + .set(OPTICAL_ANNOTATION + "cost", Double.toString(value.getDistance()))
280 + .set(OPTICAL_ANNOTATION + "adminWeight", Double.toString(value.getAdminWeight()))
281 + .set(OPTICAL_ANNOTATION + "wavelengthNum", Integer.toString(value.getWavelengthNumber()))
282 + .build();
283 +
284 + DefaultLinkDescription linkDescription =
285 + new DefaultLinkDescription(srcPoint,
286 + snkPoint,
287 + Link.Type.DIRECT,
288 + extendedAttributes);
289 +
290 + linkProviderService.linkDetected(linkDescription);
291 + log.info(String.format("WDM link: %s : %s",
292 + linkDescription.src().toString(), linkDescription.dst().toString()));
293 + }
294 +
295 + // Discover the packet optical link objects
296 + Iterator<PktOptLink> iterPktOptlink = RAW_PKTOPTLINKS.iterator();
297 + while (iterPktOptlink.hasNext()) {
298 + PktOptLink value = iterPktOptlink.next();
299 + DeviceId srcNodeId = deviceId("of:" + value.getSrcNodeId().replace(":", ""));
300 + DeviceId snkNodeId = deviceId("of:" + value.getSnkNodeId().replace(":", ""));
301 +
302 + PortNumber srcPort = PortNumber.portNumber(value.getSrcPort());
303 + PortNumber snkPort = PortNumber.portNumber(value.getSnkPort());
304 +
305 + ConnectPoint srcPoint = new ConnectPoint(srcNodeId, srcPort);
306 + ConnectPoint snkPoint = new ConnectPoint(snkNodeId, snkPort);
307 +
308 + DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
309 + .set(OPTICAL_ANNOTATION + "linkType", "PktOptLink")
310 + .set(OPTICAL_ANNOTATION + "bandwidth", Double.toString(value.getBandwidth()))
311 + .set(OPTICAL_ANNOTATION + "cost", Double.toString(value.getBandwidth()))
312 + .set(OPTICAL_ANNOTATION + "adminWeight", Double.toString(value.getAdminWeight()))
313 + .build();
314 +
315 + DefaultLinkDescription linkDescription =
316 + new DefaultLinkDescription(srcPoint,
317 + snkPoint,
318 + Link.Type.DIRECT,
319 + extendedAttributes);
320 +
321 + linkProviderService.linkDetected(linkDescription);
322 + log.info(String.format("Packet-optical link: %s : %s",
323 + linkDescription.src().toString(), linkDescription.dst().toString()));
324 + }
325 +
326 + }
327 +
328 + @Override
329 + public void triggerProbe(Device device) {
330 + // TODO We may want to consider re-reading config files and publishing them based on this event.
331 + }
332 +
333 + @Override
334 + public void roleChanged(Device device, MastershipRole newRole) {
335 + // TODO Auto-generated method stub.
336 + }
337 +
338 +}
1 +package org.onlab.onos.optical.cfg;
2 +
3 +import java.util.Map;
4 +import org.codehaus.jackson.JsonNode;
5 +import org.onlab.util.HexString;
6 +
7 +/**
8 + * Public class corresponding to JSON described data model.
9 + */
10 +public class OpticalLinkDescription {
11 + protected String type;
12 + protected Boolean allowed;
13 + protected long dpid1;
14 + protected long dpid2;
15 + protected String nodeDpid1;
16 + protected String nodeDpid2;
17 + protected Map<String, JsonNode> params;
18 + protected Map<String, String> publishAttributes;
19 +
20 + public String getType() {
21 + return type;
22 + }
23 +
24 + public void setType(String type) {
25 + this.type = type;
26 + }
27 +
28 + public Boolean isAllowed() {
29 + return allowed;
30 + }
31 +
32 + public void setAllowed(Boolean allowed) {
33 + this.allowed = allowed;
34 + }
35 +
36 + public String getNodeDpid1() {
37 + return nodeDpid1;
38 + }
39 +
40 + public void setNodeDpid1(String nodeDpid1) {
41 + this.nodeDpid1 = nodeDpid1;
42 + this.dpid1 = HexString.toLong(nodeDpid1);
43 + }
44 +
45 + public String getNodeDpid2() {
46 + return nodeDpid2;
47 + }
48 +
49 + public void setNodeDpid2(String nodeDpid2) {
50 + this.nodeDpid2 = nodeDpid2;
51 + this.dpid2 = HexString.toLong(nodeDpid2);
52 + }
53 +
54 + public long getDpid1() {
55 + return dpid1;
56 + }
57 +
58 + public void setDpid1(long dpid1) {
59 + this.dpid1 = dpid1;
60 + this.nodeDpid1 = HexString.toHexString(dpid1);
61 + }
62 +
63 + public long getDpid2() {
64 + return dpid2;
65 + }
66 +
67 + public void setDpid2(long dpid2) {
68 + this.dpid2 = dpid2;
69 + this.nodeDpid2 = HexString.toHexString(dpid2);
70 + }
71 +
72 + public Map<String, JsonNode> getParams() {
73 + return params;
74 + }
75 +
76 + public void setParams(Map<String, JsonNode> params) {
77 + this.params = params;
78 + }
79 +
80 + public Map<String, String> getPublishAttributes() {
81 + return publishAttributes;
82 + }
83 +
84 + public void setPublishAttributes(Map<String, String> publishAttributes) {
85 + this.publishAttributes = publishAttributes;
86 + }
87 +
88 +}
89 +
1 +package org.onlab.onos.optical.cfg;
2 +
3 +import java.util.ArrayList;
4 +import java.util.List;
5 +
6 +import org.slf4j.Logger;
7 +import org.slf4j.LoggerFactory;
8 +
9 +/**
10 + * Public class corresponding to JSON described data model.
11 + */
12 +public class OpticalNetworkConfig {
13 + protected static final Logger log = LoggerFactory.getLogger(OpticalNetworkConfig.class);
14 +
15 + private List<OpticalSwitchDescription> opticalSwitches;
16 + private List<OpticalLinkDescription> opticalLinks;
17 +
18 + public OpticalNetworkConfig() {
19 + opticalSwitches = new ArrayList<OpticalSwitchDescription>();
20 + opticalLinks = new ArrayList<OpticalLinkDescription>();
21 + }
22 +
23 + public List<OpticalSwitchDescription> getOpticalSwitches() {
24 + return opticalSwitches;
25 + }
26 +
27 + public void setOpticalSwitches(List<OpticalSwitchDescription> switches) {
28 + this.opticalSwitches = switches;
29 + }
30 +
31 + public List<OpticalLinkDescription> getOpticalLinks() {
32 + return opticalLinks;
33 + }
34 +
35 + public void setOpticalLinks(List<OpticalLinkDescription> links) {
36 + this.opticalLinks = links;
37 + }
38 +
39 +}
40 +
1 +package org.onlab.onos.optical.cfg;
2 +
3 +import java.util.Map;
4 +import org.codehaus.jackson.JsonNode;
5 +import org.codehaus.jackson.annotate.JsonProperty;
6 +import org.onlab.util.HexString;
7 +
8 +/**
9 + * Public class corresponding to JSON described data model.
10 + */
11 +public class OpticalSwitchDescription {
12 + protected String name;
13 + protected long dpid;
14 + protected String nodeDpid;
15 + protected String type;
16 + protected double latitude;
17 + protected double longitude;
18 + protected boolean allowed;
19 + protected Map<String, JsonNode> params;
20 + protected Map<String, String> publishAttributes;
21 +
22 + public String getName() {
23 + return name;
24 + }
25 + @JsonProperty("name")
26 + public void setName(String name) {
27 + this.name = name;
28 + }
29 +
30 + public long getDpid() {
31 + return dpid;
32 + }
33 + @JsonProperty("dpid")
34 + public void setDpid(long dpid) {
35 + this.dpid = dpid;
36 + this.nodeDpid = HexString.toHexString(dpid);
37 + }
38 +
39 + public String getNodeDpid() {
40 + return nodeDpid;
41 + }
42 +
43 + public String getHexDpid() {
44 + return nodeDpid;
45 + }
46 +
47 + public void setNodeDpid(String nodeDpid) {
48 + this.nodeDpid = nodeDpid;
49 + this.dpid = HexString.toLong(nodeDpid);
50 + }
51 +
52 + public String getType() {
53 + return type;
54 + }
55 +
56 + public void setType(String type) {
57 + this.type = type;
58 + }
59 +
60 + public double getLatitude() {
61 + return latitude;
62 + }
63 +
64 + public void setLatitude(double latitude) {
65 + this.latitude = latitude;
66 + }
67 +
68 + public double getLongitude() {
69 + return longitude;
70 + }
71 +
72 + public void setLongitude(double longitude) {
73 + this.longitude = longitude;
74 + }
75 +
76 + public boolean isAllowed() {
77 + return allowed;
78 + }
79 +
80 + public void setAllowed(boolean allowed) {
81 + this.allowed = allowed;
82 + }
83 +
84 + public Map<String, JsonNode> getParams() {
85 + return params;
86 + }
87 +
88 + public void setParams(Map<String, JsonNode> params) {
89 + this.params = params;
90 + }
91 +
92 + public Map<String, String> getPublishAttributes() {
93 + return publishAttributes;
94 + }
95 +
96 + public void setPublishAttributes(Map<String, String> publishAttributes) {
97 + this.publishAttributes = publishAttributes;
98 + }
99 +
100 +}
1 +package org.onlab.onos.optical.cfg;
2 +
3 +/**
4 + * Packet-optical link Java data object.
5 + */
6 +class PktOptLink {
7 + private String srcNodeName;
8 + private String snkNodeName;
9 + private String srcNodeId;
10 + private String snkNodeId;
11 + private int srcPort;
12 + private int snkPort;
13 + private double bandwidth;
14 + private double cost;
15 + private long adminWeight;
16 +
17 + public PktOptLink(String srcName, String snkName) {
18 + this.srcNodeName = srcName;
19 + this.snkNodeName = snkName;
20 + }
21 +
22 + public PktOptLink() {
23 + // TODO Auto-generated constructor stub
24 + }
25 +
26 + public void setSrcNodeName(String name) {
27 + this.srcNodeName = name;
28 + }
29 +
30 + public String getSrcNodeName() {
31 + return this.srcNodeName;
32 + }
33 +
34 + public void setSnkNodeName(String name) {
35 + this.snkNodeName = name;
36 + }
37 +
38 + public String getSnkNodeName() {
39 + return this.snkNodeName;
40 + }
41 +
42 + public void setSrcNodeId(String nodeId) {
43 + this.srcNodeId = nodeId;
44 + }
45 +
46 + public String getSrcNodeId() {
47 + return this.srcNodeId;
48 + }
49 +
50 + public void setSnkNodeId(String nodeId) {
51 + this.snkNodeId = nodeId;
52 + }
53 +
54 + public String getSnkNodeId() {
55 + return this.snkNodeId;
56 + }
57 +
58 + public void setSrcPort(int port) {
59 + this.srcPort = port;
60 + }
61 +
62 + public int getSrcPort() {
63 + return this.srcPort;
64 + }
65 +
66 + public void setSnkPort(int port) {
67 + this.snkPort = port;
68 + }
69 +
70 + public int getSnkPort() {
71 + return this.snkPort;
72 + }
73 +
74 + public void setBandwdith(double x) {
75 + this.bandwidth = x;
76 + }
77 +
78 + public double getBandwidth() {
79 + return this.bandwidth;
80 + }
81 +
82 + public void setCost(double x) {
83 + this.cost = x;
84 + }
85 +
86 + public double getCost() {
87 + return this.cost;
88 + }
89 +
90 + public void setAdminWeight(long x) {
91 + this.adminWeight = x;
92 + }
93 +
94 + public long getAdminWeight() {
95 + return this.adminWeight;
96 + }
97 +
98 + @Override
99 + public String toString() {
100 + return new StringBuilder(" srcNodeName: ").append(this.srcNodeName)
101 + .append(" snkNodeName: ").append(this.snkNodeName)
102 + .append(" srcNodeId: ").append(this.srcNodeId)
103 + .append(" snkNodeId: ").append(this.snkNodeId)
104 + .append(" srcPort: ").append(this.srcPort)
105 + .append(" snkPort: ").append(this.snkPort)
106 + .append(" bandwidth: ").append(this.bandwidth)
107 + .append(" cost: ").append(this.cost)
108 + .append(" adminWeight: ").append(this.adminWeight).toString();
109 + }
110 +}
1 +package org.onlab.onos.optical.cfg;
2 +
3 +/**
4 + * ROADM java data object converted from a JSON file.
5 + */
6 +class Roadm {
7 + private String name;
8 + private String nodeID;
9 + private double longtitude;
10 + private double latitude;
11 + private int regenNum;
12 +
13 + //TODO use the following attributes when needed for configurations
14 + private int tPort10G;
15 + private int tPort40G;
16 + private int tPort100G;
17 + private int wPort;
18 +
19 + public Roadm() {
20 + }
21 +
22 + public Roadm(String name) {
23 + this.name = name;
24 + }
25 +
26 + public void setName(String name) {
27 + this.name = name;
28 + }
29 +
30 + public String getName() {
31 + return this.name;
32 + }
33 +
34 + public void setNodeId(String nameId) {
35 + this.nodeID = nameId;
36 + }
37 +
38 + public String getNodeId() {
39 + return this.nodeID;
40 + }
41 +
42 + public void setLongtitude(double x) {
43 + this.longtitude = x;
44 + }
45 +
46 + public double getLongtitude() {
47 + return this.longtitude;
48 + }
49 +
50 + public void setLatitude(double y) {
51 + this.latitude = y;
52 + }
53 +
54 + public double getLatitude() {
55 + return this.latitude;
56 + }
57 +
58 + public void setRegenNum(int num) {
59 + this.regenNum = num;
60 + }
61 + public int getRegenNum() {
62 + return this.regenNum;
63 + }
64 +
65 + public void setTport10GNum(int num) {
66 + this.tPort10G = num;
67 + }
68 + public int getTport10GNum() {
69 + return this.tPort10G;
70 + }
71 +
72 + public void setTport40GNum(int num) {
73 + this.tPort40G = num;
74 + }
75 + public int getTport40GNum() {
76 + return this.tPort40G;
77 + }
78 +
79 + public void setTport100GNum(int num) {
80 + this.tPort100G = num;
81 + }
82 + public int getTport100GNum() {
83 + return this.tPort100G;
84 + }
85 +
86 + public void setWportNum(int num) {
87 + this.wPort = num;
88 + }
89 + public int getWportNum() {
90 + return this.wPort;
91 + }
92 +
93 + @Override
94 + public String toString() {
95 + return new StringBuilder(" ROADM Name: ").append(this.name)
96 + .append(" nodeID: ").append(this.nodeID)
97 + .append(" longtitude: ").append(this.longtitude)
98 + .append(" latitude: ").append(this.latitude)
99 + .append(" regenNum: ").append(this.regenNum)
100 + .append(" 10GTportNum: ").append(this.tPort10G)
101 + .append(" 40GTportNum: ").append(this.tPort40G)
102 + .append(" 100GTportNum: ").append(this.tPort100G)
103 + .append(" WportNum: ").append(this.wPort).toString();
104 + }
105 +}
106 +
1 +package org.onlab.onos.optical.cfg;
2 +
3 +/**
4 + * WDM Link Java data object converted from a JSON file.
5 + */
6 +class WdmLink {
7 + private String srcNodeName;
8 + private String snkNodeName;
9 + private String srcNodeId;
10 + private String snkNodeId;
11 + private int srcPort;
12 + private int snkPort;
13 + private double distance;
14 + private double cost;
15 + private int wavelengthNumber;
16 + private long adminWeight;
17 +
18 + public WdmLink(String name1, String name2) {
19 + this.srcNodeName = name1;
20 + this.snkNodeName = name2;
21 + }
22 +
23 + public WdmLink() {
24 + // TODO Auto-generated constructor stub
25 + }
26 +
27 + public void setSrcNodeName(String name) {
28 + this.srcNodeName = name;
29 + }
30 +
31 + public String getSrcNodeName() {
32 + return this.srcNodeName;
33 + }
34 +
35 + public void setSnkNodeName(String name) {
36 + this.snkNodeName = name;
37 + }
38 +
39 + public String getSnkNodeName() {
40 + return this.snkNodeName;
41 + }
42 +
43 + public void setSrcNodeId(String nodeId) {
44 + this.srcNodeId = nodeId;
45 + }
46 +
47 + public String getSrcNodeId() {
48 + return this.srcNodeId;
49 + }
50 +
51 + public void setSnkNodeId(String nodeId) {
52 + this.snkNodeId = nodeId;
53 + }
54 +
55 + public String getSnkNodeId() {
56 + return this.snkNodeId;
57 + }
58 +
59 + public void setSrcPort(int port) {
60 + this.srcPort = port;
61 + }
62 +
63 + public int getSrcPort() {
64 + return this.srcPort;
65 + }
66 +
67 + public void setSnkPort(int port) {
68 + this.snkPort = port;
69 + }
70 +
71 + public int getSnkPort() {
72 + return this.snkPort;
73 + }
74 +
75 + public void setDistance(double x) {
76 + this.distance = x;
77 + }
78 +
79 + public double getDistance() {
80 + return this.distance;
81 + }
82 +
83 + public void setCost(double x) {
84 + this.cost = x;
85 + }
86 +
87 + public double getCost() {
88 + return this.cost;
89 + }
90 +
91 + public void setWavelengthNumber(int x) {
92 + this.wavelengthNumber = x;
93 + }
94 +
95 + public int getWavelengthNumber() {
96 + return this.wavelengthNumber;
97 + }
98 +
99 + public void setAdminWeight(long x) {
100 + this.adminWeight = x;
101 + }
102 +
103 + public long getAdminWeight() {
104 + return this.adminWeight;
105 + }
106 +
107 + @Override
108 + public String toString() {
109 + return new StringBuilder(" srcNodeName: ").append(this.srcNodeName)
110 + .append(" snkNodeName: ").append(this.snkNodeName)
111 + .append(" srcNodeId: ").append(this.srcNodeId)
112 + .append(" snkNodeId: ").append(this.snkNodeId)
113 + .append(" srcPort: ").append(this.srcPort)
114 + .append(" snkPort: ").append(this.snkPort)
115 + .append(" distance: ").append(this.distance)
116 + .append(" cost: ").append(this.cost)
117 + .append(" wavelengthNumber: ").append(this.wavelengthNumber)
118 + .append(" adminWeight: ").append(this.adminWeight).toString();
119 + }
120 +}
121 +
1 +{
2 + "opticalSwitches": [
3 + {
4 + "allowed": true,
5 + "latitude": 37.6,
6 + "longitude": 122.3,
7 + "name": "SFO-W10",
8 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:01",
9 + "params": {
10 + "numRegen": 0
11 + },
12 + "type": "Roadm"
13 + },
14 +
15 + {
16 + "allowed": true,
17 + "latitude": 37.3,
18 + "longitude": 121.9,
19 + "name": "SJC-W10",
20 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:02",
21 + "params": {
22 + "numRegen": 0
23 + },
24 + "type": "Roadm"
25 + },
26 +
27 + {
28 + "allowed": true,
29 + "latitude": 33.9,
30 + "longitude": 118.4
31 + "name": "LAX-W10",
32 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:03",
33 + "params": {
34 + "numRegen": 0
35 + },
36 + "type": "Roadm"
37 + },
38 +
39 + {
40 + "allowed": true,
41 + "latitude": 32.8,
42 + "longitude": 117.1,
43 + "name": "SDG-W10",
44 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:04",
45 + "params": {
46 + "numRegen": 3
47 + },
48 + "type": "Roadm"
49 + },
50 +
51 + {
52 + "allowed": true,
53 + "latitude": 44.8,
54 + "longitude": 93.1,
55 + "name": "MSP-M10",
56 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:05",
57 + "params": {
58 + "numRegen": 3
59 + },
60 + "type": "Roadm"
61 + },
62 +
63 + {
64 + "allowed": true,
65 + "latitude": 32.8,
66 + "longitude": 97.1,
67 + "name": "DFW-M10",
68 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:06",
69 + "params": {
70 + "numRegen": 3
71 + },
72 + "type": "Roadm"
73 + },
74 +
75 + {
76 + "allowed": true,
77 + "latitude": 41.8,
78 + "longitude": 120.1,
79 + "name": "CHG-N10",
80 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:07",
81 + "params": {
82 + "numRegen": 3
83 + },
84 + "type": "Roadm"
85 + },
86 +
87 + {
88 + "allowed": true,
89 + "latitude": 38.8,
90 + "longitude": 77.1,
91 + "name": "IAD-M10",
92 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:08",
93 + "params": {
94 + "numRegen": 3
95 + },
96 + "type": "Roadm"
97 + },
98 +
99 + {
100 + "allowed": true,
101 + "latitude": 40.8,
102 + "longitude": 73.1,
103 + "name": "JFK-E10",
104 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:09",
105 + "params": {
106 + "numRegen": 0
107 + },
108 + "type": "Roadm"
109 +
110 + },
111 +
112 + {
113 + "allowed": true,
114 + "latitude": 33.8,
115 + "longitude": 84.1,
116 + "name": "ATL-S10",
117 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:0A",
118 + "params": {
119 + "numRegen": 0
120 + },
121 + "type": "Roadm"
122 + }
123 +
124 + ],
125 +
126 + "opticalLinks": [
127 + {
128 + "allowed": true,
129 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:01",
130 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:02",
131 + "params": {
132 + "distKms": 1000,
133 + "nodeName1": "SFO-W10",
134 + "nodeName2": "SJC-W10",
135 + "numWaves": 80,
136 + "port1": 10,
137 + "port2": 10
138 + },
139 + "type": "wdmLink"
140 + },
141 +
142 + {
143 + "allowed": true,
144 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:02",
145 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:03",
146 + "params": {
147 + "distKms": 1000,
148 + "nodeName1": "SJC-W10",
149 + "nodeName2": "LAX-W10",
150 + "numWaves": 80,
151 + "port1": 20,
152 + "port2": 10
153 + },
154 + "type": "wdmLink"
155 + },
156 +
157 + {
158 + "allowed": true,
159 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:03",
160 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:04",
161 + "params": {
162 + "distKms": 1000,
163 + "nodeName1": "LAX-W10",
164 + "nodeName2": "SDG-W10",
165 + "numWaves": 80,
166 + "port1": 30,
167 + "port2": 10
168 + },
169 + "type": "wdmLink"
170 + },
171 +
172 + {
173 + "allowed": true,
174 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:02",
175 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:05",
176 + "params": {
177 + "distKms": 4000,
178 + "nodeName1": "SJC-W10",
179 + "nodeName2": "MSP-M10",
180 + "numWaves": 80,
181 + "port1": 20,
182 + "port2": 10
183 + },
184 + "type": "wdmLink"
185 + },
186 +
187 + {
188 +
189 + "allowed": true,
190 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:03",
191 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:06",
192 + "params": {
193 + "distKms": 5000,
194 + "nodeName1": "LAX-W10",
195 + "nodeName2": "DFW-M10",
196 + "numWaves": 80,
197 + "port1": 20,
198 + "port2": 10
199 + },
200 + "type": "wdmLink"
201 + },
202 +
203 + {
204 + "allowed": true,
205 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:05",
206 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:06",
207 + "params": {
208 + "distKms": 3000,
209 + "nodeName1": "MSP-M10",
210 + "nodeName2": "DFW-M10",
211 + "numWaves": 80,
212 + "port1": 30,
213 + "port2": 20
214 + },
215 + "type": "wdmLink"
216 + },
217 +
218 + {
219 + "allowed": true,
220 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:05",
221 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:07",
222 + "params": {
223 + "distKms": 3000,
224 + "nodeName1": "MSP-M10",
225 + "nodeName2": "CHG-N10",
226 + "numWaves": 80,
227 + "port1": 20,
228 + "port2": 21
229 + },
230 + "type": "wdmLink"
231 + },
232 +
233 + {
234 +
235 + "allowed": true,
236 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:06",
237 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:08",
238 + "params": {
239 + "distKms": 4000,
240 + "nodeName1": "DFW-M10",
241 + "nodeName2": "IAD-M10",
242 + "numWaves": 80,
243 + "port1": 30,
244 + "port2": 10
245 + },
246 + "type": "wdmLink"
247 + },
248 +
249 + {
250 +
251 + "allowed": true,
252 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:07",
253 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:08",
254 + "params": {
255 + "distKms": 4000,
256 + "nodeName1": "CHG-M10",
257 + "nodeName2": "IAD-M10",
258 + "numWaves": 80,
259 + "port1": 30,
260 + "port2": 20
261 + },
262 + "type": "wdmLink"
263 + },
264 +
265 + {
266 + "allowed": true,
267 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:07",
268 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:09",
269 + "params": {
270 + "distKms": 5000,
271 + "nodeName1": "CHG-M10",
272 + "nodeName2": "JFK-E10",
273 + "numWaves": 80,
274 + "port1": 20,
275 + "port2": 10
276 + },
277 + "type": "wdmLink"
278 + },
279 +
280 + {
281 + "allowed": true,
282 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:08",
283 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:0A",
284 + "params": {
285 + "distKms": 3000,
286 + "nodeName1": "IAD-M10",
287 + "nodeName2": "ATL-S10",
288 + "numWaves": 80,
289 + "port1": 30,
290 + "port2": 10
291 + },
292 + "type": "wdmLink"
293 + },
294 +
295 + {
296 +
297 + "allowed": true,
298 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:09",
299 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:0A",
300 + "params": {
301 + "distKms": 4000,
302 + "nodeName1": "JFK-E10",
303 + "nodeName2": "ATL-S10",
304 + "numWaves": 80,
305 + "port1": 20,
306 + "port2": 20
307 + },
308 + "type": "wdmLink"
309 + },
310 +
311 +
312 + {
313 + "allowed": true,
314 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:01",
315 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:01",
316 + "params": {
317 + "nodeName1": "SFO-R10",
318 + "nodeName2": "SFO-W10",
319 + "port1": 10,
320 + "port2": 1
321 + },
322 + "type": "pktOptLink"
323 + },
324 +
325 + {
326 + "allowed": true,
327 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:03",
328 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:03",
329 + "params": {
330 + "nodeName1": "LAX-R10",
331 + "nodeName2": "LAX-W10",
332 + "port1": 10,
333 + "port2": 1
334 + },
335 + "type": "pktOptLink"
336 + },
337 +
338 + {
339 + "allowed": true,
340 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:04",
341 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:04",
342 + "params": {
343 + "nodeName1": "SDG-R10",
344 + "nodeName2": "SDG-W10",
345 + "port1": 10,
346 + "port2": 1
347 + },
348 + "type": "pktOptLink"
349 + },
350 +
351 + {
352 + "allowed": true,
353 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:07",
354 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:07",
355 + "params": {
356 + "nodeName1": "CHG-R10",
357 + "nodeName2": "CHG-W10",
358 + "port1": 10,
359 + "port2": 1
360 + },
361 + "type": "pktOptLink"
362 + },
363 +
364 + {
365 + "allowed": true,
366 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:09",
367 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:09",
368 + "params": {
369 + "nodeName1": "JFK-R10",
370 + "nodeName2": "JFK-W10",
371 + "port1": 10,
372 + "port2": 1
373 + },
374 + "type": "pktOptLink"
375 + },
376 +
377 + {
378 + "allowed": true,
379 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:0A",
380 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:0A",
381 + "params": {
382 + "nodeName1": "ATL-R10",
383 + "nodeName2": "ATL-W10",
384 + "port1": 10,
385 + "port2": 1
386 + },
387 + "type": "pktOptLink"
388 + },
389 +
390 + ]
391 +}
1 +{
2 + "opticalSwitches": [
3 + {
4 + "allowed": true,
5 + "latitude": 37.6,
6 + "longitude": 122.3,
7 + "name": "ROADM1",
8 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:01",
9 + "params": {
10 + "numRegen": 0
11 + },
12 + "type": "Roadm"
13 + },
14 +
15 + {
16 + "allowed": true,
17 + "latitude": 37.3,
18 + "longitude": 121.9,
19 + "name": "ROADM2",
20 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:02",
21 + "params": {
22 + "numRegen": 0
23 + },
24 + "type": "Roadm"
25 + },
26 +
27 + {
28 + "allowed": true,
29 + "latitude": 33.9,
30 + "longitude": 118.4,
31 + "name": "ROADM3",
32 + "nodeDpid": "00:00:ff:ff:ff:ff:ff:03",
33 + "params": {
34 + "numRegen": 2
35 + },
36 + "type": "Roadm"
37 + }
38 + ],
39 +
40 + "opticalLinks": [
41 + {
42 + "allowed": true,
43 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:01",
44 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:03",
45 + "params": {
46 + "distKms": 1000,
47 + "nodeName1": "ROADM1",
48 + "nodeName2": "ROADM3",
49 + "numWaves": 80,
50 + "port1": 10,
51 + "port2": 30
52 + },
53 + "type": "wdmLink"
54 + },
55 +
56 + {
57 + "allowed": true,
58 + "nodeDpid1": "00:00:ff:ff:ff:ff:ff:03",
59 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:02",
60 + "params": {
61 + "distKms": 2000,
62 + "nodeName1": "ROADM3",
63 + "nodeName2": "ROADM2",
64 + "numWaves": 80,
65 + "port1": 31,
66 + "port2": 20
67 + },
68 + "type": "wdmLink"
69 + },
70 +
71 +
72 + {
73 + "allowed": true,
74 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:01",
75 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:01",
76 + "params": {
77 + "nodeName1": "ROUTER1",
78 + "nodeName2": "ROADM1",
79 + "bandWidth": 100000,
80 + "port1": 10,
81 + "port2": 11
82 + },
83 + "type": "pktOptLink"
84 + },
85 +
86 + {
87 + "allowed": true,
88 + "nodeDpid1": "00:00:ff:ff:ff:ff:00:02",
89 + "nodeDpid2": "00:00:ff:ff:ff:ff:ff:02",
90 + "params": {
91 + "nodeName1": "ROUTER2",
92 + "nodeName2": "ROADM2",
93 + "bandWidth": 100000,
94 + "port1": 10,
95 + "port2": 21
96 + },
97 + "type": "pktOptLink"
98 + }
99 +
100 + ]
101 +}
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
26 <module>config</module> 26 <module>config</module>
27 <module>sdnip</module> 27 <module>sdnip</module>
28 <module>calendar</module> 28 <module>calendar</module>
29 + <module>optical</module>
29 </modules> 30 </modules>
30 31
31 <properties> 32 <properties>
......
...@@ -155,6 +155,13 @@ ...@@ -155,6 +155,13 @@
155 <feature>onos-api</feature> 155 <feature>onos-api</feature>
156 <bundle>mvn:org.onlab.onos/onos-app-config/1.0.0-SNAPSHOT</bundle> 156 <bundle>mvn:org.onlab.onos/onos-app-config/1.0.0-SNAPSHOT</bundle>
157 </feature> 157 </feature>
158 +
159 + <feature name="onos-app-optical" version="1.0.0"
160 + description="ONOS optical network config">
161 + <feature>onos-api</feature>
162 + <bundle>mvn:org.onlab.onos/onos-app-optical/1.0.0-SNAPSHOT</bundle>
163 + </feature>
164 +
158 165
159 <feature name="onos-app-sdnip" version="1.0.0" 166 <feature name="onos-app-sdnip" version="1.0.0"
160 description="SDN-IP peering application"> 167 description="SDN-IP peering application">
......
1 +# Local VirtualBox-based single ONOS instance & ONOS mininet box
2 +
3 +export ONOS_NIC=192.168.56.*
4 +export OC1="192.168.56.101"
5 +export OCN="192.168.56.103"
6 +
7 +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
1 +package org.onlab.util;
2 +
3 +public final class HexString {
4 +
5 + private HexString() {
6 +
7 + }
8 +
9 + /**
10 + * Convert a string of bytes to a ':' separated hex string.
11 + *
12 + * @param bytes
13 + * @return "0f:ca:fe:de:ad:be:ef"
14 + */
15 + public static String toHexString(final byte[] bytes) {
16 + int i;
17 + StringBuilder ret = new StringBuilder();
18 + String tmp;
19 + for (i = 0; i < bytes.length; i++) {
20 + if (i > 0) {
21 + ret.append(':');
22 + }
23 + tmp = Integer.toHexString((bytes[i] & 0xff));
24 + if (tmp.length() == 1) {
25 + ret.append('0');
26 + }
27 + ret.append(tmp);
28 + }
29 + return ret.toString();
30 + }
31 +
32 + public static String toHexString(final long val, final int padTo) {
33 + char[] arr = Long.toHexString(val).toCharArray();
34 + String ret = "";
35 + // prepend the right number of leading zeros
36 + int i = 0;
37 + for (; i < (padTo * 2 - arr.length); i++) {
38 + ret += "0";
39 + if ((i % 2) != 0) {
40 + ret += ":";
41 + }
42 + }
43 + for (int j = 0; j < arr.length; j++) {
44 + ret += arr[j];
45 + if ((((i + j) % 2) != 0) && (j < (arr.length - 1))) {
46 + ret += ":";
47 + }
48 + }
49 + return ret;
50 + }
51 +
52 + public static String toHexString(final long val) {
53 + return toHexString(val, 8);
54 + }
55 +
56 + /**
57 + * Convert a string of hex values into a string of bytes.
58 + *
59 + * @param values
60 + * "0f:ca:fe:de:ad:be:ef"
61 + * @return [15, 5 ,2, 5, 17]
62 + * @throws NumberFormatException
63 + * If the string can not be parsed
64 + */
65 + public static byte[] fromHexString(final String values) {
66 + String[] octets = values.split(":");
67 + byte[] ret = new byte[octets.length];
68 +
69 + for (int i = 0; i < octets.length; i++) {
70 + if (octets[i].length() > 2) {
71 + throw new NumberFormatException("Invalid octet length");
72 + }
73 + ret[i] = Integer.valueOf(octets[i], 16).byteValue();
74 + }
75 + return ret;
76 + }
77 +
78 + public static long toLong(String value) {
79 + String[] octets = value.split(":");
80 + if (octets.length > 8) {
81 + throw new NumberFormatException("Input string is too big to fit in long: " + value);
82 + }
83 + long l = 0;
84 + for (String octet: octets) {
85 + if (octet.length() > 2) {
86 + throw new NumberFormatException(
87 + "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value);
88 + }
89 + short s = Short.parseShort(octet, 16);
90 + l = (l << 8) + s;
91 + }
92 + return l;
93 + }
94 +}
1 +package org.onlab.util;
2 +
3 +import org.junit.Test;
4 +
5 +import com.esotericsoftware.minlog.Log;
6 +
7 +import junit.framework.TestCase;
8 +
9 +/**
10 + * Test of the Hexstring.
11 + *
12 + */
13 +
14 +public class HexStringTest extends TestCase {
15 +
16 + @Test
17 + public void testMarshalling() throws Exception {
18 + String dpidStr = "00:00:00:23:20:2d:16:71";
19 + long dpid = HexString.toLong(dpidStr);
20 + String testStr = HexString.toHexString(dpid);
21 + TestCase.assertEquals(dpidStr, testStr);
22 + }
23 +
24 + @Test
25 + public void testToLong() {
26 + String dpidStr = "3e:1f:01:fc:72:8c:63:31";
27 + long valid = 0x3e1f01fc728c6331L;
28 + long testLong = HexString.toLong(dpidStr);
29 + TestCase.assertEquals(valid, testLong);
30 + }
31 +
32 + @Test
33 + public void testToLongMSB() {
34 + String dpidStr = "ca:7c:5e:d1:64:7a:95:9b";
35 + long valid = -3856102927509056101L;
36 + long testLong = HexString.toLong(dpidStr);
37 + TestCase.assertEquals(valid, testLong);
38 + }
39 +
40 + @Test
41 + public void testToLongError() {
42 + String dpidStr = "09:08:07:06:05:04:03:02:01";
43 + try {
44 + HexString.toLong(dpidStr);
45 + fail("HexString.toLong() should have thrown a NumberFormatException");
46 + } catch (NumberFormatException expected) {
47 + Log.info("HexString.toLong() have thrown a NumberFormatException");
48 + }
49 + }
50 +
51 + @Test
52 + public void testToStringBytes() {
53 + byte[] dpid = {0, 0, 0, 0, 0, 0, 0, -1 };
54 + String valid = "00:00:00:00:00:00:00:ff";
55 + String testString = HexString.toHexString(dpid);
56 + TestCase.assertEquals(valid, testString);
57 + }
58 +
59 + @Test
60 + public void testFromHexStringError() {
61 + String invalidStr = "00:00:00:00:00:00:ffff";
62 + try {
63 + HexString.fromHexString(invalidStr);
64 + fail("HexString.fromHexString() should have thrown a NumberFormatException");
65 + } catch (NumberFormatException expected) {
66 + Log.info("HexString.toLong() have thrown a NumberFormatException");
67 + }
68 + }
69 +}
70 +