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 | */ |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 16 | package org.opencord.aaa.impl; |
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 | |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 23 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 24 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
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); |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 43 | SadisService sadisService = |
| 44 | AbstractShellCommand.get(SadisService.class); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 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(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 49 | |
| 50 | String username = "UNKNOWN"; |
| 51 | if (stateMachine.username() != null) { |
| 52 | username = new String(stateMachine.username()); |
| 53 | } |
| 54 | String mac = "UNKNOWN"; |
| 55 | if (stateMachine.supplicantAddress() != null) { |
| 56 | mac = stateMachine.supplicantAddress().toString(); |
| 57 | } |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 58 | |
| 59 | String nasPortId = devService.getPort(stateMachine.supplicantConnectpoint()). |
| 60 | annotations().value(AnnotationKeys.PORT_NAME); |
| 61 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 62 | String subsId = "UNKNOWN"; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 63 | SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 64 | if (subscriber != null) { |
| 65 | subsId = subscriber.nasPortId(); |
| 66 | } |
| 67 | |
| 68 | print("UserName=%s,CurrentState=%s,DeviceId=%s,MAC=%s,PortNumber=%s,SubscriberId=%s", |
| 69 | username, state[stateMachine.state()], deviceId, mac, portNum, subsId); |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |