Search in sources :

Example 21 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class GetFlowStatisticsCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    FlowStatisticService flowStatsService = get(FlowStatisticService.class);
    String deviceUri = getDeviceId(devicePort);
    String portUri = getPortNumber(devicePort);
    DeviceId ingressDeviceId = deviceId(deviceUri);
    PortNumber ingressPortNumber;
    if (portUri.length() == 0) {
        ingressPortNumber = null;
    } else {
        ingressPortNumber = portNumber(portUri);
    }
    Device device = deviceService.getDevice(ingressDeviceId);
    if (device == null) {
        error("No such device %s", ingressDeviceId.uri());
        return;
    }
    if (ingressPortNumber != null) {
        Port port = deviceService.getPort(ingressDeviceId, ingressPortNumber);
        if (port == null) {
            error("No such port %s on device %s", portUri, ingressDeviceId.uri());
            return;
        }
    }
    if (flowLiveType != null) {
        flowLiveType = flowLiveType.toUpperCase();
    }
    if (instructionType != null) {
        instructionType = instructionType.toUpperCase();
    }
    // convert String to FlowLiveType and check validity
    FlowEntry.FlowLiveType inLiveType;
    if (flowLiveType == null) {
        inLiveType = null;
    } else {
        inLiveType = getFlowLiveType(flowLiveType);
        if (inLiveType == null) {
            error("Invalid flow live type [%s] error", flowLiveType);
            return;
        }
    }
    // convert String to InstructionType and check validity
    Instruction.Type inInstructionType;
    if (instructionType == null) {
        inInstructionType = null;
    } else {
        inInstructionType = getInstructionType(instructionType);
        if (inInstructionType == null) {
            error("Invalid instruction type [%s] error", instructionType);
            return;
        }
    }
    if (showTopn != null) {
        int topn = Integer.parseInt(showTopn);
        if (topn <= 0) {
            // default value
            topn = 100;
        } else if (topn > 1000) {
            // max value
            topn = 1000;
        }
        // print show topn head line with type
        print("deviceId=%s, show TOPN=%s flows, liveType=%s, instruction type=%s", deviceUri, Integer.toString(topn), flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadTopnByType(device, inLiveType, inInstructionType, topn);
            // print all ports topn flows load for a given device
            for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
                printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
            }
        } else {
            List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadTopnByType(device, ingressPortNumber, inLiveType, inInstructionType, topn);
            // print device/port topn flows load
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortFlowsLoad(cp, typedFlowLoad);
        }
    } else if (showAll) {
        // is true?
        // print show all head line with type
        print("deviceId=%s, show ALL flows, liveType=%s, instruction type=%s", deviceUri, flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadAllByType(device, inLiveType, inInstructionType);
            // print all ports all flows load for a given device
            for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
                printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
            }
        } else {
            List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadAllByType(device, ingressPortNumber, inLiveType, inInstructionType);
            // print device/port all flows load
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortFlowsLoad(cp, typedFlowLoad);
        }
    } else {
        // if (showSummary == true) //always is true
        // print show summary head line
        print("deviceId=%s, show SUMMARY flows", deviceUri);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryFlowLoadMap = flowStatsService.loadSummary(device);
            // print all ports flow load summary for a given device
            for (ConnectPoint cp : summaryFlowLoadMap.keySet()) {
                printPortSummaryLoad(cp, summaryFlowLoadMap.get(cp));
            }
        } else {
            SummaryFlowEntryWithLoad summaryFlowLoad = flowStatsService.loadSummary(device, ingressPortNumber);
            // print device/port flow load summary
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortSummaryLoad(cp, summaryFlowLoad);
        }
    }
}
Also used : FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) List(java.util.List) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) Map(java.util.Map)

Example 22 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class DevicePortStatsCommand method jsonPortStats.

/**
 * Produces JSON array containing portstats of the specified devices.
 *
 * @param deviceService device service
 * @param devices       collection of devices
 * @return JSON Array
 */
protected JsonNode jsonPortStats(DeviceService deviceService, Iterable<Device> devices) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (Device device : devices) {
        result.add(jsonPortStats(device.id(), mapper, deviceService.getPortStatistics(device.id())));
    }
    return result;
}
Also used : Device(org.onosproject.net.Device) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class DevicePortStatsCommand method jsonPortStatsDelta.

/**
 * Produces JSON array containing delta portstats of the specified devices.
 *
 * @param deviceService device service
 * @param devices       collection of devices
 * @return JSON Array
 */
protected JsonNode jsonPortStatsDelta(DeviceService deviceService, Iterable<Device> devices) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (Device device : devices) {
        result.add(jsonPortStatsDelta(device.id(), mapper, deviceService.getPortDeltaStatistics(device.id())));
    }
    return result;
}
Also used : Device(org.onosproject.net.Device) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 24 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class GetInternalConnectivityOutputPortsCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    ConnectPoint inputConnectPoint = ConnectPoint.deviceConnectPoint(input);
    DeviceService deviceService = get(DeviceService.class);
    DeviceId inputDeviceId = inputConnectPoint.deviceId();
    PortNumber inputPortNumber = inputConnectPoint.port();
    InternalConnectivity internalConnectivityBehaviour;
    Device device = deviceService.getDevice(inputDeviceId);
    if (device != null && device.is(InternalConnectivity.class)) {
        internalConnectivityBehaviour = device.as(InternalConnectivity.class);
    } else {
        print("[ERROR] specified device %s does not support Internal Connectivity Behaviour.", device.toString());
        return;
    }
    Set<PortNumber> outputPorts = internalConnectivityBehaviour.getOutputPorts(inputPortNumber);
    List<PortNumber> outputPortsList = outputPorts.stream().sorted((a, b) -> (int) (a.toLong() - b.toLong())).collect(Collectors.toList());
    if (outputPorts.isEmpty()) {
        print("[POSSIBLE OUTPUT PORTS] None!");
    } else {
        print("[POSSIBLE OUTPUT PORTS] " + outputPortsList.toString());
    }
}
Also used : Logger(org.slf4j.Logger) InternalConnectivity(org.onosproject.net.behaviour.InternalConnectivity) Device(org.onosproject.net.Device) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Service(org.apache.karaf.shell.api.action.lifecycle.Service) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Completion(org.apache.karaf.shell.api.action.Completion) DeviceId(org.onosproject.net.DeviceId) InternalConnectivity(org.onosproject.net.behaviour.InternalConnectivity) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 25 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class GroupsListCommand method json.

private JsonNode json(Map<Device, List<Group>> sortedGroups) {
    ArrayNode result = mapper().createArrayNode();
    sortedGroups.forEach((device, groups) -> groups.forEach(group -> result.add(jsonForEntity(group, Group.class))));
    return result;
}
Also used : Comparators(org.onosproject.utils.Comparators) DeviceService(org.onosproject.net.device.DeviceService) GroupBucket(org.onosproject.net.group.GroupBucket) Command(org.apache.karaf.shell.api.action.Command) Group(org.onosproject.net.group.Group) Lists(com.google.common.collect.Lists) GroupState(org.onosproject.net.group.Group.GroupState) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) Collections(java.util.Collections) SortedMap(java.util.SortedMap) Group(org.onosproject.net.group.Group) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

Device (org.onosproject.net.Device)344 DeviceService (org.onosproject.net.device.DeviceService)111 DeviceId (org.onosproject.net.DeviceId)106 Port (org.onosproject.net.Port)63 ConnectPoint (org.onosproject.net.ConnectPoint)62 List (java.util.List)53 PortNumber (org.onosproject.net.PortNumber)51 DefaultDevice (org.onosproject.net.DefaultDevice)50 Test (org.junit.Test)43 Set (java.util.Set)40 Logger (org.slf4j.Logger)40 DeviceEvent (org.onosproject.net.device.DeviceEvent)39 Link (org.onosproject.net.Link)37 TrafficSelector (org.onosproject.net.flow.TrafficSelector)35 ArrayList (java.util.ArrayList)34 Optional (java.util.Optional)32 Collectors (java.util.stream.Collectors)32 Map (java.util.Map)31 IpAddress (org.onlab.packet.IpAddress)31 ApplicationId (org.onosproject.core.ApplicationId)31