Search in sources :

Example 1 with Builder

use of org.onosproject.net.meter.Band.Builder 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)

Aggregations

Band (org.onosproject.net.meter.Band)1 Builder (org.onosproject.net.meter.Band.Builder)1 DefaultBand (org.onosproject.net.meter.DefaultBand)1