Search in sources :

Example 6 with MeterRequest

use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.

the class MeterRequestCodecTest method testMeterRequestDecode.

/**
 * Test decoding of a MeterRequest object.
 */
@Test
public void testMeterRequestDecode() throws IOException {
    MeterRequest meterRequest = getMeterRequest("simple-meter-request.json");
    checkCommonData(meterRequest);
    assertThat(meterRequest.bands().size(), is(1));
    Band band = meterRequest.bands().iterator().next();
    assertThat(band.type().toString(), is("REMARK"));
    assertThat(band.rate(), is(10L));
    assertThat(band.dropPrecedence(), is((short) 20));
    assertThat(band.burst(), is(30L));
}
Also used : Band(org.onosproject.net.meter.Band) MeterRequest(org.onosproject.net.meter.MeterRequest) Test(org.junit.Test)

Example 7 with MeterRequest

use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.

the class MeterAddCommand method doExecute.

@Override
protected void doExecute() {
    MeterService service = get(MeterService.class);
    CoreService coreService = get(CoreService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);
    checkOptions();
    MeterRequest.Builder builder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(coreService.registerApplication(appId)).withUnit(unit).withBands(bands);
    if (isBurst) {
        builder = builder.burst();
    }
    // the user defined mode being active.
    if (scope != null) {
        builder = builder.withScope(scope);
    }
    if (index != null) {
        builder = builder.withIndex(index);
    }
    MeterRequest request = builder.add();
    Meter m = service.submit(request);
    log.info("Requested meter with cellId {}: {}", m.meterCellId().toString(), m.toString());
    print("Requested meter with cellId %s: %s", m.meterCellId().toString(), m.toString());
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) CoreService(org.onosproject.core.CoreService) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) MeterService(org.onosproject.net.meter.MeterService)

Example 8 with MeterRequest

use of org.onosproject.net.meter.MeterRequest in project up4 by omec-project.

the class Up4DeviceManager method meterToMeterRequestForDevice.

private MeterRequest meterToMeterRequestForDevice(Meter meter, DeviceId deviceId, boolean add) {
    assert meter.meterCellId().type().equals(MeterCellId.MeterCellType.PIPELINE_INDEPENDENT);
    PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
    MeterScope meterScope = MeterScope.of(piMeterCellId.meterId().id());
    MeterRequest.Builder mRequestBuilder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(meter.appId()).withUnit(meter.unit()).withScope(meterScope).withBands(meter.bands()).withIndex(piMeterCellId.index());
    if (add) {
        return mRequestBuilder.add();
    }
    return mRequestBuilder.remove();
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterScope(org.onosproject.net.meter.MeterScope) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 9 with MeterRequest

use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.

the class MeterRemoveCommand method doExecute.

@Override
protected void doExecute() {
    MeterService service = get(MeterService.class);
    CoreService coreService = get(CoreService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);
    MeterScope scope = MeterScope.globalScope();
    if (!isNullOrEmpty(scopeString)) {
        scope = MeterScope.of(scopeString);
    }
    MeterCellId meterCellId;
    long index = Long.parseLong(indexString);
    if (scope.equals(MeterScope.globalScope())) {
        meterCellId = MeterId.meterId(index);
    } else {
        meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(scope.id()), index);
    }
    MeterRequest.Builder builder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(coreService.registerApplication(appId));
    MeterRequest meterRequest = builder.remove();
    service.withdraw(builder.remove(), meterCellId);
    log.info("Requested meter {} removal: {}", meterCellId.toString(), meterRequest.toString());
    print("Requested meter %s removal: %s", meterCellId.toString(), meterRequest.toString());
}
Also used : DeviceId(org.onosproject.net.DeviceId) MeterScope(org.onosproject.net.meter.MeterScope) CoreService(org.onosproject.core.CoreService) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId)

Example 10 with MeterRequest

use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.

the class DefaultOFSwitch method processMeterMod.

private void processMeterMod(OFMeterMod meterMod, Channel channel) {
    log.debug("processing METER_MOD {} message", meterMod.getCommand());
    long meterModId = meterMod.getMeterId();
    Meter existingMeter = meterService.getMeter(deviceId, MeterId.meterId(meterModId));
    MeterRequest meterRequest = null;
    switch(meterMod.getCommand()) {
        case ADD:
            if (existingMeter != null) {
                meterModError(meterMod, OFMeterModFailedCode.METER_EXISTS, channel);
                return;
            }
            meterRequest = meterRequestBuilder(meterMod).add();
            break;
        case MODIFY:
            if (existingMeter == null) {
                meterModError(meterMod, OFMeterModFailedCode.UNKNOWN_METER, channel);
                return;
            }
            meterRequest = meterRequestBuilder(meterMod).add();
            break;
        case DELETE:
            // non-existing meter id will not result in OFMeterModFailedErrorMsg
            // being sent to the controller
            meterRequest = meterRequestBuilder(meterMod).remove();
            break;
        default:
            log.warn("Unexpected message {} received for switch {}", meterMod.getCommand(), this);
            return;
    }
    meterService.submit(meterRequest);
}
Also used : Meter(org.onosproject.net.meter.Meter) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Aggregations

MeterRequest (org.onosproject.net.meter.MeterRequest)11 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)9 DeviceId (org.onosproject.net.DeviceId)6 Meter (org.onosproject.net.meter.Meter)5 MeterService (org.onosproject.net.meter.MeterService)5 MeterScope (org.onosproject.net.meter.MeterScope)4 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Path (javax.ws.rs.Path)3 CoreService (org.onosproject.core.CoreService)3 Band (org.onosproject.net.meter.Band)3 MeterCellId (org.onosproject.net.meter.MeterCellId)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DELETE (javax.ws.rs.DELETE)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1