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