use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doReinstallDefaultFlowForSwitchManager.
/**
* Reinstall default flow.
*
* @param message command message for flow deletion
*/
private void doReinstallDefaultFlowForSwitchManager(CommandMessage message) {
ReinstallDefaultFlowForSwitchManagerRequest request = (ReinstallDefaultFlowForSwitchManagerRequest) message.getData();
IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaSwitchManagerTopic();
long cookie = request.getCookie();
if (!Cookie.isDefaultRule(cookie)) {
logger.warn("Failed to reinstall default switch rule for switch: '{}'. Rule {} is not default.", request.getSwitchId(), Long.toHexString(cookie));
anError(ErrorType.DATA_INVALID).withMessage(format("Failed to reinstall default switch rule for switch %s. Rule %s is not default", request.getSwitchId(), Long.toHexString(cookie))).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
SwitchId switchId = request.getSwitchId();
DatapathId dpid = DatapathId.of(switchId.toLong());
try {
RemoveFlow command = RemoveFlow.builder().flowId("REMOVE_DEFAULT_FLOW").cookie(cookie).switchId(switchId).build();
Set<Long> removedFlows = new HashSet<>(processDeleteFlow(command, dpid));
for (Long removedFlow : removedFlows) {
Long installedFlow;
if (request instanceof ReinstallServer42FlowForSwitchManagerRequest) {
installedFlow = processInstallServer42Rule((ReinstallServer42FlowForSwitchManagerRequest) request);
} else {
installedFlow = processInstallDefaultFlowByCookie(switchId, removedFlow);
}
InfoMessage response = new InfoMessage(new FlowReinstallResponse(removedFlow, installedFlow), System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
}
} catch (SwitchOperationException e) {
logger.error("Failed to reinstall switch rule for switch: '{}'", request.getSwitchId(), e);
anError(ErrorType.INTERNAL_ERROR).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doModifyMeterRequest.
private void doModifyMeterRequest(CommandMessage message) {
MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
final IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaNbWorkerTopic();
SwitchId switchId = request.getSwitchId();
DatapathId datapathId = DatapathId.of(switchId.toLong());
long meterId = request.getMeterId();
ISwitchManager switchManager = context.getSwitchManager();
try {
switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
} catch (UnsupportedSwitchOperationException e) {
String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
logger.error(messageString, e);
anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchNotFoundException e) {
logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchOperationException e) {
String messageString = "Unable to update meter";
logger.error(messageString, e);
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doDeleteFlowForSwitchManager.
/**
* Removes flow.
*
* @param message command message for flow deletion
*/
private void doDeleteFlowForSwitchManager(final CommandMessage message) {
RemoveFlowForSwitchManagerRequest request = (RemoveFlowForSwitchManagerRequest) message.getData();
IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaSwitchManagerTopic();
DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
try {
processDeleteFlow(request.getFlowCommand(), dpid);
InfoMessage response = new InfoMessage(new FlowRemoveResponse(), System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
} catch (SwitchOperationException e) {
logger.error("Failed to process switch rule deletion for switch: '{}'", request.getSwitchId(), e);
anError(ErrorType.DELETION_FAILURE).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doInstallIslDefaultRule.
private void doInstallIslDefaultRule(CommandMessage message) {
InstallIslDefaultRulesCommand toSetup = (InstallIslDefaultRulesCommand) message.getData();
InstallIslDefaultRulesResult result = new InstallIslDefaultRulesResult(toSetup.getSrcSwitch(), toSetup.getSrcPort(), toSetup.getDstSwitch(), toSetup.getDstPort(), true);
DatapathId dpid = DatapathId.of(toSetup.getSrcSwitch().toLong());
try {
if (toSetup.isMultitableMode()) {
context.getSwitchManager().installMultitableEndpointIslRules(dpid, toSetup.getSrcPort());
}
if (toSetup.isServer42IslRtt()) {
context.getSwitchManager().installServer42IslRttInputFlow(dpid, toSetup.getServer42Port(), toSetup.getSrcPort());
}
} catch (SwitchOperationException e) {
logger.error("Failed to install isl rules for switch: '{}'", toSetup.getSrcSwitch(), e);
result.setSuccess(false);
}
getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), record.key(), new InfoMessage(result, System.currentTimeMillis(), message.getCorrelationId(), context.getRegion()));
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doConfigurePort.
private void doConfigurePort(final CommandMessage message) {
PortConfigurationRequest request = (PortConfigurationRequest) message.getData();
logger.info("Port configuration request. Switch '{}', Port '{}'", request.getSwitchId(), request.getPortNumber());
final IKafkaProducerService producerService = getKafkaProducer();
final String replyToTopic = context.getKafkaNorthboundTopic();
try {
ISwitchManager switchManager = context.getSwitchManager();
DatapathId dpId = DatapathId.of(request.getSwitchId().toLong());
switchManager.configurePort(dpId, request.getPortNumber(), request.getAdminDown());
InfoMessage infoMessage = new InfoMessage(new PortConfigurationResponse(request.getSwitchId(), request.getPortNumber()), message.getTimestamp(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, infoMessage);
} catch (SwitchOperationException e) {
logger.error("Port configuration request failed. " + e.getMessage(), e);
anError(ErrorType.DATA_INVALID).withMessage(e.getMessage()).withDescription("Port configuration request failed").withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
Aggregations