Added a standalone utility to convert ONOS topology JSON config to OELinc JSON config.
Showing
6 changed files
with
228 additions
and
7 deletions
apps/oecfg/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Licensed to the Apache Software Foundation (ASF) under one | ||
4 | + ~ or more contributor license agreements. See the NOTICE file | ||
5 | + ~ distributed with this work for additional information | ||
6 | + ~ regarding copyright ownership. The ASF licenses this file | ||
7 | + ~ to you under the Apache License, Version 2.0 (the | ||
8 | + ~ "License"); you may not use this file except in compliance | ||
9 | + ~ with the License. You may obtain a copy of the License at | ||
10 | + ~ | ||
11 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
12 | + ~ | ||
13 | + ~ Unless required by applicable law or agreed to in writing, | ||
14 | + ~ software distributed under the License is distributed on an | ||
15 | + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
16 | + ~ KIND, either express or implied. See the License for the | ||
17 | + ~ specific language governing permissions and limitations | ||
18 | + ~ under the License. | ||
19 | + --> | ||
20 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
21 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
22 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
23 | + <modelVersion>4.0.0</modelVersion> | ||
24 | + | ||
25 | + <parent> | ||
26 | + <groupId>org.onlab.onos</groupId> | ||
27 | + <artifactId>onos-apps</artifactId> | ||
28 | + <version>1.0.0-SNAPSHOT</version> | ||
29 | + <relativePath>../pom.xml</relativePath> | ||
30 | + </parent> | ||
31 | + | ||
32 | + <artifactId>onos-app-oecfg</artifactId> | ||
33 | + <packaging>jar</packaging> | ||
34 | + | ||
35 | + <description>Standalone utility for converting ONOS JSON config to OE-Linc JSON config</description> | ||
36 | + | ||
37 | + <dependencies> | ||
38 | + <dependency> | ||
39 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
40 | + <artifactId>jackson-databind</artifactId> | ||
41 | + <scope>compile</scope> | ||
42 | + </dependency> | ||
43 | + <dependency> | ||
44 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
45 | + <artifactId>jackson-annotations</artifactId> | ||
46 | + <scope>compile</scope> | ||
47 | + </dependency> | ||
48 | + </dependencies> | ||
49 | + | ||
50 | + <build> | ||
51 | + <plugins> | ||
52 | + <plugin> | ||
53 | + <groupId>org.apache.maven.plugins</groupId> | ||
54 | + <artifactId>maven-shade-plugin</artifactId> | ||
55 | + <executions> | ||
56 | + <execution> | ||
57 | + <phase>package</phase> | ||
58 | + <goals> | ||
59 | + <goal>shade</goal> | ||
60 | + </goals> | ||
61 | + <configuration> | ||
62 | + <transformers> | ||
63 | + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
64 | + <manifestEntries> | ||
65 | + <Main-Class>org.onlab.onos.oecfg.OELinkConfig</Main-Class> | ||
66 | + </manifestEntries> | ||
67 | + </transformer> | ||
68 | + </transformers> | ||
69 | + </configuration> | ||
70 | + </execution> | ||
71 | + </executions> | ||
72 | + </plugin> | ||
73 | + </plugins> | ||
74 | + </build> | ||
75 | + | ||
76 | +</project> |
1 | +/* | ||
2 | + * Licensed to the Apache Software Foundation (ASF) under one | ||
3 | + * or more contributor license agreements. See the NOTICE file | ||
4 | + * distributed with this work for additional information | ||
5 | + * regarding copyright ownership. The ASF licenses this file | ||
6 | + * to you under the Apache License, Version 2.0 (the | ||
7 | + * "License"); you may not use this file except in compliance | ||
8 | + * with the License. You may obtain a copy of the License at | ||
9 | + * | ||
10 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
11 | + * | ||
12 | + * Unless required by applicable law or agreed to in writing, | ||
13 | + * software distributed under the License is distributed on an | ||
14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
15 | + * KIND, either express or implied. See the License for the | ||
16 | + * specific language governing permissions and limitations | ||
17 | + * under the License. | ||
18 | + */ | ||
19 | +package org.onlab.onos.oecfg; | ||
20 | + | ||
21 | +import com.fasterxml.jackson.databind.JsonNode; | ||
22 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
23 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
24 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
25 | + | ||
26 | +import java.io.IOException; | ||
27 | +import java.io.InputStream; | ||
28 | +import java.util.HashMap; | ||
29 | +import java.util.Map; | ||
30 | + | ||
31 | +/** | ||
32 | + * Utility program to convert standard ONOS config JSON to format expected | ||
33 | + * by the OE Link switch. | ||
34 | + */ | ||
35 | +public final class OELinkConfig { | ||
36 | + | ||
37 | + private ObjectMapper mapper = new ObjectMapper(); | ||
38 | + private Map<String, String> dpidToName = new HashMap<>(); | ||
39 | + | ||
40 | + public static void main(String[] args) { | ||
41 | + try { | ||
42 | + OELinkConfig config = new OELinkConfig(); | ||
43 | + JsonNode json = config.convert(System.in); | ||
44 | + System.out.println(json.toString()); | ||
45 | + } catch (IOException e) { | ||
46 | + System.err.println("Unable to convert JSON due to: " + e.getMessage()); | ||
47 | + e.printStackTrace(); | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + private OELinkConfig() { | ||
52 | + } | ||
53 | + | ||
54 | + private JsonNode convert(InputStream input) throws IOException { | ||
55 | + JsonNode json = mapper.readTree(input); | ||
56 | + ObjectNode result = mapper.createObjectNode(); | ||
57 | + result.set("opticalSwitches", opticalSwitches(json)); | ||
58 | + result.set("opticalLinks", opticalLinks(json)); | ||
59 | + return result; | ||
60 | + } | ||
61 | + | ||
62 | + private JsonNode opticalSwitches(JsonNode json) { | ||
63 | + ArrayNode result = mapper.createArrayNode(); | ||
64 | + for (JsonNode node : json.get("devices")) { | ||
65 | + String dpid = dpid(node.path("uri")); | ||
66 | + String name = node.path("name").asText("none"); | ||
67 | + dpidToName.put(dpid, name); | ||
68 | + if (node.path("type").asText("none").equals("ROADM")) { | ||
69 | + result.add(opticalSwitch(dpid, name, (ObjectNode) node)); | ||
70 | + } | ||
71 | + } | ||
72 | + return result; | ||
73 | + } | ||
74 | + | ||
75 | + private ObjectNode opticalSwitch(String dpid, String name, ObjectNode node) { | ||
76 | + ObjectNode result = mapper.createObjectNode(); | ||
77 | + ObjectNode annot = (ObjectNode) node.path("annotations"); | ||
78 | + result.put("allowed", true).put("type", "Roadm") | ||
79 | + .put("name", name).put("nodeDpid", dpid) | ||
80 | + .put("latitude", annot.path("latitude").asDouble(0.0)) | ||
81 | + .put("longitude", annot.path("longitude").asDouble(0.0)) | ||
82 | + .set("params", switchParams(annot)); | ||
83 | + return result; | ||
84 | + } | ||
85 | + | ||
86 | + private ObjectNode switchParams(ObjectNode annot) { | ||
87 | + return mapper.createObjectNode() | ||
88 | + .put("numRegen", annot.path("optical.regens").asInt(0)); | ||
89 | + } | ||
90 | + | ||
91 | + private JsonNode opticalLinks(JsonNode json) { | ||
92 | + ArrayNode result = mapper.createArrayNode(); | ||
93 | + for (JsonNode node : json.get("links")) { | ||
94 | + if (node.path("type").asText("none").equals("OPTICAL")) { | ||
95 | + result.add(opticalLink((ObjectNode) node)); | ||
96 | + } | ||
97 | + } | ||
98 | + return result; | ||
99 | + } | ||
100 | + | ||
101 | + private ObjectNode opticalLink(ObjectNode node) { | ||
102 | + ObjectNode result = mapper.createObjectNode(); | ||
103 | + ObjectNode annot = (ObjectNode) node.path("annotations"); | ||
104 | + String src = dpid(node.path("src")); | ||
105 | + String dst = dpid(node.path("dst")); | ||
106 | + result.put("allowed", true).put("type", linkType(annot)) | ||
107 | + .put("nodeDpid1", src).put("nodeDpid2", dst) | ||
108 | + .set("params", linkParams(src, dst, node, annot)); | ||
109 | + return result; | ||
110 | + } | ||
111 | + | ||
112 | + private String linkType(ObjectNode annot) { | ||
113 | + return annot.path("optical.type").asText("cross-connect").equals("WDM") ? | ||
114 | + "wdmLink" : "pktOptLink"; | ||
115 | + } | ||
116 | + | ||
117 | + private ObjectNode linkParams(String src, String dst, | ||
118 | + ObjectNode node, ObjectNode annot) { | ||
119 | + ObjectNode result = mapper.createObjectNode() | ||
120 | + .put("nodeName1", dpidToName.get(src)) | ||
121 | + .put("nodeName2", dpidToName.get(dst)) | ||
122 | + .put("port1", port(node.path("src"))) | ||
123 | + .put("port2", port(node.path("dst"))); | ||
124 | + if (annot.has("bandwidth")) { | ||
125 | + result.put("bandwidth", annot.path("bandwidth").asInt()); | ||
126 | + } | ||
127 | + if (annot.has("optical.waves")) { | ||
128 | + result.put("numWaves", annot.path("optical.waves").asInt()); | ||
129 | + } | ||
130 | + return result; | ||
131 | + } | ||
132 | + | ||
133 | + private String dpid(JsonNode node) { | ||
134 | + String s = node.asText("of:0000000000000000").substring(3); | ||
135 | + return s.substring(0, 2) + ":" + s.substring(2, 4) + ":" + | ||
136 | + s.substring(4, 6) + ":" + s.substring(6, 8) + ":" + | ||
137 | + s.substring(8, 10) + ":" + s.substring(10, 12) + ":" + | ||
138 | + s.substring(12, 14) + ":" + s.substring(14, 16); | ||
139 | + } | ||
140 | + | ||
141 | + private int port(JsonNode node) { | ||
142 | + return Integer.parseInt(node.asText("of:0000000000000000/0").substring(20)); | ||
143 | + } | ||
144 | + | ||
145 | +} |
... | @@ -59,7 +59,6 @@ | ... | @@ -59,7 +59,6 @@ |
59 | <artifactId>jackson-annotations</artifactId> | 59 | <artifactId>jackson-annotations</artifactId> |
60 | <scope>provided</scope> | 60 | <scope>provided</scope> |
61 | </dependency> | 61 | </dependency> |
62 | - | ||
63 | </dependencies> | 62 | </dependencies> |
64 | 63 | ||
65 | </project> | 64 | </project> | ... | ... |
... | @@ -46,6 +46,7 @@ | ... | @@ -46,6 +46,7 @@ |
46 | <module>calendar</module> | 46 | <module>calendar</module> |
47 | <module>optical</module> | 47 | <module>optical</module> |
48 | <module>metrics</module> | 48 | <module>metrics</module> |
49 | + <module>oecfg</module> | ||
49 | </modules> | 50 | </modules> |
50 | 51 | ||
51 | <properties> | 52 | <properties> | ... | ... |
... | @@ -2,28 +2,28 @@ | ... | @@ -2,28 +2,28 @@ |
2 | "devices" : [ | 2 | "devices" : [ |
3 | { | 3 | { |
4 | "uri": "of:0000ffffffffff01", "mac": "ffffffffffff01", "type": "ROADM", | 4 | "uri": "of:0000ffffffffff01", "mac": "ffffffffffff01", "type": "ROADM", |
5 | - "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", | 5 | + "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM1", |
6 | "annotations": { "latitude": 37.6, "longitude": 122.3, "optical.regens": 0 } | 6 | "annotations": { "latitude": 37.6, "longitude": 122.3, "optical.regens": 0 } |
7 | }, | 7 | }, |
8 | { | 8 | { |
9 | "uri": "of:0000ffffffffff02", "mac": "ffffffffffff02", "type": "ROADM", | 9 | "uri": "of:0000ffffffffff02", "mac": "ffffffffffff02", "type": "ROADM", |
10 | - "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", | 10 | + "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM2", |
11 | "annotations": { "latitude": 37.3, "longitude": 121.9, "optical.regens": 0 } | 11 | "annotations": { "latitude": 37.3, "longitude": 121.9, "optical.regens": 0 } |
12 | }, | 12 | }, |
13 | { | 13 | { |
14 | "uri": "of:0000ffffffffff03", "mac": "ffffffffffff03", "type": "ROADM", | 14 | "uri": "of:0000ffffffffff03", "mac": "ffffffffffff03", "type": "ROADM", |
15 | - "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", | 15 | + "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM3", |
16 | "annotations": { "latitude": 33.9, "longitude": 118.4, "optical.regens": 2 } | 16 | "annotations": { "latitude": 33.9, "longitude": 118.4, "optical.regens": 2 } |
17 | }, | 17 | }, |
18 | 18 | ||
19 | { | 19 | { |
20 | "uri": "of:0000ffffffff0001", "mac": "ffffffffff0003", "type": "SWITCH", | 20 | "uri": "of:0000ffffffff0001", "mac": "ffffffffff0003", "type": "SWITCH", |
21 | - "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", | 21 | + "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER1", |
22 | "annotations": { "latitude": 37.6, "longitude": 122.3 } | 22 | "annotations": { "latitude": 37.6, "longitude": 122.3 } |
23 | }, | 23 | }, |
24 | { | 24 | { |
25 | "uri": "of:0000ffffffff0002", "mac": "ffffffffff0002", "type": "SWITCH", | 25 | "uri": "of:0000ffffffff0002", "mac": "ffffffffff0002", "type": "SWITCH", |
26 | - "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", | 26 | + "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER2", |
27 | "annotations": { "latitude": 37.3, "longitude": 121.9 } | 27 | "annotations": { "latitude": 37.3, "longitude": 121.9 } |
28 | } | 28 | } |
29 | ], | 29 | ], | ... | ... |
-
Please register or login to post a comment