blob: 2a32cdf2901317794e808df04648568c63c5bc62 [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 Milkeyd5435182018-10-11 16:18:51 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070022import org.onosproject.cli.AbstractShellCommand;
Ray Milkeyd5435182018-10-11 16:18:51 -070023import org.onosproject.cli.UpDownCompleter;
24import org.onosproject.cli.net.LinkDstCompleter;
25import org.onosproject.cli.net.LinkSrcCompleter;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070026import org.onosproject.net.ConnectPoint;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070027import org.onosproject.provider.nil.NullProviders;
28
29import static org.onosproject.cli.UpDownCompleter.DOWN;
30import static org.onosproject.cli.UpDownCompleter.UP;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070031
32/**
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020033 * Severs or repairs a simulated link.
Thomas Vachuskac40d4632015-04-09 16:55:03 -070034 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070035@Service
Thomas Vachuskac40d4632015-04-09 16:55:03 -070036@Command(scope = "onos", name = "null-link",
37 description = "Severs or repairs a simulated link")
38public class NullLinkCommand extends AbstractShellCommand {
39
40 @Argument(index = 0, name = "one", description = "One link end-point as device/port",
41 required = true, multiValued = false)
Ray Milkeyd5435182018-10-11 16:18:51 -070042 @Completion(LinkSrcCompleter.class)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070043 String one = null;
44
45 @Argument(index = 1, name = "two", description = "Another link end-point as device/port",
46 required = true, multiValued = false)
Ray Milkeyd5435182018-10-11 16:18:51 -070047 @Completion(LinkDstCompleter.class)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070048 String two = null;
49
50 @Argument(index = 2, name = "cmd", description = "up/down",
51 required = true, multiValued = false)
Ray Milkeyd5435182018-10-11 16:18:51 -070052 @Completion(UpDownCompleter.class)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070053 String cmd = null;
54
55
56 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070057 protected void doExecute() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -070058 NullProviders service = get(NullProviders.class);
59
60 try {
Jonathan Hartc3af35a2015-04-30 22:20:29 -070061 ConnectPoint onePoint = ConnectPoint.deviceConnectPoint(one);
Jonathan Hartc3af35a2015-04-30 22:20:29 -070062 ConnectPoint twoPoint = ConnectPoint.deviceConnectPoint(two);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070063
64 if (cmd.equals(UP)) {
65 service.repairLink(onePoint, twoPoint);
66 } else if (cmd.equals(DOWN)) {
67 service.severLink(onePoint, twoPoint);
68 } else {
69 error("Illegal command %s; must be up or down", cmd);
70 }
71 } catch (NumberFormatException e) {
72 error("Invalid port number specified", e);
73 }
74 }
75
76}