Search in sources :

Example 1 with IngressFlowSegmentRequest

use of org.openkilda.floodlight.api.request.IngressFlowSegmentRequest 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 2 with IngressFlowSegmentRequest

use of org.openkilda.floodlight.api.request.IngressFlowSegmentRequest in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilderTest method verifyCommonIngressRequest.

private IngressFlowSegmentRequest verifyCommonIngressRequest(Flow flow, FlowPath path, FlowSegmentRequest rawRequest) {
    assertThat("Should be egress segment request", rawRequest, instanceOf(IngressFlowSegmentRequest.class));
    IngressFlowSegmentRequest request = (IngressFlowSegmentRequest) rawRequest;
    assertEquals(flow.getFlowId(), request.getFlowId());
    assertEquals(path.getCookie(), request.getCookie());
    assertEquals(path.getSegments().get(0).getSrcPort(), (int) request.getIslPort());
    if (0 < flow.getBandwidth()) {
        MeterConfig config = new MeterConfig(path.getMeterId(), flow.getBandwidth());
        assertEquals(config, request.getMeterConfig());
    } else {
        assertNull(request.getMeterConfig());
    }
    verifyVlanEncapsulation(flow, path, request.getEncapsulation());
    return request;
}
Also used : IngressFlowSegmentRequest(org.openkilda.floodlight.api.request.IngressFlowSegmentRequest) MeterConfig(org.openkilda.model.MeterConfig)

Example 3 with IngressFlowSegmentRequest

use of org.openkilda.floodlight.api.request.IngressFlowSegmentRequest in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilderTest method verifyForwardIngressRequest.

private IngressFlowSegmentRequest verifyForwardIngressRequest(Flow flow, FlowSegmentRequest rawRequest) {
    FlowPath path = Objects.requireNonNull(flow.getForwardPath());
    IngressFlowSegmentRequest request = verifyCommonIngressRequest(flow, path, rawRequest);
    assertEquals(flow.getSrcSwitchId(), request.getSwitchId());
    FlowEndpoint endpoint = new FlowEndpoint(flow.getSrcSwitchId(), flow.getSrcPort(), flow.getSrcVlan());
    assertEquals(endpoint, request.getEndpoint());
    return request;
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) IngressFlowSegmentRequest(org.openkilda.floodlight.api.request.IngressFlowSegmentRequest) FlowPath(org.openkilda.model.FlowPath)

Example 4 with IngressFlowSegmentRequest

use of org.openkilda.floodlight.api.request.IngressFlowSegmentRequest in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilderTest method verifyReverseIngressRequest.

private IngressFlowSegmentRequest verifyReverseIngressRequest(Flow flow, FlowSegmentRequest rawRequest) {
    FlowPath path = Objects.requireNonNull(flow.getReversePath());
    IngressFlowSegmentRequest request = verifyCommonIngressRequest(flow, path, rawRequest);
    assertEquals(flow.getDestSwitchId(), request.getSwitchId());
    FlowEndpoint endpoint = new FlowEndpoint(flow.getDestSwitchId(), flow.getDestPort(), flow.getDestVlan());
    assertEquals(endpoint, request.getEndpoint());
    return request;
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) IngressFlowSegmentRequest(org.openkilda.floodlight.api.request.IngressFlowSegmentRequest) FlowPath(org.openkilda.model.FlowPath)

Aggregations

IngressFlowSegmentRequest (org.openkilda.floodlight.api.request.IngressFlowSegmentRequest)4 FlowPath (org.openkilda.model.FlowPath)3 FlowEndpoint (org.openkilda.model.FlowEndpoint)2 Test (org.junit.Test)1 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)1 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)1 Flow (org.openkilda.model.Flow)1 MeterConfig (org.openkilda.model.MeterConfig)1 Switch (org.openkilda.model.Switch)1 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)1 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)1