blob: b857dc8d86e689394e61fa489f4f7f5c3f95f9c6 [file] [log] [blame]
Thomas Vachuskac40d4632015-04-09 16:55:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.ConnectPoint;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070022import org.onosproject.provider.nil.NullProviders;
23
24import static org.onosproject.cli.UpDownCompleter.DOWN;
25import static org.onosproject.cli.UpDownCompleter.UP;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070026
27/**
28 * Servers or repairs a simulated link.
29 */
30@Command(scope = "onos", name = "null-link",
31 description = "Severs or repairs a simulated link")
32public 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 Hartc3af35a2015-04-30 22:20:29 -070052 ConnectPoint onePoint = ConnectPoint.deviceConnectPoint(one);
Jonathan Hartc3af35a2015-04-30 22:20:29 -070053 ConnectPoint twoPoint = ConnectPoint.deviceConnectPoint(two);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070054
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}