jiangrui | 264dede | 2015-11-28 14:02:34 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
jiangrui | 264dede | 2015-11-28 14:02:34 +0800 | [diff] [blame] | 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.router; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | import java.util.List; |
| 20 | import java.util.Set; |
| 21 | |
| 22 | import org.apache.karaf.shell.commands.Argument; |
| 23 | import org.apache.karaf.shell.commands.Command; |
| 24 | import org.apache.karaf.shell.commands.Option; |
| 25 | import org.onosproject.cli.AbstractShellCommand; |
| 26 | import org.onosproject.vtnrsc.DefaultRouter; |
| 27 | import org.onosproject.vtnrsc.Router; |
| 28 | import org.onosproject.vtnrsc.Router.Status; |
| 29 | import org.onosproject.vtnrsc.RouterId; |
| 30 | import org.onosproject.vtnrsc.TenantId; |
| 31 | import org.onosproject.vtnrsc.VirtualPortId; |
| 32 | import org.onosproject.vtnrsc.router.RouterService; |
| 33 | |
| 34 | import 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") |
| 41 | public 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 | } |