blob: 712092361361ae722daee115aa0e2a9f33ce841a [file] [log] [blame]
Matteo Scandoloab346512020-04-17 13:39:55 -07001/*
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 */
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
56 Boolean success = service.removeAllocationByConnectPoint(cp);
57
58 if (success) {
59 print("DHCP Allocation removed for port %s on device %s", strPort, strDeviceId);
60 } else {
61 print("DHCP Allocation not found for port %s on device %s", strPort, strDeviceId);
62 }
63
64 }
65}