use of org.openkilda.model.MirrorConfig 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.MirrorConfig in project open-kilda by telstra.
the class CommandBuilderImpl method buildCommandsToSyncMissingRules.
@Override
public List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules) {
List<BaseFlow> commands = new ArrayList<>(buildInstallDefaultRuleCommands(switchId, switchRules));
commands.addAll(buildInstallFlowSharedRuleCommands(switchId, switchRules));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
log.info("Rule {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
commands.addAll(buildInstallCommandFromSegment(flowPath, segment, switchRulesContainsFlowPathCookie, switchRulesContainsMirrorCookie));
}
});
SwitchProperties switchProperties = getSwitchProperties(switchId);
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
log.info("One-switch flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
if (switchRulesContainsMirrorCookie) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
commands.add(flowCommandFactory.makeOneSwitchMirrorRule(flow, flowPath, mirrorConfig));
}
if (switchRulesContainsFlowPathCookie) {
commands.add(flowCommandFactory.makeOneSwitchRule(flow, flowPath));
}
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
log.info("Ingress flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for ingress flow rule");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
if (switchRulesContainsMirrorCookie) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
commands.add(flowCommandFactory.buildInstallIngressMirrorFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable(), mirrorConfig));
}
if (switchRulesContainsFlowPathCookie) {
commands.add(flowCommandFactory.buildInstallIngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
}
}
}
}
long server42Cookie = flowPath.getCookie().toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build().getValue();
if (switchRules.contains(server42Cookie) && !flowPath.isOneSwitchFlow() && flowPath.getSrcSwitchId().equals(switchId)) {
log.info("Ingress server 42 flow {} is to be (re)installed on switch {}", server42Cookie, switchId);
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for server 42 ingress flow rule {}", server42Cookie);
} else {
Flow flow = getFlow(flowPath);
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
commands.add(flowCommandFactory.buildInstallServer42IngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), switchProperties.getServer42Port(), switchProperties.getServer42MacAddress(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
}
}
long loopCookie = flowPath.getCookie().toBuilder().looped(true).build().getValue();
if (switchRules.contains(loopCookie)) {
log.info("Loop rule with cookie {} is to be reinstalled on switch {}", loopCookie, switchId);
Flow flow = getFlow(flowPath);
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
if (flowPath.getSrcSwitch().getSwitchId().equals(switchId)) {
boolean srcWithMultiTable = flowPath.getSegments().get(0).isSrcWithMultiTable();
commands.add(flowCommandFactory.buildInstallIngressLoopFlow(flow, flowPath, encapsulationResources, srcWithMultiTable));
} else {
PathSegment lastSegment = flowPath.getSegments().get(flowPath.getSegments().size() - 1);
boolean destWithMultiTable = lastSegment.isDestWithMultiTable();
commands.add(flowCommandFactory.buildInstallTransitLoopFlow(flow, flowPath, lastSegment.getDestPort(), encapsulationResources, destWithMultiTable));
}
}
});
return commands;
}
use of org.openkilda.model.MirrorConfig in project open-kilda by telstra.
the class CommandBuilderImpl method buildGroupInstallContexts.
@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
Flow flow = flowPath.getFlow();
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
});
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for mirror config");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
}
});
return groupInstallContexts;
}
use of org.openkilda.model.MirrorConfig in project open-kilda by telstra.
the class CommandBuilderImpl method buildInstallCommandFromSegment.
private List<BaseInstallFlow> buildInstallCommandFromSegment(FlowPath flowPath, PathSegment segment, boolean switchRulesContainsFlowPathCookie, boolean switchRulesContainsMirrorCookie) {
if (segment.getSrcSwitchId().equals(segment.getDestSwitchId())) {
log.warn("One-switch flow segment {} is provided", flowPath.getCookie());
return new ArrayList<>();
}
Optional<Flow> foundFlow = flowRepository.findById(flowPath.getFlow().getFlowId());
if (!foundFlow.isPresent()) {
log.warn("Flow with id {} was not found", flowPath.getFlow().getFlowId());
return new ArrayList<>();
}
Flow flow = foundFlow.get();
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
List<BaseInstallFlow> commands = new ArrayList<>();
if (switchRulesContainsMirrorCookie) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
commands.add(flowCommandFactory.buildInstallEgressMirrorFlow(flowPath, segment.getDestPort(), encapsulationResources, segment.isDestWithMultiTable(), mirrorConfig));
}
if (switchRulesContainsFlowPathCookie) {
commands.add(flowCommandFactory.buildInstallEgressFlow(flowPath, segment.getDestPort(), encapsulationResources, segment.isDestWithMultiTable()));
}
return commands;
} else {
int segmentIdx = flowPath.getSegments().indexOf(segment);
if (segmentIdx < 0 || segmentIdx + 1 == flowPath.getSegments().size()) {
log.warn("Paired segment for switch {} and cookie {} has not been found", segment.getDestSwitchId(), flowPath.getCookie());
return new ArrayList<>();
}
PathSegment foundPairedFlowSegment = flowPath.getSegments().get(segmentIdx + 1);
return Collections.singletonList(flowCommandFactory.buildInstallTransitFlow(flowPath, segment.getDestSwitchId(), segment.getDestPort(), foundPairedFlowSegment.getSrcPort(), encapsulationResources, segment.isDestWithMultiTable()));
}
}
use of org.openkilda.model.MirrorConfig in project open-kilda by telstra.
the class RecordHandler method doInstallGroupRequest.
private void doInstallGroupRequest(CommandMessage message) {
SwitchId switchId = ((InstallGroupRequest) message.getData()).getSwitchId();
MirrorConfig mirrorConfig = ((InstallGroupRequest) message.getData()).getMirrorConfig();
FlowTransitEncapsulation encapsulation = ((InstallGroupRequest) message.getData()).getEncapsulation();
SwitchId egressSwitchId = ((InstallGroupRequest) message.getData()).getEgressSwitchId();
FlowTransitData flowTransitData = null;
if (encapsulation != null) {
flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
}
logger.debug("Install group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
handleSpeakerCommand(new GroupInstallCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
InstallGroupResponse response = new InstallGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
String correlationId = message.getCorrelationId();
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
Aggregations