Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 4e33be2 | 2017-08-03 22:45:46 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 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 | */ |
alshabib | 6d52745 | 2016-06-01 18:00:47 -0700 | [diff] [blame] | 16 | package org.opencord.aaa; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 17 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
| 19 | import org.onosproject.cli.AbstractShellCommand; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame^] | 20 | import org.onosproject.net.AnnotationKeys; |
| 21 | import org.onosproject.net.device.DeviceService; |
| 22 | |
| 23 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 24 | import org.opencord.sadis.SubscriberAndDeviceInformationService; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Shows the users in the aaa. |
| 28 | */ |
| 29 | @Command(scope = "onos", name = "aaa-users", |
| 30 | description = "Shows the aaa users") |
| 31 | public class AaaShowUsersCommand extends AbstractShellCommand { |
| 32 | @Override |
| 33 | protected void execute() { |
| 34 | String[] state = { |
| 35 | "IDLE", |
| 36 | "STARTED", |
| 37 | "PENDING", |
| 38 | "AUTHORIZED", |
| 39 | "UNAUTHORIZED" |
| 40 | }; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame^] | 41 | |
| 42 | DeviceService devService = AbstractShellCommand.get(DeviceService.class); |
| 43 | SubscriberAndDeviceInformationService subsService = |
| 44 | AbstractShellCommand.get(SubscriberAndDeviceInformationService.class); |
| 45 | |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 46 | for (StateMachine stateMachine : StateMachine.sessionIdMap().values()) { |
| 47 | String deviceId = stateMachine.supplicantConnectpoint().deviceId().toString(); |
| 48 | String portNum = stateMachine.supplicantConnectpoint().port().toString(); |
| 49 | String username = new String(stateMachine.username()); |
David K. Bainbridge | 6201949 | 2017-07-28 17:02:10 -0700 | [diff] [blame] | 50 | String mac = stateMachine.supplicantAddress().toString(); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame^] | 51 | |
| 52 | String nasPortId = devService.getPort(stateMachine.supplicantConnectpoint()). |
| 53 | annotations().value(AnnotationKeys.PORT_NAME); |
| 54 | |
| 55 | String subsId = "Unknown"; |
| 56 | SubscriberAndDeviceInformation subscriber = subsService.get(nasPortId); |
| 57 | if (subscriber != null) { |
| 58 | subsId = subscriber.nasPortId(); |
| 59 | } |
| 60 | |
| 61 | print("UserName=%s,CurrentState=%s,DeviceId=%s,MAC=%s,PortNumber=%s,SubscriberId=%s", |
| 62 | username, state[stateMachine.state()], deviceId, mac, portNum, subsId); |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |