本文整理汇总了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);
}
示例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();
}
}
示例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());
}
示例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;
}
示例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();
}
示例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());
}
示例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));
}
示例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;
}
示例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());
}
示例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());
}
示例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;
}