Search in sources :

Example 6 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class SwitchManagerTest method mockGetMetersRequest.

private void mockGetMetersRequest(List<Long> meterIds, boolean supportsPkts, long rate, long burstSize) throws Exception {
    List<OFMeterConfig> meterConfigs = new ArrayList<>(meterIds.size());
    for (Long meterId : meterIds) {
        OFMeterBandDrop bandDrop = mock(OFMeterBandDrop.class);
        expect(bandDrop.getRate()).andStubReturn(rate);
        expect(bandDrop.getBurstSize()).andStubReturn(burstSize);
        OFMeterConfig meterConfig = mock(OFMeterConfig.class);
        expect(meterConfig.getEntries()).andStubReturn(Collections.singletonList(bandDrop));
        expect(meterConfig.getMeterId()).andStubReturn(meterId);
        Set<OFMeterFlags> flags = ImmutableSet.of(OFMeterFlags.STATS, OFMeterFlags.BURST, supportsPkts ? OFMeterFlags.PKTPS : OFMeterFlags.KBPS);
        expect(meterConfig.getFlags()).andStubReturn(flags);
        replay(bandDrop, meterConfig);
        meterConfigs.add(meterConfig);
    }
    OFMeterConfigStatsReply statsReply = mock(OFMeterConfigStatsReply.class);
    expect(statsReply.getEntries()).andStubReturn(meterConfigs);
    ListenableFuture<List<OFMeterConfigStatsReply>> ofStatsFuture = mock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Collections.singletonList(statsReply));
    replay(statsReply, ofStatsFuture);
    expect(iofSwitch.writeStatsRequest(isA(OFMeterConfigStatsRequest.class))).andStubReturn(ofStatsFuture);
}
Also used : OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFMeterConfigStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) ArrayList(java.util.ArrayList) EasyMock.anyLong(org.easymock.EasyMock.anyLong) OFMeterBandDrop(org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig)

Example 7 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class SwitchManagerTest method dumpMetersTimeoutException.

@Test
public void dumpMetersTimeoutException() throws SwitchOperationException, InterruptedException, ExecutionException, TimeoutException {
    ListenableFuture<List<OFMeterConfigStatsReply>> ofStatsFuture = createMock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andThrow(new TimeoutException());
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(switchDescription.getManufacturerDescription()).andStubReturn("");
    expect(iofSwitch.getSwitchDescription()).andStubReturn(switchDescription);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    expect(iofSwitch.writeStatsRequest(isA(OFMeterConfigStatsRequest.class))).andStubReturn(ofStatsFuture);
    replay(ofSwitchService, iofSwitch, switchDescription, ofStatsFuture);
    List<OFMeterConfig> meters = switchManager.dumpMeters(dpid);
    assertNotNull(meters);
    assertTrue(meters.isEmpty());
}
Also used : OFMeterConfigStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 8 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class MeterVerifyCommandTest method shouldVerifyInaccurateMeterBurst.

@Test
public void shouldVerifyInaccurateMeterBurst() throws Exception {
    MeterConfig validConfig = new MeterConfig(new MeterId(1), (long) (100 / 1.05));
    MeterVerifyCommand command1 = new MeterVerifyCommand(new MessageContext(), mapSwitchId(dpId), validConfig);
    switchFeaturesSetup(sw, SwitchFeature.METERS, SwitchFeature.INACCURATE_METER);
    SettableFuture<List<OFMeterConfigStatsReply>> statsReplyProxy = setupMeterConfigStatsReply();
    // for command2
    setupMeterConfigStatsReply();
    replayAll();
    CompletableFuture<MeterVerifyReport> result = command1.execute(commandProcessor);
    // make one more command with altered config, to produce meter config flags/bands
    MeterConfig invalidConfig = new MeterConfig(validConfig.getId(), validConfig.getBandwidth() + 1);
    MeterVerifyCommand command2 = new MeterVerifyCommand(command1.getMessageContext(), command1.getSwitchId(), invalidConfig);
    // must be executed, for let .setup() method to initialize all dependencies
    command2.execute(commandProcessor);
    OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(validConfig.getId().getValue()).setFlags(command2.makeMeterFlags()).setEntries(command2.makeMeterBands()).build();
    statsReplyProxy.set(wrapMeterStatsReply(reply));
    verifySuccessCompletion(result);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MessageContext(org.openkilda.messaging.MessageContext) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterConfig(org.openkilda.model.MeterConfig) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 9 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class MeterVerifyCommandTest method testBurstDeviationOnAccurateMeter.

private CompletableFuture<MeterVerifyReport> testBurstDeviationOnAccurateMeter(long deviation) {
    switchFeaturesSetup(sw, true);
    SettableFuture<List<OFMeterConfigStatsReply>> statsReplyProxy = setupMeterConfigStatsReply();
    replayAll();
    CompletableFuture<MeterVerifyReport> futureResult = command.execute(commandProcessor);
    OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(meterConfig.getId().getValue()).setFlags(command.makeMeterFlags()).setEntries(patchMeterBand(command.makeMeterBands(), 0, deviation)).build();
    statsReplyProxy.set(wrapMeterStatsReply(reply));
    return futureResult;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig)

Example 10 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class SwitchManagerTest method dumpMeters.

@Test
public void dumpMeters() throws InterruptedException, ExecutionException, TimeoutException, SwitchOperationException {
    OFMeterConfig firstMeter = ofFactory.buildMeterConfig().setMeterId(1).build();
    OFMeterConfig secondMeter = ofFactory.buildMeterConfig().setMeterId(2).build();
    ListenableFuture<List<OFMeterConfigStatsReply>> ofStatsFuture = createMock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Lists.newArrayList(ofFactory.buildMeterConfigStatsReply().setEntries(Lists.newArrayList(firstMeter)).build(), ofFactory.buildMeterConfigStatsReply().setEntries(Lists.newArrayList(secondMeter)).build()));
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(switchDescription.getManufacturerDescription()).andStubReturn("");
    expect(iofSwitch.getSwitchDescription()).andStubReturn(switchDescription);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    expect(iofSwitch.writeStatsRequest(isA(OFMeterConfigStatsRequest.class))).andStubReturn(ofStatsFuture);
    replay(ofSwitchService, iofSwitch, switchDescription, ofStatsFuture);
    List<OFMeterConfig> meters = switchManager.dumpMeters(dpid);
    assertNotNull(meters);
    assertEquals(2, meters.size());
    assertEquals(Sets.newHashSet(firstMeter, secondMeter), new HashSet<>(meters));
}
Also used : OFMeterConfigStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Test(org.junit.Test)

Aggregations

OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)15 ImmutableList (com.google.common.collect.ImmutableList)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Test (org.junit.Test)6 Collections.singletonList (java.util.Collections.singletonList)5 Collectors.toList (java.util.stream.Collectors.toList)5 OFMeterConfigStatsRequest (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest)5 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)4 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)4 MeterConfig (org.openkilda.model.MeterConfig)4 OFMeterConfigStatsReply (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply)4 TimeoutException (java.util.concurrent.TimeoutException)3 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)3 AbstractSpeakerCommandTest (org.openkilda.floodlight.command.AbstractSpeakerCommandTest)3 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)3 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)3 MessageContext (org.openkilda.messaging.MessageContext)3 MeterId (org.openkilda.model.MeterId)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2