use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchManager method buildExpectedServer42FlowRttFlows.
@Override
public List<OFFlowMod> buildExpectedServer42FlowRttFlows(DatapathId dpid, boolean server42FlowRttFeatureToggle, boolean server42FlowRttSwitchProperty, Integer server42Port, Integer server42Vlan, org.openkilda.model.MacAddress server42MacAddress, Set<Integer> customerPorts) throws SwitchNotFoundException {
List<SwitchFlowGenerator> generators = new ArrayList<>();
if (server42FlowRttFeatureToggle) {
generators.add(switchFlowFactory.getServer42FlowRttTurningFlowGenerator());
generators.add(switchFlowFactory.getServer42FlowRttVxlanTurningFlowGenerator());
if (server42FlowRttSwitchProperty) {
for (Integer port : customerPorts) {
generators.add(switchFlowFactory.getServer42FlowRttInputFlowGenerator(server42Port, port, server42MacAddress));
}
generators.add(switchFlowFactory.getServer42FlowRttOutputVlanFlowGenerator(server42Port, server42Vlan, server42MacAddress));
generators.add(switchFlowFactory.getServer42FlowRttOutputVxlanFlowGenerator(server42Port, server42Vlan, server42MacAddress));
}
}
IOFSwitch sw = lookupSwitch(dpid);
return generators.stream().map(g -> g.generateFlow(sw)).map(SwitchFlowTuple::getFlow).filter(Objects::nonNull).collect(toList());
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchManager method dumpFlowTable.
/**
* {@inheritDoc}
*/
@Override
public List<OFFlowStatsEntry> dumpFlowTable(final DatapathId dpid) throws SwitchNotFoundException {
List<OFFlowStatsEntry> entries = new ArrayList<>();
IOFSwitch sw = lookupSwitch(dpid);
OFFactory ofFactory = sw.getOFFactory();
OFFlowStatsRequest flowRequest = ofFactory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(U64.ZERO).build();
try {
Future<List<OFFlowStatsReply>> future = sw.writeStatsRequest(flowRequest);
List<OFFlowStatsReply> values = future.get(10, TimeUnit.SECONDS);
if (values != null) {
entries = values.stream().map(OFFlowStatsReply::getEntries).flatMap(List::stream).collect(toList());
}
} catch (ExecutionException | TimeoutException e) {
logger.error("Could not get flow stats for {}.", dpid, e);
throw new SwitchNotFoundException(dpid);
} catch (InterruptedException e) {
logger.error("Could not get flow stats for {}.", dpid, e);
Thread.currentThread().interrupt();
throw new SwitchNotFoundException(dpid);
}
return entries;
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchTrackingService method switchDiscoveryAction.
private void switchDiscoveryAction(DatapathId dpId, SwitchChangeType event) {
logger.info("Send switch discovery ({} - {})", dpId, event);
SwitchInfoData payload = null;
if (SwitchChangeType.DEACTIVATED != event && SwitchChangeType.REMOVED != event) {
try {
IOFSwitch sw = switchManager.lookupSwitch(dpId);
SpeakerSwitchView switchView = buildSwitch(sw);
payload = buildSwitchMessage(sw, switchView, event);
} catch (SwitchNotFoundException | InvalidConnectionDataException e) {
logger.error("Switch {} is not in management state now({}), switch ISL discovery details will be degraded.", dpId, e.getMessage());
}
}
if (payload == null) {
payload = buildSwitchMessage(dpId, event);
}
emitDiscoveryEvent(dpId, payload);
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class EnableBfdResource method enableBfd.
/**
* Setting up BFD session.
*
* @param json the json from request.
* @return json response.
* @throws JsonProcessingException if response can't be wrote to string.
*/
@Post("json")
@Put("json")
public String enableBfd(String json) {
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
NoviBfdSession request;
try {
request = MAPPER.readValue(json, NoviBfdSession.class);
if (request.getIntervalMs() < CONSTRAINT_INTERVAL_MIN) {
throw new IllegalArgumentException(String.format("Invalid bfd session interval value: %d < %d", request.getIntervalMs(), CONSTRAINT_INTERVAL_MIN));
}
DatapathId datapathIdtarget = DatapathId.of(request.getTarget().getDatapath().toLong());
IOFSwitch iofSwitch = switchManager.lookupSwitch(datapathIdtarget);
OFPacketOut outPacket = makeSessionConfigMessage(request, iofSwitch, switchManager);
if (!iofSwitch.write(outPacket)) {
throw new IllegalStateException("Failed to set up BFD session");
}
} catch (IOException e) {
logger.error("Message received is not valid BFD Request: {}", json);
MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, now(), ErrorType.DATA_INVALID.toString(), "Message received is not valid BFD Request", e.getMessage());
return generateJson(responseMessage);
} catch (SwitchNotFoundException e) {
MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, now(), ErrorType.DATA_INVALID.toString(), "Switch not found", e.getMessage());
return generateJson(responseMessage);
}
return generateJson("ok");
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class RecordHandler method processDumpRuleManagerRulesRequest.
private void processDumpRuleManagerRulesRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Loading installed rules for switch {}", switchId);
List<OFFlowStatsEntry> flowEntries = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId.toLong()));
List<FlowSpeakerData> flows = flowEntries.stream().map(entry -> OfFlowConverter.INSTANCE.convertToFlowSpeakerData(entry, switchId)).collect(Collectors.toList());
FlowDumpResponse response = FlowDumpResponse.builder().switchId(switchId).flowSpeakerData(flows).build();
sender.accept(response);
} catch (SwitchNotFoundException e) {
logger.error("Dumping of rules 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 rules dump.").buildData();
sender.accept(errorData);
}
}
Aggregations