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);
}
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());
}
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);
}
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;
}
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));
}
Aggregations