Search in sources :

Example 1 with OFMeterConfigStatsReply

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

the class SwitchManager method dumpMeters.

/**
 * {@inheritDoc}
 */
@Override
public OFMeterConfigStatsReply dumpMeters(final DatapathId dpid) throws SwitchOperationException {
    OFMeterConfigStatsReply values = null;
    IOFSwitch sw = lookupSwitch(dpid);
    if (sw == null) {
        throw new IllegalArgumentException(String.format("Switch %s was not found", dpid.toString()));
    }
    OFFactory ofFactory = sw.getOFFactory();
    OFMeterConfigStatsRequest meterRequest = ofFactory.buildMeterConfigStatsRequest().setMeterId(0xffffffff).build();
    try {
        ListenableFuture<OFMeterConfigStatsReply> future = sw.writeRequest(meterRequest);
        values = future.get(5, TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        logger.error("Could not get meter config stats: {}", e.getMessage());
    }
    return values;
}
Also used : OFMeterConfigStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with OFMeterConfigStatsReply

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

the class MetersResource method getMeters.

// FIXME(surabujin): is it used anywhere?
@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 {
        OFMeterConfigStatsReply replay = switchManager.dumpMeters(DatapathId.of(switchId));
        logger.debug("Meters from switch {} received: {}", switchId, replay);
        if (replay != null) {
            for (OFMeterConfig entry : replay.getEntries()) {
                response.put(entry.getMeterId(), entry);
            }
        }
    } catch (IllegalArgumentException | SwitchOperationException exception) {
        String messageString = "No such switch";
        logger.error("{}: {}", messageString, switchId, exception);
        MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
    }
    return response;
}
Also used : SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) HashMap(java.util.HashMap) MessageError(org.openkilda.messaging.error.MessageError) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Get(org.restlet.resource.Get)

Aggregations

OFMeterConfigStatsReply (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply)2 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)1 SwitchOperationException (org.openkilda.floodlight.switchmanager.SwitchOperationException)1 MessageError (org.openkilda.messaging.error.MessageError)1 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)1 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)1 OFMeterConfigStatsRequest (org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest)1 Get (org.restlet.resource.Get)1