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));
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldBuildFlowPathFor1SwitchPath.
@Test
public void shouldBuildFlowPathFor1SwitchPath() {
SwitchId switchId = new SwitchId(1);
Path path = Path.builder().srcSwitchId(switchId).destSwitchId(switchId).segments(Collections.emptyList()).build();
Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(switchId).build()).destSwitch(Switch.builder().switchId(switchId).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(pathId, flowPath.getPathId());
assertEquals(meterId, flowPath.getMeterId());
assertEquals(cookie, flowPath.getCookie());
assertThat(flowPath.getSegments(), empty());
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class SpeakerFlowSegmentRequestBuilder method makeOneSwitchRequest.
private List<FlowSegmentRequestFactory> makeOneSwitchRequest(CommandContext context, FlowPath path, FlowSideAdapter ingressSide, FlowSideAdapter egressSide, RulesContext rulesContext, MirrorContext mirrorContext) {
Flow flow = ingressSide.getFlow();
UUID commandId = commandIdGenerator.generate();
MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
FlowSegmentMetadata metadata = makeMetadata(path, ensureEqualMultiTableFlag(path.isSrcWithMultiTable(), path.isDestWithMultiTable(), String.format("Flow(id:%s) have incompatible for one-switch flow per-side multi-table flags - " + "src(%s) != dst(%s)", flow.getFlowId(), path.isSrcWithMultiTable(), path.isDestWithMultiTable())));
List<FlowSegmentRequestFactory> oneSwitchFactories = new ArrayList<>();
if (!mirrorContext.isBuildMirrorFactoryOnly()) {
oneSwitchFactories.add(OneSwitchFlowRequestFactory.builder().messageContext(messageContext).metadata(metadata).endpoint(ingressSide.getEndpoint()).meterConfig(getMeterConfig(path)).egressEndpoint(egressSide.getEndpoint()).rulesContext(rulesContext).build());
}
Optional<MirrorConfig> mirrorConfig = makeMirrorConfig(path, egressSide.getEndpoint(), mirrorContext);
if (mirrorConfig.isPresent() || mirrorContext.isRemoveFlowOperation()) {
FlowSegmentCookie mirrorCookie = path.getCookie().toBuilder().mirror(true).build();
oneSwitchFactories.add(OneSwitchMirrorFlowRequestFactory.builder().messageContext(new MessageContext(commandIdGenerator.generate().toString(), context.getCorrelationId())).metadata(makeMetadata(metadata.getFlowId(), mirrorCookie, metadata.isMultiTable())).endpoint(ingressSide.getEndpoint()).meterConfig(getMeterConfig(path)).egressEndpoint(egressSide.getEndpoint()).rulesContext(rulesContext).mirrorConfig(mirrorConfig.orElse(null)).build());
}
return oneSwitchFactories;
}
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);
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class StartReroutingYFlowAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
YFlow yFlow = getYFlow(yFlowId);
saveOldResources(stateMachine, yFlow);
stateMachine.setDeleteOldYFlowCommands(buildYFlowDeleteCommands(yFlow, stateMachine.getCommandContext()));
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
return yFlow.getSubFlows().stream().map(YSubFlow::getFlow).flatMap(flow -> Stream.of(flow.getForwardPath(), flow.getReversePath())).filter(path -> sharedSwitchId.equals(path.getSrcSwitchId())).collect(Collectors.toList());
});
stateMachine.setOldYFlowPathCookies(flowPaths.stream().map(FlowPath::getCookie).map(FlowSegmentCookie::getValue).collect(Collectors.toList()));
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
stateMachine.setOldSharedPath(sharedPath);
List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
stateMachine.setOldSubFlowPathDtos(subFlowPathDtos);
}
Aggregations