Search in sources :

Example 1 with MeterId

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

the class TrafficTreatmentCodecTest method testTrafficTreatmentEncode.

/**
 * Tests encoding of a traffic treatment object.
 */
@Test
public void testTrafficTreatmentEncode() {
    Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
    Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
    Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
    MeterId meterId = MeterId.meterId(1);
    Instruction meter = Instructions.meterTraffic(meterId);
    Instruction transition = Instructions.transition(1);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    TrafficTreatment treatment = tBuilder.add(output).add(modL2Src).add(modL2Dst).add(meter).add(transition).build();
    ObjectNode treatmentJson = trafficTreatmentCodec.encode(treatment, context);
    assertThat(treatmentJson, TrafficTreatmentJsonMatcher.matchesTrafficTreatment(treatment));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Instruction(org.onosproject.net.flow.instructions.Instruction) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) MeterId(org.onosproject.net.meter.MeterId) Test(org.junit.Test)

Example 2 with MeterId

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

the class DistributedMeterStore method validIndex.

// Validate index using the meter features, useful mainly
// when user defined index mode is enabled
private boolean validIndex(Meter meter) {
    long index;
    MeterTableKey key;
    if (meter.meterCellId().type() == PIPELINE_INDEPENDENT) {
        PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
        index = piMeterCellId.index();
        key = MeterTableKey.key(meter.deviceId(), MeterScope.of(piMeterCellId.meterId().id()));
    } else if (meter.meterCellId().type() == INDEX) {
        MeterId meterId = (MeterId) meter.meterCellId();
        index = meterId.id();
        key = MeterTableKey.key(meter.deviceId(), MeterScope.globalScope());
    } else {
        log.warn("Unable to validate index unsupported cell type {}", meter.meterCellId().type());
        return false;
    }
    MeterFeatures features = metersFeatures.get(key);
    long startIndex = features == null ? -1L : features.startIndex();
    long endIndex = features == null ? -1L : features.endIndex();
    return index >= startIndex && index <= endIndex;
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterFeatures(org.onosproject.net.meter.MeterFeatures) DefaultMeterFeatures(org.onosproject.net.meter.DefaultMeterFeatures) PiMeterId(org.onosproject.net.pi.model.PiMeterId) MeterId(org.onosproject.net.meter.MeterId)

Example 3 with MeterId

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

the class DistributedMeterStore method freeMeterId.

protected void freeMeterId(MeterTableKey meterTableKey, MeterCellId meterCellId) {
    if (userDefinedIndexMode) {
        log.debug("Unable to free meter id when user defined index mode is enabled");
        return;
    }
    long index;
    if (meterCellId.type() == PIPELINE_INDEPENDENT) {
        PiMeterCellId piMeterCellId = (PiMeterCellId) meterCellId;
        index = piMeterCellId.index();
    } else if (meterCellId.type() == INDEX) {
        MeterId meterId = (MeterId) meterCellId;
        index = meterId.id();
    } else {
        log.warn("Unable to free meter id unsupported cell type {}", meterCellId.type());
        return;
    }
    // Avoid to free meter not allocated
    if (meterIdGenerators.get(meterTableKey) <= index) {
        return;
    }
    updateMeterIdAvailability(meterTableKey, meterCellId, true);
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) PiMeterId(org.onosproject.net.pi.model.PiMeterId) MeterId(org.onosproject.net.meter.MeterId)

Example 4 with MeterId

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

the class OpenFlowPolicerConfigurable method freePolicerId.

@Override
public void freePolicerId(PolicerId id) {
    // Init step
    DriverHandler handler = handler();
    // First step is to get MeterService
    MeterService meterService = handler.get(MeterService.class);
    // There was a problem, return none
    if (meterService == null) {
        log.warn("MeterService is null");
        return;
    }
    // Let's get the device id
    DeviceId deviceId = handler.data().deviceId();
    // Double check correspondence with device schema
    if (!deviceId.uri().getScheme().equals(OF_SCHEME)) {
        log.warn("The device {} does not seem to be managed by OpenFlow", deviceId);
        return;
    }
    // Double check correspondence with pid schema
    if (!id.uri().getScheme().equals(OF_SCHEME)) {
        log.warn("The id {} does not seem to be OpenFlow", id);
        return;
    }
    // Get the meter id
    MeterId meterId = getMeterIdFromPolicerId(id);
    // Free the meter id
    meterService.freeMeterId(deviceId, meterId);
}
Also used : DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MeterService(org.onosproject.net.meter.MeterService) MeterId(org.onosproject.net.meter.MeterId)

Example 5 with MeterId

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

the class VirtualNetworkMeterManager method submit.

@Override
public Meter submit(MeterRequest request) {
    MeterId id = allocateMeterId(request.deviceId());
    Meter.Builder mBuilder = DefaultMeter.builder().forDevice(request.deviceId()).fromApp(request.appId()).withBands(request.bands()).withId(id).withUnit(request.unit());
    if (request.isBurst()) {
        mBuilder.burst();
    }
    DefaultMeter m = (DefaultMeter) mBuilder.build();
    m.setState(MeterState.PENDING_ADD);
    store.storeMeter(networkId(), m).whenComplete((result, error) -> onComplete.accept(request, result, error));
    return m;
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterId(org.onosproject.net.meter.MeterId)

Aggregations

MeterId (org.onosproject.net.meter.MeterId)6 DeviceId (org.onosproject.net.DeviceId)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 MeterService (org.onosproject.net.meter.MeterService)2 PiMeterId (org.onosproject.net.pi.model.PiMeterId)2 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Test (org.junit.Test)1 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)1 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)1 Instruction (org.onosproject.net.flow.instructions.Instruction)1 DefaultMeter (org.onosproject.net.meter.DefaultMeter)1 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)1 Meter (org.onosproject.net.meter.Meter)1 MeterFeatures (org.onosproject.net.meter.MeterFeatures)1 MeterTableKey (org.onosproject.net.meter.MeterTableKey)1