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


Java DefaultMeterRequest类代码示例

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


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

示例1: execute

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
@Override
protected void execute() {
    MeterService service = get(MeterService.class);
    CoreService coreService = get(CoreService.class);

    DeviceId deviceId = DeviceId.deviceId(uri);

    Band band = DefaultBand.builder()
                    .ofType(Band.Type.DROP)
                    .withRate(500)
                    .build();


    MeterRequest request = DefaultMeterRequest.builder()
            .forDevice(deviceId)
            .fromApp(coreService.registerApplication(appId))
            .withUnit(Meter.Unit.KB_PER_SEC)
            .withBands(Collections.singleton(band))
            .add();

    service.submit(request);

}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:AddMeter.java

示例2: translate

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的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

示例3: execute

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
@Override
protected void execute() {
    MeterService service = get(MeterService.class);
    CoreService coreService = get(CoreService.class);

    DeviceId deviceId = DeviceId.deviceId(uri);
    MeterId meterId = MeterId.meterId(Long.parseLong(meterIdstr, 16));

    Band b = new DefaultBand(Band.Type.DROP, 0L, 0L, (short) 0);

    MeterRequest.Builder builder = DefaultMeterRequest.builder()
            .forDevice(deviceId)
            .withBands(Collections.singleton(b))
            .withUnit(Meter.Unit.PKTS_PER_SEC)
            .fromApp(coreService.registerApplication(appId));
    MeterRequest meterRequest = builder.remove();
    service.withdraw(meterRequest, meterId);
    log.info("Requested meter removal: {}", meterRequest.toString());

    print("Requested meter removal: %s", meterRequest.toString());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:22,代码来源:MeterRemoveCommand.java

示例4: meterToMeterRequest

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
/**
 * Converts a meter instance to meterRequest instance with a certain operation.
 *
 * @param meter     meter instance
 * @param operation operation
 * @return converted meterRequest instance
 */
private MeterRequest meterToMeterRequest(Meter meter, String operation) {
    MeterRequest.Builder builder;
    MeterRequest meterRequest;

    if (meter == null) {
        return null;
    }

    if (meter.isBurst()) {
        builder = DefaultMeterRequest.builder()
                .fromApp(meter.appId())
                .forDevice(meter.deviceId())
                .withUnit(meter.unit())
                .withBands(meter.bands())
                .burst();
    } else {
        builder = DefaultMeterRequest.builder()
                .fromApp(meter.appId())
                .forDevice(meter.deviceId())
                .withUnit(meter.unit())
                .withBands(meter.bands());
    }

    switch (operation) {
        case "ADD":
            meterRequest = builder.add();
            break;
        case "REMOVE":
            meterRequest = builder.remove();
            break;
        default:
            log.warn("Invalid operation {}.", operation);
            return null;
    }

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

示例5: processMeterTable

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
protected void processMeterTable(boolean install) {
    //Green meter : Pass all traffic
    Band dropBand = DefaultBand.builder()
            .ofType(Band.Type.DROP)
            .withRate(0xFFFFFFFF)   /* Max Rate */
            .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();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:15,代码来源:CorsaPipelineV3.java

示例6: execute

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
@Override
protected void execute() {
    MeterService service = get(MeterService.class);
    CoreService coreService = get(CoreService.class);

    DeviceId deviceId = DeviceId.deviceId(uri);

    checkOptions();


    MeterRequest.Builder builder = DefaultMeterRequest.builder()
            .forDevice(deviceId)
            .fromApp(coreService.registerApplication(appId))
            .withUnit(unit)
            .withBands(bands);


    if (isBurst) {
        builder = builder.burst();
    }

    MeterRequest request = builder.add();

    Meter m = service.submit(request);
    log.info("Requested meter with id {}: {}", m.id().toString(), m.toString());
    print("Requested meter with id %s: %s", m.id().toString(), m.toString());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:28,代码来源:MeterAddCommand.java

示例7: setup

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    meterStore = new DistributedMeterStore();
    TestUtils.setField(meterStore, "storageService", new TestStorageService());
    TestUtils.setField(meterStore, "clusterService", new TestClusterService());
    TestUtils.setField(meterStore, "mastershipService", new TestMastershipService());
    meterStore.activate();

    manager = new MeterManager();
    manager.store = meterStore;
    TestUtils.setField(manager, "storageService", new TestStorageService());
    injectEventDispatcher(manager, new TestEventDispatcher());
    service = manager;
    registry = manager;

    manager.activate();

    provider = new TestProvider(PID);
    providerService = registry.register(provider);

    appId = new TestApplicationId(0, "MeterManagerTest");

    assertTrue("provider should be registered",
               registry.getProviders().contains(provider.id()));

    Band band = DefaultBand.builder()
            .ofType(Band.Type.DROP)
            .withRate(500)
            .build();

    m1 = DefaultMeter.builder()
            .forDevice(did("1"))
            .fromApp(APP_ID)
            .withId(MeterId.meterId(1))
            .withUnit(Meter.Unit.KB_PER_SEC)
            .withBands(Collections.singletonList(band))
            .build();

    m2 = DefaultMeter.builder()
            .forDevice(did("2"))
            .fromApp(APP_ID)
            .withId(MeterId.meterId(1))
            .withUnit(Meter.Unit.KB_PER_SEC)
            .withBands(Collections.singletonList(band))
            .build();

    m1Request = DefaultMeterRequest.builder()
            .forDevice(did("1"))
            .fromApp(APP_ID)
            .withUnit(Meter.Unit.KB_PER_SEC)
            .withBands(Collections.singletonList(band));

    m2Request = DefaultMeterRequest.builder()
            .forDevice(did("2"))
            .fromApp(APP_ID)
            .withUnit(Meter.Unit.KB_PER_SEC)
            .withBands(Collections.singletonList(band));


}
 
开发者ID:shlee89,项目名称:athena,代码行数:61,代码来源:MeterManagerTest.java

示例8: decode

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的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

示例9: setupMeterTestVariables

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
/** 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());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:78,代码来源:VirtualNetworkMeterManagerTest.java

示例10: meterRequestBuilder

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的package包/类
private MeterRequest.Builder meterRequestBuilder(OFMeterMod meterMod) {
    Collection<Band> bands = meterMod.getBands().stream()
            .map(ofMeterBand -> band(ofMeterBand)).collect(Collectors.toList());
    return DefaultMeterRequest.builder().forDevice(deviceId)
            .withBands(bands).fromApp(ofSwitchService.appId());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:7,代码来源:DefaultOFSwitch.java

示例11: decode

import org.onosproject.net.meter.DefaultMeterRequest; //导入依赖的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.DefaultMeterRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。