blob: 4fd9b0dfff0037e0241ff271e3c396bef7ee78b2 [file] [log] [blame]
Jonathan Hart0bdf8372015-10-08 14:30:36 -07001/*
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
17package org.onosproject.cli.net;
18
19import com.google.common.collect.Sets;
20import org.apache.karaf.shell.commands.Command;
21import org.apache.karaf.shell.commands.Option;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.VlanId;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.incubator.net.intf.Interface;
26import org.onosproject.incubator.net.intf.InterfaceAdminService;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.host.InterfaceIpAddress;
29
30import java.util.Set;
31
32/**
33 * Adds a new interface configuration.
34 */
35@Command(scope = "onos", name = "add-interface",
36 description = "Adds a new configured interface")
37public class InterfaceAddCommand extends AbstractShellCommand {
38
39 @Option(name = "-c", aliases = "--connectPoint",
40 description = "Device port that the interface is associated with",
41 required = true, multiValued = false)
42 private String connectPoint = null;
43
44 @Option(name = "-m", aliases = "--mac",
45 description = "MAC address of the interface",
Luca Pretee3879f72015-10-16 11:19:53 +020046 required = false, multiValued = false)
Jonathan Hart0bdf8372015-10-08 14:30:36 -070047 private String mac = null;
48
49 @Option(name = "-i", aliases = "--ip",
50 description = "IP address configured on the interface\n" +
51 "(e.g. 10.0.1.1/24). Can be specified multiple times.",
52 required = false, multiValued = true)
53 private String[] ips = null;
54
55 @Option(name = "-v", aliases = "--vlan",
56 description = "VLAN configured on the interface",
57 required = false, multiValued = false)
58 private String vlan = null;
59
60 @Override
61 protected void execute() {
62 InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
63
64 Set<InterfaceIpAddress> ipAddresses = Sets.newHashSet();
65 if (ips != null) {
66 for (String strIp : ips) {
67 ipAddresses.add(InterfaceIpAddress.valueOf(strIp));
68 }
69 }
70
Luca Pretee3879f72015-10-16 11:19:53 +020071 MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac);
72
Jonathan Hart0bdf8372015-10-08 14:30:36 -070073 VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan));
74
75 Interface intf = new Interface(ConnectPoint.deviceConnectPoint(connectPoint),
Luca Pretee3879f72015-10-16 11:19:53 +020076 ipAddresses, macAddr, vlanId);
Jonathan Hart0bdf8372015-10-08 14:30:36 -070077
78 interfaceService.add(intf);
79 }
80
81}