blob: 5b6221af37a94382c755a308cdc338e9d0ad6b76 [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
Jonathan Hart382119e2016-09-02 13:14:49 -070031/**
32 * Command for adding a new patch.
33 */
Parvathi Mef749632016-07-07 13:30:43 -070034@Command(scope = "onos", name = "patch",
35 description = "Gets the 2 ports of one ConnectPoint that will be patched")
Parvathi Mef749632016-07-07 13:30:43 -070036public class PatchPanelCommand extends AbstractShellCommand {
37 //the 2 arguments, both connect points
38 @Argument(index = 0, name = "switch/portNumber", description = "ConnectPoint and first port number",
39 required = true, multiValued = false)
40 String port1 = null;
41 @Argument (index = 1, name = "switch/portNumber2", description = "ConnectPoint and second port number",
42 required = true, multiValued = false)
43 String port2 = null;
44
45 private ConnectPoint cp1, cp2;
46 private PatchPanelService patchPanelService;
47 private DeviceId deviceId, deviceId2;
48
49 /**
50 * This method creates an instance of the Service class and then uses the user
51 * input to call the addPatch method in PatchPanel. It also
52 * @throws IllegalArgumentException if the 2 connectpoints are of different devices
53 */
54 @Override
55 protected void execute() {
56 patchPanelService = get(PatchPanelService.class);
57 boolean done = false;
58 cp1 = ConnectPoint.deviceConnectPoint(port1);
59 cp2 = ConnectPoint.deviceConnectPoint(port2);
60 deviceId = cp1.deviceId();
61 deviceId2 = cp2.deviceId();
62 if (!(deviceId.equals(deviceId2))) {
63 throw new IllegalArgumentException("ERROR: Two Different Device Id's");
64 } else {
65 done = patchPanelService.addPatch(cp1, cp2);
66 }
67 if (done) {
68 log.info("This patch has been created");
69 } else {
70 log.info("This patch was NOT created");
71 }
72
73 }
74
75}