blob: 112d70b861c57c6a5de449d002ed344832b148dd [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 */
Carmelo Cascone58b53292019-09-30 12:35:31 -070016package org.opencord.aaa.cli;
Qianqian Hu61a6a402016-02-16 15:18:05 +080017
Carmelo Cascone58b53292019-09-30 12:35:31 -070018import org.apache.karaf.shell.api.action.Command;
19import org.apache.karaf.shell.api.action.lifecycle.Service;
Qianqian Hu61a6a402016-02-16 15:18:05 +080020import org.onosproject.cli.AbstractShellCommand;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010021import org.onosproject.net.AnnotationKeys;
22import org.onosproject.net.device.DeviceService;
Carmelo Cascone58b53292019-09-30 12:35:31 -070023import org.opencord.aaa.impl.StateMachine;
Gamze Abaka1cfdb192018-10-25 11:39:19 +000024import org.opencord.sadis.SadisService;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010025import org.opencord.sadis.SubscriberAndDeviceInformation;
Qianqian Hu61a6a402016-02-16 15:18:05 +080026
27/**
28 * Shows the users in the aaa.
29 */
Carmelo Cascone58b53292019-09-30 12:35:31 -070030@Service
Qianqian Hu61a6a402016-02-16 15:18:05 +080031@Command(scope = "onos", name = "aaa-users",
32 description = "Shows the aaa users")
33public class AaaShowUsersCommand extends AbstractShellCommand {
34 @Override
Carmelo Cascone58b53292019-09-30 12:35:31 -070035 protected void doExecute() {
Qianqian Hu61a6a402016-02-16 15:18:05 +080036 String[] state = {
37 "IDLE",
38 "STARTED",
39 "PENDING",
40 "AUTHORIZED",
41 "UNAUTHORIZED"
42 };
Amit Ghosh6bf21a22017-08-23 12:45:09 +010043
44 DeviceService devService = AbstractShellCommand.get(DeviceService.class);
Gamze Abaka1cfdb192018-10-25 11:39:19 +000045 SadisService sadisService =
46 AbstractShellCommand.get(SadisService.class);
Amit Ghosh6bf21a22017-08-23 12:45:09 +010047
Qianqian Hu61a6a402016-02-16 15:18:05 +080048 for (StateMachine stateMachine : StateMachine.sessionIdMap().values()) {
49 String deviceId = stateMachine.supplicantConnectpoint().deviceId().toString();
50 String portNum = stateMachine.supplicantConnectpoint().port().toString();
Amit Ghoshf739be52017-09-21 15:49:37 +010051
52 String username = "UNKNOWN";
53 if (stateMachine.username() != null) {
54 username = new String(stateMachine.username());
55 }
56 String mac = "UNKNOWN";
57 if (stateMachine.supplicantAddress() != null) {
58 mac = stateMachine.supplicantAddress().toString();
59 }
Amit Ghosh6bf21a22017-08-23 12:45:09 +010060
61 String nasPortId = devService.getPort(stateMachine.supplicantConnectpoint()).
62 annotations().value(AnnotationKeys.PORT_NAME);
63
Amit Ghoshf739be52017-09-21 15:49:37 +010064 String subsId = "UNKNOWN";
Gamze Abaka1cfdb192018-10-25 11:39:19 +000065 SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId);
Amit Ghosh6bf21a22017-08-23 12:45:09 +010066 if (subscriber != null) {
67 subsId = subscriber.nasPortId();
68 }
69
70 print("UserName=%s,CurrentState=%s,DeviceId=%s,MAC=%s,PortNumber=%s,SubscriberId=%s",
71 username, state[stateMachine.state()], deviceId, mac, portNum, subsId);
Qianqian Hu61a6a402016-02-16 15:18:05 +080072 }
73 }
74}