use of org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory 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);
}
Aggregations