Java Code Examples for org.onosproject.net.device.DeviceService#getDevices()

The following examples show how to use org.onosproject.net.device.DeviceService#getDevices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets port statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }

    return ok(root).build();
}
 
Example 2
Source File: StatisticsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets port delta statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }

    return ok(root).build();
}
 
Example 3
Source File: ConnectPointCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    DeviceService service = AbstractShellCommand.get(DeviceService.class);

    // Generate the device ID/port number identifiers
    for (Device device : service.getDevices()) {
        SortedSet<String> strings = delegate.getStrings();
        for (Port port : service.getPorts(device.id())) {
            if (!port.number().isLogical()) {
                strings.add(device.id().toString() + "/" + port.number());
            }
        }
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 4
Source File: OpticalConnectPointCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    DeviceService service = AbstractShellCommand.get(DeviceService.class);

    // Generate the device ID/port number identifiers
    for (Device device : service.getDevices()) {
        SortedSet<String> strings = delegate.getStrings();
        for (Port port : service.getPorts(device.id())) {
            if (!port.number().isLogical() && (port.type().equals(Port.Type.OCH) ||
                    port.type().equals(Port.Type.OMS) || port.type().equals(Port.Type.OTU))) {
                strings.add(device.id().toString() + "/" + port.number());
            }
        }
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 5
Source File: MappingsListCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {

    MappingStore.Type typeEnum = getTypeEnum(type);

    DeviceService deviceService = get(DeviceService.class);
    Iterable<Device> devices = deviceService.getDevices();

    if (outputJson()) {
        print(JSON_FORMAT, json(typeEnum, devices));
    } else {
        if (deviceId != null) {
            mappings = newArrayList(mappingService.getMappingEntries(typeEnum,
                    DeviceId.deviceId(deviceId)));
            printMappings(DeviceId.deviceId(deviceId), mappings);

        } else {

            for (Device d : devices) {
                mappings = newArrayList(mappingService.getMappingEntries(typeEnum, d.id()));
                printMappings(d.id(), mappings);
            }
        }
    }
}
 
Example 6
Source File: DeviceViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
    DeviceService ds = get(DeviceService.class);
    MastershipService ms = get(MastershipService.class);
    for (Device dev : ds.getDevices()) {
        populateRow(tm.addRow(), dev, ds, ms);
    }
}
 
Example 7
Source File: FlowsListCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of devices sorted using the device ID URIs.
 *
 * @param deviceService device service
 * @param service flow rule service
 * @param coreService core service
 * @return sorted device list
 */
protected SortedMap<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService,
                                                      FlowRuleService service, CoreService coreService) {
    SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
    List<FlowEntry> rules;

    Iterable<Device> devices = null;
    if (uri == null) {
        devices = deviceService.getDevices();
    } else {
        Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
        devices = (dev == null) ? deviceService.getDevices()
                                : Collections.singletonList(dev);
    }

    for (Device d : devices) {
        if (predicate.equals(TRUE_PREDICATE)) {
            rules = newArrayList(service.getFlowEntries(d.id()));
        } else {
            rules = newArrayList();
            for (FlowEntry f : service.getFlowEntries(d.id())) {
                if (predicate.test(f)) {
                    rules.add(f);
                }
            }
        }
        rules.sort(Comparators.FLOW_RULE_COMPARATOR);

        if (suppressCoreOutput) {
            short coreAppId = coreService.getAppId("org.onosproject.core").id();
            rules = rules.stream()
                    .filter(f -> f.appId() != coreAppId)
                    .collect(Collectors.toList());
        }
        flows.put(d, rules);
    }
    return flows;
}
 
Example 8
Source File: TableStatisticsCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of table statistics sorted using the device ID URIs and table IDs.
 *
 * @param deviceService device service
 * @param flowService flow rule service
 * @return sorted table statistics list
 */
protected SortedMap<Device, List<TableStatisticsEntry>> getSortedTableStats(DeviceService deviceService,
                                                                            FlowRuleService flowService) {
    SortedMap<Device, List<TableStatisticsEntry>> deviceTableStats = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
    List<TableStatisticsEntry> tableStatsList;
    Iterable<Device> devices = uri == null ? deviceService.getDevices() :
            Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri)));
    for (Device d : devices) {
        tableStatsList = newArrayList(flowService.getFlowTableStatistics(d.id()));
        tableStatsList.sort((p1, p2) -> Integer.valueOf(p1.tableId()).compareTo(Integer.valueOf(p2.tableId())));
        deviceTableStats.put(d, tableStatsList);
    }
    return deviceTableStats;
}
 
Example 9
Source File: VirtualNetworkFlowRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<FlowEntry> getFlowEntriesById(ApplicationId id) {
    DeviceService deviceService = manager.get(networkId(), DeviceService.class);

    Set<FlowEntry> flowEntries = Sets.newHashSet();
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
            if (flowEntry.appId() == id.id()) {
                flowEntries.add(flowEntry);
            }
        }
    }
    return flowEntries;
}
 
Example 10
Source File: VirtualNetworkFlowRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
    DeviceService deviceService = manager.get(networkId(), DeviceService.class);

    Set<FlowRule> matches = Sets.newHashSet();
    long toLookUp = ((long) appId.id() << 16) | groupId;
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
            if ((flowEntry.id().value() >>> 32) == toLookUp) {
                matches.add(flowEntry);
            }
        }
    }
    return matches;
}
 
Example 11
Source File: VirtualFlowsListCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of devices sorted using the device ID URIs.
 *
 * @param deviceService device service
 * @param service flow rule service
 * @return sorted device list
 */
protected SortedMap<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService,
                                                      FlowRuleService service) {
    SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
    List<FlowEntry> rules;

    Iterable<Device> devices = null;
    if (uri == null) {
        devices = deviceService.getDevices();
    } else {
        Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
        devices = (dev == null) ? deviceService.getDevices()
                                : Collections.singletonList(dev);
    }

    for (Device d : devices) {
        if (predicate.equals(TRUE_PREDICATE)) {
            rules = newArrayList(service.getFlowEntries(d.id()));
        } else {
            rules = newArrayList();
            for (FlowEntry f : service.getFlowEntries(d.id())) {
                if (predicate.test(f)) {
                    rules.add(f);
                }
            }
        }
        rules.sort(Comparators.FLOW_RULE_COMPARATOR);

        flows.put(d, rules);
    }
    return flows;
}
 
Example 12
Source File: VirtualNetworkDeviceManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests querying for a device using a null device type.
 */
@Test(expected = NullPointerException.class)
public void testGetDeviceByNullType() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);

    // test the getDevices() method with null type value.
    deviceService.getDevices(null);
}