jiangrui
Committed by Gerrit Code Review

[ONOS-2254] The CLIs of port resource.

Change-Id: I35c3da7c0d6a7f5f170d74d63a1ab85415b34191
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.Collection;
19 +import java.util.Map;
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.onlab.packet.MacAddress;
26 +import org.onosproject.cli.AbstractShellCommand;
27 +import org.onosproject.net.DeviceId;
28 +import org.onosproject.vtnrsc.AllowedAddressPair;
29 +import org.onosproject.vtnrsc.BindingHostId;
30 +import org.onosproject.vtnrsc.DefaultVirtualPort;
31 +import org.onosproject.vtnrsc.FixedIp;
32 +import org.onosproject.vtnrsc.SecurityGroup;
33 +import org.onosproject.vtnrsc.TenantId;
34 +import org.onosproject.vtnrsc.TenantNetworkId;
35 +import org.onosproject.vtnrsc.VirtualPort;
36 +import org.onosproject.vtnrsc.VirtualPortId;
37 +import org.onosproject.vtnrsc.virtualport.VirtualPortService;
38 +
39 +import com.google.common.collect.Maps;
40 +import com.google.common.collect.Sets;
41 +
42 +/**
43 + * Supports for creating a virtualPort.
44 + */
45 +@Command(scope = "onos", name = "virtualport-create",
46 + description = "Supports for creating a virtualPort.")
47 +public class VirtualPortCreateCommand extends AbstractShellCommand {
48 +
49 + @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
50 + multiValued = false)
51 + String id = null;
52 +
53 + @Argument(index = 1, name = "networkId", description = "network id.", required = true,
54 + multiValued = false)
55 + String networkId = null;
56 +
57 + @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
58 + multiValued = false)
59 + String name = null;
60 +
61 + @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
62 + multiValued = false)
63 + String tenantId = null;
64 +
65 + @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
66 + multiValued = false)
67 + String deviceId = null;
68 +
69 + @Option(name = "-a", aliases = "--adminStateUp",
70 + description = "administrative status of the virtualPort which is true or false.",
71 + required = false, multiValued = false)
72 + Boolean adminStateUp = false;
73 +
74 + @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
75 + multiValued = false)
76 + String state = null;
77 +
78 + @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
79 + multiValued = false)
80 + String macAddress = "";
81 +
82 + @Option(name = "-d", aliases = "--deviceOwner", description = "ID of the entity that uses this "
83 + + "virtualPort.", required = false, multiValued = false)
84 + String deviceOwner = null;
85 +
86 + @Option(name = "-f", aliases = "--fixedIp",
87 + description = "The IP address for the port,include the IP address "
88 + + "and subnet identity.", required = false, multiValued = false)
89 + FixedIp fixedIp = null;
90 +
91 + @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
92 + required = false, multiValued = false)
93 + String bindingHostId = null;
94 +
95 + @Option(name = "-t", aliases = "--bindingvnicType", description = "virtualPort bindingvnicType.",
96 + required = false, multiValued = false)
97 + String bindingvnicType = null;
98 +
99 + @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
100 + required = false, multiValued = false)
101 + String bindingvifType = null;
102 +
103 + @Option(name = "-b", aliases = "--bindingvnicDetails",
104 + description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
105 + String bindingvnicDetails = null;
106 +
107 + @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
108 + required = false, multiValued = false)
109 + Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
110 +
111 + @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
112 + required = false, multiValued = false)
113 + Collection<SecurityGroup> securityGroups = Sets.newHashSet();
114 +
115 + @Override
116 + protected void execute() {
117 + Map<String, String> strMap = Maps.newHashMap();
118 + strMap.putIfAbsent("name", name);
119 + strMap.putIfAbsent("deviceOwner", deviceOwner);
120 + strMap.putIfAbsent("bindingvnicType", bindingvnicType);
121 + strMap.putIfAbsent("bindingvifType", bindingvifType);
122 + strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
123 + VirtualPortService service = get(VirtualPortService.class);
124 + VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
125 + TenantNetworkId.networkId(networkId),
126 + false, strMap, VirtualPort.State.ACTIVE,
127 + MacAddress.valueOf(macAddress),
128 + TenantId.tenantId(tenantId),
129 + DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
130 + BindingHostId.bindingHostId(bindingHostId),
131 + allowedAddressPairs, securityGroups);
132 + Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
133 + service.createPorts(virtualPorts);
134 + }
135 +}
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.Collection;
19 +
20 +import org.apache.karaf.shell.commands.Command;
21 +import org.apache.karaf.shell.commands.Option;
22 +import org.onosproject.cli.AbstractShellCommand;
23 +import org.onosproject.net.DeviceId;
24 +import org.onosproject.vtnrsc.TenantNetworkId;
25 +import org.onosproject.vtnrsc.VirtualPort;
26 +import org.onosproject.vtnrsc.VirtualPortId;
27 +import org.onosproject.vtnrsc.virtualport.VirtualPortService;
28 +
29 +/**
30 + * Supports for querying virtualPorts.
31 + */
32 +@Command(scope = "onos", name = "virtualports", description = "Supports for querying virtualPorts.")
33 +public class VirtualPortQueryCommand extends AbstractShellCommand {
34 +
35 + @Option(name = "-v", aliases = "--vPortId", description = "virtualPort ID.", required = false,
36 + multiValued = false)
37 + String vPortId;
38 +
39 + @Option(name = "-n", aliases = "--networkId", description = "network ID.", required = false,
40 + multiValued = false)
41 + String networkId;
42 +
43 + @Option(name = "-d", aliases = "--deviceId", description = "device ID.", required = false,
44 + multiValued = false)
45 + String deviceId;
46 +
47 + @Option(name = "-t", aliases = "--tenantId", description = "tenant ID.", required = false,
48 + multiValued = false)
49 + String tenantId;
50 +
51 + private static final String FMT = "virtualPortId=%s, networkId=%s, name=%s,"
52 + + " tenantId=%s, deviceId=%s, adminStateUp=%s, state=%s,"
53 + + " macAddress=%s, deviceOwner=%s, fixedIp=%s, bindingHostId=%s,"
54 + + " bindingvnicType=%s, bindingvifType=%s, bindingvnicDetails=%s,"
55 + + " allowedAddress=%s, securityGroups=%s";
56 +
57 + @Override
58 + protected void execute() {
59 + VirtualPortService service = get(VirtualPortService.class);
60 + if (vPortId != null && networkId == null && deviceId == null && tenantId == null) {
61 + VirtualPort port = service.getPort(VirtualPortId.portId(vPortId));
62 + printPort(port);
63 + } else if (vPortId == null && networkId != null && deviceId == null && tenantId == null) {
64 + Collection<VirtualPort> ports = service.getPorts(TenantNetworkId.networkId(networkId));
65 + printPorts(ports);
66 + } else if (vPortId == null && networkId == null && deviceId != null && tenantId == null) {
67 + Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(deviceId));
68 + printPorts(ports);
69 + } else if (vPortId == null && networkId == null && deviceId == null && tenantId != null) {
70 + Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(tenantId));
71 + printPorts(ports);
72 + } else if (vPortId == null && networkId == null && deviceId == null && tenantId == null) {
73 + Collection<VirtualPort> ports = service.getPorts();
74 + printPorts(ports);
75 + } else {
76 + print("cannot input more than one parameter");
77 + }
78 +
79 + }
80 +
81 + private void printPorts(Collection<VirtualPort> ports) {
82 + for (VirtualPort port : ports) {
83 + printPort(port);
84 + }
85 + }
86 +
87 + private void printPort(VirtualPort port) {
88 + print(FMT, port.portId(), port.networkId(), port.name(), port.tenantId(), port.deviceId(),
89 + port.adminStateUp(), port.state(), port.macAddress(), port.deviceOwner(), port
90 + .fixedIps(), port.bindingHostId(), port.bindingVnicType(),
91 + port.bindingVifType(), port.bindingVifDetails(), port.allowedAddressPairs(),
92 + port.securityGroups());
93 + }
94 +}
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.Set;
19 +
20 +import org.apache.karaf.shell.commands.Argument;
21 +import org.apache.karaf.shell.commands.Command;
22 +import org.onosproject.cli.AbstractShellCommand;
23 +import org.onosproject.vtnrsc.VirtualPortId;
24 +import org.onosproject.vtnrsc.virtualport.VirtualPortService;
25 +
26 +import com.google.common.collect.Sets;
27 +
28 +/**
29 + * Supports for removing a virtualPort.
30 + */
31 +@Command(scope = "onos", name = "virtualport-remove",
32 + description = "Supports for removing a virtualPort.")
33 +public class VirtualPortRemoveCommand extends AbstractShellCommand {
34 +
35 + @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
36 + multiValued = false)
37 + String id = null;
38 +
39 + @Override
40 + protected void execute() {
41 + VirtualPortService service = get(VirtualPortService.class);
42 + Set<VirtualPortId> virtualPorts = Sets.newHashSet(VirtualPortId.portId(id));
43 + service.removePorts(virtualPorts);
44 + }
45 +}
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.Collection;
19 +import java.util.Map;
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.onlab.packet.MacAddress;
26 +import org.onosproject.cli.AbstractShellCommand;
27 +import org.onosproject.net.DeviceId;
28 +import org.onosproject.vtnrsc.AllowedAddressPair;
29 +import org.onosproject.vtnrsc.BindingHostId;
30 +import org.onosproject.vtnrsc.DefaultVirtualPort;
31 +import org.onosproject.vtnrsc.FixedIp;
32 +import org.onosproject.vtnrsc.SecurityGroup;
33 +import org.onosproject.vtnrsc.TenantId;
34 +import org.onosproject.vtnrsc.TenantNetworkId;
35 +import org.onosproject.vtnrsc.VirtualPort;
36 +import org.onosproject.vtnrsc.VirtualPortId;
37 +import org.onosproject.vtnrsc.virtualport.VirtualPortService;
38 +
39 +import com.google.common.collect.Maps;
40 +import com.google.common.collect.Sets;
41 +
42 +/**
43 + * Supports for updating a virtualPort.
44 + */
45 +@Command(scope = "onos", name = "virtualport-update",
46 + description = "Supports for updating a virtualPort.")
47 +public class VirtualPortUpdateCommand extends AbstractShellCommand {
48 +
49 + @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
50 + multiValued = false)
51 + String id = null;
52 +
53 + @Argument(index = 1, name = "networkId", description = "network id.", required = true,
54 + multiValued = false)
55 + String networkId = null;
56 +
57 + @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
58 + multiValued = false)
59 + String name = null;
60 +
61 + @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
62 + multiValued = false)
63 + String tenantId = null;
64 +
65 + @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
66 + multiValued = false)
67 + String deviceId = null;
68 +
69 + @Option(name = "-a", aliases = "--adminStateUp",
70 + description = "administrative status of the virtualPort which is true or false.",
71 + required = false, multiValued = false)
72 + Boolean adminStateUp = false;
73 +
74 + @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
75 + multiValued = false)
76 + String state = null;
77 +
78 + @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
79 + multiValued = false)
80 + String macAddress = "";
81 +
82 + @Option(name = "-d", aliases = "--deviceOwner",
83 + description = "ID of the entity that uses this " + "virtualPort.", required = false,
84 + multiValued = false)
85 + String deviceOwner = null;
86 +
87 + @Option(name = "-f", aliases = "--fixedIp",
88 + description = "The IP address for the port,include the IP address "
89 + + "and subnet identity.", required = false, multiValued = false)
90 + FixedIp fixedIp = null;
91 +
92 + @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
93 + required = false, multiValued = false)
94 + String bindingHostId = "";
95 +
96 + @Option(name = "-t", aliases = "--bindingvnicType",
97 + description = "virtualPort bindingvnicType.", required = false, multiValued = false)
98 + String bindingvnicType = null;
99 +
100 + @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
101 + required = false, multiValued = false)
102 + String bindingvifType = null;
103 +
104 + @Option(name = "-b", aliases = "--bindingvnicDetails",
105 + description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
106 + String bindingvnicDetails = null;
107 +
108 + @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
109 + required = false, multiValued = false)
110 + Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
111 +
112 + @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
113 + required = false, multiValued = false)
114 + Collection<SecurityGroup> securityGroups = Sets.newHashSet();
115 +
116 + @Override
117 + protected void execute() {
118 + VirtualPortService service = get(VirtualPortService.class);
119 + Map<String, String> strMap = Maps.newHashMap();
120 + strMap.putIfAbsent("name", name);
121 + strMap.putIfAbsent("deviceOwner", deviceOwner);
122 + strMap.putIfAbsent("bindingvnicType", bindingvnicType);
123 + strMap.putIfAbsent("bindingvifType", bindingvifType);
124 + strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
125 + VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
126 + TenantNetworkId.networkId(networkId),
127 + false, strMap, VirtualPort.State.ACTIVE,
128 + MacAddress.valueOf(macAddress),
129 + TenantId.tenantId(tenantId),
130 + DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
131 + BindingHostId.bindingHostId(bindingHostId),
132 + allowedAddressPairs, securityGroups);
133 + Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
134 + service.updatePorts(virtualPorts);
135 + }
136 +}
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 +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 +
18 + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
19 + <command>
20 + <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkCreateCommand"/>
21 + </command>
22 + <command>
23 + <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkQueryCommand"/>
24 + </command>
25 + <command>
26 + <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkRemoveCommand"/>
27 + </command>
28 + <command>
29 + <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkUpdateCommand"/>
30 + </command>
31 + <command>
32 + <action class="org.onosproject.vtnrsc.cli.subnet.SubnetCreateCommand"/>
33 + </command>
34 + <command>
35 + <action class="org.onosproject.vtnrsc.cli.subnet.SubnetQueryCommand"/>
36 + </command>
37 + <command>
38 + <action class="org.onosproject.vtnrsc.cli.subnet.SubnetRemoveCommand"/>
39 + </command>
40 + <command>
41 + <action class="org.onosproject.vtnrsc.cli.subnet.SubnetUpdateCommand"/>
42 + </command>
43 + <command>
44 + <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortCreateCommand"/>
45 + </command>
46 + <command>
47 + <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortQueryCommand"/>
48 + </command>
49 + <command>
50 + <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortRemoveCommand"/>
51 + </command>
52 + <command>
53 + <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortUpdateCommand"/>
54 + </command>
55 + </command-bundle>
56 +</blueprint>