use of org.openkilda.rulemanager.FlowSpeakerData 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.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class RuleManagerHelperTest method sortCommandsByDependencies3Test.
@Test
public void sortCommandsByDependencies3Test() {
FlowSpeakerData command1 = buildFullFlowSpeakerCommandData(METER_ID_1, null);
FlowSpeakerData command2 = buildFullFlowSpeakerCommandData(METER_ID_1, command1.getUuid());
FlowSpeakerData command3 = buildFullFlowSpeakerCommandData(METER_ID_2, command2.getUuid());
List<SpeakerData> result = sortCommandsByDependencies(newArrayList(command3, command2, command1));
assertEquals(3, result.size());
assertEquals(command1.getUuid(), result.get(0).getUuid());
assertEquals(command2.getUuid(), result.get(1).getUuid());
assertEquals(command3.getUuid(), result.get(2).getUuid());
}
use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class RuleManagerHelperTest method checkCircularDependenciesUnknownDependsOnTest.
@Test(expected = IllegalStateException.class)
public void checkCircularDependenciesUnknownDependsOnTest() {
FlowSpeakerData command = buildFullFlowSpeakerCommandData(METER_ID_1, UUID.randomUUID());
checkCircularDependencies(newArrayList(command));
}
use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class Server42IslRttTurningRuleGeneratorTest method server42IslRttTurningRuleGeneratorTest.
@Test
public void server42IslRttTurningRuleGeneratorTest() {
Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
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 Cookie(SERVER_42_ISL_RTT_TURNING_COOKIE), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(SERVER_42_ISL_RTT_TURNING_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(MAC_ADDRESS.toLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_FORWARD_UDP_PORT).build());
assertEquals(expectedMatch, flowCommandData.getMatch());
List<Action> expectedApplyActions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_REVERSE_UDP_PORT).build(), new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)));
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class OfBatchExecutor method verifyFlows.
private void verifyFlows() {
log.debug("Verify flows with key: {} (hasFlows={})", kafkaKey, hasFlows);
if (!hasFlows) {
return;
}
try {
List<OFFlowStatsReply> replies = flowStats.get();
List<FlowSpeakerData> switchFlows = new ArrayList<>();
replies.forEach(reply -> switchFlows.addAll(OfFlowConverter.INSTANCE.convertToFlowSpeakerData(reply, new SwitchId(iofSwitch.getId().getLong()))));
Map<Long, Long> cookieCounts = switchFlows.stream().map(v -> v.getCookie().getValue()).collect(groupingBy(identity(), counting()));
for (FlowSpeakerData switchFlow : switchFlows) {
FlowSpeakerData expectedFlow = holder.getByCookie(switchFlow.getCookie());
if (expectedFlow != null) {
if (switchFlow.equals(expectedFlow)) {
holder.recordSuccessUuid(expectedFlow.getUuid());
} else {
long cookie = switchFlow.getCookie().getValue();
// Go through all duplicate cookies, and fail on the last one.
if (cookieCounts.get(cookie) > 1) {
log.debug("Detected duplicate cookies {} on switch {}, skipping...", switchFlow.getCookie(), switchFlow.getSwitchId());
cookieCounts.compute(cookie, (k, v) -> v - 1);
} else {
holder.recordFailedUuid(expectedFlow.getUuid(), format("Failed to validate flow on a switch. Expected: %s, actual: %s", expectedFlow, switchFlow));
}
}
}
}
} catch (Exception e) {
log.error("Failed to verify flows for message", e);
}
}
Aggregations