use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MetersResourceTest method setupMockMeters.
/**
* Populates some meters used as testing data.
*/
private void setupMockMeters() {
final Set<Meter> meters1 = new HashSet<>();
meters1.add(meter1);
meters1.add(meter2);
final Set<Meter> meters2 = new HashSet<>();
meters2.add(meter3);
meters2.add(meter4);
meters.put(deviceId1, meters1);
meters.put(deviceId2, meters2);
Set<Meter> allMeters = new HashSet<>();
for (DeviceId deviceId : meters.keySet()) {
allMeters.addAll(meters.get(deviceId));
}
expect(mockMeterService.getAllMeters()).andReturn(allMeters).anyTimes();
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MetersWebResource method getMeterByDeviceIdAndMeterId.
/**
* Returns a meter by the meter id.
*
* @param deviceId device identifier
* @param meterId meter identifier
* @return 200 OK with a meter, return 404 if no entry has been found
* @onos.rsModel Meter
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{meterId}")
public Response getMeterByDeviceIdAndMeterId(@PathParam("deviceId") String deviceId, @PathParam("meterId") String meterId) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterCellId mid = MeterId.meterId(Long.valueOf(meterId));
MeterService meterService = get(MeterService.class);
final Meter meter = nullIsNotFound(meterService.getMeter(did, mid), METER_NOT_FOUND + mid);
metersNode.add(codec(Meter.class).encode(meter, this));
return ok(root).build();
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MetersWebResource method getMeterByDeviceIdAndMeterCellId.
/**
* Returns a meter by the meter cell id.
*
* @param deviceId device identifier
* @param scope scope identifier
* @param index index
* @return 200 OK with a meter, return 404 if no entry has been found
* @onos.rsModel Meter
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{scope}/{index}")
public Response getMeterByDeviceIdAndMeterCellId(@PathParam("deviceId") String deviceId, @PathParam("scope") String scope, @PathParam("index") String index) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterScope meterScope = MeterScope.of(scope);
long meterIndex = Long.parseLong(index);
MeterCellId meterCellId;
if (meterScope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(meterIndex);
} else {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), meterIndex);
}
MeterService meterService = get(MeterService.class);
final Meter meter = nullIsNotFound(meterService.getMeter(did, meterCellId), METER_NOT_FOUND + meterCellId);
metersNode.add(codec(Meter.class).encode(meter, this));
return ok(root).build();
}
use of org.onosproject.net.meter.Meter 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);
}
use of org.onosproject.net.meter.Meter in project fabric-tna by stratum.
the class MockMeterService method withdraw.
@Override
public void withdraw(MeterRequest meter, MeterCellId meterCellId) {
Meter withDrawnMeter = DefaultMeter.builder().forDevice(meter.deviceId()).fromApp(meter.appId()).withUnit(meter.unit()).withCellId(meterCellId).withBands(meter.bands()).build();
((DefaultMeter) withDrawnMeter).setState(MeterState.PENDING_REMOVE);
// Remove the meter and add it in PENDING_REMOVE state
meters.remove(withDrawnMeter);
meters.add(withDrawnMeter);
}
Aggregations