Search in sources :

Example 66 with PortNumber

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

the class SimpleIntManager method configDevice.

protected boolean configDevice(DeviceId deviceId) {
    // Returns true if config was successful, false if not and a clean up is
    // needed.
    final Device device = deviceService.getDevice(deviceId);
    if (device == null || !device.is(IntProgrammable.class)) {
        return true;
    }
    if (isNotIntConfigured()) {
        log.warn("Missing INT config, aborting programming of INT device {}", deviceId);
        return true;
    }
    final boolean isEdge = !hostService.getConnectedHosts(deviceId).isEmpty();
    final IntDeviceRole intDeviceRole = isEdge ? IntDeviceRole.SOURCE_SINK : IntDeviceRole.TRANSIT;
    log.info("Started programming of INT device {} with role {}...", deviceId, intDeviceRole);
    final IntProgrammable intProg = device.as(IntProgrammable.class);
    if (!isIntStarted()) {
        // Leave device with no INT configuration.
        return true;
    }
    if (!intProg.init()) {
        log.warn("Unable to init INT pipeline on {}", deviceId);
        return false;
    }
    boolean supportSource = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SOURCE);
    boolean supportSink = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SINK);
    boolean supportPostcard = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.POSTCARD);
    if (intDeviceRole != IntDeviceRole.SOURCE_SINK && !supportPostcard) {
        // Stop here, no more configuration needed for transit devices unless it support postcard.
        return true;
    }
    if (supportSink || supportPostcard) {
        if (!intProg.setupIntConfig(intConfig.get())) {
            log.warn("Unable to apply INT report config on {}", deviceId);
            return false;
        }
    }
    // Port configuration.
    final Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream().map(port -> new ConnectPoint(deviceId, port.number())).filter(cp -> !hostService.getConnectedHosts(cp).isEmpty()).map(ConnectPoint::port).collect(Collectors.toSet());
    for (PortNumber port : hostPorts) {
        if (supportSource) {
            log.info("Setting port {}/{} as INT source port...", deviceId, port);
            if (!intProg.setSourcePort(port)) {
                log.warn("Unable to set INT source port {} on {}", port, deviceId);
                return false;
            }
        }
        if (supportSink) {
            log.info("Setting port {}/{} as INT sink port...", deviceId, port);
            if (!intProg.setSinkPort(port)) {
                log.warn("Unable to set INT sink port {} on {}", port, deviceId);
                return false;
            }
        }
    }
    if (!supportSource && !supportPostcard) {
        // it supports postcard mode.
        return true;
    }
    // Apply intents.
    // This is a trivial implementation where we simply get the
    // corresponding INT objective from an intent and we apply to all
    // device which support reporting.
    int appliedCount = 0;
    for (Versioned<IntIntent> versionedIntent : intentMap.values()) {
        IntIntent intent = versionedIntent.value();
        IntObjective intObjective = getIntObjective(intent);
        if (intent.telemetryMode() == IntIntent.TelemetryMode.INBAND_TELEMETRY && supportSource) {
            intProg.addIntObjective(intObjective);
            appliedCount++;
        } else if (intent.telemetryMode() == IntIntent.TelemetryMode.POSTCARD && supportPostcard) {
            intProg.addIntObjective(intObjective);
            appliedCount++;
        } else {
            log.warn("Device {} does not support intent {}.", deviceId, intent);
        }
    }
    log.info("Completed programming of {}, applied {} INT objectives of {} total", deviceId, appliedCount, intentMap.size());
    return true;
}
Also used : IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) ScheduledFuture(java.util.concurrent.ScheduledFuture) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) TimeoutException(java.util.concurrent.TimeoutException) SharedScheduledExecutors(org.onlab.util.SharedScheduledExecutors) ConnectPoint(org.onosproject.net.ConnectPoint) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StorageService(org.onosproject.store.service.StorageService) SubjectFactories(org.onosproject.net.config.basics.SubjectFactories) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) Serializer(org.onosproject.store.service.Serializer) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) AtomicIdGenerator(org.onosproject.store.service.AtomicIdGenerator) Set(java.util.Set) Collectors(java.util.stream.Collectors) Versioned(org.onosproject.store.service.Versioned) ConfigFactory(org.onosproject.net.config.ConfigFactory) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) IntIntentCodec(org.onosproject.inbandtelemetry.rest.IntIntentCodec) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) AtomicValueEvent(org.onosproject.store.service.AtomicValueEvent) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) KryoNamespace(org.onlab.util.KryoNamespace) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) MapEventListener(org.onosproject.store.service.MapEventListener) ConcurrentMap(java.util.concurrent.ConcurrentMap) AtomicValue(org.onosproject.store.service.AtomicValue) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) IntService(org.onosproject.inbandtelemetry.api.IntService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) DeviceListener(org.onosproject.net.device.DeviceListener) Striped(com.google.common.util.concurrent.Striped) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IntDeviceConfig(org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) AtomicValueEventListener(org.onosproject.store.service.AtomicValueEventListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Lock(java.util.concurrent.locks.Lock) IntObjective(org.onosproject.net.behaviour.inbandtelemetry.IntObjective) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) IntMetadataType(org.onosproject.net.behaviour.inbandtelemetry.IntMetadataType) Device(org.onosproject.net.Device) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntObjective(org.onosproject.net.behaviour.inbandtelemetry.IntObjective) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 67 with PortNumber

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

the class DefaultCheckLoop method processOneOutputInstruction.

/**
 * Process one output instruction.
 *
 * Params are passed from processOneInstruction directly,
 * and obey the same rules.
 *
 * @param instOne the instruction to be processed
 * @param currentDeviceId id of the device we are now in
 * @param initPkt the packet before being copied
 * @param matchedPkt the packet which matched the flow entry,
 *                   to which this instruction belongs
 * @param isFindLoop indicate if it is invoked by findLoop method
 * @param firstEntry the flow entry from which the packet is generated
 * @return true, if a loop is discovered;
 *         false, 1. invoked by matchDeviceFlows method, and detected no loop;
 *                2. invoked by findLoop method
 */
private boolean processOneOutputInstruction(Instruction instOne, DeviceId currentDeviceId, TsLoopPacket initPkt, TsLoopPacket matchedPkt, boolean isFindLoop, FlowEntry firstEntry) {
    OutputInstruction instOutput = (OutputInstruction) instOne;
    PortNumber instPort = instOutput.port();
    if (!instPort.isLogical()) {
        // single OUTPUT - NIC or normal port
        Set<Link> dstLink = tsGetEgressLinks(new ConnectPoint(currentDeviceId, instPort));
        if (!dstLink.isEmpty()) {
            // TODO - now, just deal with the first destination.
            // will there be more destinations?
            Link dstThisLink = dstLink.iterator().next();
            ConnectPoint dstPoint = dstThisLink.dst();
            // check output to devices only (output to a host is normal)
            if (isDevice(dstPoint)) {
                PortCriterion oldInPort = updatePktInportPerHop(matchedPkt, dstPoint);
                matchedPkt.pushPathLink(dstThisLink);
                TsLoopPacket newNewPkt = matchedPkt.copyPacketMatch();
                boolean loopFound = matchDeviceFlows(dstPoint.deviceId(), newNewPkt);
                if (isFindLoop) {
                    if (loopFound) {
                        loops.add(newNewPkt);
                        updateExcludeDeviceSet(newNewPkt);
                    }
                    matchedPkt.resetLinkFlow(firstEntry);
                } else {
                    if (loopFound) {
                        initPkt.handInLoopMatch(newNewPkt);
                        return true;
                    }
                    matchedPkt.popPathLink();
                }
                restorePktInportPerHop(matchedPkt, oldInPort);
            }
        } else {
            if (!isFindLoop) {
                // TODO - NEED
                log.warn("no link connecting at device {}, port {}", currentDeviceId, instPort);
            }
        }
    } else if (instPort.equals(PortNumber.IN_PORT)) {
        // TODO - in the future,
        // we may need to resolve this condition 1
        log.warn("can not handle {} port now.", PortNumber.IN_PORT);
    } else if (instPort.equals(PortNumber.NORMAL) || instPort.equals(PortNumber.FLOOD) || instPort.equals(PortNumber.ALL)) {
        // TODO - in the future,
        // we may need to resolve this condition 2
        log.warn("can not handle {}/{}/{} now.", PortNumber.NORMAL, PortNumber.FLOOD, PortNumber.ALL);
    }
    return false;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) TsLoopPacket(org.onosproject.fnl.base.TsLoopPacket)

Example 68 with PortNumber

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

the class OpticalPathIntentCompiler method reversePort.

/**
 * Returns the PortNum of reverse port if annotation is present, otherwise return PortNum of the port itself.
 * In the OpenROADM YANG models it is used the term "partner-port.
 *
 * @param portNumber the port
 * @return the PortNum of reverse port if annotation is present, otherwise PortNum of the port itself.
 */
private PortNumber reversePort(DeviceId deviceId, PortNumber portNumber) {
    Port port = deviceService.getPort(deviceId, portNumber);
    String reversePort = port.annotations().value(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY);
    if (reversePort != null) {
        PortNumber reversePortNumber = PortNumber.portNumber(reversePort);
        return reversePortNumber;
    } else {
        return portNumber;
    }
}
Also used : Port(org.onosproject.net.Port) PortNumber(org.onosproject.net.PortNumber)

Example 69 with PortNumber

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

the class PortLoadBalancerManager method updatePortLoadBalancer.

private void updatePortLoadBalancer(PortLoadBalancer newPortLoadBalancer, PortLoadBalancer oldPortLoadBalancer) {
    DeviceId deviceId = newPortLoadBalancer.portLoadBalancerId().deviceId();
    if (!isLocalLeader(deviceId)) {
        log.debug("Not the leader of {}. Skip updatePortLoadBalancer {}", deviceId, newPortLoadBalancer.portLoadBalancerId());
        return;
    }
    portLoadBalancerProvExecutor.execute(() -> {
        Integer nextid = Versioned.valueOrNull(portLoadBalancerNextStore.get(newPortLoadBalancer.portLoadBalancerId()));
        if (nextid != null) {
            // Compute modifications and context
            PortLoadBalancerObjectiveContext context = new PortLoadBalancerObjectiveContext(newPortLoadBalancer.portLoadBalancerId());
            Set<PortNumber> portsToBeAdded = Sets.difference(newPortLoadBalancer.ports(), oldPortLoadBalancer.ports());
            Set<PortNumber> portsToBeRemoved = Sets.difference(oldPortLoadBalancer.ports(), newPortLoadBalancer.ports());
            // and send them to the flowobj subsystem
            if (!portsToBeAdded.isEmpty()) {
                flowObjService.next(deviceId, nextObjBuilder(newPortLoadBalancer.portLoadBalancerId(), portsToBeAdded, nextid).addToExisting(context));
            } else {
                log.debug("NextObj for {} nothing to add", newPortLoadBalancer.portLoadBalancerId());
            }
            if (!portsToBeRemoved.isEmpty()) {
                flowObjService.next(deviceId, nextObjBuilder(newPortLoadBalancer.portLoadBalancerId(), portsToBeRemoved, nextid).removeFromExisting(context));
            } else {
                log.debug("NextObj for {} nothing to remove", newPortLoadBalancer.portLoadBalancerId());
            }
        } else {
            log.info("NextObj for {} does not exist. Skip updatePortLoadBalancer", newPortLoadBalancer.portLoadBalancerId());
        }
    });
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber)

Example 70 with PortNumber

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

the class PortLoadBalancerManager method onErrorHandler.

private void onErrorHandler(NextObjective nextObjective, PortLoadBalancerId portLoadBalancerId) {
    // There was a failure
    PortLoadBalancerData portLoadBalancerData = new PortLoadBalancerData(portLoadBalancerId);
    // send FAILED event;
    switch(nextObjective.op()) {
        case ADD:
            // If ADD is failing apps do not know the next id; let's update the store
            portLoadBalancerNextStore.remove(portLoadBalancerId);
            portLoadBalancerResStore.remove(portLoadBalancerId);
            portLoadBalancerStore.remove(portLoadBalancerId);
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case ADD_TO_EXISTING:
            // If ADD_TO_EXISTING is failing let's remove the failed ports
            Collection<PortNumber> addedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
            portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
                if (value != null && value.ports() != null && !value.ports().isEmpty()) {
                    value.ports().removeAll(addedPorts);
                }
                return value;
            });
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case REMOVE_FROM_EXISTING:
            // If REMOVE_TO_EXISTING is failing let's re-add the failed ports
            Collection<PortNumber> removedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
            portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
                if (value != null && value.ports() != null) {
                    value.ports().addAll(removedPorts);
                }
                return value;
            });
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case VERIFY:
        case REMOVE:
            // If ADD/REMOVE_TO_EXISTING, REMOVE and VERIFY are failing let's send
            // also the info about the next id
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        default:
            break;
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableMap(com.google.common.collect.ImmutableMap) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) Versioned(org.onosproject.store.service.Versioned) PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) PortLoadBalancerMode(org.onosproject.portloadbalancer.api.PortLoadBalancerMode) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PortLoadBalancerAdminService(org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService) PortLoadBalancerService(org.onosproject.portloadbalancer.api.PortLoadBalancerService) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceListener(org.onosproject.net.device.DeviceListener) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) Instruction(org.onosproject.net.flow.instructions.Instruction) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PortLoadBalancerListener(org.onosproject.portloadbalancer.api.PortLoadBalancerListener) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) PortNumber(org.onosproject.net.PortNumber)

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