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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations