blob: 5448ef148126f9d907d22e9520679e2094554be5 [file] [log] [blame]
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -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.cordvtn.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onlab.packet.IpAddress;
22import org.onlab.packet.TpPort;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.cordvtn.CordVtnService;
Hyunsun Moon8539b042015-11-07 22:08:43 -080025import org.onosproject.cordvtn.CordVtnNode;
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070026import org.onosproject.net.DeviceId;
27
28import static com.google.common.base.Preconditions.checkArgument;
29
30/**
Hyunsun Moon8539b042015-11-07 22:08:43 -080031 * Adds a new node to the service.
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070032 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080033@Command(scope = "onos", name = "cordvtn-node-add",
34 description = "Adds a new node to CORD VTN service")
35public class CordVtnNodeAddCommand extends AbstractShellCommand {
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070036
Hyunsun Moon8539b042015-11-07 22:08:43 -080037 @Argument(index = 0, name = "hostname", description = "Hostname",
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070038 required = true, multiValued = false)
Hyunsun Moon8539b042015-11-07 22:08:43 -080039 private String hostname = null;
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070040
Hyunsun Moon8539b042015-11-07 22:08:43 -080041 @Argument(index = 1, name = "ovsdb",
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070042 description = "OVSDB server listening address (ip:port)",
43 required = true, multiValued = false)
Hyunsun Moon8539b042015-11-07 22:08:43 -080044 private String ovsdb = null;
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070045
46 @Argument(index = 2, name = "bridgeId",
47 description = "Device ID of integration bridge",
48 required = true, multiValued = false)
49 private String bridgeId = null;
50
Hyunsun Moonb219fc42016-01-14 03:42:47 -080051 @Argument(index = 3, name = "phyPortName",
52 description = "Physical port name",
53 required = true, multiValued = false)
54 private String phyPortName = null;
55
56 @Argument(index = 4, name = "localIp",
57 description = "Local data plane IP address",
58 required = true, multiValued = false)
59 private String localIp = null;
60
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070061 @Override
62 protected void execute() {
Hyunsun Moon8539b042015-11-07 22:08:43 -080063 checkArgument(ovsdb.contains(":"), "OVSDB address should be ip:port format");
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070064 checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format");
65
66 CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
Hyunsun Moon8539b042015-11-07 22:08:43 -080067 String[] ipPort = ovsdb.split(":");
68 CordVtnNode node = new CordVtnNode(hostname,
69 IpAddress.valueOf(ipPort[0]),
70 TpPort.tpPort(Integer.parseInt(ipPort[1])),
Hyunsun Moonb219fc42016-01-14 03:42:47 -080071 DeviceId.deviceId(bridgeId),
72 phyPortName,
73 IpAddress.valueOf(localIp));
Hyunsun Moon8539b042015-11-07 22:08:43 -080074 service.addNode(node);
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070075 }
76}