当前位置: 首页>>代码示例>>Java>>正文


Java Meter.Unit方法代码示例

本文整理汇总了Java中org.onosproject.net.meter.Meter.Unit方法的典型用法代码示例。如果您正苦于以下问题:Java Meter.Unit方法的具体用法?Java Meter.Unit怎么用?Java Meter.Unit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.onosproject.net.meter.Meter的用法示例。


在下文中一共展示了Meter.Unit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: translate

import org.onosproject.net.meter.Meter; //导入方法依赖的package包/类
/**
 * Translates gRPC MeterRequest to {@link MeterRequest}.
 *
 * @param meterRequest gRPC message
 * @return {@link MeterRequest}
 */
public static MeterRequest translate(MeterRequestProto meterRequest) {

    DeviceId deviceid = DeviceId.deviceId(meterRequest.getDeviceId());
    ApplicationId appId = translate(meterRequest.getApplicationId());
    Meter.Unit unit = translate(meterRequest.getUnit());
    boolean burst = meterRequest.getIsBurst();
    Collection<Band> bands = translate(meterRequest.getBandsList());
    MeterRequest.Type type = translate(meterRequest.getType());
    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();
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:31,代码来源:MeterProtoTranslator.java

示例2: withRateUnit

import org.onosproject.net.meter.Meter; //导入方法依赖的package包/类
public MeterModBuilder withRateUnit(Meter.Unit unit) {
    this.unit = unit;
    return this;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:MeterModBuilder.java

示例3: decode

import org.onosproject.net.meter.Meter; //导入方法依赖的package包/类
@Override
public MeterRequest decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    final JsonCodec<Band> meterBandCodec = context.codec(Band.class);
    CoreService coreService = context.getService(CoreService.class);

    // parse device id
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID),
            DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());

    // application id
    ApplicationId appId = 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;

    switch (unit) {
        case "KB_PER_SEC":
            meterUnit = Meter.Unit.KB_PER_SEC;
            break;
        case "PKTS_PER_SEC":
            meterUnit = Meter.Unit.PKTS_PER_SEC;
            break;
        default:
            log.warn("The requested unit {} is not defined for meter.", unit);
            return null;
    }

    // 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));
        });
    }

    MeterRequest meterRequest;
    if (burst) {
        meterRequest = DefaultMeterRequest.builder()
                .fromApp(appId)
                .forDevice(deviceId)
                .withUnit(meterUnit)
                .withBands(bandList)
                .burst().add();
    } else {
        meterRequest = DefaultMeterRequest.builder()
                .fromApp(appId)
                .forDevice(deviceId)
                .withUnit(meterUnit)
                .withBands(bandList).add();
    }

    return meterRequest;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:69,代码来源:MeterRequestCodec.java

示例4: build

import org.onosproject.net.meter.Meter; //导入方法依赖的package包/类
/**
 * To build a MeterFeatures using the openflow object
 * provided by the southbound.
 *
 * @return the meter features object
 */
public MeterFeatures build() {
    /*
     * We set the basic values before to extract the other information.
     */
    MeterFeatures.Builder builder = DefaultMeterFeatures.builder()
            .forDevice(deviceId)
            .withMaxBands(ofMeterFeatures.getMaxBands())
            .withMaxColors(ofMeterFeatures.getMaxColor())
            .withMaxMeters(ofMeterFeatures.getMaxMeter());
    /*
     * We extract the supported band types.
     */
    Set<Band.Type> bands = Sets.newHashSet();
    if ((DROP_VAL & ofMeterFeatures.getCapabilities()) != 0) {
        bands.add(DROP);
    }
    if ((DSCP_REMARK_VAL & ofMeterFeatures.getCapabilities()) != 0) {
        bands.add(REMARK);
    }
    builder.withBandTypes(bands);
    /*
     * We extract the supported units;
     */
    Set<Meter.Unit> units = Sets.newHashSet();
    if ((PKTPS_VAL & ofMeterFeatures.getCapabilities()) != 0) {
        units.add(PKTS_PER_SEC);
    }
    if ((KBPS_VAL & ofMeterFeatures.getCapabilities()) != 0) {
        units.add(KB_PER_SEC);
    }
    if (units.isEmpty()) {
        units.add(PKTS_PER_SEC);
    }
    builder.withUnits(units);
    /*
     * Burst is supported ?
     */
    builder.hasBurst((BURST_VAL & ofMeterFeatures.getCapabilities()) != 0);
    /*
     * Stats are supported ?
     */
    builder.hasStats((STATS_VAL & ofMeterFeatures.getCapabilities()) != 0);

    /*
     * Along with the OF1.5, we extract meter features flags
     */
    if (ofMeterFeatures.getVersion().wireVersion >= OFVersion.OF_15.wireVersion) {
        Set<MeterFeaturesFlag> meterFeaturesFlags = Sets.newHashSet();
        if ((ACTION_SET_VAL & ofMeterFeatures.getFeatures()) != 0) {
            meterFeaturesFlags.add(ACTION_SET);
        }
        if ((ANY_POSITION_VAL & ofMeterFeatures.getFeatures()) != 0) {
            meterFeaturesFlags.add(ANY_POSITION);
        }
        if ((MULTI_LIST_VAL & ofMeterFeatures.getFeatures()) != 0) {
            meterFeaturesFlags.add(MULTI_LIST);
        }
        builder.withFeatures(meterFeaturesFlags);
    }

    return builder.build();
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:69,代码来源:MeterFeaturesBuilder.java

示例5: decode

import org.onosproject.net.meter.Meter; //导入方法依赖的package包/类
@Override
public MeterRequest decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    final JsonCodec<Band> meterBandCodec = context.codec(Band.class);
    CoreService coreService = context.getService(CoreService.class);

    // parse device id
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID),
            DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());

    // application id
    ApplicationId appId = 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;
        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));
        });
    }

    MeterRequest meterRequest;
    if (burst) {
        meterRequest = DefaultMeterRequest.builder()
                .fromApp(appId)
                .forDevice(deviceId)
                .withUnit(meterUnit)
                .withBands(bandList)
                .burst().add();
    } else {
        meterRequest = DefaultMeterRequest.builder()
                .fromApp(appId)
                .forDevice(deviceId)
                .withUnit(meterUnit)
                .withBands(bandList).add();
    }

    return meterRequest;
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:68,代码来源:MeterRequestCodec.java


注:本文中的org.onosproject.net.meter.Meter.Unit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。