use of org.openkilda.adapter.FlowSideAdapter in project open-kilda by telstra.
the class InputArpRuleGeneratorTest method buildCorrectRuleForOf13Test.
@Test
public void buildCorrectRuleForOf13Test() {
FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, false, true);
FlowSideAdapter overlapAdapter = new FlowSourceAdapter(Flow.builder().flowId("some").srcSwitch(SW).destSwitch(buildSwitch("OF_13", Collections.emptySet())).detectConnectedDevices(DetectConnectedDevices.builder().srcArp(false).srcSwitchArp(false).build()).build());
InputArpRuleGenerator generator = InputArpRuleGenerator.builder().ingressEndpoint(endpoint).multiTable(true).overlappingIngressAdapters(Sets.newHashSet(overlapAdapter)).build();
List<SpeakerData> commands = generator.generateCommands(SW);
assertEquals(1, commands.size());
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
assertEquals(SW.getSwitchId(), flowCommandData.getSwitchId());
assertEquals(SW.getOfVersion(), flowCommandData.getOfVersion().toString());
assertTrue(flowCommandData.getDependsOn().isEmpty());
assertEquals(new PortColourCookie(CookieType.ARP_INPUT_CUSTOMER_TYPE, PORT_NUMBER_1), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(Priority.ARP_INPUT_CUSTOMER_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.ARP).build());
assertEqualsMatch(expectedMatch, flowCommandData.getMatch());
RoutingMetadata metadata = RoutingMetadata.builder().arpFlag(true).build(SW.getFeatures());
Instructions expectedInstructions = Instructions.builder().writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).goToTable(OfTable.PRE_INGRESS).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
assertTrue(flowCommandData.getFlags().isEmpty());
}
use of org.openkilda.adapter.FlowSideAdapter in project open-kilda by telstra.
the class MultiTableIngressRuleGeneratorTest method buildCommandsVlanEncapsulationDoubleVlanPortOverlappingTest.
@Test
public void buildCommandsVlanEncapsulationDoubleVlanPortOverlappingTest() {
Flow oneSwitchFlow = buildFlow(ONE_SWITCH_PATH, OUTER_VLAN_ID_2, 0);
Set<FlowSideAdapter> overlapping = Sets.newHashSet(FlowSideAdapter.makeIngressAdapter(oneSwitchFlow, ONE_SWITCH_PATH));
Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1, INNER_VLAN_ID_1);
MultiTableIngressRuleGenerator generator = buildGenerator(PATH, flow, VLAN_ENCAPSULATION, overlapping);
List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
assertEquals(3, commands.size());
FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
FlowSpeakerData preIngressCommand = (FlowSpeakerData) commands.get(1);
MeterSpeakerData meterCommand = (MeterSpeakerData) commands.get(2);
assertEquals(newArrayList(meterCommand.getUuid()), new ArrayList<>(ingressCommand.getDependsOn()));
RoutingMetadata ingressMetadata = RoutingMetadata.builder().outerVlanId(OUTER_VLAN_ID_1).build(SWITCH_1.getFeatures());
Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(INNER_VLAN_ID_1).build(), FieldMatch.builder().field(Field.METADATA).value(ingressMetadata.getValue()).mask(ingressMetadata.getMask()).build());
List<Action> expectedIngressActions = newArrayList(SetFieldAction.builder().field(Field.VLAN_VID).value(TRANSIT_VLAN_ID).build(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
Set<FieldMatch> expectedPreIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
FlowSharedSegmentCookie preIngressCookie = FlowSharedSegmentCookie.builder(SharedSegmentType.QINQ_OUTER_VLAN).portNumber(PORT_NUMBER_1).vlanId(OUTER_VLAN_ID_1).build();
RoutingMetadata preIngressMetadata = RoutingMetadata.builder().outerVlanId(OUTER_VLAN_ID_1).build(SWITCH_1.getFeatures());
assertPreIngressCommand(preIngressCommand, preIngressCookie, Priority.FLOW_PRIORITY, expectedPreIngressMatch, newArrayList(new PopVlanAction()), mapMetadata(preIngressMetadata));
assertIngressCommand(ingressCommand, Priority.DOUBLE_VLAN_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, METER_ID, null);
assertMeterCommand(meterCommand);
}
use of org.openkilda.adapter.FlowSideAdapter 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.adapter.FlowSideAdapter 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;
}
use of org.openkilda.adapter.FlowSideAdapter in project open-kilda by telstra.
the class InputLldpRuleGeneratorTest method buildLldpRuleWithOverlappedEndpointsTest.
@Test
public void buildLldpRuleWithOverlappedEndpointsTest() {
FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, true, false);
FlowSideAdapter adapter = new FlowSourceAdapter(Flow.builder().flowId("some").srcSwitch(SW).destSwitch(buildSwitch("OF_13", Collections.emptySet())).detectConnectedDevices(DetectConnectedDevices.builder().srcLldp(true).srcSwitchLldp(true).build()).build());
InputLldpRuleGenerator generator = InputLldpRuleGenerator.builder().ingressEndpoint(endpoint).multiTable(true).overlappingIngressAdapters(Sets.newHashSet(adapter)).build();
assertEquals(0, generator.generateCommands(SW).size());
}
Aggregations