use of org.openkilda.messaging.info.rule.SwitchFlowEntries in project open-kilda by telstra.
the class RecordHandler method processDumpRulesRequest.
private void processDumpRulesRequest(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<FlowEntry> flows = flowEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowEntry).collect(Collectors.toList());
SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
sender.accept(response);
} catch (SwitchOperationException 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);
}
}
use of org.openkilda.messaging.info.rule.SwitchFlowEntries in project open-kilda by telstra.
the class YFlowValidationService method validateYFlowResources.
/**
* Validate y-flow.
*/
public YFlowDiscrepancyDto validateYFlowResources(String yFlowId, List<SwitchFlowEntries> actualSwitchFlowEntries, List<SwitchMeterEntries> actualSwitchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> actualRules = new HashMap<>();
for (SwitchFlowEntries switchRulesEntries : actualSwitchFlowEntries) {
SwitchMeterEntries switchMeters = actualSwitchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, null);
actualRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId));
List<SimpleSwitchRule> expectedRules = new ArrayList<>();
for (YSubFlow subFlow : yFlow.getSubFlows()) {
Flow flow = subFlow.getFlow();
expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getForwardPathId(), flow.getReversePathId(), yFlow.getYPoint(), yFlow.getMeterId()));
if (flow.isAllocateProtectedPath()) {
if (flow.getProtectedForwardPathId() != null && flow.getProtectedReversePathId() != null) {
expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), yFlow.getProtectedPathYPoint(), yFlow.getProtectedPathMeterId()));
} else {
log.warn("Sub-flow {} of y-flow {} has no expected protected paths", flow.getFlowId(), yFlowId);
}
}
}
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
for (SimpleSwitchRule simpleRule : expectedRules) {
discrepancies.addAll(simpleSwitchRuleComparator.findDiscrepancy(simpleRule, actualRules.get(simpleRule.getSwitchId())));
}
return YFlowDiscrepancyDto.builder().discrepancies(discrepancies).asExpected(discrepancies.isEmpty()).build();
}
use of org.openkilda.messaging.info.rule.SwitchFlowEntries in project open-kilda by telstra.
the class SwitchFlowEntriesBuilder method getSwitchFlowEntries.
/**
* Construct a list of {@link SwitchFlowEntries} that corresponds to the builder's flow.
*/
public List<SwitchFlowEntries> getSwitchFlowEntries(int forwardTransitEncapId, int reverseTransitEncapId, Integer forwardProtectedTransitEncapId, Integer reverseProtectedTransitEncapId) {
List<SwitchFlowEntries> switchEntries = new ArrayList<>();
boolean isVxlan = flow.getEncapsulationType() == FlowEncapsulationType.VXLAN;
FlowPath forwardPath = flow.getForwardPath();
FlowPath reversePath = flow.getReversePath();
long forwardCookie = forwardPath.getCookie().getValue();
long reverseCookie = reversePath.getCookie().getValue();
Optional<FlowPath> protectedForwardPath = Optional.ofNullable(flow.getProtectedForwardPath());
Optional<FlowPath> protectedReversePath = Optional.ofNullable(flow.getProtectedReversePath());
Long protectedForwardCookie = protectedForwardPath.map(FlowPath::getCookie).map(Cookie::getValue).orElse(null);
Long protectedReverseCookie = protectedReversePath.map(FlowPath::getCookie).map(Cookie::getValue).orElse(null);
List<PathSegment> forwardSegments = forwardPath.getSegments();
if (forwardSegments.isEmpty()) {
throw new IllegalArgumentException("One-switch flows are unsupported");
}
PathSegment firstSegment = forwardSegments.get(0);
switchEntries.add(buildSwitchFlowEntries(flow.getSrcSwitchId(), getFlowEntry(forwardCookie, flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncapId, isVxlan ? forwardTransitEncapId : null, forwardPath.getMeterId().getValue()), getFlowEntry(reverseCookie, firstSegment.getSrcPort(), isVxlan ? null : reverseTransitEncapId, isVxlan ? reverseTransitEncapId : null, flow.getSrcPort(), flow.getSrcVlan(), null, null)));
if (protectedForwardPath.isPresent()) {
List<PathSegment> protectedForwardSegments = protectedForwardPath.get().getSegments();
PathSegment firstProtectedSegment = protectedForwardSegments.get(0);
switchEntries.add(buildSwitchFlowEntries(flow.getSrcSwitchId(), getFlowEntry(protectedReverseCookie, firstProtectedSegment.getSrcPort(), isVxlan ? null : reverseProtectedTransitEncapId, isVxlan ? reverseProtectedTransitEncapId : null, flow.getSrcPort(), flow.getSrcVlan(), null, null)));
}
for (int i = 0; i < forwardSegments.size() - 1; i++) {
PathSegment nsegment = forwardSegments.get(i);
PathSegment n1segment = forwardSegments.get(i + 1);
switchEntries.add(buildSwitchFlowEntries(nsegment.getDestSwitchId(), getFlowEntry(forwardCookie, nsegment.getDestPort(), isVxlan ? null : forwardTransitEncapId, isVxlan ? forwardTransitEncapId : null, n1segment.getSrcPort(), null, null, null), getFlowEntry(reverseCookie, n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncapId, isVxlan ? reverseTransitEncapId : null, nsegment.getDestPort(), null, null, null)));
}
if (protectedForwardPath.isPresent()) {
List<PathSegment> forwardProtectedSegments = protectedForwardPath.get().getSegments();
for (int i = 0; i < forwardProtectedSegments.size() - 1; i++) {
PathSegment nsegment = forwardProtectedSegments.get(i);
PathSegment n1segment = forwardProtectedSegments.get(i + 1);
switchEntries.add(buildSwitchFlowEntries(nsegment.getDestSwitchId(), getFlowEntry(protectedForwardCookie, nsegment.getDestPort(), isVxlan ? null : forwardProtectedTransitEncapId, isVxlan ? forwardProtectedTransitEncapId : null, n1segment.getSrcPort(), null, null, null), getFlowEntry(protectedReverseCookie, n1segment.getSrcPort(), isVxlan ? null : reverseProtectedTransitEncapId, isVxlan ? reverseProtectedTransitEncapId : null, nsegment.getDestPort(), null, null, null)));
}
}
PathSegment lastSegment = forwardSegments.get(forwardSegments.size() - 1);
switchEntries.add(buildSwitchFlowEntries(flow.getDestSwitchId(), getFlowEntry(forwardCookie, lastSegment.getDestPort(), isVxlan ? null : forwardTransitEncapId, isVxlan ? forwardTransitEncapId : null, flow.getDestPort(), flow.getDestVlan(), null, null), getFlowEntry(reverseCookie, flow.getDestPort(), flow.getDestVlan(), null, lastSegment.getDestPort(), isVxlan ? null : reverseTransitEncapId, isVxlan ? reverseTransitEncapId : null, reversePath.getMeterId().getValue())));
if (protectedForwardPath.isPresent()) {
List<PathSegment> forwardProtectedSegments = protectedForwardPath.get().getSegments();
PathSegment lastProtectedSegment = forwardProtectedSegments.get(forwardProtectedSegments.size() - 1);
switchEntries.add(buildSwitchFlowEntries(flow.getDestSwitchId(), getFlowEntry(protectedForwardCookie, lastProtectedSegment.getDestPort(), isVxlan ? null : forwardProtectedTransitEncapId, isVxlan ? forwardProtectedTransitEncapId : null, flow.getDestPort(), flow.getDestVlan(), null, null)));
}
return switchEntries;
}
use of org.openkilda.messaging.info.rule.SwitchFlowEntries in project open-kilda by telstra.
the class FlowValidationFsm method receivedRules.
protected void receivedRules(State from, State to, Event event, Object context) {
SwitchFlowEntries switchFlowEntries = (SwitchFlowEntries) context;
log.info("Switch rules received for switch {}", switchFlowEntries.getSwitchId());
receivedRules.add(switchFlowEntries);
awaitingRules--;
checkOfCompleteDataCollection();
}
use of org.openkilda.messaging.info.rule.SwitchFlowEntries in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testFlowNotFoundError.
@Test
public void testFlowNotFoundError() 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) {
fail();
}
@Override
public void sendNorthboundResponse(Message message) {
assertEquals(ErrorType.NOT_FOUND, ((ErrorMessage) message).getData().getErrorType());
}
@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"));
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
transactionManager.doInTransaction(() -> flowRepository.remove(flowRepository.findById(TEST_FLOW_ID_A).get()));
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