blob: a6f4b3110af28176014b91db15609278c6894cac [file] [log] [blame]
jiangrui9ba8cda2015-08-12 11:41:47 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui9ba8cda2015-08-12 11:41:47 +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.subnet;
17
18import java.util.Set;
19
20import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
22import org.apache.karaf.shell.commands.Option;
23import org.onlab.packet.IpAddress;
24import org.onlab.packet.IpAddress.Version;
25import org.onlab.packet.IpPrefix;
26import org.onosproject.cli.AbstractShellCommand;
27import org.onosproject.vtnrsc.AllocationPool;
28import org.onosproject.vtnrsc.DefaultSubnet;
29import org.onosproject.vtnrsc.HostRoute;
30import org.onosproject.vtnrsc.Subnet;
31import org.onosproject.vtnrsc.Subnet.Mode;
32import org.onosproject.vtnrsc.SubnetId;
33import org.onosproject.vtnrsc.TenantId;
34import org.onosproject.vtnrsc.TenantNetworkId;
35import org.onosproject.vtnrsc.subnet.SubnetService;
36
37import com.google.common.collect.Sets;
38
39/**
40 * Supports for creating a subnet.
41 */
42@Command(scope = "onos", name = "subnet-create", description = "Supports for creating a subnet")
43public class SubnetCreateCommand extends AbstractShellCommand {
44
45 @Argument(index = 0, name = "id", description = "Subnet Id", required = true,
46 multiValued = false)
47 String id = null;
48
49 @Argument(index = 1, name = "subnetName", description = "Subnet String name", required = true,
50 multiValued = false)
51 String subnetName = null;
52
53 @Argument(index = 2, name = "networkId", description = "Subnet Network Id", required = true,
54 multiValued = false)
55 String networkId = null;
56
57 @Argument(index = 3, name = "tenantId", description = "Subnet Tenant Id", required = true,
58 multiValued = false)
59 String tenantId = null;
60
61 @Option(name = "-i", aliases = "--ipVersion", description = "Subnet Version ipVersion",
62 required = false, multiValued = false)
63 Version ipVersion = null;
64
65 @Option(name = "-c", aliases = "--cidr", description = "Subnet IpPrefix cidr",
66 required = false, multiValued = false)
67 String cidr = "0.0.0.0/0";
68
69 @Option(name = "-g", aliases = "--gatewayIp", description = "Subnet IpAddress gatewayIp",
70 required = false, multiValued = false)
71 String gatewayIp = "0.0.0.0";
72
73 @Option(name = "-d", aliases = "--dhcpEnabled", description = "Subnet boolean dhcpEnabled",
74 required = false, multiValued = false)
75 boolean dhcpEnabled = false;
76
77 @Option(name = "-s", aliases = "--shared", description = "Subnet boolean shared",
78 required = false, multiValued = false)
79 boolean shared = false;
80
81 @Option(name = "-m", aliases = "--ipV6AddressMode",
82 description = "Subnet Mode ipV6AddressMode", required = false, multiValued = false)
83 String ipV6AddressMode = null;
84
85 @Option(name = "-r", aliases = "--ipV6RaMode", description = "Subnet Mode ipV6RaMode",
86 required = false, multiValued = false)
87 String ipV6RaMode = null;
88
89 @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes",
90 required = false, multiValued = false)
jiangruiac0879a2015-09-08 16:58:49 +080091 Set<HostRoute> hostRoutes = Sets.newHashSet();
jiangrui9ba8cda2015-08-12 11:41:47 +080092
93 @Option(name = "-a", aliases = "--allocationPools",
94 description = "Subnet jsonnode allocationPools", required = false, multiValued = false)
jiangruiac0879a2015-09-08 16:58:49 +080095 Set<AllocationPool> allocationPools = Sets.newHashSet();
jiangrui9ba8cda2015-08-12 11:41:47 +080096
97 @Override
98 protected void execute() {
99 SubnetService service = get(SubnetService.class);
100 if (id == null || networkId == null || tenantId == null) {
Satish K1b81f852015-11-29 15:32:23 +0530101 print("id,networkId,tenantId can not be null");
jiangrui9ba8cda2015-08-12 11:41:47 +0800102 return;
103 }
104 Subnet subnet = new DefaultSubnet(SubnetId.subnetId(id), subnetName,
105 TenantNetworkId.networkId(networkId),
106 TenantId.tenantId(tenantId), ipVersion,
107 cidr == null ? null : IpPrefix.valueOf(cidr),
108 gatewayIp == null ? null : IpAddress.valueOf(gatewayIp),
109 dhcpEnabled, shared, hostRoutes,
110 ipV6AddressMode == null ? null : Mode.valueOf(ipV6AddressMode),
111 ipV6RaMode == null ? null : Mode.valueOf(ipV6RaMode),
112 allocationPools);
113
114 Set<Subnet> subnetsSet = Sets.newHashSet(subnet);
115 service.createSubnets(subnetsSet);
116 }
117
118}