Search in sources :

Example 1 with PortLoadBalancerId

use of org.onosproject.portloadbalancer.api.PortLoadBalancerId 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)

Example 2 with PortLoadBalancerId

use of org.onosproject.portloadbalancer.api.PortLoadBalancerId in project onos by opennetworkinglab.

the class PortLoadBalancerRemoveCommand method doExecute.

@Override
protected void doExecute() {
    DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
    int portLoadBalancerKey = Integer.parseInt(keyStr);
    PortLoadBalancerAdminService portLoadBalancerAdminService = get(PortLoadBalancerAdminService.class);
    PortLoadBalancerId portLoadBalancerId = new PortLoadBalancerId(deviceId, portLoadBalancerKey);
    PortLoadBalancer portLoadBalancer = portLoadBalancerAdminService.remove(portLoadBalancerId);
    print("Removal of %s %s", portLoadBalancerId, portLoadBalancer != null ? EXECUTED : FAILED);
}
Also used : PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) DeviceId(org.onosproject.net.DeviceId) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) PortLoadBalancerAdminService(org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService)

Example 3 with PortLoadBalancerId

use of org.onosproject.portloadbalancer.api.PortLoadBalancerId in project onos by opennetworkinglab.

the class PortLoadBalancerListCommand method doExecute.

@Override
public void doExecute() {
    PortLoadBalancerService service = get(PortLoadBalancerService.class);
    // Get port load balancers and reservations
    Map<PortLoadBalancerId, PortLoadBalancer> portLoadBalancerStore = service.getPortLoadBalancers();
    Map<PortLoadBalancerId, ApplicationId> portLoadBalancerResStore = service.getReservations();
    // Print id -> ports, mode, reservation
    portLoadBalancerStore.forEach((portLoadBalancerId, portLoadBalancer) -> print("%s -> %s, %s, %s", portLoadBalancerId, portLoadBalancer.ports(), portLoadBalancer.mode(), portLoadBalancerResStore.get(portLoadBalancerId) == null ? AVAILABLE : portLoadBalancerResStore.get(portLoadBalancerId).name()));
}
Also used : PortLoadBalancerService(org.onosproject.portloadbalancer.api.PortLoadBalancerService) PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) ApplicationId(org.onosproject.core.ApplicationId) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer)

Example 4 with PortLoadBalancerId

use of org.onosproject.portloadbalancer.api.PortLoadBalancerId in project onos by opennetworkinglab.

the class PortLoadBalancerAddCommand method doExecute.

@Override
protected void doExecute() {
    DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
    int portLoadBalancerKey = Integer.parseInt(keyStr);
    PortLoadBalancerMode mode = PortLoadBalancerMode.valueOf(modeStr.toUpperCase());
    Set<PortNumber> ports = Sets.newHashSet(portsStr).stream().map(PortNumber::fromString).collect(Collectors.toSet());
    PortLoadBalancerAdminService portLoadBalancerAdminService = get(PortLoadBalancerAdminService.class);
    PortLoadBalancerId portLoadBalancerId = new PortLoadBalancerId(deviceId, portLoadBalancerKey);
    PortLoadBalancer portLoadBalancer = portLoadBalancerAdminService.createOrUpdate(portLoadBalancerId, ports, mode);
    print("%s of %s executed", portLoadBalancer == null ? CREATE : UPDATE, portLoadBalancerId);
}
Also used : PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) DeviceId(org.onosproject.net.DeviceId) PortLoadBalancerMode(org.onosproject.portloadbalancer.api.PortLoadBalancerMode) PortNumber(org.onosproject.net.PortNumber) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) PortLoadBalancerAdminService(org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService)

Aggregations

PortLoadBalancer (org.onosproject.portloadbalancer.api.PortLoadBalancer)4 PortLoadBalancerId (org.onosproject.portloadbalancer.api.PortLoadBalancerId)4 DeviceId (org.onosproject.net.DeviceId)3 PortLoadBalancerAdminService (org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService)3 ApplicationId (org.onosproject.core.ApplicationId)2 PortNumber (org.onosproject.net.PortNumber)2 PortLoadBalancerService (org.onosproject.portloadbalancer.api.PortLoadBalancerService)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Collectors (java.util.stream.Collectors)1 KryoNamespace (org.onlab.util.KryoNamespace)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ClusterService (org.onosproject.cluster.ClusterService)1 LeadershipService (org.onosproject.cluster.LeadershipService)1 NodeId (org.onosproject.cluster.NodeId)1