Search in sources :

Example 41 with Meter

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();
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) HashSet(java.util.HashSet)

Example 42 with Meter

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();
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 43 with Meter

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();
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) MeterScope(org.onosproject.net.meter.MeterScope) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 44 with Meter

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);
}
Also used : Meter(org.onosproject.net.meter.Meter) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 45 with Meter

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);
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter)

Aggregations

Meter (org.onosproject.net.meter.Meter)45 DefaultMeter (org.onosproject.net.meter.DefaultMeter)32 Test (org.junit.Test)21 DeviceId (org.onosproject.net.DeviceId)12 MeterService (org.onosproject.net.meter.MeterService)8 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)8 MeterCellId (org.onosproject.net.meter.MeterCellId)7 MeterKey (org.onosproject.net.meter.MeterKey)7 Produces (javax.ws.rs.Produces)6 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Band (org.onosproject.net.meter.Band)5 DefaultBand (org.onosproject.net.meter.DefaultBand)4 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)4 MeterOperation (org.onosproject.net.meter.MeterOperation)4 MeterRequest (org.onosproject.net.meter.MeterRequest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3