Search in sources :

Example 1 with PortLoadBalancer

use of org.onosproject.portloadbalancer.api.PortLoadBalancer 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 2 with PortLoadBalancer

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

the class PortLoadBalancerManager method activate.

@Activate
public void activate() {
    appId = coreService.registerApplication(APP_NAME);
    portLoadBalancerEventExecutor = Executors.newSingleThreadExecutor(groupedThreads("portloadbalancer-event", "%d", log));
    portLoadBalancerProvExecutor = Executors.newSingleThreadExecutor(groupedThreads("portloadbalancer-prov", "%d", log));
    deviceEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("portloadbalancer-dev-event", "%d", log));
    portLoadBalancerStoreListener = new PortLoadBalancerStoreListener();
    portLoadBalancerNextStoreListener = new PortLoadBalancerNextStoreListener();
    portLoadBalancerResStoreListener = new PortLoadBalancerResStoreListener();
    KryoNamespace serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(PortLoadBalancer.class).register(PortLoadBalancerId.class).register(PortLoadBalancerMode.class).build();
    portLoadBalancerStore = storageService.<PortLoadBalancerId, PortLoadBalancer>consistentMapBuilder().withName("onos-portloadbalancer-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
    portLoadBalancerStore.addListener(portLoadBalancerStoreListener);
    portLoadBalancerNextStore = storageService.<PortLoadBalancerId, Integer>consistentMapBuilder().withName("onos-portloadbalancer-next-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
    portLoadBalancerNextStore.addListener(portLoadBalancerNextStoreListener);
    portLoadBalancerResStore = storageService.<PortLoadBalancerId, ApplicationId>consistentMapBuilder().withName("onos-portloadbalancer-res-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
    portLoadBalancerResStore.addListener(portLoadBalancerResStoreListener);
    deviceService.addListener(deviceListener);
    log.info("Started");
}
Also used : PortLoadBalancerMode(org.onosproject.portloadbalancer.api.PortLoadBalancerMode) KryoNamespace(org.onlab.util.KryoNamespace) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with PortLoadBalancer

use of org.onosproject.portloadbalancer.api.PortLoadBalancer 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 4 with PortLoadBalancer

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

the class PortLoadBalancerManager method reserve.

@Override
public boolean reserve(PortLoadBalancerId portLoadBalancerId, ApplicationId appId) {
    // Check if the resource is available
    ApplicationId reservation = Versioned.valueOrNull(portLoadBalancerResStore.get(portLoadBalancerId));
    PortLoadBalancer portLoadBalancer = Versioned.valueOrNull(portLoadBalancerStore.get(portLoadBalancerId));
    if (reservation == null && portLoadBalancer != null) {
        log.debug("Reserving {} -> {} into port load balancer reservation store", portLoadBalancerId, appId);
        return portLoadBalancerResStore.put(portLoadBalancerId, appId) == null;
    } else if (reservation != null && reservation.equals(appId)) {
        // App try to reserve the resource a second time
        log.debug("Already reserved {} -> {} skip reservation", portLoadBalancerId, appId);
        return true;
    }
    log.warn("Reservation failed {} -> {}", portLoadBalancerId, appId);
    return false;
}
Also used : ApplicationId(org.onosproject.core.ApplicationId) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer)

Example 5 with PortLoadBalancer

use of org.onosproject.portloadbalancer.api.PortLoadBalancer 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)5 PortLoadBalancerId (org.onosproject.portloadbalancer.api.PortLoadBalancerId)3 ApplicationId (org.onosproject.core.ApplicationId)2 DeviceId (org.onosproject.net.DeviceId)2 PortLoadBalancerAdminService (org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService)2 PortLoadBalancerMode (org.onosproject.portloadbalancer.api.PortLoadBalancerMode)2 KryoNamespace (org.onlab.util.KryoNamespace)1 PortNumber (org.onosproject.net.PortNumber)1 PortLoadBalancerService (org.onosproject.portloadbalancer.api.PortLoadBalancerService)1 Activate (org.osgi.service.component.annotations.Activate)1