use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class EgressMirrorRuleGeneratorTest method buildMirrorPoints.
private static FlowMirrorPoints buildMirrorPoints(Switch sw) {
FlowMirrorPoints mirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(sw).mirrorGroup(MirrorGroup.builder().flowId(FLOW_ID).pathId(PATH_ID).groupId(GROUP_ID).switchId(SWITCH_ID_2).mirrorDirection(MirrorDirection.EGRESS).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).build()).build();
mirrorPoints.addPaths(FlowMirrorPath.builder().mirrorSwitch(SWITCH_2).egressSwitch(SWITCH_2).pathId(PATH_ID).egressPort(MIRROR_PORT).egressOuterVlan(MIRROR_VLAN).build());
return mirrorPoints;
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class IngressMirrorRuleGeneratorTest method buildMirrorPoints.
private static FlowMirrorPoints buildMirrorPoints(Switch sw) {
FlowMirrorPoints mirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(sw).mirrorGroup(MirrorGroup.builder().flowId(FLOW_ID).pathId(PATH_ID).groupId(GROUP_ID).switchId(SWITCH_ID_1).mirrorDirection(MirrorDirection.EGRESS).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).build()).build();
mirrorPoints.addPaths(FlowMirrorPath.builder().mirrorSwitch(SWITCH_1).egressSwitch(SWITCH_1).pathId(PATH_ID).egressPort(MIRROR_PORT).egressOuterVlan(MIRROR_VLAN).build());
return mirrorPoints;
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class IngressMirrorRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
List<SpeakerData> result = new ArrayList<>();
FlowMirrorPoints mirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(points -> sw.getSwitchId().equals(points.getMirrorSwitchId())).findFirst().orElse(null);
if (mirrorPoints == null) {
return result;
}
FlowEndpoint ingressEndpoint = checkAndBuildIngressEndpoint(flow, flowPath, sw.getSwitchId());
FlowSpeakerData ingressCommand = buildFlowIngressCommand(sw, ingressEndpoint, mirrorPoints.getMirrorGroupId());
result.add(ingressCommand);
SpeakerData groupCommand = buildGroup(sw, mirrorPoints);
result.add(groupCommand);
ingressCommand.getDependsOn().add(groupCommand.getUuid());
if (sharedMeterCommandUuid != null) {
ingressCommand.getDependsOn().add(sharedMeterCommandUuid);
}
return result;
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildIngressSimpleSwitchRules.
/**
* Build ingress rules ({@link SimpleSwitchRule}) for provided {@link FlowPath}.
*/
public List<SimpleSwitchRule> buildIngressSimpleSwitchRules(Flow flow, FlowPath flowPath, EncapsulationId encapsulationId, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient) {
boolean forward = flow.isForward(flowPath);
int inPort = forward ? flow.getSrcPort() : flow.getDestPort();
int outPort = forward ? flow.getDestPort() : flow.getSrcPort();
SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(flowPath.getSrcSwitchId()).cookie(flowPath.getCookie().getValue()).inPort(inPort).meterId(flowPath.getMeterId() != null ? flowPath.getMeterId().getValue() : null).meterRate(flow.getBandwidth()).meterBurstSize(Meter.calculateBurstSize(flow.getBandwidth(), flowMeterMinBurstSizeInKbits, flowMeterBurstCoefficient, flowPath.getSrcSwitch().getDescription())).meterFlags(Meter.getMeterKbpsFlags()).ingressRule(true).build();
FlowSideAdapter ingress = FlowSideAdapter.makeIngressAdapter(flow, flowPath);
FlowEndpoint endpoint = ingress.getEndpoint();
if (flowPath.isSrcWithMultiTable()) {
// in multi-table mode actual ingress rule will match port+inner_vlan+metadata(outer_vlan)
if (FlowEndpoint.isVlanIdSet(endpoint.getInnerVlanId())) {
rule.setInVlan(endpoint.getInnerVlanId());
}
} else {
rule.setInVlan(endpoint.getOuterVlanId());
}
int transitVlan = 0;
int vni = 0;
if (flow.isOneSwitchFlow()) {
FlowEndpoint egressEndpoint = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
rule.setOutPort(outPort);
rule.setOutVlan(calcVlanSetSequence(ingress, flowPath, egressEndpoint.getVlanStack()));
} else {
PathSegment ingressSegment = flowPath.getSegments().stream().filter(segment -> segment.getSrcSwitchId().equals(flowPath.getSrcSwitchId())).findAny().orElseThrow(() -> new IllegalStateException(String.format("PathSegment was not found for ingress flow rule, flowId: %s", flow.getFlowId())));
outPort = ingressSegment.getSrcPort();
rule.setOutPort(outPort);
if (flow.getEncapsulationType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
transitVlan = encapsulationId.getEncapsulationId();
rule.setOutVlan(calcVlanSetSequence(ingress, flowPath, Collections.singletonList(transitVlan)));
} else if (flow.getEncapsulationType().equals(FlowEncapsulationType.VXLAN)) {
vni = encapsulationId.getEncapsulationId();
rule.setTunnelId(vni);
}
}
List<SimpleSwitchRule> rules = Lists.newArrayList(rule);
if (ingress.isLooped() && !flowPath.isProtected()) {
rules.add(buildIngressLoopSimpleSwitchRule(rule, flowPath, ingress));
}
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorPoints.getMirrorSwitchId().equals(flowPath.getSrcSwitchId())).findFirst();
if (foundFlowMirrorPoints.isPresent()) {
FlowMirrorPoints flowMirrorPoints = foundFlowMirrorPoints.get();
SimpleSwitchRule mirrorRule = rule.toBuilder().outPort(0).tunnelId(0).cookie(flowPath.getCookie().toBuilder().mirror(true).build().getValue()).groupId(flowMirrorPoints.getMirrorGroupId().intValue()).groupBuckets(mapGroupBuckets(flowMirrorPoints.getMirrorPaths(), outPort, transitVlan, vni)).build();
if (!flow.isOneSwitchFlow()) {
mirrorRule.setOutVlan(Collections.emptyList());
}
rules.add(mirrorRule);
}
return rules;
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildEgressSimpleSwitchRules.
private List<SimpleSwitchRule> buildEgressSimpleSwitchRules(Flow flow, FlowPath flowPath, PathSegment egressSegment, EncapsulationId encapsulationId) {
List<SimpleSwitchRule> rules = new ArrayList<>();
FlowSideAdapter egressAdapter = FlowSideAdapter.makeEgressAdapter(flow, flowPath);
FlowEndpoint endpoint = egressAdapter.getEndpoint();
SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(flowPath.getDestSwitchId()).outPort(endpoint.getPortNumber()).inPort(egressSegment.getDestPort()).cookie(flowPath.getCookie().getValue()).egressRule(true).build();
if (flow.getEncapsulationType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
rule.setInVlan(encapsulationId.getEncapsulationId());
rule.setOutVlan(calcVlanSetSequence(Collections.singletonList(encapsulationId.getEncapsulationId()), endpoint.getVlanStack()));
} else if (flow.getEncapsulationType().equals(FlowEncapsulationType.VXLAN)) {
rule.setTunnelId(encapsulationId.getEncapsulationId());
rule.setOutVlan(calcVlanSetSequence(Collections.emptyList(), endpoint.getVlanStack()));
}
if (egressAdapter.isLooped() && !flowPath.isProtected()) {
rules.add(buildTransitLoopRuleForEgressSwitch(rule, flowPath));
}
rules.add(rule);
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorPoints.getMirrorSwitchId().equals(egressSegment.getDestSwitchId())).findFirst();
if (foundFlowMirrorPoints.isPresent()) {
FlowMirrorPoints flowMirrorPoints = foundFlowMirrorPoints.get();
rules.add(rule.toBuilder().outPort(0).cookie(flowPath.getCookie().toBuilder().mirror(true).build().getValue()).groupId(flowMirrorPoints.getMirrorGroupId().intValue()).groupBuckets(mapGroupBuckets(flowMirrorPoints.getMirrorPaths(), endpoint.getPortNumber(), 0, 0)).build());
}
return rules;
}
Aggregations