Hyunsun Moon | 4f02b3a | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.cordvtn.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.TpPort; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.cordvtn.CordVtnService; |
| 25 | import org.onosproject.cordvtn.DefaultOvsdbNode; |
| 26 | import org.onosproject.cordvtn.OvsdbNode; |
| 27 | import org.onosproject.net.DeviceId; |
| 28 | |
| 29 | import 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") |
| 36 | public 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 | } |