Search in sources :

Example 1 with FlowSegmentCookie

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

the class FlowCommandFactory method buildInstallServer42IngressFlow.

/**
 * Generate install server 42 ingress flow command.
 *
 * @param flow the flow.
 * @param flowPath flow path with segments to be used for building of install rules.
 * @param outputPort the number of output port.
 * @param resources the encapsulation resources.
 * @return install server 42 ingress flow command
 */
public InstallServer42IngressFlow buildInstallServer42IngressFlow(Flow flow, FlowPath flowPath, int outputPort, int server42Port, MacAddress server42MacAddress, EncapsulationResources resources, boolean multiTable) {
    boolean isForward = flow.isForward(flowPath);
    SwitchId switchId = isForward ? flow.getSrcSwitchId() : flow.getDestSwitchId();
    SwitchId egressSwitchId = isForward ? flow.getDestSwitchId() : flow.getSrcSwitchId();
    int customerPort = isForward ? flow.getSrcPort() : flow.getDestPort();
    int inputOuterVlan = isForward ? flow.getSrcVlan() : flow.getDestVlan();
    int inputInnerVlan = isForward ? flow.getSrcInnerVlan() : flow.getDestInnerVlan();
    long cookie = new FlowSegmentCookie(flowPath.getCookie().getValue()).toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build().getValue();
    return new InstallServer42IngressFlow(transactionIdGenerator.generate(), flow.getFlowId(), cookie, switchId, server42Port, outputPort, customerPort, inputOuterVlan, inputInnerVlan, resources.getTransitEncapsulationId(), resources.getEncapsulationType(), egressSwitchId, server42MacAddress, multiTable);
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) InstallServer42IngressFlow(org.openkilda.messaging.command.flow.InstallServer42IngressFlow) SwitchId(org.openkilda.model.SwitchId) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 2 with FlowSegmentCookie

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

the class SpeakerFlowSegmentRequestBuilderTest method useActualFlowEndpoint.

@Test
public void useActualFlowEndpoint() {
    Switch srcSwitch = Switch.builder().switchId(SWITCH_1).build();
    Switch destSwitch = Switch.builder().switchId(SWITCH_2).build();
    // having flow stored in DB
    Flow origin = buildFlow(srcSwitch, 1, 5, destSwitch, 2, 0, 0);
    setSegmentsWithoutTransitSwitches(Objects.requireNonNull(origin.getForwardPath()), Objects.requireNonNull(origin.getReversePath()));
    // then new set of paths are created
    FlowPath goalForwardPath = buildFlowPath(origin, origin.getSrcSwitch(), origin.getDestSwitch(), new FlowSegmentCookie(FlowPathDirection.FORWARD, cookieFactory.next()));
    FlowPath goalReversePath = buildFlowPath(origin, origin.getDestSwitch(), origin.getSrcSwitch(), new FlowSegmentCookie(FlowPathDirection.REVERSE, cookieFactory.next()));
    setSegmentsWithTransitSwitches(goalForwardPath, goalReversePath);
    // than new version of flow is created to fulfill update request
    Flow goal = Flow.builder().flowId(origin.getFlowId()).srcSwitch(origin.getSrcSwitch()).srcPort(origin.getSrcPort()).srcVlan(// update
    origin.getSrcVlan() + 10).destSwitch(origin.getDestSwitch()).destPort(origin.getDestPort()).destVlan(origin.getDestVlan()).bandwidth(origin.getBandwidth()).encapsulationType(origin.getEncapsulationType()).build();
    // emulate db behaviour - flow will have "existing" paths after fetching it from DB
    goal.setForwardPath(origin.getForwardPath());
    goal.setReversePath(origin.getReversePath());
    goal.addPaths(goalForwardPath, goalReversePath);
    // then produce path segment request factories
    List<FlowSegmentRequestFactory> commands = target.buildIngressOnly(COMMAND_CONTEXT, goal, goalForwardPath, goalReversePath, SpeakerRequestBuildContext.getEmpty());
    boolean haveMatch = false;
    for (FlowSegmentRequestFactory entry : commands) {
        // search command for flow source side
        if (SWITCH_1.equals(entry.getSwitchId())) {
            haveMatch = true;
            Assert.assertTrue(entry instanceof IngressFlowSegmentRequestFactory);
            IngressFlowSegmentRequestFactory segment = (IngressFlowSegmentRequestFactory) entry;
            IngressFlowSegmentRequest request = segment.makeInstallRequest(commandIdGenerator.generate());
            Assert.assertEquals(goal.getSrcVlan(), request.getEndpoint().getOuterVlanId());
        }
    }
    Assert.assertTrue(haveMatch);
}
Also used : IngressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) IngressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory) Switch(org.openkilda.model.Switch) IngressFlowSegmentRequest(org.openkilda.floodlight.api.request.IngressFlowSegmentRequest) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 3 with FlowSegmentCookie

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

the class SimpleSwitchRuleConverterTest method shouldConvertLoopedFlowPathWithTransitVlanEncapToSimpleSwitchRules.

@Test
public void shouldConvertLoopedFlowPathWithTransitVlanEncapToSimpleSwitchRules() {
    Flow flow = buildFlow(FlowEncapsulationType.TRANSIT_VLAN);
    flow.setLoopSwitchId(flow.getSrcSwitchId());
    List<SimpleSwitchRule> expectedSwitchRules = getSimpleSwitchRuleForTransitVlan();
    expectedSwitchRules.add(SimpleSwitchRule.builder().switchId(TEST_SWITCH_ID_A).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_VALUE).toBuilder().looped(true).build().getValue()).inPort(FLOW_A_SRC_PORT).outPort(FLOW_A_SRC_PORT).inVlan(FLOW_A_SRC_VLAN).build());
    List<SimpleSwitchRule> switchRules = simpleSwitchRuleConverter.convertFlowPathToSimpleSwitchRules(flow, flow.getForwardPath(), TransitVlan.builder().flowId(TEST_FLOW_ID_A).pathId(FLOW_A_FORWARD_PATH_ID).vlan(FLOW_A_ENCAP_ID).build(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
    assertEquals(expectedSwitchRules.size(), switchRules.size());
    assertTrue(expectedSwitchRules.containsAll(switchRules));
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 4 with FlowSegmentCookie

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

the class FlowMapperTest method buildFlow.

private Flow buildFlow() {
    Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).destSwitch(Switch.builder().switchId(DST_SWITCH_ID).build()).allocateProtectedPath(true).build();
    FlowPath forwardFlowPath = FlowPath.builder().pathId(new PathId("forward_flow_path")).srcSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).destSwitch(Switch.builder().switchId(DST_SWITCH_ID).build()).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1)).status(FlowPathStatus.ACTIVE).build();
    flow.setForwardPath(forwardFlowPath);
    FlowPath reverseFlowPath = FlowPath.builder().pathId(new PathId("reverse_flow_path")).srcSwitch(Switch.builder().switchId(DST_SWITCH_ID).build()).destSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 1)).status(FlowPathStatus.ACTIVE).build();
    flow.setReversePath(reverseFlowPath);
    FlowPath forwardProtectedFlowPath = FlowPath.builder().pathId(new PathId("forward_protected_flow_path")).srcSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).destSwitch(Switch.builder().switchId(DST_SWITCH_ID).build()).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 2)).status(FlowPathStatus.INACTIVE).build();
    flow.setProtectedForwardPath(forwardProtectedFlowPath);
    FlowPath reverseProtectedFlowPath = FlowPath.builder().pathId(new PathId("reverse_protected_flow_path")).srcSwitch(Switch.builder().switchId(DST_SWITCH_ID).build()).destSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 2)).status(FlowPathStatus.INACTIVE).build();
    flow.setProtectedReversePath(reverseProtectedFlowPath);
    return flow;
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 5 with FlowSegmentCookie

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

the class FlowPathBuilderTest method shouldBuildFlowPathFor3SwitchPath.

@Test
public void shouldBuildFlowPathFor3SwitchPath() {
    SwitchId switchId1 = new SwitchId(1);
    SwitchId switchId2 = new SwitchId(2);
    SwitchId switchId3 = new SwitchId(3);
    Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId2).segments(asList(Segment.builder().srcSwitchId(switchId1).srcPort(1).destSwitchId(switchId3).destPort(2).build(), Segment.builder().srcSwitchId(switchId3).srcPort(1).destSwitchId(switchId2).destPort(2).build())).build();
    Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(switchId1).build()).destSwitch(Switch.builder().switchId(switchId2).build()).build();
    PathId pathId = new PathId("test_path_id");
    MeterId meterId = new MeterId(MeterId.MIN_FLOW_METER_ID);
    PathResources pathResources = PathResources.builder().pathId(pathId).meterId(meterId).build();
    FlowSegmentCookie cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1);
    FlowPath flowPath = builder.buildFlowPath(flow, pathResources, path, cookie, false, flow.getFlowId());
    assertEquals(switchId1, flowPath.getSrcSwitchId());
    assertEquals(switchId2, flowPath.getDestSwitchId());
    assertEquals(pathId, flowPath.getPathId());
    assertEquals(meterId, flowPath.getMeterId());
    assertEquals(cookie, flowPath.getCookie());
    assertThat(flowPath.getSegments(), hasSize(2));
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PathResources(org.openkilda.wfm.share.flow.resources.FlowResources.PathResources) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Aggregations

FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)59 Flow (org.openkilda.model.Flow)33 FlowPath (org.openkilda.model.FlowPath)31 PathId (org.openkilda.model.PathId)23 MeterId (org.openkilda.model.MeterId)19 Test (org.junit.Test)15 PathSegment (org.openkilda.model.PathSegment)15 Switch (org.openkilda.model.Switch)15 ArrayList (java.util.ArrayList)8 SwitchId (org.openkilda.model.SwitchId)8 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)6 UUID (java.util.UUID)5 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)5 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)5 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)5 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)4 MirrorConfig (org.openkilda.model.MirrorConfig)4 YFlow (org.openkilda.model.YFlow)4 Before (org.junit.Before)3 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)3