Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [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 | */ |
Carmelo Cascone | de1e6e3 | 2019-07-15 19:39:08 -0700 | [diff] [blame] | 16 | package org.opencord.dhcpl2relay.cli; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 17 | |
Carmelo Cascone | de1e6e3 | 2019-07-15 19:39:08 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractShellCommand; |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 21 | import org.opencord.dhcpl2relay.DhcpL2RelayService; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Shows the Successful DHCP allocations relayed by the dhcpl2relay. |
| 25 | */ |
Carmelo Cascone | de1e6e3 | 2019-07-15 19:39:08 -0700 | [diff] [blame] | 26 | @Service |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 27 | @Command(scope = "onos", name = "dhcpl2relay-allocations", |
| 28 | description = "Shows the Successful DHCP allocations relayed by the dhcpl2relay") |
| 29 | public class DhcpL2RelayAllocationsCommand extends AbstractShellCommand { |
| 30 | @Override |
Carmelo Cascone | de1e6e3 | 2019-07-15 19:39:08 -0700 | [diff] [blame] | 31 | protected void doExecute() { |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 32 | DhcpL2RelayService service = get(DhcpL2RelayService.class); |
| 33 | |
| 34 | service.getAllocationInfo().forEach((key, value) -> { |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 35 | print("SubscriberId=%s,ConnectPoint=%s,State=%s,MAC=%s,CircuitId=%s" + |
| 36 | ",IP Allocated=%s,Allocation Timestamp=%s", |
| 37 | key, value.location(), value.type(), value.macAddress().toString(), value.circuitId(), |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 38 | value.ipAddress().getIp4Address().toString(), value.allocationTime().toString()); |
| 39 | }); |
| 40 | } |
| 41 | } |