use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.
the class BandProtoTranslator method translate.
/**
* Translates gRPC Band to {@link Band}.
*
* @param gBand gRPC message
* @return {@link Band}
*/
public static Band translate(BandProto gBand) {
Band.Type type = BandEnumsProtoTranslator.translate(gBand.getType()).get();
long rate = gBand.getRate();
long burstSize = gBand.getBurst();
short prec = (short) gBand.getDropPrecedence();
Band band = new DefaultBand(type, rate, burstSize, prec);
return band;
}
use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.
the class MeterBandCodec method decode.
@Override
public Band decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
Builder builder = DefaultBand.builder();
// parse rate
long rate = nullIsIllegal(json.get(RATE), RATE + MISSING_MEMBER_MESSAGE).asLong();
builder.withRate(rate);
// parse burst size
long burstSize = nullIsIllegal(json.get(BURST_SIZE), BURST_SIZE + MISSING_MEMBER_MESSAGE).asLong();
builder.burstSize(burstSize);
// parse precedence
Short precedence = null;
// parse band type
String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
Band.Type type = null;
switch(typeStr) {
case "DROP":
type = Band.Type.DROP;
builder.ofType(type);
break;
case "REMARK":
type = Band.Type.REMARK;
precedence = (short) nullIsIllegal(json.get(PREC), PREC + MISSING_MEMBER_MESSAGE).asInt();
builder.ofType(type);
builder.dropPrecedence(precedence);
break;
case "NONE":
type = Band.Type.NONE;
builder.ofType(type);
break;
case "MARK_YELLOW":
type = Band.Type.MARK_YELLOW;
builder.ofType(type);
break;
case "MARK_RED":
type = Band.Type.MARK_RED;
builder.ofType(type);
break;
default:
nullIsIllegal(type, "The requested type " + typeStr + " is not defined for band.");
}
Band band = builder.build();
return band;
}
use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.
the class MeterCodec method encode.
@Override
public ObjectNode encode(Meter meter, CodecContext context) {
checkNotNull(meter, "Meter cannot be null");
ObjectNode result = context.mapper().createObjectNode().put(ID, meter.meterCellId().toString()).put(LIFE, meter.life()).put(PACKETS, meter.packetsSeen()).put(BYTES, meter.bytesSeen()).put(REFERENCE_COUNT, meter.referenceCount()).put(UNIT, meter.unit().toString()).put(BURST, meter.isBurst()).put(DEVICE_ID, meter.deviceId().toString());
if (meter.appId() != null) {
result.put(APP_ID, meter.appId().name());
}
if (meter.state() != null) {
result.put(STATE, meter.state().toString());
}
ArrayNode bands = context.mapper().createArrayNode();
meter.bands().forEach(band -> {
ObjectNode bandJson = context.codec(Band.class).encode(band, context);
bands.add(bandJson);
});
result.set(BANDS, bands);
return result;
}
use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.
the class VirtualNetworkMeterManagerTest method setupMeterTestVariables.
/**
* Set variables such as meters and request required for testing.
*/
private void setupMeterTestVariables() {
Band band = DefaultBand.builder().ofType(Band.Type.DROP).withRate(500).build();
m1 = DefaultMeter.builder().forDevice(VDID1).fromApp(appId).withId(MeterId.meterId(1)).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(band)).build();
m2 = DefaultMeter.builder().forDevice(VDID2).fromApp(appId).withId(MeterId.meterId(1)).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(band)).build();
m1Request = DefaultMeterRequest.builder().forDevice(VDID1).fromApp(appId).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(band));
m2Request = DefaultMeterRequest.builder().forDevice(VDID2).fromApp(appId).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(band));
meterStore.storeMeterFeatures(vnet1.id(), DefaultMeterFeatures.builder().forDevice(VDID1).withMaxMeters(255L).withBandTypes(new HashSet<>()).withUnits(new HashSet<>()).hasStats(false).hasBurst(false).withMaxBands((byte) 0).withMaxColors((byte) 0).build());
meterStore.storeMeterFeatures(vnet1.id(), DefaultMeterFeatures.builder().forDevice(VDID2).withMaxMeters(2).withBandTypes(new HashSet<>()).withUnits(new HashSet<>()).hasBurst(false).hasStats(false).withMaxBands((byte) 0).withMaxColors((byte) 0).build());
meterStore.storeMeterFeatures(vnet2.id(), DefaultMeterFeatures.builder().forDevice(VDID1).withMaxMeters(100L).withBandTypes(new HashSet<>()).withUnits(new HashSet<>()).hasStats(false).hasBurst(false).withMaxBands((byte) 0).withMaxColors((byte) 0).build());
meterStore.storeMeterFeatures(vnet2.id(), DefaultMeterFeatures.builder().forDevice(VDID2).withMaxMeters(10).withBandTypes(new HashSet<>()).withUnits(new HashSet<>()).hasBurst(false).hasStats(false).withMaxBands((byte) 0).withMaxColors((byte) 0).build());
}
use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.
the class MeterCodecTest method testMeterEncode.
/**
* Tests encoding of a Meter object.
*/
@Test
public void testMeterEncode() {
Band band1 = DefaultBand.builder().ofType(Band.Type.DROP).burstSize(10).withRate(10).build();
Band band2 = DefaultBand.builder().ofType(Band.Type.REMARK).burstSize(10).withRate(10).dropPrecedence((short) 10).build();
Meter meter = DefaultMeter.builder().fromApp(APP_ID).withId(MeterId.meterId(1L)).forDevice(NetTestTools.did("d1")).withBands(ImmutableList.of(band1, band2)).withUnit(Meter.Unit.KB_PER_SEC).build();
ObjectNode meterJson = meterCodec.encode(meter, context);
assertThat(meterJson, matchesMeter(meter));
}
Aggregations