Nikhil Cheerla
Committed by Gerrit Code Review

OECFG (onos-oecfg) completely removed

Change-Id: Id44f58c0402cfdb0fedd91d8a3479cc817f2b4a4
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,7 +41,6 @@ ...@@ -41,7 +41,6 @@
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>
45 <module>routing</module> 44 <module>routing</module>
46 <module>routing-api</module> 45 <module>routing-api</module>
47 <module>reactive-routing</module> 46 <module>reactive-routing</module>
......
...@@ -366,11 +366,17 @@ class LINCSwitch(OpticalSwitch): ...@@ -366,11 +366,17 @@ class LINCSwitch(OpticalSwitch):
366 with open('Topology.json', 'w') as outfile: 366 with open('Topology.json', 'w') as outfile:
367 json.dump(opticalJSON, outfile, indent=4, separators=(',', ': ')) 367 json.dump(opticalJSON, outfile, indent=4, separators=(',', ': '))
368 368
369 - info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file\n') 369 + info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file (no oecfg) \n')
370 - output = quietRun('%s/tools/test/bin/onos-oecfg ./Topology.json > TopoConfig.json' % LINCSwitch.onosDir, shell=True) 370 +
371 - if output: 371 + topoConfigJson = {};
372 - error('***ERROR: Error creating topology file: %s ' % output + '\n') 372 + dpIdToName = {};
373 - return False 373 +
374 + topoConfigJson["switchConfig"] = getSwitchConfig(dpIdToName);
375 + topoConfigJson["linkConfig"] = getLinkConfig(dpIdToName);
376 +
377 + #Writing to TopoConfig.json
378 + with open( 'TopoConfig.json', 'w' ) as outfile:
379 + json.dump( topoConfigJson, outfile, indent=4, separators=(',', ': ') )
374 380
375 info('*** Creating sys.config...\n') 381 info('*** Creating sys.config...\n')
376 output = quietRun('%s/config_generator TopoConfig.json %s/sys.config.template %s %s' 382 output = quietRun('%s/config_generator TopoConfig.json %s/sys.config.template %s %s'
...@@ -452,6 +458,87 @@ class LINCSwitch(OpticalSwitch): ...@@ -452,6 +458,87 @@ class LINCSwitch(OpticalSwitch):
452 if output.strip('{}'): 458 if output.strip('{}'):
453 warn('***WARNING: Could not push topology file to ONOS: %s\n' % output) 459 warn('***WARNING: Could not push topology file to ONOS: %s\n' % output)
454 460
461 + #converts node ids to linc-oe format, with colons every two chars
462 + def dpId(id):
463 + nodeDpid = ""
464 + id = id.split("/", 1)[0]
465 + for i in range(3, len(id) - 1, 2):
466 + nodeDpid += (id[i:(i + 2):]) + ":"
467 + return nodeDpid[0:(len(nodeDpid) - 1)];
468 +
469 + def getSwitchConfig (dpIdToName):
470 + switchConfig = [];
471 + #Iterate through all switches and convert the ROADM switches to linc-oe format
472 + for switch in opticalJSON["devices"]:
473 + if switch.get("type", "none") == "ROADM":
474 + builtSwitch = {}
475 +
476 + #set basic switch params based on annotations
477 + builtSwitch["allowed"] = True;
478 + builtSwitch["latitude"] = switch["annotations"].get("latitude", 0.0);
479 + builtSwitch["longitude"] = switch["annotations"].get("longitude", 0.0);
480 +
481 + #assumed that all switches have this entry
482 + nodeId = switch["uri"]
483 +
484 + #convert the nodeId to linc-oe format
485 + nodeDpid = dpId(nodeId);
486 +
487 + builtSwitch["name"] = switch.get("name", "none");
488 +
489 + #keep track of the name corresponding to each switch dpid
490 + dpIdToName[nodeDpid] = builtSwitch["name"];
491 +
492 + builtSwitch["nodeDpid"] = nodeDpid
493 +
494 + #set switch params and type
495 + builtSwitch["params"] = {};
496 + builtSwitch["params"]["numregens"] = switch["annotations"].get("optical.regens", 0);
497 + builtSwitch["type"] = "Roadm"
498 +
499 + #append to list of switches
500 + switchConfig.append(builtSwitch);
501 + return switchConfig
502 +
503 +
504 + def getLinkConfig (dpIdToName):
505 + newLinkConfig = [];
506 + #Iterate through all optical links and convert them to linc-oe format
507 + for link in opticalJSON["links"]:
508 + if link.get("type", "none") == "OPTICAL":
509 + builtLink = {}
510 +
511 + #set basic link params for src and dst
512 + builtLink["allowed"] = True;
513 + builtLink["nodeDpid1"] = dpId(link["src"])
514 + builtLink["nodeDpid2"] = dpId(link["dst"])
515 +
516 + #set more params such as name/bandwidth/port/waves if they exist
517 + params = {}
518 + params["nodeName1"] = dpIdToName.get(builtLink["nodeDpid1"], "none")
519 + params["nodeName2"] = dpIdToName.get(builtLink["nodeDpid2"], "none")
520 +
521 + params["port1"] = int(link["src"].split("/")[1])
522 + params["port2"] = int(link["dst"].split("/")[1])
523 +
524 + if "bandwidth" in link["annotations"]:
525 + params["bandwidth"] = link["annotations"]["bandwidth"]
526 +
527 + if "optical.waves" in link["annotations"]:
528 + params["numWaves"] = link["annotations"]["optical.waves"]
529 +
530 + builtLink["params"] = params
531 +
532 + #set type of link (WDM or pktOpt)
533 + if link["annotations"].get("optical.type", "cross-connect") == "WDM":
534 + builtLink["type"] = "wdmLink"
535 + else:
536 + builtLink["type"] = "pktOptLink"
537 +
538 + newLinkConfig.append(builtLink);
539 + return newLinkConfig
540 +
541 +
455 @staticmethod 542 @staticmethod
456 def waitStarted(net, timeout=TIMEOUT): 543 def waitStarted(net, timeout=TIMEOUT):
457 "wait until all tap interfaces are available" 544 "wait until all tap interfaces are available"
...@@ -559,6 +646,8 @@ class LINCSwitch(OpticalSwitch): ...@@ -559,6 +646,8 @@ class LINCSwitch(OpticalSwitch):
559 def terminate(self): 646 def terminate(self):
560 pass 647 pass
561 648
649 +
650 +
562 class LINCLink(Link): 651 class LINCLink(Link):
563 """ 652 """
564 LINC link class 653 LINC link class
......