Search in sources :

Example 1 with SadisService

use of org.opencord.sadis.SadisService in project aaa by opencord.

the class AaaShowUsersCommand method doExecute.

@Override
protected void doExecute() {
    final Comparator<AuthenticationRecord> authenticationRecordComparator = (a1, a2) -> Comparators.CONNECT_POINT_COMPARATOR.compare(a1.supplicantConnectPoint(), a2.supplicantConnectPoint());
    DeviceService devService = get(DeviceService.class);
    SadisService sadisService = get(SadisService.class);
    AuthenticationService authService = get(AuthenticationService.class);
    List<AuthenticationRecord> authentications = newArrayList(authService.getAuthenticationRecords());
    authentications.sort(authenticationRecordComparator);
    if (strDeviceId != null && !strDeviceId.isEmpty()) {
        DeviceId deviceId = DeviceId.deviceId(strDeviceId);
        authentications = authentications.stream().filter(a -> a.supplicantConnectPoint().deviceId().equals(deviceId)).collect(Collectors.toList());
    }
    for (AuthenticationRecord auth : authentications) {
        String username = UNKNOWN;
        if (auth.username() != null) {
            username = new String(auth.username());
        }
        String mac = UNKNOWN;
        if (auth.supplicantAddress() != null) {
            mac = auth.supplicantAddress().toString();
        }
        Port port = devService.getPort(auth.supplicantConnectPoint());
        String nasPortId = UNKNOWN;
        if (port != null) {
            nasPortId = devService.getPort(auth.supplicantConnectPoint()).annotations().value(AnnotationKeys.PORT_NAME);
        }
        String subsId = UNKNOWN;
        SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId);
        if (subscriber != null) {
            subsId = subscriber.nasPortId();
        }
        print("%s: %s, last-changed=%s, mac=%s, subid=%s, username=%s", auth.supplicantConnectPoint(), auth.state(), Tools.timeAgo(auth.lastChanged()), mac, subsId, username);
    }
}
Also used : Comparators(org.onosproject.utils.Comparators) AuthenticationService(org.opencord.aaa.AuthenticationService) Tools(org.onlab.util.Tools) AuthenticationRecord(org.opencord.aaa.AuthenticationRecord) DeviceService(org.onosproject.net.device.DeviceService) SubscriberAndDeviceInformation(org.opencord.sadis.SubscriberAndDeviceInformation) Argument(org.apache.karaf.shell.api.action.Argument) AnnotationKeys(org.onosproject.net.AnnotationKeys) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SadisService(org.opencord.sadis.SadisService) Port(org.onosproject.net.Port) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) DeviceId(org.onosproject.net.DeviceId) Comparator(java.util.Comparator) DeviceIdCompleter(org.onosproject.cli.net.DeviceIdCompleter) SadisService(org.opencord.sadis.SadisService) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) SubscriberAndDeviceInformation(org.opencord.sadis.SubscriberAndDeviceInformation) AuthenticationRecord(org.opencord.aaa.AuthenticationRecord) AuthenticationService(org.opencord.aaa.AuthenticationService)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Completion (org.apache.karaf.shell.api.action.Completion)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 Tools (org.onlab.util.Tools)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 DeviceIdCompleter (org.onosproject.cli.net.DeviceIdCompleter)1 AnnotationKeys (org.onosproject.net.AnnotationKeys)1 DeviceId (org.onosproject.net.DeviceId)1 Port (org.onosproject.net.Port)1 DeviceService (org.onosproject.net.device.DeviceService)1 Comparators (org.onosproject.utils.Comparators)1 AuthenticationRecord (org.opencord.aaa.AuthenticationRecord)1 AuthenticationService (org.opencord.aaa.AuthenticationService)1 SadisService (org.opencord.sadis.SadisService)1 SubscriberAndDeviceInformation (org.opencord.sadis.SubscriberAndDeviceInformation)1