Search in sources :

Example 81 with PortNumber

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

the class AllocationsCommand method doExecute.

@Override
protected void doExecute() {
    deviceService = get(DeviceService.class);
    resourceService = get(ResourceService.class);
    if (typeStrings != null) {
        typesToPrint = new HashSet<>(Arrays.asList(typeStrings));
    } else {
        typesToPrint = Collections.emptySet();
    }
    if (intentStrings != null) {
        intentsToPrint = new HashSet<>(Arrays.asList(intentStrings));
    } else {
        intentsToPrint = Collections.emptySet();
    }
    if (deviceIdStr != null && portNumberStr != null) {
        DeviceId deviceId = deviceId(deviceIdStr);
        PortNumber portNumber = PortNumber.fromString(portNumberStr);
        printAllocation(deviceId, portNumber, 0);
    } else if (deviceIdStr != null) {
        DeviceId deviceId = deviceId(deviceIdStr);
        printAllocation(deviceId, 0);
    } else {
        printAllocation();
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ResourceService(org.onosproject.net.resource.ResourceService) PortNumber(org.onosproject.net.PortNumber)

Example 82 with PortNumber

use of org.onosproject.net.PortNumber 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 83 with PortNumber

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

the class ConnectivityIntentCommand method buildTrafficTreatment.

/**
 * Generates a traffic treatment for this intent based on command line
 * arguments presented to the command.
 *
 * @return traffic treatment
 */
protected TrafficTreatment buildTrafficTreatment() {
    final TrafficTreatment.Builder treatmentBuilder = builder();
    boolean emptyTreatment = true;
    if (!isNullOrEmpty(setEthSrcString)) {
        treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setEthDstString)) {
        treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setIpSrcString)) {
        treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setIpDstString)) {
        treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setVlan)) {
        treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
        emptyTreatment = false;
    }
    if (popVlan) {
        treatmentBuilder.popVlan();
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(pushVlan)) {
        treatmentBuilder.pushVlan();
        treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setQueue)) {
        // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
        if (setQueue.contains("/")) {
            String[] queueConfig = setQueue.split("/");
            PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
            long queueId = Long.parseLong(queueConfig[1]);
            treatmentBuilder.setQueue(queueId, port);
        } else {
            treatmentBuilder.setQueue(Long.parseLong(setQueue));
        }
        emptyTreatment = false;
    }
    if (emptyTreatment) {
        return DefaultTrafficTreatment.emptyTreatment();
    } else {
        return treatmentBuilder.build();
    }
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 84 with PortNumber

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

Example 85 with PortNumber

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

the class IntentCycleCommand method doExecute.

@Override
protected void doExecute() {
    service = get(IntentService.class);
    DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
    PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
    ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
    DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
    PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
    ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
    count = Integer.parseInt(numberOfIntents);
    keyOffset = (keyOffsetStr != null) ? Integer.parseInt(keyOffsetStr) : 1;
    service.addListener(this);
    List<Intent> operations = generateIntents(ingress, egress);
    add = true;
    start = System.currentTimeMillis();
    while (start + 10000 > System.currentTimeMillis()) {
        submitIntents(operations);
    }
    delay(5000);
    printResults();
    add = false;
    submitIntents(operations);
    service.removeListener(this);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) DeviceId(org.onosproject.net.DeviceId) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Aggregations

PortNumber (org.onosproject.net.PortNumber)336 DeviceId (org.onosproject.net.DeviceId)136 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)109 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)103 ConnectPoint (org.onosproject.net.ConnectPoint)82 TrafficSelector (org.onosproject.net.flow.TrafficSelector)80 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)74 Port (org.onosproject.net.Port)67 ArrayList (java.util.ArrayList)64 Set (java.util.Set)64 List (java.util.List)59 Logger (org.slf4j.Logger)58 Collectors (java.util.stream.Collectors)51 DeviceService (org.onosproject.net.device.DeviceService)49 VlanId (org.onlab.packet.VlanId)42 MacAddress (org.onlab.packet.MacAddress)41 Device (org.onosproject.net.Device)40 FlowRule (org.onosproject.net.flow.FlowRule)40 Optional (java.util.Optional)39 Sets (com.google.common.collect.Sets)35