Matteo Scandolo | ab34651 | 2020-04-17 13:39:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Foundation |
| 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 | package org.opencord.dhcpl2relay.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.Completion; |
| 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 24 | import org.onosproject.cli.net.PortNumberCompleter; |
| 25 | import org.onosproject.net.ConnectPoint; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.opencord.dhcpl2relay.DhcpL2RelayService; |
| 29 | |
| 30 | /** |
| 31 | * Remove all the DHCP allocations relayed by the dhcpl2relay. |
| 32 | */ |
| 33 | @Service |
| 34 | @Command(scope = "onos", name = "dhcpl2relay-remove-allocation", |
| 35 | description = "Remove the DHCP allocation relayed by the dhcpl2relay") |
| 36 | public class DhcpL2RelayRemoveAllocationsCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "deviceId", description = "Device ID", |
| 39 | required = true, multiValued = false) |
| 40 | @Completion(DeviceIdCompleter.class) |
| 41 | private String strDeviceId = null; |
| 42 | |
| 43 | @Argument(index = 1, name = "port", description = "Port number", |
| 44 | required = true, multiValued = false) |
| 45 | @Completion(PortNumberCompleter.class) |
| 46 | private String strPort = null; |
| 47 | |
| 48 | @Override |
| 49 | protected void doExecute() { |
| 50 | DhcpL2RelayService service = get(DhcpL2RelayService.class); |
| 51 | |
| 52 | DeviceId deviceId = DeviceId.deviceId(strDeviceId); |
| 53 | PortNumber port = PortNumber.portNumber(strPort); |
| 54 | ConnectPoint cp = new ConnectPoint(deviceId, port); |
| 55 | |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 56 | Boolean success = service.removeAllocationsByConnectPoint(cp); |
Matteo Scandolo | ab34651 | 2020-04-17 13:39:55 -0700 | [diff] [blame] | 57 | |
| 58 | if (success) { |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 59 | print("DHCP Allocation(s) removed for port %s on device %s", strPort, strDeviceId); |
Matteo Scandolo | ab34651 | 2020-04-17 13:39:55 -0700 | [diff] [blame] | 60 | } else { |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 61 | print("DHCP Allocation(s) not found for port %s on device %s", strPort, strDeviceId); |
Matteo Scandolo | ab34651 | 2020-04-17 13:39:55 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } |
| 65 | } |