use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method dumpRuleMangerGroupsRequest.
private void dumpRuleMangerGroupsRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Loading installed groups for switch {}", switchId);
List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = context.getSwitchManager().dumpGroups(DatapathId.of(switchId.toLong()));
List<GroupSpeakerData> groups = ofGroupDescStatsEntries.stream().map(OfGroupConverter.INSTANCE::convertToGroupSpeakerData).collect(Collectors.toList());
GroupDumpResponse response = GroupDumpResponse.builder().switchId(switchId).groupSpeakerData(groups).build();
sender.accept(response);
} catch (SwitchOperationException e) {
logger.error("Dumping of groups on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a groups dump.").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doInstallFlowForSwitchManager.
/**
* Install of flow on the switch from SwitchManager topology.
*
* @param message with list of flows.
*/
private void doInstallFlowForSwitchManager(final CommandMessage message) {
InstallFlowForSwitchManagerRequest request = (InstallFlowForSwitchManagerRequest) message.getData();
String replyToTopic = context.getKafkaSwitchManagerTopic();
FlowSegmentResponseFactory responseFactory = new FlowSegmentSyncResponseFactory(message.getCorrelationId(), replyToTopic);
MessageContext messageContext = new MessageContext(message);
Optional<FlowSegmentWrapperCommand> syncCommand = makeSyncCommand(request.getFlowCommand(), messageContext, responseFactory);
if (syncCommand.isPresent()) {
handleSpeakerCommand(syncCommand.get());
return;
}
try {
installFlow(request.getFlowCommand());
} catch (SwitchOperationException e) {
logger.error("Error during flow installation", e);
ErrorData errorData = new ErrorData(ErrorType.INTERNAL_ERROR, "Error during flow installation", "Switch operation error");
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId());
getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), error);
} catch (FlowCommandException e) {
String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
logger.error("Failed to handle message {}: {}", message, errorMessage);
ErrorData errorData = new FlowCommandErrorData(e.getFlowId(), e.getCookie(), e.getTransactionId(), e.getErrorType(), errorMessage, e.getMessage());
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId());
getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), error);
}
InfoMessage response = new InfoMessage(new FlowInstallResponse(), System.currentTimeMillis(), message.getCorrelationId());
getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class SwitchManager method updatePortStatus.
private void updatePortStatus(IOFSwitch sw, int portNumber, boolean isAdminDown) throws SwitchOperationException {
Set<OFPortConfig> config = new HashSet<>(1);
if (isAdminDown) {
config.add(OFPortConfig.PORT_DOWN);
}
Set<OFPortConfig> portMask = ImmutableSet.of(OFPortConfig.PORT_DOWN);
final OFFactory ofFactory = sw.getOFFactory();
OFPortMod ofPortMod = ofFactory.buildPortMod().setPortNo(OFPort.of(portNumber)).setHwAddr(getPortHwAddress(sw, portNumber)).setConfig(config).setMask(portMask).build();
if (!sw.write(ofPortMod)) {
throw new SwitchOperationException(sw.getId(), format("Unable to update port configuration: %s", ofPortMod));
}
logger.debug("Successfully updated port status {}", ofPortMod);
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class SwitchManager method removeFlowByOfFlowDelete.
private List<Long> removeFlowByOfFlowDelete(DatapathId dpid, int tableId, OFFlowDelete dropFlowDelete) throws SwitchOperationException {
List<OFFlowStatsEntry> flowStatsBefore = dumpFlowTable(dpid, tableId);
IOFSwitch sw = lookupSwitch(dpid);
pushFlow(sw, "--DeleteFlow--", dropFlowDelete);
// Wait for OFFlowDelete to be processed.
sendBarrierRequest(sw);
List<OFFlowStatsEntry> flowStatsAfter = dumpFlowTable(dpid, tableId);
Set<Long> cookiesAfter = flowStatsAfter.stream().map(entry -> entry.getCookie().getValue()).collect(toSet());
return flowStatsBefore.stream().map(entry -> entry.getCookie().getValue()).filter(cookie -> !cookiesAfter.contains(cookie)).peek(cookie -> logger.info("Rule with cookie {} has been removed from switch {}.", cookie, dpid)).collect(toList());
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class SwitchManager method deleteRulesByCriteria.
@Override
public List<Long> deleteRulesByCriteria(DatapathId dpid, boolean multiTable, RuleType ruleType, DeleteRulesCriteria... criteria) throws SwitchOperationException {
List<OFFlowStatsEntry> flowStatsBefore = dumpFlowTable(dpid);
IOFSwitch sw = lookupSwitch(dpid);
OFFactory ofFactory = sw.getOFFactory();
for (DeleteRulesCriteria criteriaEntry : criteria) {
OFFlowDelete dropFlowDelete = buildFlowDeleteByCriteria(ofFactory, criteriaEntry, multiTable, ruleType);
logger.info("Rules by criteria {} are to be removed from switch {}.", criteria, dpid);
pushFlow(sw, "--DeleteFlow--", dropFlowDelete);
}
// Wait for OFFlowDelete to be processed.
sendBarrierRequest(sw);
List<OFFlowStatsEntry> flowStatsAfter = dumpFlowTable(dpid);
Set<Long> cookiesAfter = flowStatsAfter.stream().map(entry -> entry.getCookie().getValue()).collect(Collectors.toSet());
return flowStatsBefore.stream().map(entry -> entry.getCookie().getValue()).filter(cookie -> !cookiesAfter.contains(cookie)).peek(cookie -> logger.info("Rule with cookie {} has been removed from switch {}.", cookie, dpid)).collect(toList());
}
Aggregations