Committed by
Gerrit Code Review
CORD-280 Added CLIs for cordvtn
Change-Id: I76e0358ccf3f71ad7cb1f9ba048616f0177d7666
Showing
10 changed files
with
410 additions
and
0 deletions
... | @@ -54,6 +54,16 @@ | ... | @@ -54,6 +54,16 @@ |
54 | <artifactId>onos-ovsdb-api</artifactId> | 54 | <artifactId>onos-ovsdb-api</artifactId> |
55 | <version>${project.version}</version> | 55 | <version>${project.version}</version> |
56 | </dependency> | 56 | </dependency> |
57 | + <dependency> | ||
58 | + <groupId>org.onosproject</groupId> | ||
59 | + <artifactId>onos-cli</artifactId> | ||
60 | + <version>${project.version}</version> | ||
61 | + </dependency> | ||
62 | + <dependency> | ||
63 | + <groupId>org.apache.karaf.shell</groupId> | ||
64 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
65 | + <version>3.0.3</version> | ||
66 | + </dependency> | ||
57 | </dependencies> | 67 | </dependencies> |
58 | 68 | ||
59 | </project> | 69 | </project> | ... | ... |
... | @@ -19,11 +19,20 @@ import org.onlab.packet.IpAddress; | ... | @@ -19,11 +19,20 @@ import org.onlab.packet.IpAddress; |
19 | import org.onlab.packet.TpPort; | 19 | import org.onlab.packet.TpPort; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | 21 | ||
22 | +import java.util.Comparator; | ||
23 | + | ||
22 | /** | 24 | /** |
23 | * Representation of a node with ovsdb server. | 25 | * Representation of a node with ovsdb server. |
24 | */ | 26 | */ |
25 | public interface OvsdbNode { | 27 | public interface OvsdbNode { |
26 | 28 | ||
29 | + Comparator<OvsdbNode> OVSDB_NODE_COMPARATOR = new Comparator<OvsdbNode>() { | ||
30 | + @Override | ||
31 | + public int compare(OvsdbNode ovsdb1, OvsdbNode ovsdb2) { | ||
32 | + return ovsdb1.host().compareTo(ovsdb2.host()); | ||
33 | + } | ||
34 | + }; | ||
35 | + | ||
27 | /** | 36 | /** |
28 | * Returns the IP address of the ovsdb server. | 37 | * Returns the IP address of the ovsdb server. |
29 | * | 38 | * | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +package org.onosproject.cordvtn.cli; | ||
18 | + | ||
19 | +import org.apache.karaf.shell.commands.Argument; | ||
20 | +import org.apache.karaf.shell.commands.Command; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | +import org.onlab.packet.TpPort; | ||
23 | +import org.onosproject.cli.AbstractShellCommand; | ||
24 | +import org.onosproject.cordvtn.CordVtnService; | ||
25 | +import org.onosproject.cordvtn.DefaultOvsdbNode; | ||
26 | +import org.onosproject.cordvtn.OvsdbNode; | ||
27 | +import org.onosproject.net.DeviceId; | ||
28 | + | ||
29 | +import static com.google.common.base.Preconditions.checkArgument; | ||
30 | + | ||
31 | +/** | ||
32 | + * Adds a new OVSDB nodes. | ||
33 | + */ | ||
34 | +@Command(scope = "onos", name = "ovsdb-add", | ||
35 | + description = "Adds a new OVSDB node to cordvtn") | ||
36 | +public class OvsdbNodeAddCommand extends AbstractShellCommand { | ||
37 | + | ||
38 | + @Argument(index = 0, name = "host", description = "Hostname or IP", | ||
39 | + required = true, multiValued = false) | ||
40 | + private String host = null; | ||
41 | + | ||
42 | + @Argument(index = 1, name = "address", | ||
43 | + description = "OVSDB server listening address (ip:port)", | ||
44 | + required = true, multiValued = false) | ||
45 | + private String address = null; | ||
46 | + | ||
47 | + @Argument(index = 2, name = "bridgeId", | ||
48 | + description = "Device ID of integration bridge", | ||
49 | + required = true, multiValued = false) | ||
50 | + private String bridgeId = null; | ||
51 | + | ||
52 | + @Override | ||
53 | + protected void execute() { | ||
54 | + checkArgument(address.contains(":"), "address should be ip:port format"); | ||
55 | + checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format"); | ||
56 | + | ||
57 | + CordVtnService service = AbstractShellCommand.get(CordVtnService.class); | ||
58 | + String[] ipPort = address.split(":"); | ||
59 | + OvsdbNode ovsdb = new DefaultOvsdbNode(host, | ||
60 | + IpAddress.valueOf(ipPort[0]), | ||
61 | + TpPort.tpPort(Integer.parseInt(ipPort[1])), | ||
62 | + DeviceId.deviceId(bridgeId)); | ||
63 | + service.addNode(ovsdb); | ||
64 | + } | ||
65 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +package org.onosproject.cordvtn.cli; | ||
18 | + | ||
19 | +import org.apache.karaf.shell.commands.Argument; | ||
20 | +import org.apache.karaf.shell.commands.Command; | ||
21 | +import org.onosproject.cli.AbstractShellCommand; | ||
22 | +import org.onosproject.cordvtn.CordVtnService; | ||
23 | +import org.onosproject.cordvtn.OvsdbNode; | ||
24 | + | ||
25 | +import java.util.NoSuchElementException; | ||
26 | + | ||
27 | +/** | ||
28 | + * Connects to OVSDBs. | ||
29 | + */ | ||
30 | +@Command(scope = "onos", name = "ovsdb-connect", | ||
31 | + description = "Connects to OVSDBs") | ||
32 | +public class OvsdbNodeConnectCommand extends AbstractShellCommand { | ||
33 | + | ||
34 | + @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)", | ||
35 | + required = true, multiValued = true) | ||
36 | + private String[] hosts = null; | ||
37 | + | ||
38 | + @Override | ||
39 | + protected void execute() { | ||
40 | + CordVtnService service = AbstractShellCommand.get(CordVtnService.class); | ||
41 | + | ||
42 | + for (String host : hosts) { | ||
43 | + OvsdbNode ovsdb; | ||
44 | + try { | ||
45 | + ovsdb = service.getNodes().stream() | ||
46 | + .filter(node -> node.host().equals(host)) | ||
47 | + .findFirst().get(); | ||
48 | + } catch (NoSuchElementException e) { | ||
49 | + print("Unable to find %s", host); | ||
50 | + continue; | ||
51 | + } | ||
52 | + | ||
53 | + if (service.isNodeConnected(ovsdb)) { | ||
54 | + print("OVSDB %s is already in connected state, do nothing", host); | ||
55 | + } else { | ||
56 | + service.connect(ovsdb); | ||
57 | + } | ||
58 | + } | ||
59 | + } | ||
60 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +package org.onosproject.cordvtn.cli; | ||
18 | + | ||
19 | +import org.apache.karaf.shell.commands.Argument; | ||
20 | +import org.apache.karaf.shell.commands.Command; | ||
21 | +import org.onosproject.cli.AbstractShellCommand; | ||
22 | +import org.onosproject.cordvtn.CordVtnService; | ||
23 | +import org.onosproject.cordvtn.OvsdbNode; | ||
24 | + | ||
25 | +import java.util.NoSuchElementException; | ||
26 | + | ||
27 | +/** | ||
28 | + * Deletes OVSDB nodes from cordvtn. | ||
29 | + */ | ||
30 | +@Command(scope = "onos", name = "ovsdb-delete", | ||
31 | + description = "Deletes OVSDB nodes from cordvtn") | ||
32 | +public class OvsdbNodeDeleteCommand extends AbstractShellCommand { | ||
33 | + | ||
34 | + @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)", | ||
35 | + required = true, multiValued = true) | ||
36 | + private String[] hosts = null; | ||
37 | + | ||
38 | + @Override | ||
39 | + protected void execute() { | ||
40 | + CordVtnService service = AbstractShellCommand.get(CordVtnService.class); | ||
41 | + | ||
42 | + for (String host : hosts) { | ||
43 | + OvsdbNode ovsdb; | ||
44 | + try { | ||
45 | + ovsdb = service.getNodes().stream() | ||
46 | + .filter(node -> node.host().equals(host)) | ||
47 | + .findFirst().get(); | ||
48 | + | ||
49 | + } catch (NoSuchElementException e) { | ||
50 | + print("Unable to find %s", host); | ||
51 | + continue; | ||
52 | + } | ||
53 | + | ||
54 | + service.deleteNode(ovsdb); | ||
55 | + } | ||
56 | + } | ||
57 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +package org.onosproject.cordvtn.cli; | ||
18 | + | ||
19 | +import org.apache.karaf.shell.commands.Argument; | ||
20 | +import org.apache.karaf.shell.commands.Command; | ||
21 | +import org.onosproject.cli.AbstractShellCommand; | ||
22 | +import org.onosproject.cordvtn.CordVtnService; | ||
23 | +import org.onosproject.cordvtn.OvsdbNode; | ||
24 | + | ||
25 | +import java.util.NoSuchElementException; | ||
26 | + | ||
27 | +/** | ||
28 | + * Disconnects OVSDBs. | ||
29 | + */ | ||
30 | +@Command(scope = "onos", name = "ovsdb-disconnect", | ||
31 | + description = "Disconnects OVSDBs") | ||
32 | +public class OvsdbNodeDisconnectCommand extends AbstractShellCommand { | ||
33 | + | ||
34 | + @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)", | ||
35 | + required = true, multiValued = true) | ||
36 | + private String[] hosts = null; | ||
37 | + | ||
38 | + @Override | ||
39 | + protected void execute() { | ||
40 | + CordVtnService service = AbstractShellCommand.get(CordVtnService.class); | ||
41 | + | ||
42 | + for (String host : hosts) { | ||
43 | + OvsdbNode ovsdb; | ||
44 | + try { | ||
45 | + ovsdb = service.getNodes().stream() | ||
46 | + .filter(node -> node.host().equals(host)) | ||
47 | + .findFirst().get(); | ||
48 | + } catch (NoSuchElementException e) { | ||
49 | + print("Unable to find %s", host); | ||
50 | + continue; | ||
51 | + } | ||
52 | + | ||
53 | + if (!service.isNodeConnected(ovsdb)) { | ||
54 | + print("OVSDB %s is already in disconnected state, do nothing", host); | ||
55 | + } else { | ||
56 | + service.disconnect(ovsdb); | ||
57 | + } | ||
58 | + } | ||
59 | + } | ||
60 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +package org.onosproject.cordvtn.cli; | ||
18 | + | ||
19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
20 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
21 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
22 | +import org.apache.karaf.shell.commands.Command; | ||
23 | +import org.onosproject.cli.AbstractShellCommand; | ||
24 | +import org.onosproject.cordvtn.CordVtnService; | ||
25 | +import org.onosproject.cordvtn.OvsdbNode; | ||
26 | + | ||
27 | +import java.util.Collections; | ||
28 | +import java.util.List; | ||
29 | + | ||
30 | +/** | ||
31 | + * Lists all OVSDB nodes. | ||
32 | + */ | ||
33 | +@Command(scope = "onos", name = "ovsdbs", | ||
34 | + description = "Lists all OVSDB nodes registered in cordvtn application") | ||
35 | +public class OvsdbNodeListCommand extends AbstractShellCommand { | ||
36 | + | ||
37 | + @Override | ||
38 | + protected void execute() { | ||
39 | + CordVtnService service = AbstractShellCommand.get(CordVtnService.class); | ||
40 | + List<OvsdbNode> ovsdbs = service.getNodes(); | ||
41 | + Collections.sort(ovsdbs, OvsdbNode.OVSDB_NODE_COMPARATOR); | ||
42 | + | ||
43 | + if (outputJson()) { | ||
44 | + print("%s", json(service, ovsdbs)); | ||
45 | + } else { | ||
46 | + for (OvsdbNode ovsdb : ovsdbs) { | ||
47 | + print("host=%s, address=%s, br-int=%s, state=%s", | ||
48 | + ovsdb.host(), | ||
49 | + ovsdb.ip().toString() + ":" + ovsdb.port().toString(), | ||
50 | + ovsdb.intBrId().toString(), | ||
51 | + getState(service, ovsdb)); | ||
52 | + } | ||
53 | + print("Total %s nodes", service.getNodeCount()); | ||
54 | + } | ||
55 | + } | ||
56 | + | ||
57 | + private JsonNode json(CordVtnService service, List<OvsdbNode> ovsdbs) { | ||
58 | + ObjectMapper mapper = new ObjectMapper(); | ||
59 | + ArrayNode result = mapper.createArrayNode(); | ||
60 | + for (OvsdbNode ovsdb : ovsdbs) { | ||
61 | + String ipPort = ovsdb.ip().toString() + ":" + ovsdb.port().toString(); | ||
62 | + result.add(mapper.createObjectNode() | ||
63 | + .put("host", ovsdb.host()) | ||
64 | + .put("address", ipPort) | ||
65 | + .put("brInt", ovsdb.intBrId().toString()) | ||
66 | + .put("state", getState(service, ovsdb))); | ||
67 | + } | ||
68 | + return result; | ||
69 | + } | ||
70 | + | ||
71 | + private String getState(CordVtnService service, OvsdbNode ovsdb) { | ||
72 | + return service.isNodeConnected(ovsdb) ? "CONNECTED" : "DISCONNECTED"; | ||
73 | + } | ||
74 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +/** | ||
18 | + * Console commands to manage OVSDB nodes for cordvtn. | ||
19 | + */ | ||
20 | +package org.onosproject.cordvtn.cli; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +/** | ||
18 | + * Application for provisioning virtual tenant networks. | ||
19 | + */ | ||
20 | +package org.onosproject.cordvtn; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +<!-- | ||
2 | + ~ Copyright 2015 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 | +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> | ||
17 | + | ||
18 | + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | ||
19 | + <command> | ||
20 | + <action class="org.onosproject.cordvtn.cli.OvsdbNodeListCommand"/> | ||
21 | + </command> | ||
22 | + <command> | ||
23 | + <action class="org.onosproject.cordvtn.cli.OvsdbNodeAddCommand"/> | ||
24 | + </command> | ||
25 | + <command> | ||
26 | + <action class="org.onosproject.cordvtn.cli.OvsdbNodeDeleteCommand"/> | ||
27 | + </command> | ||
28 | + <command> | ||
29 | + <action class="org.onosproject.cordvtn.cli.OvsdbNodeConnectCommand"/> | ||
30 | + </command> | ||
31 | + <command> | ||
32 | + <action class="org.onosproject.cordvtn.cli.OvsdbNodeDisconnectCommand"/> | ||
33 | + </command> | ||
34 | + </command-bundle> | ||
35 | +</blueprint> |
-
Please register or login to post a comment