Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -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 | package org.onosproject.provider.nil.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.provider.nil.NullProviders; |
| 25 | |
| 26 | import static org.onosproject.cli.UpDownCompleter.DOWN; |
| 27 | import static org.onosproject.cli.UpDownCompleter.UP; |
| 28 | import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId; |
| 29 | import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber; |
| 30 | import static org.onosproject.net.DeviceId.deviceId; |
| 31 | import static org.onosproject.net.PortNumber.portNumber; |
| 32 | |
| 33 | /** |
| 34 | * Servers or repairs a simulated link. |
| 35 | */ |
| 36 | @Command(scope = "onos", name = "null-link", |
| 37 | description = "Severs or repairs a simulated link") |
| 38 | public class NullLinkCommand extends AbstractShellCommand { |
| 39 | |
| 40 | @Argument(index = 0, name = "one", description = "One link end-point as device/port", |
| 41 | required = true, multiValued = false) |
| 42 | String one = null; |
| 43 | |
| 44 | @Argument(index = 1, name = "two", description = "Another link end-point as device/port", |
| 45 | required = true, multiValued = false) |
| 46 | String two = null; |
| 47 | |
| 48 | @Argument(index = 2, name = "cmd", description = "up/down", |
| 49 | required = true, multiValued = false) |
| 50 | String cmd = null; |
| 51 | |
| 52 | |
| 53 | @Override |
| 54 | protected void execute() { |
| 55 | NullProviders service = get(NullProviders.class); |
| 56 | |
| 57 | try { |
| 58 | DeviceId oneId = deviceId(getDeviceId(one)); |
| 59 | PortNumber onePort = portNumber(getPortNumber(one)); |
| 60 | ConnectPoint onePoint = new ConnectPoint(oneId, onePort); |
| 61 | |
| 62 | DeviceId twoId = deviceId(getDeviceId(two)); |
| 63 | PortNumber twoPort = portNumber(getPortNumber(two)); |
| 64 | ConnectPoint twoPoint = new ConnectPoint(twoId, twoPort); |
| 65 | |
| 66 | if (cmd.equals(UP)) { |
| 67 | service.repairLink(onePoint, twoPoint); |
| 68 | } else if (cmd.equals(DOWN)) { |
| 69 | service.severLink(onePoint, twoPoint); |
| 70 | } else { |
| 71 | error("Illegal command %s; must be up or down", cmd); |
| 72 | } |
| 73 | } catch (NumberFormatException e) { |
| 74 | error("Invalid port number specified", e); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | } |