blob: f05dd8aabc07d7338775ab0ecb2af89b27ff2abe [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();
Amit Ghosh3f8ee432017-09-21 15:49:37 +010049
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 Ghosh6bf21a22017-08-23 12:45:09 +010058
59 String nasPortId = devService.getPort(stateMachine.supplicantConnectpoint()).
60 annotations().value(AnnotationKeys.PORT_NAME);
61
Amit Ghosh3f8ee432017-09-21 15:49:37 +010062 String subsId = "UNKNOWN";
Amit Ghosh6bf21a22017-08-23 12:45:09 +010063 SubscriberAndDeviceInformation subscriber = subsService.get(nasPortId);
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 Hu61a6a402016-02-16 15:18:05 +080070 }
71 }
72}