Search in sources :

Example 11 with Band

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

Example 12 with 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;
}
Also used : Builder(org.onosproject.net.meter.Band.Builder) DefaultBand(org.onosproject.net.meter.DefaultBand) Band(org.onosproject.net.meter.Band)

Example 13 with 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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Band(org.onosproject.net.meter.Band) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 14 with Band

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

Example 15 with Band

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) MeterJsonMatcher.matchesMeter(org.onosproject.codec.impl.MeterJsonMatcher.matchesMeter) DefaultBand(org.onosproject.net.meter.DefaultBand) Band(org.onosproject.net.meter.Band) Test(org.junit.Test)

Aggregations

Band (org.onosproject.net.meter.Band)16 DefaultBand (org.onosproject.net.meter.DefaultBand)9 Meter (org.onosproject.net.meter.Meter)5 MeterRequest (org.onosproject.net.meter.MeterRequest)5 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.Test)3 DeviceId (org.onosproject.net.DeviceId)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ApplicationId (org.onosproject.core.ApplicationId)2 DefaultMeter (org.onosproject.net.meter.DefaultMeter)2 PiMeterId (org.onosproject.net.pi.model.PiMeterId)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TestApplicationId (org.onosproject.TestApplicationId)1 MeterJsonMatcher.matchesMeter (org.onosproject.codec.impl.MeterJsonMatcher.matchesMeter)1 CoreService (org.onosproject.core.CoreService)1 UpfMeter (org.onosproject.net.behaviour.upf.UpfMeter)1 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)1