blob: 744cb87538d6a95e3304d6ba4906c5713a81d123 [file] [log] [blame]
Matteo Scandoloab346512020-04-17 13:39:55 -07001/*
Joey Armstrong7e08d2a2022-12-30 12:25:42 -05002 * Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandoloab346512020-04-17 13:39:55 -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.opencord.dhcpl2relay.cli;
17
18import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.Completion;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.cli.net.DeviceIdCompleter;
24import org.onosproject.cli.net.PortNumberCompleter;
25import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.PortNumber;
28import 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")
36public 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 Scandolo64bba8c2020-08-19 11:50:33 -070056 Boolean success = service.removeAllocationsByConnectPoint(cp);
Matteo Scandoloab346512020-04-17 13:39:55 -070057
58 if (success) {
Matteo Scandolo64bba8c2020-08-19 11:50:33 -070059 print("DHCP Allocation(s) removed for port %s on device %s", strPort, strDeviceId);
Matteo Scandoloab346512020-04-17 13:39:55 -070060 } else {
Matteo Scandolo64bba8c2020-08-19 11:50:33 -070061 print("DHCP Allocation(s) not found for port %s on device %s", strPort, strDeviceId);
Matteo Scandoloab346512020-04-17 13:39:55 -070062 }
63
64 }
65}