use of org.openkilda.rulemanager.factory.RuleGenerator in project open-kilda by telstra.
the class RuleManagerImpl method getServiceRuleGenerators.
@VisibleForTesting
List<RuleGenerator> getServiceRuleGenerators(SwitchId switchId, DataAdapter adapter) {
List<RuleGenerator> generators = new ArrayList<>();
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(DROP_RULE_COOKIE), OfTable.INPUT));
generators.add(serviceRulesFactory.getUniCastDiscoveryRuleGenerator());
generators.add(serviceRulesFactory.getBroadCastDiscoveryRuleGenerator());
generators.add(serviceRulesFactory.getDropDiscoveryLoopRuleGenerator());
generators.add(serviceRulesFactory.getBfdCatchRuleGenerator());
generators.add(serviceRulesFactory.getRoundTripLatencyRuleGenerator());
generators.add(serviceRulesFactory.getUnicastVerificationVxlanRuleGenerator());
SwitchProperties switchProperties = adapter.getSwitchProperties(switchId);
if (switchProperties.isMultiTable()) {
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_INGRESS_DROP_COOKIE), OfTable.INGRESS));
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_TRANSIT_DROP_COOKIE), OfTable.TRANSIT));
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_POST_INGRESS_DROP_COOKIE), OfTable.POST_INGRESS));
generators.add(serviceRulesFactory.getTablePassThroughDefaultRuleGenerator(new Cookie(MULTITABLE_EGRESS_PASS_THROUGH_COOKIE), OfTable.TRANSIT, OfTable.EGRESS));
generators.add(serviceRulesFactory.getTablePassThroughDefaultRuleGenerator(new Cookie(MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE), OfTable.INGRESS, OfTable.PRE_INGRESS));
generators.add(serviceRulesFactory.getLldpPostIngressRuleGenerator());
generators.add(serviceRulesFactory.getLldpPostIngressVxlanRuleGenerator());
generators.add(serviceRulesFactory.getLldpPostIngressOneSwitchRuleGenerator());
generators.add(serviceRulesFactory.getArpPostIngressRuleGenerator());
generators.add(serviceRulesFactory.getArpPostIngressVxlanRuleGenerator());
generators.add(serviceRulesFactory.getArpPostIngressOneSwitchRuleGenerator());
if (switchProperties.isSwitchLldp()) {
generators.add(serviceRulesFactory.getLldpTransitRuleGenerator());
generators.add(serviceRulesFactory.getLldpInputPreDropRuleGenerator());
generators.add(serviceRulesFactory.getLldpIngressRuleGenerator());
}
if (switchProperties.isSwitchArp()) {
generators.add(serviceRulesFactory.getArpTransitRuleGenerator());
generators.add(serviceRulesFactory.getArpInputPreDropRuleGenerator());
generators.add(serviceRulesFactory.getArpIngressRuleGenerator());
}
Set<Integer> islPorts = adapter.getSwitchIslPorts(switchId);
islPorts.forEach(islPort -> {
generators.add(serviceRulesFactory.getEgressIslVxlanRuleGenerator(islPort));
generators.add(serviceRulesFactory.getEgressIslVlanRuleGenerator(islPort));
generators.add(serviceRulesFactory.getTransitIslVxlanRuleGenerator(islPort));
});
}
Integer server42Port = switchProperties.getServer42Port();
Integer server42Vlan = switchProperties.getServer42Vlan();
MacAddress server42MacAddress = switchProperties.getServer42MacAddress();
KildaFeatureToggles featureToggles = adapter.getFeatureToggles();
if (featureToggles.getServer42FlowRtt()) {
generators.add(serviceRulesFactory.getServer42FlowRttTurningRuleGenerator());
generators.add(serviceRulesFactory.getServer42FlowRttVxlanTurningRuleGenerator());
if (switchProperties.isServer42FlowRtt()) {
generators.add(serviceRulesFactory.getServer42FlowRttOutputVlanRuleGenerator(server42Port, server42Vlan, server42MacAddress));
generators.add(serviceRulesFactory.getServer42FlowRttOutputVxlanRuleGenerator(server42Port, server42Vlan, server42MacAddress));
}
}
if (featureToggles.getServer42IslRtt() && switchProperties.hasServer42IslRttEnabled()) {
generators.add(serviceRulesFactory.getServer42IslRttTurningRuleGenerator());
generators.add(serviceRulesFactory.getServer42IslRttOutputRuleGenerator(server42Port, server42Vlan, server42MacAddress));
for (Integer islPort : adapter.getSwitchIslPorts(switchId)) {
generators.add(serviceRulesFactory.getServer42IslRttInputRuleGenerator(server42Port, islPort));
}
}
return generators;
}
use of org.openkilda.rulemanager.factory.RuleGenerator in project open-kilda by telstra.
the class RuleManagerImpl method buildIngressYFlowCommands.
private List<SpeakerData> buildIngressYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
Flow flow = adapter.getFlow(flowPath.getPathId());
Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
if (flow.isProtectedPath(flowPath.getPathId()) || altFlow.isProtectedPath(altFlowPath.getPathId())) {
return Collections.emptyList();
}
YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
if (yFlow == null) {
return Collections.emptyList();
}
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
Switch sharedSwitch = adapter.getSwitch(sharedSwitchId);
if (sharedSwitch == null || !sharedSwitchId.equals(flowPath.getSrcSwitchId()) || !sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
return Collections.emptyList();
}
FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
MeterId sharedMeterId = yFlow.getSharedEndpointMeterId();
RuleGenerator generator = flowRulesFactory.getIngressYRuleGenerator(flowPath, flow, encapsulation, new HashSet<>(), altFlowPath, altFlow, altEncapsulation, new HashSet<>(), sharedMeterId);
return generator.generateCommands(sharedSwitch);
}
use of org.openkilda.rulemanager.factory.RuleGenerator in project open-kilda by telstra.
the class RuleManagerImpl method buildTransitYFlowCommands.
private List<SpeakerData> buildTransitYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
Flow flow = adapter.getFlow(flowPath.getPathId());
Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
if (yFlow == null) {
return Collections.emptyList();
}
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
if (sharedSwitchId.equals(flowPath.getSrcSwitchId()) || sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
return Collections.emptyList();
}
SwitchId yPointSwitchId = yFlow.getYPoint();
MeterId yPointMeterId = yFlow.getMeterId();
if (flow.isProtectedPath(flowPath.getPathId()) && altFlow.isProtectedPath(altFlowPath.getPathId())) {
yPointSwitchId = yFlow.getProtectedPathYPoint();
yPointMeterId = yFlow.getProtectedPathMeterId();
}
Switch yPointSwitch = adapter.getSwitch(yPointSwitchId);
if (yPointSwitch == null) {
return Collections.emptyList();
}
FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
SwitchPathSegments switchPathSegments = findPathSegmentsForSwitch(yPointSwitchId, flowPath.getSegments());
SwitchPathSegments altSwitchPathSegments = findPathSegmentsForSwitch(yPointSwitchId, altFlowPath.getSegments());
if (switchPathSegments == null || altSwitchPathSegments == null) {
return Collections.emptyList();
}
RuleGenerator generator = flowRulesFactory.getTransitYRuleGenerator(flowPath, encapsulation, switchPathSegments.getFirstPathSegment(), switchPathSegments.getSecondPathSegment(), altFlowPath, altEncapsulation, altSwitchPathSegments.getFirstPathSegment(), altSwitchPathSegments.getSecondPathSegment(), yPointMeterId);
return generator.generateCommands(yPointSwitch);
}
use of org.openkilda.rulemanager.factory.RuleGenerator in project open-kilda by telstra.
the class RuleManagerImpl method buildIngressCommands.
private List<SpeakerData> buildIngressCommands(Switch sw, FlowPath flowPath, Flow flow, FlowTransitEncapsulation encapsulation, Set<FlowSideAdapter> overlappingIngressAdapters, SwitchProperties switchProperties, KildaFeatureToggles featureToggles) {
List<SpeakerData> ingressCommands = flowRulesFactory.getIngressRuleGenerator(flowPath, flow, encapsulation, overlappingIngressAdapters).generateCommands(sw);
UUID ingressMeterCommandUuid = Utils.getCommand(MeterSpeakerData.class, ingressCommands).map(SpeakerData::getUuid).orElse(null);
List<RuleGenerator> generators = new ArrayList<>();
if (featureToggles.getServer42FlowRtt()) {
generators.add(flowRulesFactory.getServer42IngressRuleGenerator(flowPath, flow, encapsulation, switchProperties));
}
generators.add(flowRulesFactory.getInputLldpRuleGenerator(flowPath, flow, overlappingIngressAdapters));
generators.add(flowRulesFactory.getInputArpRuleGenerator(flowPath, flow, overlappingIngressAdapters));
if (flow.isLooped() && sw.getSwitchId().equals(flow.getLoopSwitchId())) {
generators.add(flowRulesFactory.getIngressLoopRuleGenerator(flowPath, flow));
}
if (flowPath.getFlowMirrorPointsSet() != null && !flowPath.getFlowMirrorPointsSet().isEmpty()) {
generators.add(flowRulesFactory.getIngressMirrorRuleGenerator(flowPath, flow, encapsulation, ingressMeterCommandUuid));
}
ingressCommands.addAll(generateRules(sw, generators));
return ingressCommands;
}
use of org.openkilda.rulemanager.factory.RuleGenerator in project open-kilda by telstra.
the class RuleManagerServiceRulesTest method shouldUseCorrectServiceRuleGeneratorsForSwitchInSingleTableMode.
@Test
public void shouldUseCorrectServiceRuleGeneratorsForSwitchInSingleTableMode() {
Switch sw = buildSwitch("OF_13", Collections.emptySet());
SwitchId switchId = sw.getSwitchId();
SwitchProperties switchProperties = buildSwitchProperties(sw, false);
List<RuleGenerator> generators = ruleManager.getServiceRuleGenerators(switchId, buildAdapter(switchId, switchProperties, new HashSet<>(), false));
assertEquals(7, generators.size());
assertTrue(generators.stream().anyMatch(g -> g instanceof TableDefaultRuleGenerator));
assertTrue(generators.stream().anyMatch(g -> g instanceof BroadCastDiscoveryRuleGenerator));
assertTrue(generators.stream().anyMatch(g -> g instanceof UniCastDiscoveryRuleGenerator));
assertTrue(generators.stream().anyMatch(g -> g instanceof DropDiscoveryLoopRuleGenerator));
assertTrue(generators.stream().anyMatch(g -> g instanceof BfdCatchRuleGenerator));
assertTrue(generators.stream().anyMatch(g -> g instanceof RoundTripLatencyRuleGenerator));
assertTrue(generators.stream().anyMatch(g -> g instanceof UnicastVerificationVxlanRuleGenerator));
}
Aggregations