use of org.openkilda.messaging.info.switches.SwitchRulesResponse in project open-kilda by telstra.
the class SwitchServiceImpl method installRules.
@Override
public List<Long> installRules(String switchId, InstallRulesAction installAction, String correlationId) {
LOGGER.debug("Install switch rules request received");
SwitchRulesInstallRequest data = new SwitchRulesInstallRequest(switchId, installAction);
CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
messageProducer.send(floodlightTopic, request);
Message message = messageConsumer.poll(correlationId);
SwitchRulesResponse response = (SwitchRulesResponse) validateInfoMessage(request, message, correlationId);
return response.getRuleIds();
}
use of org.openkilda.messaging.info.switches.SwitchRulesResponse in project open-kilda by telstra.
the class RecordHandler method doInstallSwitchRules.
private void doInstallSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
SwitchRulesInstallRequest request = (SwitchRulesInstallRequest) message.getData();
logger.debug("Installing rules on '{}' switch: action={}", request.getSwitchId(), request.getInstallRulesAction());
DatapathId dpid = DatapathId.of(request.getSwitchId());
ISwitchManager switchManager = context.getSwitchManager();
InstallRulesAction installAction = request.getInstallRulesAction();
List<Long> installedRules = new ArrayList<>();
try {
if (installAction == InstallRulesAction.INSTALL_DROP) {
switchManager.installDropFlow(dpid);
installedRules.add(ISwitchManager.DROP_RULE_COOKIE);
} else if (installAction == InstallRulesAction.INSTALL_BROADCAST) {
switchManager.installVerificationRule(dpid, true);
installedRules.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
} else if (installAction == InstallRulesAction.INSTALL_UNICAST) {
// TODO: this isn't always added (ie if OF1.2). Is there a better response?
switchManager.installVerificationRule(dpid, false);
installedRules.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
} else {
switchManager.installDefaultRules(dpid);
installedRules.addAll(asList(ISwitchManager.DROP_RULE_COOKIE, ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE, ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE));
}
SwitchRulesResponse response = new SwitchRulesResponse(installedRules);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
} catch (SwitchOperationException e) {
ErrorData errorData = new ErrorData(ErrorType.CREATION_FAILURE, e.getMessage(), request.getSwitchId());
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, error);
}
}
use of org.openkilda.messaging.info.switches.SwitchRulesResponse 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.messaging.info.switches.SwitchRulesResponse in project open-kilda by telstra.
the class SwitchServiceImpl method deleteRules.
@Override
public List<Long> deleteRules(String switchId, DeleteRulesAction deleteAction, Long cookie, String correlationId) {
LOGGER.debug("Delete switch rules request received");
// TODO: remove messageConsumer.clear() as a part of NB cleanup (clear isn't required)
messageConsumer.clear();
SwitchRulesDeleteRequest data = new SwitchRulesDeleteRequest(switchId, deleteAction, cookie);
CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
messageProducer.send(floodlightTopic, request);
Message message = messageConsumer.poll(correlationId);
SwitchRulesResponse response = (SwitchRulesResponse) validateInfoMessage(request, message, correlationId);
return response.getRuleIds();
}
Aggregations