Search in sources :

Example 36 with DeviceService

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

the class IntentsDiagnosisCommand method buildServiceRefs.

private ServiceRefs buildServiceRefs() {
    IntentService intentsService = get(IntentService.class);
    if (intentsService == null) {
        return null;
    }
    DeviceService deviceService = get(DeviceService.class);
    if (deviceService == null) {
        return null;
    }
    FlowStatisticService flowStatsService = get(FlowStatisticService.class);
    if (flowStatsService == null) {
        return null;
    }
    FlowRuleService flowService = get(FlowRuleService.class);
    if (flowService == null) {
        return null;
    }
    WorkPartitionService workPartitionService = get(WorkPartitionService.class);
    if (workPartitionService == null) {
        return null;
    }
    ObjectiveTrackerService objectiveTrackerService = get(ObjectiveTrackerService.class);
    if (objectiveTrackerService == null) {
        return null;
    }
    return new ServiceRefs(intentsService, deviceService, flowService, workPartitionService, objectiveTrackerService);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) DeviceService(org.onosproject.net.device.DeviceService) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService)

Example 37 with DeviceService

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

the class InternalConnectivityCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    ConnectPoint inputConnectPoint = ConnectPoint.deviceConnectPoint(input);
    ConnectPoint outputConnectPoint = ConnectPoint.deviceConnectPoint(output);
    DeviceService deviceService = get(DeviceService.class);
    DeviceId inputDeviceId = inputConnectPoint.deviceId();
    DeviceId outputDeviceId = outputConnectPoint.deviceId();
    PortNumber inputPortNumber = inputConnectPoint.port();
    PortNumber outputPortNumber = outputConnectPoint.port();
    InternalConnectivity internalConnectivityBehaviour;
    if (!inputDeviceId.equals(outputDeviceId)) {
        print("[ERROR] specified connect points should belong to the same device.");
        return;
    }
    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;
    }
    if (internalConnectivityBehaviour.testConnectivity(inputPortNumber, outputPortNumber)) {
        print("[CONNECTIVITY ALLOWED] device %s from input-port %s to output-port %s", device.id().toString(), inputPortNumber.toString(), outputPortNumber.toString());
    } else {
        print("[CONNECTIVITY NOT ALLOWED] device %s from input-port %s to output-port %s", device.id().toString(), inputPortNumber.toString(), outputPortNumber.toString());
    }
}
Also used : 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 38 with DeviceService

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

the class FlowsListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    DeviceService deviceService = get(DeviceService.class);
    FlowRuleService service = get(FlowRuleService.class);
    contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
    compilePredicate();
    if (countOnly && !suppressCoreOutput && filter.isEmpty() && remove == null) {
        if (state == null && uri == null) {
            deviceService.getDevices().forEach(device -> printCount(device, service));
        } else if (uri == null) {
            deviceService.getDevices().forEach(device -> printCount(device, FlowEntryState.valueOf(state.toUpperCase()), service));
        } else {
            Device device = deviceService.getDevice(DeviceId.deviceId(uri));
            if (device != null) {
                printCount(device, FlowEntryState.valueOf(state.toUpperCase()), service);
            }
        }
        return;
    }
    SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service, coreService);
    // Remove flows
    if (remove != null) {
        flows.values().forEach(flowList -> {
            if (!remove.isEmpty()) {
                filter.add(remove);
                contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
            }
            if (!filter.isEmpty() || (remove != null && !remove.isEmpty())) {
                flowList = filterFlows(flowList);
                this.removeFlowsInteractive(flowList, service, coreService);
            }
        });
        return;
    }
    // Show flows
    if (outputJson()) {
        print("%s", json(flows.keySet(), flows));
    } else {
        flows.forEach((device, flow) -> printFlows(device, flow, coreService));
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) Comparators(org.onosproject.utils.Comparators) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) PlaceholderCompleter(org.onosproject.cli.PlaceholderCompleter) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Device(org.onosproject.net.Device) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) BufferedReader(java.io.BufferedReader) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) SortedMap(java.util.SortedMap) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) StringFilter(org.onlab.util.StringFilter) ArrayList(java.util.ArrayList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 39 with DeviceService

use of org.onosproject.net.device.DeviceService 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 40 with DeviceService

use of org.onosproject.net.device.DeviceService 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)

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