Parvathi M | ef74963 | 2016-07-07 13:30:43 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 22 | package org.onosproject.patchpanel.cli; |
| 23 | |
| 24 | import org.apache.karaf.shell.commands.Argument; |
| 25 | import org.apache.karaf.shell.commands.Command; |
| 26 | import org.onosproject.cli.AbstractShellCommand; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.patchpanel.impl.PatchPanelService; |
| 30 | |
Jonathan Hart | 382119e | 2016-09-02 13:14:49 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Command for adding a new patch. |
| 33 | */ |
Parvathi M | ef74963 | 2016-07-07 13:30:43 -0700 | [diff] [blame] | 34 | @Command(scope = "onos", name = "patch", |
| 35 | description = "Gets the 2 ports of one ConnectPoint that will be patched") |
Parvathi M | ef74963 | 2016-07-07 13:30:43 -0700 | [diff] [blame] | 36 | public 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 | } |