use of org.projectfloodlight.openflow.protocol.OFMeterFlags in project open-kilda by telstra.
the class SwitchManager method installMeter.
private long installMeter(final IOFSwitch sw, final DatapathId dpid, final long bandwidth, final long burstSize, final long meterId) throws OFInstallException {
logger.debug("installing meter {} on switch {} width bandwidth {}", meterId, dpid, bandwidth);
Set<OFMeterFlags> flags = new HashSet<>(asList(OFMeterFlags.KBPS, OFMeterFlags.BURST));
OFFactory ofFactory = sw.getOFFactory();
OFMeterBandDrop.Builder bandBuilder = ofFactory.meterBands().buildDrop().setRate(bandwidth).setBurstSize(burstSize);
OFMeterMod.Builder meterModBuilder = ofFactory.buildMeterMod().setMeterId(meterId).setCommand(OFMeterModCommand.ADD).setFlags(flags);
if (sw.getOFFactory().getVersion().compareTo(OF_13) > 0) {
meterModBuilder.setBands(singletonList(bandBuilder.build()));
} else {
meterModBuilder.setMeters(singletonList(bandBuilder.build()));
}
OFMeterMod meterMod = meterModBuilder.build();
return pushFlow(sw, "--InstallMeter--", meterMod);
}
use of org.projectfloodlight.openflow.protocol.OFMeterFlags in project open-kilda by telstra.
the class SwitchManagerTest method shouldRenstallMetersIfRateIsUpdated.
@Test
public void shouldRenstallMetersIfRateIsUpdated() throws Exception {
long unicastMeter = createMeterIdForDefaultRule(VERIFICATION_UNICAST_RULE_COOKIE).getValue();
long originRate = config.getBroadcastRateLimit();
long updatedRate = config.getBroadcastRateLimit() + 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, originRate, config.getSystemMeterBurstSizeInPackets());
replay(ofSwitchService, iofSwitch, switchDescription, featureDetectorService);
// when
Set<OFMeterFlags> flags = ImmutableSet.of(OFMeterFlags.PKTPS, OFMeterFlags.STATS, OFMeterFlags.BURST);
OFMeterMod ofMeterMod = buildMeterMod(iofSwitch.getOFFactory(), updatedRate, config.getSystemMeterBurstSizeInPackets(), 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 shouldInstallMeterWithKbpsFlag.
@Test
public void shouldInstallMeterWithKbpsFlag() throws Exception {
// 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));
mockGetMetersRequest(Collections.emptyList(), true, 0, 0);
mockBarrierRequest();
Capture<OFMeterMod> capture = EasyMock.newCapture(CaptureType.ALL);
expect(iofSwitch.write(capture(capture))).andReturn(true).times(1);
replay(ofSwitchService, iofSwitch, switchDescription, featureDetectorService);
// when
long rate = 100L;
long burstSize = 1000L;
Set<OFMeterFlags> flags = ImmutableSet.of(OFMeterFlags.KBPS, OFMeterFlags.STATS, OFMeterFlags.BURST);
OFMeterMod ofMeterMod = buildMeterMod(iofSwitch.getOFFactory(), rate, burstSize, unicastMeterId, flags, ADD);
switchManager.processMeter(iofSwitch, ofMeterMod);
// then
final List<OFMeterMod> actual = capture.getValues();
assertEquals(1, actual.size());
// verify meters creation
assertThat(actual, everyItem(hasProperty("command", equalTo(ADD))));
assertThat(actual, everyItem(hasProperty("meterId", equalTo(unicastMeterId))));
assertThat(actual, everyItem(hasProperty("flags", containsInAnyOrder(flags.toArray()))));
for (OFMeterMod mod : actual) {
assertThat(mod.getMeters(), everyItem(hasProperty("rate", is(rate))));
assertThat(mod.getMeters(), everyItem(hasProperty("burstSize", is(burstSize))));
}
}
Aggregations