Search in sources :

Example 51 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class YFlowSwitchFlowEntriesBuilder method getFlowEntries.

/**
 * Construct a set of {@link FlowEntry} that corresponds to the builder's y-flow.
 */
public Map<SwitchId, Collection<FlowEntry>> getFlowEntries() {
    MultiValuedMap<SwitchId, FlowEntry> flowEntries = new ArrayListValuedHashMap<>();
    yFlow.getSubFlows().forEach(subFlow -> {
        Flow flow = subFlow.getFlow();
        SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
        int forwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getForwardPathId()).orElseThrow(IllegalStateException::new);
        int reverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getReversePathId()).orElseThrow(IllegalStateException::new);
        Integer protectedForwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedForwardPathId()).orElse(null);
        Integer protectedReverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedReversePathId()).orElse(null);
        builder.getSwitchFlowEntries(forwardTransitEncId, reverseTransitEncId, protectedForwardTransitEncId, protectedReverseTransitEncId).forEach(entries -> flowEntries.putAll(entries.getSwitchId(), entries.getFlowEntries()));
        FlowPath forwardPath = flow.getForwardPath();
        PathSegment firstSegment = forwardPath.getSegments().get(0);
        FlowSegmentCookie forwardCookie = forwardPath.getCookie().toBuilder().yFlow(true).build();
        boolean isVxlan = flow.getEncapsulationType() == VXLAN;
        flowEntries.put(forwardPath.getSrcSwitchId(), builder.getFlowEntry(forwardCookie.getValue(), flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncId, isVxlan ? forwardTransitEncId : null, yFlow.getSharedEndpointMeterId().getValue()));
        if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
            FlowPath reversePath = flow.getReversePath();
            FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
            List<PathSegment> reverseSegments = reversePath.getSegments();
            for (int i = 0; i < reverseSegments.size() - 1; i++) {
                PathSegment nsegment = reverseSegments.get(i);
                PathSegment n1segment = reverseSegments.get(i + 1);
                if (nsegment.getDestSwitchId().equals(yFlow.getYPoint())) {
                    flowEntries.put(yFlow.getYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getMeterId().getValue()));
                }
            }
        }
        if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
            FlowPath reversePath = flow.getProtectedReversePath();
            FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
            List<PathSegment> reverseSegments = reversePath.getSegments();
            for (int i = 0; i < reverseSegments.size() - 1; i++) {
                PathSegment nsegment = reverseSegments.get(i);
                PathSegment n1segment = reverseSegments.get(i + 1);
                if (nsegment.getDestSwitchId().equals(yFlow.getProtectedPathYPoint())) {
                    flowEntries.put(yFlow.getProtectedPathYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getProtectedPathMeterId().getValue()));
                }
            }
        }
    });
    return flowEntries.asMap();
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) SwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder) FlowPath(org.openkilda.model.FlowPath) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap)

Example 52 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class AbstractYFlowTest method verifyAffinity.

protected void verifyAffinity(String yFlowId) {
    YFlow flow = getYFlow(yFlowId);
    Set<String> affinityGroups = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getAffinityGroupId).collect(Collectors.toSet());
    assertEquals(1, affinityGroups.size());
    String affinityGroupId = affinityGroups.iterator().next();
    Set<String> subFlowIds = flow.getSubFlows().stream().map(YSubFlow::getSubFlowId).collect(Collectors.toSet());
    assertTrue(subFlowIds.contains(affinityGroupId));
}
Also used : YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 53 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class AbstractYFlowTest method verifyYFlowAndSubFlowStatus.

protected void verifyYFlowAndSubFlowStatus(String yFlowId, FlowStatus expectedStatus) {
    YFlow flow = getYFlow(yFlowId);
    assertEquals(expectedStatus, flow.getStatus());
    flow.getSubFlows().forEach(subFlow -> {
        assertEquals(expectedStatus, subFlow.getFlow().getStatus());
    });
}
Also used : YFlow(org.openkilda.model.YFlow)

Example 54 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class AbstractYFlowTest method verifyYFlowStatus.

protected void verifyYFlowStatus(String yFlowId, FlowStatus expectedStatus) {
    YFlow flow = getYFlow(yFlowId);
    assertEquals(expectedStatus, flow.getStatus());
}
Also used : YFlow(org.openkilda.model.YFlow)

Example 55 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class PersistenceDataAdapterTest method shouldProvideCorrectYFlows.

@Test
public void shouldProvideCorrectYFlows() {
    PathId pathId = new PathId("path1");
    Set<PathId> pathIds = Sets.newHashSet(pathId);
    YFlow yFlow = YFlow.builder().yFlowId("flow").sharedEndpoint(new SharedEndpoint(SWITCH_ID_1, 1)).build();
    Map<PathId, YFlow> yFlows = new HashMap<>();
    yFlows.put(pathId, yFlow);
    when(flowPathRepository.findYFlowsByPathIds(pathIds)).thenReturn(yFlows);
    adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
    YFlow actual = adapter.getYFlow(pathId);
    assertEquals(yFlow, actual);
    adapter.getYFlow(new PathId("test"));
    verify(flowPathRepository).findYFlowsByPathIds(pathIds);
    verifyNoMoreInteractions(flowPathRepository);
}
Also used : PathId(org.openkilda.model.PathId) YFlow(org.openkilda.model.YFlow) HashMap(java.util.HashMap) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) Test(org.junit.Test)

Aggregations

YFlow (org.openkilda.model.YFlow)74 Flow (org.openkilda.model.Flow)30 SwitchId (org.openkilda.model.SwitchId)29 YSubFlow (org.openkilda.model.YSubFlow)26 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)19 Test (org.junit.Test)12 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)12 ArrayList (java.util.ArrayList)11 FlowStatus (org.openkilda.model.FlowStatus)10 CommandContext (org.openkilda.wfm.CommandContext)10 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)10 FlowPath (org.openkilda.model.FlowPath)9 FlowEndpoint (org.openkilda.model.FlowEndpoint)8 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 Switch (org.openkilda.model.Switch)6 HashSet (java.util.HashSet)5 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)5 SharedEndpoint (org.openkilda.model.YFlow.SharedEndpoint)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4