blob: 4c0aee44ea86bec2b25d5cf759e49f42fa5f7402 [file] [log] [blame]
jiangrui264dede2015-11-28 14:02:34 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui264dede2015-11-28 14:02:34 +08003 *
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 */
16package org.onosproject.vtnrsc.cli.router;
17
18import java.util.ArrayList;
19import java.util.List;
20import java.util.Set;
21
Ray Milkey86ad7bb2018-09-27 12:32:28 -070022import org.apache.karaf.shell.api.action.Argument;
23import org.apache.karaf.shell.api.action.Command;
24import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070025import org.apache.karaf.shell.api.action.lifecycle.Service;
jiangrui264dede2015-11-28 14:02:34 +080026import org.onosproject.cli.AbstractShellCommand;
27import org.onosproject.vtnrsc.DefaultRouter;
28import org.onosproject.vtnrsc.Router;
29import org.onosproject.vtnrsc.Router.Status;
30import org.onosproject.vtnrsc.RouterId;
31import org.onosproject.vtnrsc.TenantId;
32import org.onosproject.vtnrsc.VirtualPortId;
33import org.onosproject.vtnrsc.router.RouterService;
34
35import com.google.common.collect.Sets;
36
37/**
38 * Supports for create a router.
39 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070040@Service
jiangrui264dede2015-11-28 14:02:34 +080041@Command(scope = "onos", name = "router-create",
42 description = "Supports for creating a router")
43public class RouterCreateCommand extends AbstractShellCommand {
44 @Argument(index = 0, name = "id", description = "The router identifier",
45 required = true, multiValued = false)
46 String id = null;
47
48 @Argument(index = 1, name = "routerName", description = "The name of router",
49 required = true, multiValued = false)
50 String routerName = null;
51
52 @Argument(index = 2, name = "tenantId", description = "The tenant identifier of router",
53 required = true, multiValued = false)
54 String tenantId = null;
55
56 @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router",
57 required = false, multiValued = false)
58 String gatewayPortId = null;
59
60 @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The external gateway info of router",
61 required = false, multiValued = false)
62 String externalGatewayInfo = null;
63
64 @Option(name = "-s", aliases = "--status", description = "The status of router",
65 required = false, multiValued = false)
66 String status = null;
67
68 @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router",
69 required = false, multiValued = false)
70 boolean adminStateUp = true;
71
72 @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router",
73 required = false, multiValued = false)
74 boolean distributed = false;
75
76 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070077 protected void doExecute() {
jiangrui264dede2015-11-28 14:02:34 +080078 RouterService service = get(RouterService.class);
79 try {
80 List<String> routes = new ArrayList<String>();
81 Router router = new DefaultRouter(
82 RouterId.valueOf(id),
83 routerName,
84 adminStateUp,
85 status == null ? Status.ACTIVE
86 : Status.valueOf(status),
87 distributed,
88 null,
89 VirtualPortId.portId(gatewayPortId),
90 TenantId.tenantId(tenantId),
91 routes);
92 Set<Router> routerSet = Sets.newHashSet(router);
93 service.createRouters(routerSet);
94 } catch (Exception e) {
95 print(null, e.getMessage());
96 }
97 }
98
99}