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


Java Meter类代码示例

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


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

示例1: setupMockMeters

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
/**
 * Populates some meters used as testing data.
 */
private void setupMockMeters() {
    final Set<Meter> meters1 = new HashSet<>();
    meters1.add(meter1);
    meters1.add(meter2);

    final Set<Meter> meters2 = new HashSet<>();
    meters2.add(meter3);
    meters2.add(meter4);

    meters.put(deviceId1, meters1);
    meters.put(deviceId2, meters2);

    Set<Meter> allMeters = new HashSet<>();
    for (DeviceId deviceId : meters.keySet()) {
        allMeters.addAll(meters.get(deviceId));
    }

    expect(mockMeterService.getAllMeters()).andReturn(allMeters).anyTimes();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:MetersResourceTest.java

示例2: testMeterSingleDevice

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
/**
 * Tests the results of a rest api GET for a device.
 */
@Test
public void testMeterSingleDevice() {
    setupMockMeters();

    final Set<Meter> meters1 = new HashSet<>();
    meters1.add(meter1);
    meters1.add(meter2);

    expect(mockMeterService.getMeters(anyObject())).andReturn(meters1).anyTimes();
    replay(mockMeterService);
    replay(mockDeviceService);

    final WebTarget wt = target();
    final String response = wt.path("meters/" + deviceId1.toString()).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter1));
    assertThat(jsonMeters, hasMeter(meter2));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:28,代码来源:MetersResourceTest.java

示例3: buildMeters

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
private Collection<Meter> buildMeters(DeviceId deviceId,
                                      List<OFMeterStats> entries) {
    return entries.stream().map(stat -> {
        DefaultMeter.Builder builder = DefaultMeter.builder();
        Collection<Band> bands = buildBands(stat.getBandStats());
        builder.forDevice(deviceId)
                .withId(MeterId.meterId(stat.getMeterId()))
                //FIXME: need to encode appId in meter id, but that makes
                // things a little annoying for debugging
                .fromApp(coreService.getAppId("org.onosproject.core"))
                .withBands(bands);
        DefaultMeter meter = builder.build();
        meter.setState(MeterState.ADDED);
        meter.setLife(stat.getDurationSec());
        meter.setProcessedBytes(stat.getByteInCount().getValue());
        meter.setProcessedPackets(stat.getPacketInCount().getValue());
        meter.setReferenceCount(stat.getFlowCount());

        // marks the meter as seen on the dataplane
        pendingOperations.invalidate(stat.getMeterId());
        return meter;
    }).collect(Collectors.toSet());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:OpenFlowMeterProvider.java

示例4: submit

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Override
public Meter submit(MeterRequest request) {

    MeterId id = allocateMeterId(request.deviceId());

    Meter.Builder mBuilder = DefaultMeter.builder()
            .forDevice(request.deviceId())
            .fromApp(request.appId())
            .withBands(request.bands())
            .withId(id)
            .withUnit(request.unit());

    if (request.isBurst()) {
        mBuilder.burst();
    }
    DefaultMeter m = (DefaultMeter) mBuilder.build();
    m.setState(MeterState.PENDING_ADD);
    store.storeMeter(m).whenComplete((result, error) ->
                                             onComplete.accept(request, result, error));
    return m;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:MeterManager.java

示例5: withdraw

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Override
public void withdraw(MeterRequest request, MeterId meterId) {
    Meter.Builder mBuilder = DefaultMeter.builder()
            .forDevice(request.deviceId())
            .fromApp(request.appId())
            .withBands(request.bands())
            .withId(meterId)
            .withUnit(request.unit());

    if (request.isBurst()) {
        mBuilder.burst();
    }

    DefaultMeter m = (DefaultMeter) mBuilder.build();
    m.setState(MeterState.PENDING_REMOVE);
    store.deleteMeter(m).whenComplete((result, error) ->
                                              onComplete.accept(request, result, error));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:MeterManager.java

示例6: pushMeterMetrics

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Override
public void pushMeterMetrics(DeviceId deviceId, Collection<Meter> meterEntries) {
    //FIXME: FOLLOWING CODE CANNOT BE TESTED UNTIL SOMETHING THAT
    //FIXME: IMPLEMENTS METERS EXISTS
    Map<Pair<DeviceId, MeterId>, Meter> storedMeterMap = store.getAllMeters().stream()
            .collect(Collectors.toMap(m -> Pair.of(m.deviceId(), m.id()), m -> m));

    meterEntries.stream()
            .filter(m -> storedMeterMap.remove(Pair.of(m.deviceId(), m.id())) != null)
            .forEach(m -> store.updateMeterState(m));

    storedMeterMap.values().stream().forEach(m -> {
        if (m.state() == MeterState.PENDING_ADD) {
            provider().performMeterOperation(m.deviceId(),
                                             new MeterOperation(m,
                                                                MeterOperation.Type.MODIFY));
        } else if (m.state() == MeterState.PENDING_REMOVE) {
            store.deleteMeterNow(m);
        }
    });
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:MeterManager.java

示例7: activate

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Activate
public void activate() {

    local = clusterService.getLocalNode().id();


    meters = storageService.<MeterKey, MeterData>consistentMapBuilder()
                .withName(METERSTORE)
                .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API),
                                                 MeterKey.class,
                                                 MeterData.class,
                                                 DefaultMeter.class,
                                                 DefaultBand.class,
                                                 Band.Type.class,
                                                 MeterState.class,
                                                 Meter.Unit.class,
                                                 MeterFailReason.class)).build();

    meters.addListener(mapListener);

    log.info("Started");
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:DistributedMeterStore.java

示例8: storeMeter

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Override
public CompletableFuture<MeterStoreResult> storeMeter(Meter meter) {
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    futures.put(key, future);
    MeterData data = new MeterData(meter, null, local);

    try {
        meters.put(key, data);
    } catch (StorageException e) {
        future.completeExceptionally(e);
    }

    return future;

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

示例9: deleteMeter

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Override
public CompletableFuture<MeterStoreResult> deleteMeter(Meter meter) {
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    futures.put(key, future);

    MeterData data = new MeterData(meter, null, local);

    // update the state of the meter. It will be pruned by observing
    // that it has been removed from the dataplane.
    try {
        if (meters.computeIfPresent(key, (k, v) -> data) == null) {
            future.complete(MeterStoreResult.success());
        }
    } catch (StorageException e) {
        future.completeExceptionally(e);
    }


    return future;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:DistributedMeterStore.java

示例10: updateMeter

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Override
public CompletableFuture<MeterStoreResult> updateMeter(Meter meter) {
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    futures.put(key, future);

    MeterData data = new MeterData(meter, null, local);
    try {
        if (meters.computeIfPresent(key, (k, v) -> data) == null) {
            future.complete(MeterStoreResult.fail(MeterFailReason.INVALID_METER));
        }
    } catch (StorageException e) {
        future.completeExceptionally(e);
    }
    return future;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:DistributedMeterStore.java

示例11: execute

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

示例12: testMeterEncode

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
/**
 * Tests encoding of a Meter object.
 */
@Test
public void testMeterEncode() {
    Band band1 = DefaultBand.builder()
                    .ofType(Band.Type.DROP)
                    .burstSize(10)
                    .withRate(10).build();
    Band band2 = DefaultBand.builder()
                    .ofType(Band.Type.REMARK)
                    .burstSize(10)
                    .withRate(10)
                    .dropPrecedence((short) 10).build();

    Meter meter = DefaultMeter.builder()
                    .fromApp(APP_ID)
                    .withId(MeterId.meterId(1L))
                    .forDevice(NetTestTools.did("d1"))
                    .withBands(ImmutableList.of(band1, band2))
                    .withUnit(Meter.Unit.KB_PER_SEC).build();

    ObjectNode meterJson = meterCodec.encode(meter, context);
    assertThat(meterJson, matchesMeter(meter));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:MeterCodecTest.java

示例13: testPerformMeterOperationDeviceIdMeterRemove

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
@Test
public void testPerformMeterOperationDeviceIdMeterRemove() {
    DeviceId mockDeviceId = DeviceId.deviceId("netconf:1.2.3.4:830");

    Band cbsBand = DefaultBand.builder()
            .ofType(Band.Type.REMARK) //Committed - CIR & CBS
            .withRate(37500L)
            .burstSize(2000)
            .dropPrecedence((short) 0)
            .build();

    Meter.Builder mBuilder = DefaultMeter.builder()
            .forDevice(mockDeviceId)
            .withId(MeterId.meterId(1))
            .fromApp(new DefaultApplicationId(101, "unit.test"))
            .burst()
            .withBands(new HashSet<Band>() { { add(cbsBand); } });

    MeterOperation meterOp = new MeterOperation(mBuilder.build(), Type.REMOVE);

    meterProvider.performMeterOperation(mockDeviceId, meterOp);
    //The NETCONF XML generated by this matches the pattern
    // sampleXmlRegexEditConfigBwpGroup1
    // in MockNetconfSession
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:26,代码来源:EA1000MeterProviderTest.java

示例14: buildMeters

import org.onosproject.net.meter.Meter; //导入依赖的package包/类
private Collection<Meter> buildMeters(DeviceId deviceId,
                                      List<OFMeterStats> entries) {
    return entries.stream().map(stat -> {
        DefaultMeter.Builder builder = DefaultMeter.builder();
        Collection<Band> bands = buildBands(stat.getBandStats());
        builder.forDevice(deviceId)
                .withId(MeterId.meterId(stat.getMeterId()))
                //FIXME: need to encode appId in meter id, but that makes
                // things a little annoying for debugging
                .fromApp(coreService.getAppId("org.onosproject.core"))
                .withBands(bands);
        DefaultMeter meter = builder.build();
        meter.setState(MeterState.ADDED);
        meter.setLife(stat.getDurationSec());
        meter.setProcessedBytes(stat.getByteInCount().getValue());
        meter.setProcessedPackets(stat.getPacketInCount().getValue());
        if (stat.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
            meter.setReferenceCount(stat.getFlowCount());
        }
        // marks the meter as seen on the dataplane
        pendingOperations.invalidate(stat.getMeterId());
        return meter;
    }).collect(Collectors.toSet());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:25,代码来源:OpenFlowMeterProvider.java

示例15: 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


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