blob: 276c3164f255a52510ad11362ec99c1a57a760b4 [file] [log] [blame]
Simon Hunt439d6d82017-10-31 14:55:09 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.opencord.aaa.cli;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.net.AnnotationKeys;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.Port;
23import org.onosproject.net.device.DeviceService;
24import org.opencord.aaa.api.AaaService;
25import org.opencord.aaa.api.AaaSession;
26import org.opencord.sadis.SubscriberAndDeviceInformation;
27import org.opencord.sadis.SubscriberAndDeviceInformationService;
28
29import java.util.ArrayList;
30import java.util.List;
31
32/**
33 * Shows the users in the aaa.
34 */
35@Command(scope = "onos", name = "aaa-users",
36 description = "Displays the users with current AAA sessions")
37public class AaaShowUsersCommand extends AbstractShellCommand {
38
39 private static final String UNKNOWN = "UNKNOWN";
40
41 @Override
42 protected void execute() {
43 DeviceService devService = get(DeviceService.class);
44 SubscriberAndDeviceInformationService subsService =
45 get(SubscriberAndDeviceInformationService.class);
46 AaaService aaaService = get(AaaService.class);
47
48// TODO: add currentSessions() to AaaService API
49// List<AaaSession> sessionList = aaaService.currentSessions();
50 List<AaaSession> sessionList = new ArrayList<>();
51
52 for (AaaSession s : sessionList) {
53 String subsId = getSubscriberId(devService, subsService, s.getConnectPoint());
54 print("UserName=%s,CurrentState=%s,DeviceId=%s,MAC=%s,PortNumber=%s,SubscriberId=%s",
55 s.username(), s.state(), s.deviceId(), s.macAddress(), s.portNumber(), subsId);
56 }
57 }
58
59 private String getSubscriberId(DeviceService devService,
60 SubscriberAndDeviceInformationService sadis,
61 ConnectPoint cp) {
62 Port p = devService.getPort(cp);
63 String nasPortId = p.annotations().value(AnnotationKeys.PORT_NAME);
64 SubscriberAndDeviceInformation subscriber = sadis.get(nasPortId);
65 return (subscriber == null) ? UNKNOWN : subscriber.nasPortId();
66 }
67}