blob: 88d16341ae22e2fe31af6ffe2ad26fb549082b5c [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;
25import org.onosproject.cordvtn.DefaultOvsdbNode;
26import org.onosproject.cordvtn.OvsdbNode;
27import org.onosproject.net.DeviceId;
28
29import static com.google.common.base.Preconditions.checkArgument;
30
31/**
32 * Adds a new OVSDB nodes.
33 */
34@Command(scope = "onos", name = "ovsdb-add",
35 description = "Adds a new OVSDB node to cordvtn")
36public class OvsdbNodeAddCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "host", description = "Hostname or IP",
39 required = true, multiValued = false)
40 private String host = null;
41
42 @Argument(index = 1, name = "address",
43 description = "OVSDB server listening address (ip:port)",
44 required = true, multiValued = false)
45 private String address = null;
46
47 @Argument(index = 2, name = "bridgeId",
48 description = "Device ID of integration bridge",
49 required = true, multiValued = false)
50 private String bridgeId = null;
51
52 @Override
53 protected void execute() {
54 checkArgument(address.contains(":"), "address should be ip:port format");
55 checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format");
56
57 CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
58 String[] ipPort = address.split(":");
59 OvsdbNode ovsdb = new DefaultOvsdbNode(host,
60 IpAddress.valueOf(ipPort[0]),
61 TpPort.tpPort(Integer.parseInt(ipPort[1])),
62 DeviceId.deviceId(bridgeId));
63 service.addNode(ovsdb);
64 }
65}