use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.
the class Server42IslRttInputRuleGeneratorTest method server42IslRttInputRuleGeneratorTest.
@Test
public void server42IslRttInputRuleGeneratorTest() {
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 PortColourCookie(CookieType.SERVER_42_ISL_RTT_INPUT, ISL_PORT), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(SERVER_42_ISL_RTT_INPUT_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(Utils.SERVER_42_PORT).build(), FieldMatch.builder().field(Field.ETH_DST).value(sw.getSwitchId().toMacAddressAsLong()).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(OFFSET + ISL_PORT).build());
assertEquals(expectedMatch, flowCommandData.getMatch());
List<Action> expectedApplyActions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_FORWARD_UDP_PORT).build(), SetFieldAction.builder().field(Field.ETH_DST).value(MAC_ADDRESS.toLong()).build(), new PortOutAction(new PortNumber(ISL_PORT)));
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.
the class RuleManagerHelperTest method sortCommandsByDependencies2Test.
@Test
public void sortCommandsByDependencies2Test() {
FlowSpeakerData command1 = buildFullFlowSpeakerCommandData(METER_ID_1, null);
FlowSpeakerData command2 = buildFullFlowSpeakerCommandData(METER_ID_1, command1.getUuid());
FlowSpeakerData command3 = buildFullFlowSpeakerCommandData(METER_ID_1, null);
List<SpeakerData> result = sortCommandsByDependencies(newArrayList(command3, command2, command1));
assertEquals(3, result.size());
int command1Pos = -1;
int command2Pos = -1;
for (int i = 0; i < result.size(); i++) {
if (result.get(i).getUuid().equals(command1.getUuid())) {
command1Pos = i;
}
if (result.get(i).getUuid().equals(command2.getUuid())) {
command2Pos = i;
}
}
assertTrue(command1Pos < command2Pos);
}
use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf13WithOvsVxlan.
@Test
public void shouldBuildCorrectRuleWithMeterForOf13WithOvsVxlan() {
sw = buildSwitch("OF_13", Sets.newHashSet(KILDA_OVS_PUSH_POP_MATCH_VXLAN, METERS, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
checkMatch(flowCommandData.getMatch());
Instructions instructions = flowCommandData.getInstructions();
assertEquals(3, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof PopVxlanAction);
PopVxlanAction popVxlanAction = (PopVxlanAction) first;
assertEquals(ActionType.POP_VXLAN_OVS, popVxlanAction.getType());
Action second = instructions.getApplyActions().get(1);
assertTrue(second instanceof PortOutAction);
PortOutAction sendToControllerAction = (PortOutAction) second;
assertEquals(SpecialPortType.CONTROLLER, sendToControllerAction.getPortNumber().getPortType());
assertNull(instructions.getWriteActions());
assertEquals(instructions.getGoToMeter(), meterCommandData.getMeterId());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
}
use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf13.
@Test
public void shouldBuildCorrectRuleWithMeterForOf13() {
sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_PUSH_POP_VXLAN, METERS, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
checkMatch(flowCommandData.getMatch());
checkInstructions(flowCommandData.getInstructions(), meterCommandData.getMeterId());
// Check meter command
checkMeterCommand(meterCommandData);
}
use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGeneratorTest method shouldBuildCorrectRuleWithMeterInBytesForOf13.
@Test
public void shouldBuildCorrectRuleWithMeterInBytesForOf13() {
sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_PUSH_POP_VXLAN, METERS));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
checkMatch(flowCommandData.getMatch());
checkInstructions(flowCommandData.getInstructions(), meterCommandData.getMeterId());
// Check meter command
assertEquals(createMeterIdForDefaultRule(VERIFICATION_UNICAST_VXLAN_RULE_COOKIE), meterCommandData.getMeterId());
long expectedRate = Meter.convertRateToKiloBits(config.getUnicastRateLimit(), config.getDiscoPacketSize());
assertEquals(expectedRate, meterCommandData.getRate());
long expectedBurst = Meter.convertBurstSizeToKiloBits(config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
assertEquals(expectedBurst, meterCommandData.getBurst());
assertEquals(3, meterCommandData.getFlags().size());
assertTrue(Sets.newHashSet(MeterFlag.BURST, MeterFlag.STATS, MeterFlag.KBPS).containsAll(meterCommandData.getFlags()));
}
Aggregations