Search in sources :

Example 6 with Band

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

the class MeterJsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(JsonNode jsonMeter, Description description) {
    // check id
    String jsonMeterId = jsonMeter.get("id").asText();
    String meterId = meter.id().toString();
    if (!jsonMeterId.equals(meterId)) {
        description.appendText("meter id was " + jsonMeterId);
        return false;
    }
    // check unit
    String jsonUnit = jsonMeter.get("unit").asText();
    String unit = meter.unit().toString();
    if (!jsonUnit.equals(unit)) {
        description.appendText("unit was " + jsonUnit);
        return false;
    }
    // check burst
    boolean jsonBurst = jsonMeter.get("burst").asBoolean();
    boolean burst = meter.isBurst();
    if (jsonBurst != burst) {
        description.appendText("isBurst was " + jsonBurst);
        return false;
    }
    // check state
    JsonNode jsonNodeState = jsonMeter.get("state");
    if (jsonNodeState != null) {
        String state = meter.state().toString();
        if (!jsonNodeState.asText().equals(state)) {
            description.appendText("state was " + jsonNodeState.asText());
            return false;
        }
    }
    // check life
    JsonNode jsonNodeLife = jsonMeter.get("life");
    if (jsonNodeLife != null) {
        long life = meter.life();
        if (jsonNodeLife.asLong() != life) {
            description.appendText("life was " + jsonNodeLife.asLong());
            return false;
        }
    }
    // check bytes
    JsonNode jsonNodeBytes = jsonMeter.get("bytes");
    if (jsonNodeBytes != null) {
        long bytes = meter.bytesSeen();
        if (jsonNodeBytes.asLong() != bytes) {
            description.appendText("bytes was " + jsonNodeBytes.asLong());
            return false;
        }
    }
    // check packets
    JsonNode jsonNodePackets = jsonMeter.get("packets");
    if (jsonNodePackets != null) {
        long packets = meter.packetsSeen();
        if (jsonNodePackets.asLong() != packets) {
            description.appendText("packets was " + jsonNodePackets.asLong());
            return false;
        }
    }
    // check size of band array
    JsonNode jsonBands = jsonMeter.get("bands");
    if (jsonBands.size() != meter.bands().size()) {
        description.appendText("bands size was " + jsonBands.size());
        return false;
    }
    // check bands
    for (Band band : meter.bands()) {
        boolean bandFound = false;
        for (int bandIndex = 0; bandIndex < jsonBands.size(); bandIndex++) {
            MeterBandJsonMatcher bandMatcher = MeterBandJsonMatcher.matchesMeterBand(band);
            if (bandMatcher.matches(jsonBands.get(bandIndex))) {
                bandFound = true;
                break;
            }
        }
        if (!bandFound) {
            description.appendText("band not found " + band.toString());
            return false;
        }
    }
    return true;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Band(org.onosproject.net.meter.Band)

Example 7 with Band

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

the class MeterRequestCodecTest method testMeterRequestDecode.

/**
 * Test decoding of a MeterRequest object.
 */
@Test
public void testMeterRequestDecode() throws IOException {
    MeterRequest meterRequest = getMeterRequest("simple-meter-request.json");
    checkCommonData(meterRequest);
    assertThat(meterRequest.bands().size(), is(1));
    Band band = meterRequest.bands().iterator().next();
    assertThat(band.type().toString(), is("REMARK"));
    assertThat(band.rate(), is(10L));
    assertThat(band.dropPrecedence(), is((short) 20));
    assertThat(band.burst(), is(30L));
}
Also used : Band(org.onosproject.net.meter.Band) MeterRequest(org.onosproject.net.meter.MeterRequest) Test(org.junit.Test)

Example 8 with Band

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

the class CorsaPipelineV3 method processMeterTable.

protected void processMeterTable(boolean install) {
    // Green meter : Pass all traffic
    Band dropBand = DefaultBand.builder().ofType(Band.Type.DROP).withRate(0xFFFFFFFF).build();
    MeterRequest.Builder ops = DefaultMeterRequest.builder().forDevice(deviceId).withBands(Collections.singletonList(dropBand)).fromApp(appId);
    Meter meter = meterService.submit(install ? ops.add() : ops.remove());
    defaultMeterId = meter.id();
}
Also used : Meter(org.onosproject.net.meter.Meter) Band(org.onosproject.net.meter.Band) DefaultBand(org.onosproject.net.meter.DefaultBand) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 9 with Band

use of org.onosproject.net.meter.Band in project fabric-tna by stratum.

the class FabricUpfTranslator method upfMeterToFabricMeter.

public MeterRequest upfMeterToFabricMeter(UpfMeter upfMeter, DeviceId deviceId, ApplicationId appId) throws UpfProgrammableException {
    final PiMeterId meterId;
    if (upfMeter.type().equals(UpfEntityType.SESSION_METER)) {
        meterId = FABRIC_INGRESS_UPF_SESSION_METER;
    } else if (upfMeter.type().equals((UpfEntityType.APPLICATION_METER))) {
        meterId = FABRIC_INGRESS_UPF_APP_METER;
    } else {
        // I should never reach this point.
        throw new UpfProgrammableException("Unknown UPF meter type. I should never reach this point! " + upfMeter);
    }
    MeterRequest.Builder meterRequest = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(appId).withScope(MeterScope.of(meterId.id())).withUnit(Meter.Unit.BYTES_PER_SEC).withIndex((long) upfMeter.cellId());
    if (upfMeter.isReset()) {
        return meterRequest.remove();
    } else {
        Collection<Band> bands = Lists.newArrayList();
        if (upfMeter.committedBand().isPresent()) {
            bands.add(upfMeter.committedBand().get());
        } else {
            bands.add(DefaultBand.builder().ofType(Band.Type.MARK_YELLOW).withRate(0).burstSize(0).build());
        }
        if (upfMeter.peakBand().isPresent()) {
            bands.add(upfMeter.peakBand().get());
        } else {
            bands.add(DefaultBand.builder().ofType(Band.Type.MARK_RED).withRate(0).burstSize(0).build());
        }
        meterRequest.withBands(bands);
        return meterRequest.add();
    }
}
Also used : PiMeterId(org.onosproject.net.pi.model.PiMeterId) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) Band(org.onosproject.net.meter.Band) DefaultBand(org.onosproject.net.meter.DefaultBand) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 10 with Band

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

the class MeterAddCommand method checkOptions.

private void checkOptions() {
    // check units
    if (hasPkts) {
        unit = Meter.Unit.PKTS_PER_SEC;
    } else if (hasKbps) {
        unit = Meter.Unit.KB_PER_SEC;
    } else if (hasBytes) {
        unit = Meter.Unit.BYTES_PER_SEC;
    }
    int numBands = 0;
    if (hasBandDrop) {
        numBands++;
    }
    if (hasBandRemark) {
        numBands++;
    }
    if (hasBandYel) {
        numBands++;
    }
    if (hasBandRed) {
        numBands++;
    }
    long[] rates = new long[numBands];
    long[] bursts = new long[numBands];
    // check rate (does not take into account if it is kbps or pkts)
    if (bandwidthString != null && bandwidthString.length == numBands && burstSizeString != null && burstSizeString.length == numBands) {
        for (int i = 0; i < bandwidthString.length; i++) {
            rates[i] = 500L;
            bursts[i] = 0L;
            if (!isNullOrEmpty(bandwidthString[i])) {
                rates[i] = Long.parseLong(bandwidthString[i]);
            }
            if (!isNullOrEmpty(burstSizeString[i])) {
                bursts[i] = Long.parseLong(burstSizeString[i]);
            }
        }
    } else if (bandwidthString != null && bandwidthString.length < numBands && burstSizeString != null && burstSizeString.length < numBands) {
        for (int i = 0; i < numBands; i++) {
            rates[i] = 500L;
            bursts[i] = 0L;
            if (i < bandwidthString.length && !isNullOrEmpty(bandwidthString[i])) {
                rates[i] = Long.parseLong(bandwidthString[i]);
            }
            if (i < burstSizeString.length && !isNullOrEmpty(burstSizeString[i])) {
                bursts[i] = Long.parseLong(burstSizeString[i]);
            }
        }
    }
    // Create bands
    int i = 0;
    if (hasBandDrop) {
        Band band = DefaultBand.builder().ofType(Band.Type.DROP).withRate(rates[i]).burstSize(bursts[i]).build();
        bands.add(band);
        i++;
    }
    if (hasBandRemark) {
        Band band = DefaultBand.builder().ofType(Band.Type.REMARK).withRate(rates[i]).burstSize(bursts[i]).build();
        bands.add(band);
        i++;
    }
    if (hasBandYel) {
        Band band = DefaultBand.builder().ofType(Band.Type.MARK_YELLOW).withRate(rates[i]).burstSize(bursts[i]).build();
        bands.add(band);
        i++;
    }
    if (hasBandRed) {
        Band band = DefaultBand.builder().ofType(Band.Type.MARK_RED).withRate(rates[i]).burstSize(bursts[i]).build();
        bands.add(band);
    }
    // default band is drop
    if (bands.size() == 0) {
        Band band = DefaultBand.builder().ofType(Band.Type.DROP).withRate(500L).burstSize(0L).build();
        bands.add(band);
    }
    if (!isNullOrEmpty(scopeString)) {
        scope = MeterScope.of(scopeString);
    }
    if (!isNullOrEmpty(indexString) && scope != null) {
        index = Long.parseLong(indexString);
    }
}
Also used : DefaultBand(org.onosproject.net.meter.DefaultBand) Band(org.onosproject.net.meter.Band)

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