Search in sources :

Example 6 with Meter

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);
        }
    }
}
Also used : Meter(org.onosproject.net.meter.Meter) MeterService(org.onosproject.net.meter.MeterService)

Example 7 with Meter

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());
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) Test(org.junit.Test)

Example 8 with Meter

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());
    });
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) Test(org.junit.Test)

Example 9 with Meter

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());
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) Test(org.junit.Test)

Example 10 with Meter

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());
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) Test(org.junit.Test)

Aggregations

Meter (org.onosproject.net.meter.Meter)45 DefaultMeter (org.onosproject.net.meter.DefaultMeter)32 Test (org.junit.Test)21 DeviceId (org.onosproject.net.DeviceId)12 MeterService (org.onosproject.net.meter.MeterService)8 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)8 MeterCellId (org.onosproject.net.meter.MeterCellId)7 MeterKey (org.onosproject.net.meter.MeterKey)7 Produces (javax.ws.rs.Produces)6 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Band (org.onosproject.net.meter.Band)5 DefaultBand (org.onosproject.net.meter.DefaultBand)4 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)4 MeterOperation (org.onosproject.net.meter.MeterOperation)4 MeterRequest (org.onosproject.net.meter.MeterRequest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3