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