use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class RecordHandler method doDeleteSwitchRules.
private void doDeleteSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
SwitchRulesDeleteRequest request = (SwitchRulesDeleteRequest) message.getData();
logger.debug("Deleting rules from '{}' switch: action={}", request.getSwitchId(), request.getDeleteRulesAction());
DatapathId dpid = DatapathId.of(request.getSwitchId());
ISwitchManager switchManager = context.getSwitchManager();
DeleteRulesAction deleteAction = request.getDeleteRulesAction();
List<Long> removedRules = new ArrayList<>();
try {
/*
* This first part .. we are either deleting one rule, or all non-default rules (the else)
*/
List<Long> toRemove = new ArrayList<>();
if (deleteAction == DeleteRulesAction.ONE) {
toRemove.add(request.getOneCookie());
} else if (deleteAction == DeleteRulesAction.REMOVE_DROP) {
toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_BROADCAST) {
toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_UNICAST) {
toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_DEFAULTS || deleteAction == DeleteRulesAction.REMOVE_ADD) {
toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
}
// toRemove is > 0 only if we are trying to delete base rule(s).
if (toRemove.size() > 0) {
removedRules.addAll(switchManager.deleteRuleWithCookie(dpid, toRemove));
if (deleteAction == DeleteRulesAction.REMOVE_ADD) {
switchManager.installDefaultRules(dpid);
}
} else {
removedRules.addAll(switchManager.deleteAllNonDefaultRules(dpid));
/*
* The Second part - only for a subset of actions.
*/
if (deleteAction == DeleteRulesAction.DROP) {
List<Long> removedDefaultRules = switchManager.deleteDefaultRules(dpid);
// Return removedDefaultRules as a part of the result list.
removedRules.addAll(removedDefaultRules);
} else if (deleteAction == DeleteRulesAction.DROP_ADD) {
switchManager.deleteDefaultRules(dpid);
switchManager.installDefaultRules(dpid);
} else if (deleteAction == DeleteRulesAction.OVERWRITE) {
switchManager.installDefaultRules(dpid);
}
}
SwitchRulesResponse response = new SwitchRulesResponse(removedRules);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
} catch (SwitchOperationException e) {
ErrorData errorData = new ErrorData(ErrorType.DELETION_FAILURE, e.getMessage(), request.getSwitchId());
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, error);
}
}
use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class FlowsResource method getFlows.
@Get("json")
@SuppressWarnings("unchecked")
public Map<String, Object> getFlows() {
Map<String, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
LOGGER.debug("Get flows for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
OFFlowStatsReply replay = switchManager.dumpFlowTable(DatapathId.of(switchId));
LOGGER.debug("OF_STATS: {}", replay);
if (replay != null) {
for (OFFlowStatsEntry entry : replay.getEntries()) {
String key = String.format("flow-0x%s", Long.toHexString(entry.getCookie().getValue()).toUpperCase());
response.put(key, buildFlowStat(entry));
}
}
} catch (IllegalArgumentException 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;
}
use of org.openkilda.floodlight.switchmanager.ISwitchManager 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;
}
Aggregations