jiangrui
Committed by Gerrit Code Review

[ONOS-2827] add router interface service cli

Change-Id: I01a50e9d2c7ffd4f66b48e9f1ea7e14c75ae8eb4
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 +package org.onosproject.vtnrsc.cli.routerinterface;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.vtnrsc.RouterId;
22 +import org.onosproject.vtnrsc.RouterInterface;
23 +import org.onosproject.vtnrsc.SubnetId;
24 +import org.onosproject.vtnrsc.TenantId;
25 +import org.onosproject.vtnrsc.VirtualPortId;
26 +import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
27 +
28 +/**
29 + * Supports for create a router interface.
30 + */
31 +@Command(scope = "onos", name = "routerinterface-create", description = "Supports for creating a router interface")
32 +public class RouterInterfaceCreateCommand extends AbstractShellCommand {
33 + @Argument(index = 0, name = "routerId", description = "The router identifier of router interface",
34 + required = true, multiValued = false)
35 + String routerId = null;
36 +
37 + @Argument(index = 1, name = "tenantId", description = "The tenant identifier of router interface",
38 + required = true, multiValued = false)
39 + String tenantId = null;
40 +
41 + @Argument(index = 2, name = "portId", description = "The port identifier of router interface",
42 + required = true, multiValued = false)
43 + String portId = null;
44 +
45 + @Argument(index = 3, name = "subnetId", description = "The subnet identifier of router interface",
46 + required = true, multiValued = false)
47 + String subnetId = null;
48 +
49 + @Override
50 + protected void execute() {
51 + RouterInterfaceService service = get(RouterInterfaceService.class);
52 + try {
53 + RouterInterface routerInterface = RouterInterface.routerInterface(
54 + SubnetId.subnetId(subnetId),
55 + VirtualPortId.portId(portId),
56 + RouterId.valueOf(routerId),
57 + TenantId.tenantId(tenantId));
58 + service.addRouterInterface(routerInterface);
59 + } catch (Exception e) {
60 + print(null, e.getMessage());
61 + }
62 + }
63 +
64 +}
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 +package org.onosproject.vtnrsc.cli.routerinterface;
17 +
18 +import org.apache.karaf.shell.commands.Command;
19 +import org.apache.karaf.shell.commands.Option;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.vtnrsc.RouterInterface;
22 +import org.onosproject.vtnrsc.SubnetId;
23 +import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
24 +
25 +/**
26 + * Supports for query a router interface.
27 + */
28 +@Command(scope = "onos", name = "routerinterfaces", description = "Supports for querying a router interface")
29 +public class RouterInterfaceQueryCommand extends AbstractShellCommand {
30 + @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface",
31 + required = false, multiValued = false)
32 + String subnetId = null;
33 +
34 + private static final String FMT = "subnetId=%s, tenantId=%s, portId=%s, routerId=%s";
35 +
36 + @Override
37 + protected void execute() {
38 + RouterInterfaceService service = get(RouterInterfaceService.class);
39 + if (subnetId != null) {
40 + RouterInterface routerInterface = service
41 + .getRouterInterface(SubnetId.subnetId(subnetId));
42 + printRouterInterface(routerInterface);
43 + } else {
44 + Iterable<RouterInterface> routerInterfaces = service
45 + .getRouterInterfaces();
46 + for (RouterInterface routerInterface : routerInterfaces) {
47 + printRouterInterface(routerInterface);
48 + }
49 + }
50 + }
51 +
52 + private void printRouterInterface(RouterInterface routerInterface) {
53 + print(FMT, routerInterface.subnetId(), routerInterface.tenantId(),
54 + routerInterface.portId(), routerInterface.routerId());
55 + }
56 +}
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 +package org.onosproject.vtnrsc.cli.routerinterface;
17 +
18 +import org.apache.karaf.shell.commands.Command;
19 +import org.apache.karaf.shell.commands.Option;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.vtnrsc.RouterInterface;
22 +import org.onosproject.vtnrsc.SubnetId;
23 +import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
24 +
25 +/**
26 + * Supports for remove a router interface.
27 + */
28 +@Command(scope = "onos", name = "routerinterface-remove", description = "Supports for removing a router interface")
29 +public class RouterInterfaceRemoveCommand extends AbstractShellCommand {
30 + @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface",
31 + required = true, multiValued = false)
32 + String subnetId = null;
33 +
34 + @Override
35 + protected void execute() {
36 + RouterInterfaceService service = get(RouterInterfaceService.class);
37 + try {
38 + RouterInterface routerInterface = service
39 + .getRouterInterface(SubnetId.subnetId(subnetId));
40 + if (routerInterface == null) {
41 + print(null, "subnet ID of interface doesn't exist");
42 + return;
43 + }
44 + service.removeRouterInterface(routerInterface);
45 + } catch (Exception e) {
46 + print(null, e.getMessage());
47 + }
48 +
49 + }
50 +}
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 + * Command line interface for router interface.
19 + */
20 +package org.onosproject.vtnrsc.cli.routerinterface;
...@@ -52,5 +52,38 @@ ...@@ -52,5 +52,38 @@
52 <command> 52 <command>
53 <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortUpdateCommand"/> 53 <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortUpdateCommand"/>
54 </command> 54 </command>
55 + <command>
56 + <action class="org.onosproject.vtnrsc.cli.floatingip.FloatingIpCreateCommand"/>
57 + </command>
58 + <command>
59 + <action class="org.onosproject.vtnrsc.cli.floatingip.FloatingIpQueryCommand"/>
60 + </command>
61 + <command>
62 + <action class="org.onosproject.vtnrsc.cli.floatingip.FloatingIpRemoveCommand"/>
63 + </command>
64 + <command>
65 + <action class="org.onosproject.vtnrsc.cli.floatingip.FloatingIpUpdateCommand"/>
66 + </command>
67 + <command>
68 + <action class="org.onosproject.vtnrsc.cli.router.RouterCreateCommand"/>
69 + </command>
70 + <command>
71 + <action class="org.onosproject.vtnrsc.cli.router.RouterQueryCommand"/>
72 + </command>
73 + <command>
74 + <action class="org.onosproject.vtnrsc.cli.router.RouterRemoveCommand"/>
75 + </command>
76 + <command>
77 + <action class="org.onosproject.vtnrsc.cli.router.RouterUpdateCommand"/>
78 + </command>
79 + <command>
80 + <action class="org.onosproject.vtnrsc.cli.routerinterface.RouterInterfaceCreateCommand"/>
81 + </command>
82 + <command>
83 + <action class="org.onosproject.vtnrsc.cli.routerinterface.RouterInterfaceRemoveCommand"/>
84 + </command>
85 + <command>
86 + <action class="org.onosproject.vtnrsc.cli.routerinterface.RouterInterfaceQueryCommand"/>
87 + </command>
55 </command-bundle> 88 </command-bundle>
56 </blueprint> 89 </blueprint>
......