blob: 263bf5a7df0d08bfebe740fd4a1c322b5feb0815 [file] [log] [blame]
Thomas Vachuskac40d4632015-04-09 16:55:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskac40d4632015-04-09 16:55:03 -07003 *
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 */
16package org.onosproject.provider.nil.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.ConnectPoint;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070023import org.onosproject.provider.nil.NullProviders;
24
25import static org.onosproject.cli.UpDownCompleter.DOWN;
26import static org.onosproject.cli.UpDownCompleter.UP;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070027
28/**
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020029 * Severs or repairs a simulated link.
Thomas Vachuskac40d4632015-04-09 16:55:03 -070030 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070031@Service
Thomas Vachuskac40d4632015-04-09 16:55:03 -070032@Command(scope = "onos", name = "null-link",
33 description = "Severs or repairs a simulated link")
34public class NullLinkCommand extends AbstractShellCommand {
35
36 @Argument(index = 0, name = "one", description = "One link end-point as device/port",
37 required = true, multiValued = false)
38 String one = null;
39
40 @Argument(index = 1, name = "two", description = "Another link end-point as device/port",
41 required = true, multiValued = false)
42 String two = null;
43
44 @Argument(index = 2, name = "cmd", description = "up/down",
45 required = true, multiValued = false)
46 String cmd = null;
47
48
49 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070050 protected void doExecute() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -070051 NullProviders service = get(NullProviders.class);
52
53 try {
Jonathan Hartc3af35a2015-04-30 22:20:29 -070054 ConnectPoint onePoint = ConnectPoint.deviceConnectPoint(one);
Jonathan Hartc3af35a2015-04-30 22:20:29 -070055 ConnectPoint twoPoint = ConnectPoint.deviceConnectPoint(two);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070056
57 if (cmd.equals(UP)) {
58 service.repairLink(onePoint, twoPoint);
59 } else if (cmd.equals(DOWN)) {
60 service.severLink(onePoint, twoPoint);
61 } else {
62 error("Illegal command %s; must be up or down", cmd);
63 }
64 } catch (NumberFormatException e) {
65 error("Invalid port number specified", e);
66 }
67 }
68
69}