blob: e64a6fe702726048e093a80f95efea0c7784ae8e [file] [log] [blame]
Qianqian Hu61a6a402016-02-16 15:18:05 +08001/*
Brian O'Connor4e33be22017-08-03 22:45:46 -07002 * Copyright 2016-present Open Networking Foundation
Qianqian Hu61a6a402016-02-16 15:18:05 +08003 *
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 */
alshabib6d527452016-06-01 18:00:47 -070016package org.opencord.aaa;
Qianqian Hu61a6a402016-02-16 15:18:05 +080017
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010020import org.onosproject.net.AnnotationKeys;
21import org.onosproject.net.device.DeviceService;
22
23import org.opencord.sadis.SubscriberAndDeviceInformation;
24import org.opencord.sadis.SubscriberAndDeviceInformationService;
Qianqian Hu61a6a402016-02-16 15:18:05 +080025
26/**
27 * Shows the users in the aaa.
28 */
29@Command(scope = "onos", name = "aaa-users",
30 description = "Shows the aaa users")
31public 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 Ghosh6bf21a22017-08-23 12:45:09 +010041
42 DeviceService devService = AbstractShellCommand.get(DeviceService.class);
43 SubscriberAndDeviceInformationService subsService =
44 AbstractShellCommand.get(SubscriberAndDeviceInformationService.class);
45
Qianqian Hu61a6a402016-02-16 15:18:05 +080046 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. Bainbridge62019492017-07-28 17:02:10 -070050 String mac = stateMachine.supplicantAddress().toString();
Amit Ghosh6bf21a22017-08-23 12:45:09 +010051
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 Hu61a6a402016-02-16 15:18:05 +080063 }
64 }
65}