Search in sources :

Example 1 with VirtualMeterProviderService

use of org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService in project onos by opennetworkinglab.

the class DefaultVirtualMeterProvider method activate.

@Activate
public void activate() {
    providerRegistryService.registerProvider(this);
    internalMeterListener = new InternalMeterListener();
    idGenerator = getIdGenerator();
    pendingOperations = CacheBuilder.newBuilder().expireAfterWrite(TIMEOUT, TimeUnit.SECONDS).removalListener((RemovalNotification<Long, VirtualMeterOperation> notification) -> {
        if (notification.getCause() == RemovalCause.EXPIRED) {
            NetworkId networkId = notification.getValue().networkId();
            MeterOperation op = notification.getValue().operation();
            VirtualMeterProviderService providerService = (VirtualMeterProviderService) providerRegistryService.getProviderService(networkId, VirtualMeterProvider.class);
            providerService.meterOperationFailed(op, MeterFailReason.TIMEOUT);
        }
    }).build();
    meterService.addListener(internalMeterListener);
    log.info("Started");
}
Also used : VirtualMeterProvider(org.onosproject.incubator.net.virtual.provider.VirtualMeterProvider) VirtualMeterProviderService(org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService) RemovalNotification(com.google.common.cache.RemovalNotification) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MeterOperation(org.onosproject.net.meter.MeterOperation) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with VirtualMeterProviderService

use of org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService in project onos by opennetworkinglab.

the class DefaultVirtualMeterProvider method performOperation.

private void performOperation(NetworkId networkId, DeviceId deviceId, MeterOperation op) {
    VirtualMeterOperation vOp = new VirtualMeterOperation(networkId, op);
    pendingOperations.put(idGenerator.getNewId(), vOp);
    switch(op.type()) {
        case ADD:
            // TODO: devirtualize + submit
            break;
        case REMOVE:
            // TODO: devirtualize + withdraw
            break;
        case MODIFY:
            // TODO: devitualize + withdraw and submit
            break;
        default:
            log.warn("Unknown Meter command {}; not sending anything", op.type());
            VirtualMeterProviderService providerService = (VirtualMeterProviderService) providerRegistryService.getProviderService(networkId, VirtualMeterProvider.class);
            providerService.meterOperationFailed(op, MeterFailReason.UNKNOWN_COMMAND);
    }
}
Also used : VirtualMeterProvider(org.onosproject.incubator.net.virtual.provider.VirtualMeterProvider) VirtualMeterProviderService(org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService)

Aggregations

VirtualMeterProvider (org.onosproject.incubator.net.virtual.provider.VirtualMeterProvider)2 VirtualMeterProviderService (org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService)2 RemovalNotification (com.google.common.cache.RemovalNotification)1 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)1 MeterOperation (org.onosproject.net.meter.MeterOperation)1 Activate (org.osgi.service.component.annotations.Activate)1