4c555e331c777ede4849caaaee1820c95c40f9f6
[onosfw.git] /
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.virtualport;
17
18 import java.util.Map;
19 import java.util.Set;
20
21 import org.apache.karaf.shell.commands.Argument;
22 import org.apache.karaf.shell.commands.Command;
23 import org.apache.karaf.shell.commands.Option;
24 import org.onlab.packet.MacAddress;
25 import org.onosproject.cli.AbstractShellCommand;
26 import org.onosproject.net.DeviceId;
27 import org.onosproject.vtnrsc.AllowedAddressPair;
28 import org.onosproject.vtnrsc.BindingHostId;
29 import org.onosproject.vtnrsc.DefaultVirtualPort;
30 import org.onosproject.vtnrsc.FixedIp;
31 import org.onosproject.vtnrsc.SecurityGroup;
32 import org.onosproject.vtnrsc.TenantId;
33 import org.onosproject.vtnrsc.TenantNetworkId;
34 import org.onosproject.vtnrsc.VirtualPort;
35 import org.onosproject.vtnrsc.VirtualPortId;
36 import org.onosproject.vtnrsc.virtualport.VirtualPortService;
37
38 import com.google.common.collect.Maps;
39 import com.google.common.collect.Sets;
40
41 /**
42  * Supports for creating a virtualPort.
43  */
44 @Command(scope = "onos", name = "virtualport-create",
45         description = "Supports for creating a virtualPort.")
46 public class VirtualPortCreateCommand extends AbstractShellCommand {
47
48     @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
49             multiValued = false)
50     String id = null;
51
52     @Argument(index = 1, name = "networkId", description = "network id.", required = true,
53             multiValued = false)
54     String networkId = null;
55
56     @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
57             multiValued = false)
58     String name = null;
59
60     @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
61             multiValued = false)
62     String tenantId = null;
63
64     @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
65             multiValued = false)
66     String deviceId = null;
67
68     @Option(name = "-a", aliases = "--adminStateUp",
69             description = "administrative status of the virtualPort which is true or false.",
70             required = false, multiValued = false)
71     Boolean adminStateUp = false;
72
73     @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
74             multiValued = false)
75     String state = null;
76
77     @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
78             multiValued = false)
79     String macAddress = "";
80
81     @Option(name = "-d", aliases = "--deviceOwner", description = "ID of the entity that uses this "
82             + "virtualPort.", required = false, multiValued = false)
83     String deviceOwner = null;
84
85     @Option(name = "-f", aliases = "--fixedIp",
86             description = "The IP address for the port,include the IP address "
87                     + "and subnet identity.", required = false, multiValued = false)
88     FixedIp fixedIp = null;
89
90     @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
91             required = false, multiValued = false)
92     String bindingHostId = null;
93
94     @Option(name = "-t", aliases = "--bindingvnicType", description = "virtualPort bindingvnicType.",
95             required = false, multiValued = false)
96     String bindingvnicType = null;
97
98     @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
99             required = false, multiValued = false)
100     String bindingvifType = null;
101
102     @Option(name = "-b", aliases = "--bindingvnicDetails",
103             description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
104     String bindingvnicDetails = null;
105
106     @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
107             required = false, multiValued = false)
108     Set<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
109
110     @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
111             required = false, multiValued = false)
112     Set<SecurityGroup> securityGroups = Sets.newHashSet();
113
114     @Override
115     protected void execute() {
116         Map<String, String> strMap = Maps.newHashMap();
117         strMap.putIfAbsent("name", name);
118         strMap.putIfAbsent("deviceOwner", deviceOwner);
119         strMap.putIfAbsent("bindingvnicType", bindingvnicType);
120         strMap.putIfAbsent("bindingvifType", bindingvifType);
121         strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
122         VirtualPortService service = get(VirtualPortService.class);
123         VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
124                                        TenantNetworkId.networkId(networkId),
125                                        false, strMap, VirtualPort.State.ACTIVE,
126                                        MacAddress.valueOf(macAddress),
127                                        TenantId.tenantId(tenantId),
128                                        DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
129                                        BindingHostId.bindingHostId(bindingHostId),
130                                        allowedAddressPairs, securityGroups);
131         Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
132         service.createPorts(virtualPorts);
133     }
134 }