use of org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest in project open-kilda by telstra.
the class ControllerToSpeakerSharedProxyBolt method handleRegionNotFoundError.
private void handleRegionNotFoundError(CommandMessage commandMessage, SwitchId switchId) {
String errorDetails = String.format("Switch %s not found", switchId.toString());
ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, errorDetails, errorDetails);
ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), commandMessage.getCorrelationId(), null);
Tuple input = getCurrentTuple();
if (commandMessage.getData() instanceof DumpRulesForFlowHsRequest || commandMessage.getData() instanceof DumpMetersForFlowHsRequest) {
MessageContext messageContext = new MessageContext(commandMessage);
SpeakerDataResponse result = new SpeakerDataResponse(messageContext, errorData);
// FIXME(surabujin): there is no subscriber on this stream now
getOutput().emit(Stream.FLOWHS_WORKER, input, makeFlowHsWorkerTuple(commandMessage.getCorrelationId(), result));
} else if (commandMessage.getData() instanceof DumpRulesForSwitchManagerRequest || commandMessage.getData() instanceof DumpMetersForSwitchManagerRequest || commandMessage.getData() instanceof InstallFlowForSwitchManagerRequest || commandMessage.getData() instanceof RemoveFlowForSwitchManagerRequest || commandMessage.getData() instanceof ReinstallDefaultFlowForSwitchManagerRequest) {
getOutput().emit(Stream.KILDA_SWITCH_MANAGER, input, makeSwitchManagerTuple(commandMessage.getCorrelationId(), errorMessage));
} else if (commandMessage.getData() instanceof DumpSwitchPortsDescriptionRequest || commandMessage.getData() instanceof DumpPortDescriptionRequest || commandMessage.getData() instanceof DumpRulesRequest || commandMessage.getData() instanceof DumpMetersRequest || commandMessage.getData() instanceof DeleteMeterRequest || commandMessage.getData() instanceof PortConfigurationRequest) {
getOutput().emit(Stream.NORTHBOUND_REPLY, input, makeNorthboundTuple(commandMessage.getCorrelationId(), errorMessage));
} else {
log.error("Unable to lookup region for message: {}. switch is not tracked.", commandMessage);
}
}
use of org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest in project open-kilda by telstra.
the class FlowValidationFsm method receiveData.
protected void receiveData(State from, State to, Event event, Object context) {
Flow flow;
try {
flow = service.checkFlowStatusAndGetFlow(flowId);
} catch (FlowNotFoundException e) {
log.error("Flow {} not found when sending commands to SpeakerWorkerBolt", flowId, e);
sendException(e.getMessage(), "Receiving rules operation in FlowValidationFsm", ErrorType.NOT_FOUND);
return;
} catch (IllegalFlowStateException e) {
log.error("Could not validate flow: Flow {} is in DOWN state", flowId, e);
sendException("Could not validate flow", format("Could not validate flow: Flow %s is in DOWN state", flowId), ErrorType.UNPROCESSABLE_REQUEST);
return;
}
List<SwitchId> switchIds = service.getSwitchIdListByFlowId(flowId);
awaitingRules = switchIds.size();
log.debug("Send commands to get rules on the switches");
switchIds.forEach(switchId -> getCarrier().sendSpeakerRequest(flowId, new DumpRulesForFlowHsRequest(switchId)));
log.debug("Send commands to get meters on the termination switches");
awaitingMeters = TERMINATION_SWITCHES_COUNT;
getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getSrcSwitchId()));
getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getDestSwitchId()));
log.debug("Send commands to get groups on the termination switches");
awaitingGroups = TERMINATION_SWITCHES_COUNT;
getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getSrcSwitchId()));
getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getDestSwitchId()));
}
use of org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testMainPath.
@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {
@Override
public void sendSpeakerRequest(String flowId, CommandData commandData) {
assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
if (commandData instanceof DumpRulesForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
} else {
assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
}
}
@Override
public void sendNorthboundResponse(List<? extends InfoData> message) {
assertEquals(4, message.size());
try {
assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
} catch (FlowNotFoundException | SwitchNotFoundException e) {
// tested in the FlowValidationServiceTest
}
}
@Override
public void sendNorthboundResponse(Message message) {
fail();
}
@Override
public void cancelTimeoutCallback(String key) {
assertEquals(TEST_KEY, key);
}
@Override
public void sendInactive() {
}
};
flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
buildTransitVlanFlow("");
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
}
for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
}
for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
}
}
use of org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest in project open-kilda by telstra.
the class YFlowValidationHubServiceTest method handleSpeakerRequests.
private void handleSpeakerRequests(YFlowValidationHubService service, String yFlowFsmKey, Map<SwitchId, Collection<FlowEntry>> flowEntries, Map<SwitchId, Collection<MeterEntry>> meterEntries, Map<SwitchId, Collection<GroupEntry>> groupEntries) {
handleSpeakerRequests(pair -> {
CommandData commandData = pair.getValue();
InfoData result = null;
if (commandData instanceof DumpRulesForFlowHsRequest) {
SwitchId switchId = ((DumpRulesForFlowHsRequest) commandData).getSwitchId();
Collection<FlowEntry> foundFlowEntries = flowEntries.get(switchId);
result = SwitchFlowEntries.builder().switchId(switchId).flowEntries(foundFlowEntries != null ? new ArrayList<>(foundFlowEntries) : emptyList()).build();
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
SwitchId switchId = ((DumpMetersForFlowHsRequest) commandData).getSwitchId();
Collection<MeterEntry> foundMeterEntries = meterEntries.get(switchId);
result = SwitchMeterEntries.builder().switchId(switchId).meterEntries(foundMeterEntries != null ? new ArrayList<>(foundMeterEntries) : emptyList()).build();
} else if (commandData instanceof DumpGroupsForFlowHsRequest) {
SwitchId switchId = ((DumpGroupsForFlowHsRequest) commandData).getSwitchId();
Collection<GroupEntry> foundGroupEntries = groupEntries.get(switchId);
result = SwitchGroupEntries.builder().switchId(switchId).groupEntries(foundGroupEntries != null ? new ArrayList<>(foundGroupEntries) : emptyList()).build();
} else {
fail();
}
String flowId = pair.getKey();
service.handleAsyncResponse(yFlowFsmKey, flowId, result);
});
}
use of org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest in project open-kilda by telstra.
the class RecordHandler method doDumpMetersForFlowHsRequest.
private void doDumpMetersForFlowHsRequest(CommandMessage message) {
DumpMetersForFlowHsRequest request = (DumpMetersForFlowHsRequest) message.getData();
dumpMeters(request.getSwitchId(), buildSenderToFlowHs(message));
}
Aggregations