use of org.projectfloodlight.openflow.protocol.OFMeterFlags 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.OFMeterFlags in project open-kilda by telstra.
the class SwitchManagerTest method shouldRenstallMetersIfBurstSizeIsUpdated.
@Test
public void shouldRenstallMetersIfBurstSizeIsUpdated() throws Exception {
long unicastMeter = createMeterIdForDefaultRule(VERIFICATION_UNICAST_RULE_COOKIE).getValue();
long originBurstSize = config.getSystemMeterBurstSizeInPackets();
long updatedBurstSize = config.getSystemMeterBurstSizeInPackets() + 10;
// given
expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
expect(iofSwitch.getSwitchDescription()).andStubReturn(switchDescription);
expect(iofSwitch.getId()).andStubReturn(dpid);
expect(switchDescription.getManufacturerDescription()).andStubReturn(StringUtils.EMPTY);
expect(featureDetectorService.detectSwitch(iofSwitch)).andStubReturn(Sets.newHashSet(PKTPS_FLAG));
Capture<OFMeterMod> capture = EasyMock.newCapture(CaptureType.ALL);
// 1 meter deletion + 1 meters installation
expect(iofSwitch.write(capture(capture))).andReturn(true).times(2);
mockBarrierRequest();
mockGetMetersRequest(Lists.newArrayList(unicastMeter), true, config.getUnicastRateLimit(), originBurstSize);
replay(ofSwitchService, iofSwitch, switchDescription, featureDetectorService);
// when
Set<OFMeterFlags> flags = ImmutableSet.of(OFMeterFlags.PKTPS, OFMeterFlags.STATS, OFMeterFlags.BURST);
OFMeterMod ofMeterMod = buildMeterMod(iofSwitch.getOFFactory(), config.getUnicastRateLimit(), updatedBurstSize, unicastMeter, flags, ADD);
switchManager.processMeter(iofSwitch, ofMeterMod);
final List<OFMeterMod> actual = capture.getValues();
assertEquals(2, actual.size());
// verify meters deletion
assertThat(actual.get(0), hasProperty("command", equalTo(OFMeterModCommand.DELETE)));
// verify meter installation
assertThat(actual.get(1), hasProperty("command", equalTo(ADD)));
assertThat(actual.get(1), hasProperty("meterId", equalTo(unicastMeter)));
assertThat(actual.get(1), hasProperty("flags", containsInAnyOrder(flags.toArray())));
}
use of org.projectfloodlight.openflow.protocol.OFMeterFlags in project open-kilda by telstra.
the class SwitchManagerTest method shouldReinstallMeterIfFlagIsIncorrect.
@Test
public void shouldReinstallMeterIfFlagIsIncorrect() throws Exception {
long expectedRate = config.getUnicastRateLimit();
// given
expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
expect(iofSwitch.getSwitchDescription()).andStubReturn(switchDescription);
expect(iofSwitch.getId()).andStubReturn(dpid);
// define that switch is Centec
expect(switchDescription.getManufacturerDescription()).andStubReturn("Centec Inc.");
expect(featureDetectorService.detectSwitch(iofSwitch)).andStubReturn(Sets.newHashSet(METERS));
mockBarrierRequest();
mockGetMetersRequest(Lists.newArrayList(unicastMeterId), false, expectedRate, config.getSystemMeterBurstSizeInPackets());
Capture<OFMeterMod> capture = EasyMock.newCapture(CaptureType.ALL);
expect(iofSwitch.write(capture(capture))).andReturn(true).times(2);
replay(ofSwitchService, iofSwitch, switchDescription, featureDetectorService);
// when
Set<OFMeterFlags> flags = ImmutableSet.of(OFMeterFlags.KBPS, OFMeterFlags.BURST);
OFMeterMod ofMeterMod = buildMeterMod(iofSwitch.getOFFactory(), expectedRate, config.getSystemMeterBurstSizeInPackets(), unicastMeterId, flags, ADD);
switchManager.processMeter(iofSwitch, ofMeterMod);
// verify meters installation
final List<OFMeterMod> actual = capture.getValues();
assertEquals(2, actual.size());
// verify meters deletion
assertThat(actual.get(0), hasProperty("command", equalTo(OFMeterModCommand.DELETE)));
// verify meter installation
assertThat(actual.get(1), hasProperty("command", equalTo(ADD)));
assertThat(actual.get(1), hasProperty("meterId", equalTo(unicastMeterId)));
assertThat(actual.get(1), hasProperty("flags", containsInAnyOrder(flags.toArray())));
}
use of org.projectfloodlight.openflow.protocol.OFMeterFlags in project open-kilda by telstra.
the class SwitchManager method modifyMeterForFlow.
/**
* {@inheritDoc}
*/
@Override
public void modifyMeterForFlow(DatapathId dpid, long meterId, long bandwidth) throws SwitchOperationException {
if (!MeterId.isMeterIdOfFlowRule(meterId)) {
throw new InvalidMeterIdException(dpid, format("Could not modify meter '%d' on switch '%s'. Meter Id is invalid. Valid meter id range is " + "[%d, %d]", meterId, dpid, MeterId.MIN_FLOW_METER_ID, MeterId.MAX_FLOW_METER_ID));
}
IOFSwitch sw = lookupSwitch(dpid);
verifySwitchSupportsMeters(sw);
long burstSize = Meter.calculateBurstSize(bandwidth, config.getFlowMeterMinBurstSizeInKbits(), config.getFlowMeterBurstCoefficient(), sw.getSwitchDescription().getManufacturerDescription(), sw.getSwitchDescription().getSoftwareDescription());
Set<OFMeterFlags> flags = Arrays.stream(Meter.getMeterKbpsFlags()).map(OFMeterFlags::valueOf).collect(Collectors.toSet());
modifyMeter(sw, bandwidth, burstSize, meterId, flags);
}
use of org.projectfloodlight.openflow.protocol.OFMeterFlags in project open-kilda by telstra.
the class SwitchManager method processMeter.
@VisibleForTesting
void processMeter(IOFSwitch sw, OFMeterMod meterMod) {
long meterId = meterMod.getMeterId();
OFMeterConfig actualMeterConfig;
try {
actualMeterConfig = getMeter(sw.getId(), meterId);
} catch (SwitchOperationException e) {
logger.warn("Meter {} won't be installed on the switch {}: {}", meterId, sw.getId(), e.getMessage());
return;
}
OFMeterBandDrop actualMeterBandDrop = Optional.ofNullable(actualMeterConfig).map(OFMeterConfig::getEntries).flatMap(entries -> entries.stream().findFirst()).map(OFMeterBandDrop.class::cast).orElse(null);
try {
OFMeterBandDrop expectedMeterBandDrop = sw.getOFFactory().getVersion().compareTo(OF_13) > 0 ? (OFMeterBandDrop) meterMod.getBands().get(0) : (OFMeterBandDrop) meterMod.getMeters().get(0);
long expectedRate = expectedMeterBandDrop.getRate();
long expectedBurstSize = expectedMeterBandDrop.getBurstSize();
Set<OFMeterFlags> expectedFlags = meterMod.getFlags();
if (actualMeterBandDrop != null && actualMeterBandDrop.getRate() == expectedRate && actualMeterBandDrop.getBurstSize() == expectedBurstSize && CollectionUtils.isEqualCollection(actualMeterConfig.getFlags(), expectedFlags)) {
logger.debug("Meter {} won't be reinstalled on switch {}. It already exists", meterId, sw.getId());
return;
}
if (actualMeterBandDrop != null) {
logger.info("Meter {} on switch {} has rate={}, burst size={} and flags={} but it must have " + "rate={}, burst size={} and flags={}. Meter will be reinstalled.", meterId, sw.getId(), actualMeterBandDrop.getRate(), actualMeterBandDrop.getBurstSize(), actualMeterConfig.getFlags(), expectedRate, expectedBurstSize, expectedFlags);
buildAndDeleteMeter(sw, sw.getId(), meterId);
sendBarrierRequest(sw);
}
installMeterMod(sw, meterMod);
} catch (SwitchOperationException e) {
logger.warn("Failed to (re)install meter {} on switch {}: {}", meterId, sw.getId(), e.getMessage());
}
}
Aggregations