Search in sources :

Example 11 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class TableStatisticsCommand method doExecute.

@Override
protected void doExecute() {
    FlowRuleService flowService = get(FlowRuleService.class);
    DeviceService deviceService = get(DeviceService.class);
    SortedMap<Device, List<TableStatisticsEntry>> deviceTableStats = getSortedTableStats(deviceService, flowService);
    if (outputJson()) {
        print("%s", json(deviceTableStats.keySet(), deviceTableStats));
    } else {
        deviceTableStats.forEach((device, tableStats) -> printTableStats(device, tableStats));
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 12 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class PathListCommand method doExecute.

@Override
protected void doExecute() {
    init();
    DeviceService deviceService = get(DeviceService.class);
    DeviceId srcDid = deviceId(src);
    if (deviceService.getDevice(srcDid) == null) {
        print("Unknown device %s", src);
        return;
    }
    DeviceId dstDid = deviceId(dst);
    if (deviceService.getDevice(dstDid) == null) {
        print("Unknown device %s", dst);
        return;
    }
    Set<? extends Path> paths;
    if (disjoint) {
        paths = service.getDisjointPaths(topology, srcDid, dstDid);
    } else {
        paths = service.getPaths(topology, srcDid, dstDid);
    }
    if (outputJson()) {
        print("%s", json(this, paths));
    } else {
        for (Path path : paths) {
            print(pathString(path));
            if (path instanceof DisjointPath) {
                // print backup right after primary
                print(pathString(((DisjointPath) path).backup()));
            }
        }
    }
}
Also used : Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) DisjointPath(org.onosproject.net.DisjointPath)

Example 13 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class PortNumberCompleter method choices.

@Override
protected List<String> choices() {
    DeviceId deviceId = lookForDeviceId();
    if (deviceId == null) {
        return Collections.emptyList();
    }
    DeviceService deviceService = getService(DeviceService.class);
    return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false).map(port -> port.number().toString()).collect(Collectors.toList());
}
Also used : AbstractChoicesCompleter(org.onosproject.cli.AbstractChoicesCompleter) DefaultServiceDirectory.getService(org.onlab.osgi.DefaultServiceDirectory.getService) List(java.util.List) Device(org.onosproject.net.Device) Service(org.apache.karaf.shell.api.action.lifecycle.Service) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) StreamSupport(java.util.stream.StreamSupport) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService)

Example 14 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class PortQueryVlansCommand method printVlans.

private void printVlans(Port port) {
    DeviceService deviceService = get(DeviceService.class);
    DriverService driverService = get(DriverService.class);
    DeviceId deviceId = (DeviceId) port.element().id();
    Device device = deviceService.getDevice(deviceId);
    if (!device.is(VlanQuery.class)) {
        // The relevant behavior is not supported by the device.
        print(NO_SUPPORT);
        return;
    }
    DriverHandler h = driverService.createHandler(deviceId);
    VlanQuery vlanQuery = h.behaviour(VlanQuery.class);
    try {
        Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number());
        if (vlanIds.isEmpty()) {
            print(VLAN_NOT_AVAILABLE);
        } else {
            print(AVAIL_VLANS, getRanges(vlanIds).toString());
        }
    } catch (Exception e) {
        print(FAILURE + e.getMessage());
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) DriverHandler(org.onosproject.net.driver.DriverHandler) VlanQuery(org.onosproject.net.behaviour.VlanQuery) VlanId(org.onlab.packet.VlanId) DriverService(org.onosproject.net.driver.DriverService)

Example 15 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class NumericPortNumberCompleter method choices.

@Override
protected List<String> choices() {
    DeviceId deviceId = lookForDeviceId();
    if (deviceId == null) {
        return Collections.emptyList();
    }
    DeviceService deviceService = getService(DeviceService.class);
    return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false).map(port -> Long.toString(port.number().toLong())).collect(Collectors.toList());
}
Also used : PortNumberCompleter(org.onosproject.cli.net.PortNumberCompleter) DefaultServiceDirectory.getService(org.onlab.osgi.DefaultServiceDirectory.getService) List(java.util.List) DeviceService(org.onosproject.net.device.DeviceService) StreamSupport(java.util.stream.StreamSupport) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14