Search in sources :

Example 1 with OFMeterFlags

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);
}
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 2 with OFMeterFlags

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

Example 3 with OFMeterFlags

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

Example 4 with OFMeterFlags

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);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException)

Example 5 with OFMeterFlags

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());
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFMeterBandDrop(org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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