use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MetersListCommand method doExecute.
@Override
protected void doExecute() {
if (!isNullOrEmpty(scopeString)) {
meterScope = MeterScope.of(scopeString);
}
if (!isNullOrEmpty(indexString)) {
index = Long.parseLong(indexString);
if (meterScope == null) {
meterScope = MeterScope.globalScope();
}
}
if (index != null) {
if (meterScope != null && meterScope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(index);
} else if (meterScope != null) {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), index);
}
}
MeterService service = get(MeterService.class);
Collection<Meter> meters;
if (isNullOrEmpty(uri)) {
meters = service.getAllMeters();
printMeters(meters);
} else {
if (meterCellId != null) {
Meter m = service.getMeter(DeviceId.deviceId(uri), meterCellId);
if (m != null) {
print("%s", m);
} else {
error("Meter %s not found for device %s", meterCellId, uri);
}
} else if (meterScope != null) {
meters = service.getMeters(DeviceId.deviceId(uri), meterScope);
printMeters(meters);
} else {
meters = service.getMeters(DeviceId.deviceId(uri));
printMeters(meters);
}
}
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MeterManagerTest method testRemoveInUserDefinedIndexMode.
/**
* Test remove meter in user defined index mode.
*/
@Test
public void testRemoveInUserDefinedIndexMode() {
initMeterStore();
testEnableUserDefinedIndex();
manager.submit(userDefinedRequest.add());
manager.withdraw(userDefinedRequest.remove(), cid0);
Meter withdrawingMeter = manager.getMeter(PROGRAMMABLE_DID, cid0);
assertThat(withdrawingMeter.state(), is(MeterState.PENDING_REMOVE));
assertEquals("The meter was not withdrawn", 1, manager.getAllMeters().size());
assertEquals("The meter was not withdrawn", 1, manager.getMeters(PROGRAMMABLE_DID).size());
pushMetrics(MeterOperation.Type.REMOVE, withdrawingMeter);
assertNull(manager.getMeter(PROGRAMMABLE_DID, cid0));
assertEquals("The meter was not removed", 0, manager.getAllMeters().size());
assertEquals("The meter was not removed", 0, manager.getMeters(PROGRAMMABLE_DID).size());
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MeterManagerTest method testGetFromMeterProgrammable.
/**
* Verify get from meter programmable.
*/
@Test
public void testGetFromMeterProgrammable() {
initMeterStore();
MeterDriverProvider fallback = (MeterDriverProvider) manager.defaultProvider();
testAddFromMeterProgrammable();
fallback.init(manager.deviceService, fallback.meterProviderService, manager.mastershipService, 1);
TestTools.assertAfter(2000, () -> {
assertEquals("The meter was not added", 1, manager.getAllMeters().size());
Meter m = manager.getMeters(PROGRAMMABLE_DID).iterator().next();
assertEquals("incorrect state", MeterState.ADDED, m.state());
});
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MeterManagerTest method testAddMultipleDevice.
/**
* Test add multiple devices.
*/
@Test
public void testAddMultipleDevice() {
initMeterStore();
manager.submit(m1Request.add());
manager.submit(m2Request.add());
assertEquals("The meter was not added", 2, manager.getAllMeters().size());
assertEquals("The meter was not added", 1, manager.getMeters(did1).size());
assertEquals("The meter was not added", 1, manager.getMeters(did2).size());
Meter installingMeter1 = manager.getMeter(did1, mid1);
Meter installingMeter2 = manager.getMeter(did2, mid1);
assertThat(installingMeter1, is(m1));
assertThat(installingMeter2, is(m2));
assertThat(installingMeter1.state(), is(MeterState.PENDING_ADD));
assertThat(installingMeter2.state(), is(MeterState.PENDING_ADD));
pushMetrics(MeterOperation.Type.ADD, installingMeter1);
pushMetrics(MeterOperation.Type.ADD, installingMeter2);
Meter installedMeter1 = manager.getMeter(did1, mid1);
Meter installedMeter2 = manager.getMeter(did2, mid1);
assertThat(installedMeter1.state(), is(MeterState.ADDED));
assertThat(installedMeter2.state(), is(MeterState.ADDED));
assertEquals("The meter was not installed", 2, manager.getAllMeters().size());
assertEquals("The meter was not installed", 1, manager.getMeters(did1).size());
assertEquals("The meter was not installed", 1, manager.getMeters(did2).size());
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MeterManagerTest method testPurge.
/**
* Test purge meter.
*/
@Test
public void testPurge() {
initMeterStore();
manager.submit(m1Request.add());
Meter submittingMeter = manager.getMeter(did1, mid1);
assertThat(submittingMeter.state(), is(MeterState.PENDING_ADD));
assertEquals("The meter was not added", 1, manager.getAllMeters().size());
assertEquals("The meter was not added", 1, manager.getMeters(did1).size());
manager.purgeMeters(did1);
assertNull(manager.getMeter(did1, mid1));
assertEquals("The meter was not purged", 0, manager.getAllMeters().size());
assertEquals("The meter was not purged", 0, manager.getMeters(did1).size());
}
Aggregations