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));
}
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;
}
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);
}
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);
}
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;
}
Aggregations