blob: 1b7d986668a4f95f7ff1b765971b86ac9e90788b [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
51 @Override
52 protected void execute() {
Hyunsun Moon8539b042015-11-07 22:08:43 -080053 checkArgument(ovsdb.contains(":"), "OVSDB address should be ip:port format");
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070054 checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format");
55
56 CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
Hyunsun Moon8539b042015-11-07 22:08:43 -080057 String[] ipPort = ovsdb.split(":");
58 CordVtnNode node = new CordVtnNode(hostname,
59 IpAddress.valueOf(ipPort[0]),
60 TpPort.tpPort(Integer.parseInt(ipPort[1])),
61 DeviceId.deviceId(bridgeId));
62 service.addNode(node);
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070063 }
64}