Search in sources :

Example 51 with Port

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

the class RoadmUtil method createOchSignalFromWavelength.

public static OchSignal createOchSignalFromWavelength(double wavelength, DeviceService deviceService, DeviceId deviceId, PortNumber portNumber) {
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(deviceId, portNumber);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultiplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        return null;
    }
}
Also used : ChannelSpacing(org.onosproject.net.ChannelSpacing) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OchSignal(org.onosproject.net.OchSignal) OchPort(org.onosproject.net.optical.OchPort) GridType(org.onosproject.net.GridType)

Example 52 with Port

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

the class IntentsDiagnosisCommand method dumpCpStatistics.

private void dumpCpStatistics(ConnectPoint cp, Collection<PortStatistics> devPortStats, Collection<PortStatistics> devPortDeltaStats, String direction, ServiceRefs svcs) {
    if (cp == null) {
        return;
    }
    dump("  %s:", direction);
    if (cp.port().isLogical()) {
        dump("   - logical: device: %s, port: %s", cp.deviceId(), cp.port());
        return;
    }
    Port port = svcs.deviceService.getPort(cp.deviceId(), cp.port());
    if (port == null) {
        return;
    }
    try {
        devPortStats.stream().filter(stat -> stat.portNumber().equals(cp.port())).forEach(stat -> dump("   - stat   : %s:", getPortStatStr(stat, port)));
    } catch (IllegalStateException e) {
        error("error: " + e);
        return;
    }
    try {
        devPortDeltaStats.stream().filter(stat -> stat.portNumber().equals(cp.port())).forEach(stat -> dump("   - delta  : %s:", getPortStatStr(stat, port)));
    } catch (IllegalStateException e) {
        error("error: " + e);
    }
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) HashMap(java.util.HashMap) DefaultDevice(org.onosproject.net.DefaultDevice) AnnotationKeys(org.onosproject.net.AnnotationKeys) Link(org.onosproject.net.Link) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) IntentService(org.onosproject.net.intent.IntentService) Port(org.onosproject.net.Port) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) LinkKey(org.onosproject.net.LinkKey) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Streams(com.google.common.collect.Streams) Field(java.lang.reflect.Field) SetMultimap(com.google.common.collect.SetMultimap) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) Objects(java.util.Objects) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) Stream(java.util.stream.Stream) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) FlowRule(org.onosproject.net.flow.FlowRule) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port)

Example 53 with Port

use of org.onosproject.net.Port 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 54 with Port

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

the class AllocationsCommand method printAllocation.

private void printAllocation(DeviceId did, PortNumber num, int level) {
    if (level == 0) {
        // print DeviceId when Port was directly specified.
        print("%s", did);
    }
    DiscreteResourceId resourceId = Resources.discrete(did, num).id();
    List<String> portConsumers = resourceService.getResourceAllocations(resourceId).stream().filter(this::isSubjectToPrint).map(ResourceAllocation::consumerId).map(AllocationsCommand::asVerboseString).collect(Collectors.toList());
    if (portConsumers.isEmpty()) {
        print("%s%s", Strings.repeat(" ", level), asVerboseString(num));
    } else {
        print("%s%s allocated by %s", Strings.repeat(" ", level), asVerboseString(num), portConsumers);
    }
    // FIXME: This workaround induces a lot of distributed store access.
    // ResourceService should have an API to get all allocations under a parent resource.
    Set<Class<?>> subResourceTypes = ImmutableSet.<Class<?>>builder().add(OchSignal.class).add(VlanId.class).add(MplsLabel.class).add(Bandwidth.class).add(TributarySlot.class).build();
    for (Class<?> t : subResourceTypes) {
        resourceService.getResourceAllocations(resourceId, t).stream().filter(a -> isSubjectToPrint(a)).forEach(a -> print("%s%s allocated by %s", Strings.repeat(" ", level + 1), a.resource().valueAs(Object.class).orElse(""), asVerboseString(a.consumerId())));
    }
}
Also used : Arrays(java.util.Arrays) DiscreteResourceId(org.onosproject.net.resource.DiscreteResourceId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ResourceService(org.onosproject.net.resource.ResourceService) Command(org.apache.karaf.shell.api.action.Command) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Port(org.onosproject.net.Port) StreamSupport(java.util.stream.StreamSupport) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) IntentId(org.onosproject.net.intent.IntentId) ImmutableSet(com.google.common.collect.ImmutableSet) TributarySlot(org.onosproject.net.TributarySlot) MplsLabel(org.onlab.packet.MplsLabel) Device(org.onosproject.net.Device) Bandwidth(org.onlab.util.Bandwidth) ResourceConsumerId(org.onosproject.net.resource.ResourceConsumerId) Resources(org.onosproject.net.resource.Resources) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) OchSignal(org.onosproject.net.OchSignal) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) TributarySlot(org.onosproject.net.TributarySlot) OchSignal(org.onosproject.net.OchSignal) MplsLabel(org.onlab.packet.MplsLabel) DiscreteResourceId(org.onosproject.net.resource.DiscreteResourceId) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation)

Example 55 with Port

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

the class DevicePortStateCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
    Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
    if (dev == null) {
        print(" %s", "Device does not exist");
        return;
    }
    PortNumber pnum = PortNumber.fromString(portNumber);
    Port p = deviceService.getPort(dev.id(), pnum);
    if (p == null) {
        print(" %s", "Port does not exist");
        return;
    }
    if ("enable".equals(portState)) {
        deviceAdminService.changePortState(dev.id(), p.number(), true);
    } else if ("disable".equals(portState)) {
        deviceAdminService.changePortState(dev.id(), p.number(), false);
    } else {
        print(" %s", "State must be enable or disable");
    }
}
Also used : Device(org.onosproject.net.Device) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28