Search in sources :

Example 6 with OFMeterFlags

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);
}
Also used : OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFMeterBandDrop(org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop) HashSet(java.util.HashSet)

Example 7 with OFMeterFlags

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())));
}
Also used : OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) Test(org.junit.Test)

Example 8 with OFMeterFlags

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))));
    }
}
Also used : OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) Test(org.junit.Test)

Aggregations

OFMeterFlags (org.projectfloodlight.openflow.protocol.OFMeterFlags)8 OFMeterMod (org.projectfloodlight.openflow.protocol.OFMeterMod)5 Test (org.junit.Test)4 OFMeterBandDrop (org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop)3 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 EasyMock.anyLong (org.easymock.EasyMock.anyLong)1 InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)1 OFMeterConfigStatsReply (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply)1 OFMeterConfigStatsRequest (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest)1