Search in sources :

Example 11 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class MeterVerifyCommandTest method validMeter.

@Test
public void validMeter() throws Exception {
    switchFeaturesSetup(sw, true);
    SettableFuture<List<OFMeterConfigStatsReply>> statsReply = setupMeterConfigStatsReply();
    replayAll();
    CompletableFuture<MeterVerifyReport> result = command.execute(commandProcessor);
    OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(meterConfig.getId().getValue()).setFlags(command.makeMeterFlags()).setEntries(command.makeMeterBands()).build();
    statsReply.set(wrapMeterStatsReply(reply));
    verifySuccessCompletion(result);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 12 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class MeterVerifyCommandTest method invalidBands0.

@Test
public void invalidBands0() {
    switchFeaturesSetup(sw, true);
    SettableFuture<List<OFMeterConfigStatsReply>> statsReplyProxy = setupMeterConfigStatsReply();
    // for command2
    setupMeterConfigStatsReply();
    replayAll();
    CompletableFuture<MeterVerifyReport> result = command.execute(commandProcessor);
    // make one more command with altered config, to produce meter config flags/bands
    MeterConfig invalidConfig = new MeterConfig(meterConfig.getId(), meterConfig.getBandwidth() + 1);
    MeterVerifyCommand command2 = new MeterVerifyCommand(command.getMessageContext(), command.getSwitchId(), invalidConfig);
    // must be executed, for let .setup() method to initialize all dependencies
    command2.execute(commandProcessor);
    OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(meterConfig.getId().getValue()).setFlags(command2.makeMeterFlags()).setEntries(command2.makeMeterBands()).build();
    statsReplyProxy.set(wrapMeterStatsReply(reply));
    verifyErrorCompletion(result, SwitchIncorrectMeterException.class);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterConfig(org.openkilda.model.MeterConfig) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 13 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class MeterVerifyCommandTest method shouldVerifyInaccurateMeterBandwidth.

@Test
public void shouldVerifyInaccurateMeterBandwidth() throws Exception {
    MeterConfig validConfig = new MeterConfig(new MeterId(1), 100);
    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);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MessageContext(org.openkilda.messaging.MessageContext) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterConfig(org.openkilda.model.MeterConfig) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 14 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class SwitchManager method dumpMeters.

/**
 * {@inheritDoc}
 */
@Override
public List<OFMeterConfig> dumpMeters(final DatapathId dpid) throws SwitchOperationException {
    List<OFMeterConfig> result = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    if (sw == null) {
        throw new IllegalArgumentException(format("Switch %s was not found", dpid));
    }
    verifySwitchSupportsMeters(sw);
    OFFactory ofFactory = sw.getOFFactory();
    OFMeterConfigStatsRequest meterRequest = ofFactory.buildMeterConfigStatsRequest().setMeterId(0xffffffff).build();
    try {
        ListenableFuture<List<OFMeterConfigStatsReply>> future = sw.writeStatsRequest(meterRequest);
        List<OFMeterConfigStatsReply> values = future.get(10, TimeUnit.SECONDS);
        if (values != null) {
            result = values.stream().map(OFMeterConfigStatsReply::getEntries).flatMap(List::stream).collect(toList());
        }
    } catch (ExecutionException | TimeoutException e) {
        logger.error("Could not get meter config stats for {}.", dpid, e);
    } catch (InterruptedException e) {
        logger.error("Could not get meter config stats for {}.", dpid, e);
        Thread.currentThread().interrupt();
    }
    return result;
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFMeterConfigStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ExecutionException(java.util.concurrent.ExecutionException) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) TimeoutException(java.util.concurrent.TimeoutException)

Example 15 with OFMeterConfig

use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.

the class MetersResource method getMeters.

// FIXME(surabujin): is it used anywhere?
/**
 * Gets meters.
 * @return the map of meters.
 */
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
    Map<Long, Object> response = new HashMap<>();
    String switchId = (String) this.getRequestAttributes().get("switch_id");
    logger.debug("Get meters for switch: {}", switchId);
    ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
    try {
        List<OFMeterConfig> meters = switchManager.dumpMeters(DatapathId.of(switchId));
        if (meters != null) {
            logger.debug("Meters from switch {} received: {}", switchId, meters.size());
            for (OFMeterConfig entry : meters) {
                response.put(entry.getMeterId(), entry);
            }
        }
    } catch (UnsupportedSwitchOperationException ex) {
        String messageString = "Not supported";
        logger.error("{}: {}", messageString, switchId, ex);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, ex.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
        getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
    } catch (IllegalArgumentException | SwitchOperationException exception) {
        String messageString = "No such switch";
        logger.error("{}: {}", messageString, switchId, exception);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
    }
    return response;
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) HashMap(java.util.HashMap) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) MessageError(org.openkilda.messaging.error.MessageError) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Get(org.restlet.resource.Get)

Aggregations

OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)15 ImmutableList (com.google.common.collect.ImmutableList)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Test (org.junit.Test)6 Collections.singletonList (java.util.Collections.singletonList)5 Collectors.toList (java.util.stream.Collectors.toList)5 OFMeterConfigStatsRequest (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest)5 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)4 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)4 MeterConfig (org.openkilda.model.MeterConfig)4 OFMeterConfigStatsReply (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply)4 TimeoutException (java.util.concurrent.TimeoutException)3 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)3 AbstractSpeakerCommandTest (org.openkilda.floodlight.command.AbstractSpeakerCommandTest)3 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)3 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)3 MessageContext (org.openkilda.messaging.MessageContext)3 MeterId (org.openkilda.model.MeterId)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2