blob: bac3221f5ad7f31932ff5d87fb53aa04aa3f030c [file] [log] [blame]
Parvathi Mef749632016-07-07 13:30:43 -07001/*
2 * Copyright 2016-present 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
17/**
18 * This class defines the cli command for the PatchPanel class. It creates
19 * an instance of the PatchPanelService class to call it's method addPatch().
20 * The command takes 2 parameters, 2 connectPoints.
21 */
22package org.onosproject.patchpanel.cli;
23
24import org.apache.karaf.shell.commands.Argument;
25import org.apache.karaf.shell.commands.Command;
26import org.onosproject.cli.AbstractShellCommand;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.DeviceId;
29import org.onosproject.patchpanel.impl.PatchPanelService;
30
31//name of command and description
32@Command(scope = "onos", name = "patch",
33 description = "Gets the 2 ports of one ConnectPoint that will be patched")
34
35public class PatchPanelCommand extends AbstractShellCommand {
36 //the 2 arguments, both connect points
37 @Argument(index = 0, name = "switch/portNumber", description = "ConnectPoint and first port number",
38 required = true, multiValued = false)
39 String port1 = null;
40 @Argument (index = 1, name = "switch/portNumber2", description = "ConnectPoint and second port number",
41 required = true, multiValued = false)
42 String port2 = null;
43
44 private ConnectPoint cp1, cp2;
45 private PatchPanelService patchPanelService;
46 private DeviceId deviceId, deviceId2;
47
48 /**
49 * This method creates an instance of the Service class and then uses the user
50 * input to call the addPatch method in PatchPanel. It also
51 * @throws IllegalArgumentException if the 2 connectpoints are of different devices
52 */
53 @Override
54 protected void execute() {
55 patchPanelService = get(PatchPanelService.class);
56 boolean done = false;
57 cp1 = ConnectPoint.deviceConnectPoint(port1);
58 cp2 = ConnectPoint.deviceConnectPoint(port2);
59 deviceId = cp1.deviceId();
60 deviceId2 = cp2.deviceId();
61 if (!(deviceId.equals(deviceId2))) {
62 throw new IllegalArgumentException("ERROR: Two Different Device Id's");
63 } else {
64 done = patchPanelService.addPatch(cp1, cp2);
65 }
66 if (done) {
67 log.info("This patch has been created");
68 } else {
69 log.info("This patch was NOT created");
70 }
71
72 }
73
74}