Search in sources :

Example 6 with SwitchFlowEntries

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);
    }
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 7 with SwitchFlowEntries

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();
}
Also used : YFlow(org.openkilda.model.YFlow) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) HashMap(java.util.HashMap) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) PathDiscrepancyEntity(org.openkilda.messaging.info.flow.PathDiscrepancyEntity) SwitchId(org.openkilda.model.SwitchId) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with SwitchFlowEntries

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;
}
Also used : SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath)

Example 9 with SwitchFlowEntries

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();
}
Also used : SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries)

Example 10 with SwitchFlowEntries

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);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) Test(org.junit.Test)

Aggregations

SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)10 SwitchMeterEntries (org.openkilda.messaging.info.meter.SwitchMeterEntries)6 List (java.util.List)4 SwitchGroupEntries (org.openkilda.messaging.info.rule.SwitchGroupEntries)4 SwitchId (org.openkilda.model.SwitchId)4 ArrayList (java.util.ArrayList)3 ErrorData (org.openkilda.messaging.error.ErrorData)3 FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Message (org.openkilda.messaging.Message)2 CommandData (org.openkilda.messaging.command.CommandData)2 FlowValidationRequest (org.openkilda.messaging.command.flow.FlowValidationRequest)2 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)2 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)2 DumpRulesForFlowHsRequest (org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 InfoData (org.openkilda.messaging.info.InfoData)2 SwitchMeterUnsupported (org.openkilda.messaging.info.meter.SwitchMeterUnsupported)2 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)2