use of org.openkilda.messaging.info.rule.SwitchGroupEntries in project open-kilda by telstra.
the class FlowValidationFsm method receivedGroups.
protected void receivedGroups(State from, State to, Event event, Object context) {
SwitchGroupEntries switchGroupEntries = (SwitchGroupEntries) context;
log.info("Switch meters received for switch {}", switchGroupEntries.getSwitchId());
receivedGroups.add(switchGroupEntries);
awaitingGroups--;
checkOfCompleteDataCollection();
}
use of org.openkilda.messaging.info.rule.SwitchGroupEntries in project open-kilda by telstra.
the class FlowValidationService method validateFlow.
/**
* Validate flow.
*/
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
int rulesCount = 0;
int metersCount = 0;
for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
}
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (!foundFlow.isPresent()) {
throw new FlowNotFoundException(flowId);
}
Flow flow = foundFlow.get();
if (flow.getForwardPath() == null) {
throw new InvalidPathException(flowId, "Forward path was not returned.");
}
if (flow.getReversePath() == null) {
throw new InvalidPathException(flowId, "Reverse path was not returned.");
}
List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
if (flow.getProtectedForwardPath() != null) {
List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
}
if (flow.getProtectedReversePath() != null) {
List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
}
return flowValidationResponse;
}
use of org.openkilda.messaging.info.rule.SwitchGroupEntries in project open-kilda by telstra.
the class FlowValidationHubService method handleAsyncResponse.
/**
* Handles async response from worker.
*
* @param key command identifier.
*/
public void handleAsyncResponse(@NonNull String key, @NonNull MessageData data) throws UnknownKeyException {
log.debug("Received command response {}", data);
FlowValidationFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
if (data instanceof SwitchFlowEntries) {
fsmExecutor.fire(fsm, Event.RULES_RECEIVED, data);
} else if (data instanceof SwitchMeterEntries) {
fsmExecutor.fire(fsm, Event.METERS_RECEIVED, data);
} else if (data instanceof SwitchMeterUnsupported) {
SwitchMeterUnsupported meterUnsupported = (SwitchMeterUnsupported) data;
log.info("Key: {}; Meters unsupported for switch '{};", key, meterUnsupported.getSwitchId());
fsmExecutor.fire(fsm, Event.METERS_RECEIVED, SwitchMeterEntries.builder().switchId(meterUnsupported.getSwitchId()).meterEntries(Collections.emptyList()).build());
} else if (data instanceof SwitchGroupEntries) {
fsmExecutor.fire(fsm, Event.GROUPS_RECEIVED, data);
} else if (data instanceof ErrorData) {
fsmExecutor.fire(fsm, Event.ERROR, data);
} else {
log.warn("Key: {}; Unhandled message {}", key, data);
}
removeIfFinished(fsm, key);
}
use of org.openkilda.messaging.info.rule.SwitchGroupEntries in project open-kilda by telstra.
the class FlowValidationTestBase method getSwitchGroupEntries.
protected List<SwitchGroupEntries> getSwitchGroupEntries() {
List<SwitchGroupEntries> switchGroupEntries = new ArrayList<>();
switchGroupEntries.add(SwitchGroupEntries.builder().switchId(TEST_SWITCH_ID_A).groupEntries(Lists.newArrayList(GroupEntry.builder().groupId(FLOW_GROUP_ID_A).buckets(Lists.newArrayList(new GroupBucket(0, FlowApplyActions.builder().flowOutput(String.valueOf(FLOW_GROUP_ID_A_OUT_PORT)).setFieldActions(Collections.singletonList(getFlowSetFieldAction(FLOW_GROUP_ID_A_OUT_VLAN))).build()), new GroupBucket(0, FlowApplyActions.builder().flowOutput(String.valueOf(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED)).build()))).build())).build());
switchGroupEntries.add(SwitchGroupEntries.builder().switchId(TEST_SWITCH_ID_C).groupEntries(Collections.emptyList()).build());
return switchGroupEntries;
}
use of org.openkilda.messaging.info.rule.SwitchGroupEntries 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);
}
}
Aggregations