Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 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; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 22 | import org.onosproject.provider.nil.NullProviders; |
| 23 | |
| 24 | import static org.onosproject.cli.UpDownCompleter.DOWN; |
| 25 | import static org.onosproject.cli.UpDownCompleter.UP; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 28 | * Severs or repairs a simulated link. |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 29 | */ |
| 30 | @Command(scope = "onos", name = "null-link", |
| 31 | description = "Severs or repairs a simulated link") |
| 32 | public class NullLinkCommand extends AbstractShellCommand { |
| 33 | |
| 34 | @Argument(index = 0, name = "one", description = "One link end-point as device/port", |
| 35 | required = true, multiValued = false) |
| 36 | String one = null; |
| 37 | |
| 38 | @Argument(index = 1, name = "two", description = "Another link end-point as device/port", |
| 39 | required = true, multiValued = false) |
| 40 | String two = null; |
| 41 | |
| 42 | @Argument(index = 2, name = "cmd", description = "up/down", |
| 43 | required = true, multiValued = false) |
| 44 | String cmd = null; |
| 45 | |
| 46 | |
| 47 | @Override |
| 48 | protected void execute() { |
| 49 | NullProviders service = get(NullProviders.class); |
| 50 | |
| 51 | try { |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 52 | ConnectPoint onePoint = ConnectPoint.deviceConnectPoint(one); |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 53 | ConnectPoint twoPoint = ConnectPoint.deviceConnectPoint(two); |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 54 | |
| 55 | if (cmd.equals(UP)) { |
| 56 | service.repairLink(onePoint, twoPoint); |
| 57 | } else if (cmd.equals(DOWN)) { |
| 58 | service.severLink(onePoint, twoPoint); |
| 59 | } else { |
| 60 | error("Illegal command %s; must be up or down", cmd); |
| 61 | } |
| 62 | } catch (NumberFormatException e) { |
| 63 | error("Invalid port number specified", e); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | } |