Search in sources :

Example 1 with Band

use of org.onosproject.net.meter.Band in project up4 by omec-project.

the class Up4TranslatorImpl method upfEntityToUp4MeterEntry.

@Override
public PiMeterCellConfig upfEntityToUp4MeterEntry(UpfEntity entity) throws Up4TranslationException {
    PiMeterId meterId;
    switch(entity.type()) {
        case SESSION_METER:
            meterId = PRE_QOS_PIPE_SESSION_METER;
            break;
        case APPLICATION_METER:
            meterId = PRE_QOS_PIPE_APP_METER;
            break;
        default:
            throw new Up4TranslationException("Attempting to translate an unsupported UPF entity to a meter entry! " + entity);
    }
    UpfMeter upfMeter = (UpfMeter) entity;
    PiMeterCellId piMeterCellId = PiMeterCellId.ofIndirect(meterId, upfMeter.cellId());
    if (upfMeter.isReset()) {
        return PiMeterCellConfig.reset(piMeterCellId);
    }
    Band peakBand = upfMeter.peakBand().orElse(DefaultBand.builder().withRate(ZERO_BAND_RATE).burstSize(ZERO_BAND_BURST).ofType(Band.Type.MARK_RED).build());
    Band commitedBand = upfMeter.committedBand().orElse(DefaultBand.builder().withRate(ZERO_BAND_RATE).burstSize(ZERO_BAND_BURST).ofType(Band.Type.MARK_YELLOW).build());
    return PiMeterCellConfig.builder().withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, peakBand.rate(), peakBand.burst())).withMeterBand(new PiMeterBand(PiMeterBandType.COMMITTED, commitedBand.rate(), commitedBand.burst())).withMeterCellId(piMeterCellId).build();
}
Also used : PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand) PiMeterId(org.onosproject.net.pi.model.PiMeterId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) Band(org.onosproject.net.meter.Band) DefaultBand(org.onosproject.net.meter.DefaultBand) PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand)

Example 2 with Band

use of org.onosproject.net.meter.Band in project up4 by omec-project.

the class Up4Utils method ppUpfMeter.

/**
 * Pretty print UPF meter entity.
 *
 * @param meter the UPF meter
 * @return the pretty print string representation.
 */
public static String ppUpfMeter(UpfMeter meter) {
    StringBuilder sb = new StringBuilder("idx=" + meter.cellId());
    if (meter.peakBand().isPresent()) {
        Band peak = meter.peakBand().get();
        sb.append(", pir=").append(peak.rate()).append(", pburst=").append(peak.burst());
    }
    if (meter.committedBand().isPresent()) {
        Band committed = meter.committedBand().get();
        sb.append(", cir=").append(committed.rate()).append(", cburst=").append(committed.burst());
    }
    return sb.toString();
}
Also used : Band(org.onosproject.net.meter.Band)

Example 3 with Band

use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.

the class BandwidthProfile method fromMeter.

/**
 * Creates a bandwidth profile based on the parameters of a Meter.
 * NOTE: The dropPrecedence in the Meter is interpreted as
 * the DSCP class to set on the packet
 *
 * @param meter the Meter to be used for creating the bandwidth profile
 * @return the bandwidth profile created
 */
public static BandwidthProfile fromMeter(Meter meter) {
    checkNotNull(meter);
    checkArgument(meter.bands().size() <= 2, "Meter must have no more than two bands.");
    Iterator<Band> bandIterator = meter.bands().iterator();
    Band bandOne = bandIterator.next();
    Band bandTwo = bandIterator.hasNext() ? bandIterator.next() : null;
    // Assign values to yellowBand and redBand depending on
    // the number of bands in the meter.
    // If only one band exists it will be designated as the redBand.
    // If two bands exist, the one with the lower rate will be
    // the yellowBand and the other the redBand.
    Band yellowBand = (bandTwo == null ? null : bandTwo.rate() > bandOne.rate() ? bandOne : bandTwo);
    Band redBand = (bandTwo == null ? bandOne : yellowBand == bandOne ? bandTwo : bandOne);
    BandwidthProfile.Builder bandwidthProfileBuilder = new Builder().name(meter.id().toString()).colorAware(false).greenAction(getBuilder(Action.PASS).build());
    if (yellowBand != null) {
        // Try to add yellow action; CIR/CBS will be obtained from
        // yellowBand and PIR/PBS from redBand.
        BandwidthProfileAction yellowAction = getBwProfileActionFromBand(yellowBand);
        checkNotNull(yellowAction, "Could not obtain yellow action from meter band");
        bandwidthProfileBuilder.cir(Bandwidth.kBps(yellowBand.rate())).cbs(yellowBand.burst() == null ? null : yellowBand.burst().intValue()).pir(Bandwidth.kBps(redBand.rate())).pbs(redBand.burst() == null ? null : redBand.burst().intValue()).yellowAction(yellowAction);
    } else {
        // No yellow action to add; CIR/CBS will be obtained from redBand
        bandwidthProfileBuilder.cir(Bandwidth.kBps(redBand.rate())).cbs(redBand.burst() == null ? null : redBand.burst().intValue());
    }
    // Try to add red action in any case
    BandwidthProfileAction redAction = getBwProfileActionFromBand(redBand);
    checkNotNull(redAction, "Could not obtain red action from meter band");
    return bandwidthProfileBuilder.redAction(redAction).build();
}
Also used : Band(org.onosproject.net.meter.Band)

Example 4 with Band

use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.

the class MeterRequestCodec method decode.

@Override
public MeterRequest decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<Band> meterBandCodec = context.codec(Band.class);
    // parse device id
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
    // application id
    if (applicationId == null) {
        CoreService coreService = context.getService(CoreService.class);
        applicationId = coreService.registerApplication(REST_APP_ID);
    }
    // parse burst
    boolean burst = false;
    JsonNode burstJson = json.get("burst");
    if (burstJson != null) {
        burst = burstJson.asBoolean();
    }
    // parse unit type
    String unit = nullIsIllegal(json.get(UNIT), UNIT + MISSING_MEMBER_MESSAGE).asText();
    Meter.Unit meterUnit = null;
    switch(unit) {
        case "KB_PER_SEC":
            meterUnit = Meter.Unit.KB_PER_SEC;
            break;
        case "PKTS_PER_SEC":
            meterUnit = Meter.Unit.PKTS_PER_SEC;
            break;
        case "BYTES_PER_SEC":
            meterUnit = Meter.Unit.BYTES_PER_SEC;
            break;
        default:
            nullIsIllegal(meterUnit, "The requested unit " + unit + " is not defined for meter.");
    }
    // parse meter bands
    List<Band> bandList = new ArrayList<>();
    JsonNode bandsJson = json.get(BANDS);
    checkNotNull(bandsJson);
    if (bandsJson != null) {
        IntStream.range(0, bandsJson.size()).forEach(i -> {
            ObjectNode bandJson = get(bandsJson, i);
            bandList.add(meterBandCodec.decode(bandJson, context));
        });
    }
    // parse scope and index
    JsonNode scopeJson = json.get(SCOPE);
    MeterScope scope = null;
    if (scopeJson != null && !isNullOrEmpty(scopeJson.asText())) {
        scope = MeterScope.of(scopeJson.asText());
    }
    JsonNode indexJson = json.get(INDEX);
    Long index = null;
    if (indexJson != null && !isNullOrEmpty(indexJson.asText()) && scope != null) {
        index = indexJson.asLong();
    }
    // build the final request
    MeterRequest.Builder meterRequest = DefaultMeterRequest.builder();
    if (scope != null) {
        meterRequest.withScope(scope);
    }
    if (index != null) {
        meterRequest.withIndex(index);
    }
    meterRequest.fromApp(applicationId).forDevice(deviceId).withUnit(meterUnit).withBands(bandList);
    if (burst) {
        meterRequest.burst();
    }
    return meterRequest.add();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) CoreService(org.onosproject.core.CoreService) Band(org.onosproject.net.meter.Band) JsonNode(com.fasterxml.jackson.databind.JsonNode) MeterScope(org.onosproject.net.meter.MeterScope) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 5 with Band

use of org.onosproject.net.meter.Band in project onos by opennetworkinglab.

the class MeterRequestProtoTranslator method translate.

/**
 * Translates gRPC MeterRequest to {@link MeterRequest}.
 *
 * @param meterRequest gRPC message
 * @return {@link MeterRequest}
 */
public static MeterRequest translate(MeterRequestProtoOuterClass.MeterRequestProto meterRequest) {
    DeviceId deviceid = DeviceId.deviceId(meterRequest.getDeviceId());
    ApplicationId appId = ApplicationIdProtoTranslator.translate(meterRequest.getApplicationId());
    Meter.Unit unit = MeterEnumsProtoTranslator.translate(meterRequest.getUnit()).get();
    boolean burst = meterRequest.getIsBurst();
    Collection<Band> bands = BandProtoTranslator.translate(meterRequest.getBandsList());
    MeterRequest.Type type = (MeterRequest.Type) translate(meterRequest.getType()).get();
    if (type == MeterRequest.Type.ADD) {
        return DefaultMeterRequest.builder().forDevice(deviceid).fromApp(appId).withUnit(unit).withBands(bands).add();
    } else {
        return DefaultMeterRequest.builder().forDevice(deviceid).fromApp(appId).withUnit(unit).withBands(bands).remove();
    }
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) Band(org.onosproject.net.meter.Band) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) ApplicationId(org.onosproject.core.ApplicationId)

Aggregations

Band (org.onosproject.net.meter.Band)15 DefaultBand (org.onosproject.net.meter.DefaultBand)8 Meter (org.onosproject.net.meter.Meter)5 MeterRequest (org.onosproject.net.meter.MeterRequest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.Test)3 DeviceId (org.onosproject.net.DeviceId)3 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ApplicationId (org.onosproject.core.ApplicationId)2 DefaultMeter (org.onosproject.net.meter.DefaultMeter)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 Builder (org.onosproject.net.meter.Band.Builder)1 MeterScope (org.onosproject.net.meter.MeterScope)1