本文整理汇总了Java中org.onosproject.net.meter.MeterId.meterId方法的典型用法代码示例。如果您正苦于以下问题:Java MeterId.meterId方法的具体用法?Java MeterId.meterId怎么用?Java MeterId.meterId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.net.meter.MeterId
的用法示例。
在下文中一共展示了MeterId.meterId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTrafficTreatmentEncode
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
/**
* Tests encoding of a traffic treatment object.
*/
@Test
public void testTrafficTreatmentEncode() {
Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
MeterId meterId = MeterId.meterId(0);
Instruction meter = Instructions.meterTraffic(meterId);
Instruction transition = Instructions.transition(1);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
TrafficTreatment treatment = tBuilder
.add(output)
.add(modL2Src)
.add(modL2Dst)
.add(meter)
.add(transition)
.build();
ObjectNode treatmentJson = trafficTreatmentCodec.encode(treatment, context);
assertThat(treatmentJson, TrafficTreatmentJsonMatcher.matchesTrafficTreatment(treatment));
}
示例2: execute
import org.onosproject.net.meter.MeterId; //导入方法依赖的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());
}
示例3: execute
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
@Override
protected void execute() {
if (!isNullOrEmpty(meterstr)) {
meterId = MeterId.meterId(Long.parseLong(meterstr));
}
MeterService service = get(MeterService.class);
if (meterId != null && uri != null) {
Meter m = service.getMeter(DeviceId.deviceId(uri), meterId);
if (m != null) {
print("%s", m);
} else {
error("Meter %s not found for device %s", meterId, uri);
}
} else {
Collection<Meter> meters = service.getAllMeters();
if (uri == null) {
printMeters(meters);
} else {
printMeters(Collections2.filter(meters,
m -> m.deviceId().equals(DeviceId.deviceId(uri))));
}
}
}
示例4: testTrafficTreatmentEncode
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
/**
* Tests encoding of a traffic treatment object.
*/
@Test
public void testTrafficTreatmentEncode() {
Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
MeterId meterId = MeterId.meterId(1);
Instruction meter = Instructions.meterTraffic(meterId);
Instruction transition = Instructions.transition(1);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
TrafficTreatment treatment = tBuilder
.add(output)
.add(modL2Src)
.add(modL2Dst)
.add(meter)
.add(transition)
.build();
ObjectNode treatmentJson = trafficTreatmentCodec.encode(treatment, context);
assertThat(treatmentJson, TrafficTreatmentJsonMatcher.matchesTrafficTreatment(treatment));
}
示例5: getMeterByDeviceIdAndMeterId
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
/**
* Returns a meter by the meter id.
*
* @param deviceId device identifier
* @param meterId meter identifier
* @return 200 OK with a meter, return 404 if no entry has been found
* @onos.rsModel Meter
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{meterId}")
public Response getMeterByDeviceIdAndMeterId(@PathParam("deviceId") String deviceId,
@PathParam("meterId") String meterId) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterId mid = MeterId.meterId(Long.valueOf(meterId));
final Meter meter = nullIsNotFound(meterService.getMeter(did, mid),
METER_NOT_FOUND + mid.id());
metersNode.add(codec(Meter.class).encode(meter, this));
return ok(root).build();
}
示例6: deleteMeterByDeviceIdAndMeterId
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
/**
* Removes the specified meter.
*
* @param deviceId device identifier
* @param meterId meter identifier
* @return 204 NO CONTENT
*/
@DELETE
@Path("{deviceId}/{meterId}")
public Response deleteMeterByDeviceIdAndMeterId(@PathParam("deviceId") String deviceId,
@PathParam("meterId") String meterId) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterId mid = MeterId.meterId(Long.valueOf(meterId));
final Meter tmpMeter = meterService.getMeter(did, mid);
if (tmpMeter != null) {
final MeterRequest meterRequest = meterToMeterRequest(tmpMeter, "REMOVE");
meterService.withdraw(meterRequest, tmpMeter.id());
}
return Response.noContent().build();
}
示例7: MockMeter
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
public MockMeter(DeviceId deviceId, int appId, long meterId, int id) {
this.deviceId = deviceId;
this.appId = new DefaultApplicationId(appId, String.valueOf(appId));
this.baseValue = id * 200;
this.meterId = MeterId.meterId(meterId);
Band band = DefaultBand.builder()
.ofType(Band.Type.REMARK)
.withRate(10)
.dropPrecedence((short) 20)
.burstSize(30).build();
this.bandList = new ArrayList<>();
this.bandList.add(band);
}
示例8: allocateMeterId
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
private MeterId allocateMeterId(DeviceId deviceId) {
long id = meterIdCounters.compute(deviceId, (k, v) -> {
if (v == null) {
return allocateCounter(k);
}
return v;
}).incrementAndGet();
return MeterId.meterId((int) id);
}
示例9: decode
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
/**
* Decodes the JSON into an instruction object.
*
* @return Criterion object
* @throws IllegalArgumentException if the JSON is invalid
*/
public Instruction decode() {
String type = json.get(InstructionCodec.TYPE).asText();
if (type.equals(Instruction.Type.OUTPUT.name())) {
return Instructions.createOutput(getPortNumber(json));
} else if (type.equals(Instruction.Type.NOACTION.name())) {
return Instructions.createNoAction();
} else if (type.equals(Instruction.Type.TABLE.name())) {
return Instructions.transition(nullIsIllegal(json.get(InstructionCodec.TABLE_ID)
.asInt(), InstructionCodec.TABLE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE));
} else if (type.equals(Instruction.Type.GROUP.name())) {
GroupId groupId = new DefaultGroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID)
.asInt(), InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE));
return Instructions.createGroup(groupId);
} else if (type.equals(Instruction.Type.METER.name())) {
MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID)
.asLong(), InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE));
return Instructions.meterTraffic(meterId);
} else if (type.equals(Instruction.Type.QUEUE.name())) {
long queueId = nullIsIllegal(json.get(InstructionCodec.QUEUE_ID)
.asLong(), InstructionCodec.QUEUE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE);
return Instructions.setQueue(queueId, getPortNumber(json));
} else if (type.equals(Instruction.Type.L0MODIFICATION.name())) {
return decodeL0();
} else if (type.equals(Instruction.Type.L1MODIFICATION.name())) {
return decodeL1();
} else if (type.equals(Instruction.Type.L2MODIFICATION.name())) {
return decodeL2();
} else if (type.equals(Instruction.Type.L3MODIFICATION.name())) {
return decodeL3();
} else if (type.equals(Instruction.Type.L4MODIFICATION.name())) {
return decodeL4();
} else if (type.equals(Instruction.Type.EXTENSION.name())) {
return decodeExtension();
}
throw new IllegalArgumentException("Instruction type "
+ type + " is not supported");
}
示例10: MockMeter
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
public MockMeter(DeviceId deviceId, int appId, long meterId, int id) {
this.deviceId = deviceId;
this.appId = new DefaultApplicationId(appId, String.valueOf(appId));
this.baseValue = id * 200L;
this.meterId = MeterId.meterId(meterId);
Band band = DefaultBand.builder()
.ofType(Band.Type.REMARK)
.withRate(10)
.dropPrecedence((short) 20)
.burstSize(30).build();
this.bandList = new ArrayList<>();
this.bandList.add(band);
}
示例11: process
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
@Override
public void process(ObjectNode payload) {
Long id = Long.decode(string(payload, ID));
String devId = string(payload, DEV_ID);
DeviceId deviceId = DeviceId.deviceId(devId);
MeterService ms = get(MeterService.class);
MeterId meterId = MeterId.meterId(id);
Meter meter = ms.getMeter(deviceId, meterId);
ObjectNode data = objectNode();
data.put(ID, id);
data.put(DEV_ID, devId);
data.put(APP_ID, meter.appId().name());
data.put(BYTES, meter.bytesSeen());
data.put(BURST, meter.isBurst());
data.put(LIFE, meter.life());
data.put(PACKETS, meter.packetsSeen());
data.put(STATE, meter.state().toString());
data.put(TYPE_IID, "meter");
ObjectNode rootNode = objectNode();
rootNode.set(DETAILS, data);
// NOTE: ... an alternate way of getting all the details of an item:
// Use the codec context to get a JSON of the meter. See ONOS-5976.
// TODO: rootNode.set(METER, getJsonCodecContext().encode(meter, Meter.class));
sendMessage(METER_DETAILS_RESP, rootNode);
}
示例12: allocateMeterId
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
public MeterId allocateMeterId(DeviceId deviceId) {
long maxMeters = store.getMaxMeters(networkId(), MeterFeaturesKey.key(deviceId));
if (maxMeters == 0L) {
// MeterFeatures couldn't be retrieved, trying with queryMeters
maxMeters = queryMeters(deviceId);
}
if (maxMeters == 0L) {
throw new IllegalStateException("Meters not supported by device " + deviceId);
}
final long mmeters = maxMeters;
long id = meterIdCounters.compute(deviceId, (k, v) -> {
if (v == null) {
return allocateCounter(k);
}
if (v.get() >= mmeters) {
throw new IllegalStateException("Maximum number of meters " +
meterIdCounters.get(deviceId).get() +
" reached for device " + deviceId +
" virtual network " + networkId());
}
return v;
}).incrementAndGet();
return MeterId.meterId(id);
}
示例13: allocateMeterId
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
@Override
public MeterId allocateMeterId(DeviceId deviceId) {
// Init steps
MeterId meterId;
long id;
// Try to reuse meter id
meterId = firstReusableMeterId(deviceId);
// We found a reusable id, return
if (meterId != null) {
return meterId;
}
// If there was no reusable MeterId we have to generate a new value
// using maxMeters as upper limit.
long maxMeters = getMaxMeters(MeterFeaturesKey.key(deviceId));
// If the device does not give us MeterFeatures
if (maxMeters == 0L) {
// MeterFeatures couldn't be retrieved, fallback to queryMeters.
maxMeters = queryMaxMeters(deviceId);
}
// If we don't know the max, cannot proceed
if (maxMeters == 0L) {
return null;
}
// Get a new value
id = meterIdGenerators.incrementAndGet(deviceId);
// Check with the max, and if the value is bigger, cannot proceed
if (id >= maxMeters) {
return null;
}
// Done, return the value
return MeterId.meterId(id);
}
示例14: getMeterIdFromPolicerId
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
private MeterId getMeterIdFromPolicerId(PolicerId policerId) {
// Get scheme specific part
Long id = Long.parseLong(policerId.uri().getSchemeSpecificPart(), HEX);
// Return the meter id
return MeterId.meterId(id);
}
示例15: decode
import org.onosproject.net.meter.MeterId; //导入方法依赖的package包/类
/**
* Decodes the JSON into an instruction object.
*
* @return Criterion object
* @throws IllegalArgumentException if the JSON is invalid
*/
public Instruction decode() {
String type = nullIsIllegal(json.get(InstructionCodec.TYPE),
InstructionCodec.TYPE + InstructionCodec.ERROR_MESSAGE).asText();
if (type.equals(Instruction.Type.OUTPUT.name())) {
return Instructions.createOutput(getPortNumber(json));
} else if (type.equals(Instruction.Type.NOACTION.name())) {
return Instructions.createNoAction();
} else if (type.equals(Instruction.Type.TABLE.name())) {
return Instructions.transition(nullIsIllegal(json.get(InstructionCodec.TABLE_ID),
InstructionCodec.TABLE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
} else if (type.equals(Instruction.Type.GROUP.name())) {
GroupId groupId = new GroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID),
InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
return Instructions.createGroup(groupId);
} else if (type.equals(Instruction.Type.METER.name())) {
MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID),
InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong());
return Instructions.meterTraffic(meterId);
} else if (type.equals(Instruction.Type.QUEUE.name())) {
long queueId = nullIsIllegal(json.get(InstructionCodec.QUEUE_ID),
InstructionCodec.QUEUE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong();
if (json.get(InstructionCodec.PORT) == null ||
json.get(InstructionCodec.PORT).isNull()) {
return Instructions.setQueue(queueId, null);
} else {
return Instructions.setQueue(queueId, getPortNumber(json));
}
} else if (type.equals(Instruction.Type.L0MODIFICATION.name())) {
return decodeL0();
} else if (type.equals(Instruction.Type.L1MODIFICATION.name())) {
return decodeL1();
} else if (type.equals(Instruction.Type.L2MODIFICATION.name())) {
return decodeL2();
} else if (type.equals(Instruction.Type.L3MODIFICATION.name())) {
return decodeL3();
} else if (type.equals(Instruction.Type.L4MODIFICATION.name())) {
return decodeL4();
} else if (type.equals(Instruction.Type.EXTENSION.name())) {
return decodeExtension();
} else if (type.equals(Instruction.Type.STAT_TRIGGER.name())) {
return decodeStatTrigger();
}
throw new IllegalArgumentException("Instruction type "
+ type + " is not supported");
}