use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class IngressMirrorRuleGeneratorTest method assertIngressCommand.
private void assertIngressCommand(FlowSpeakerData command, int expectedPriority, OfTable expectedTable, Set<FieldMatch> expectedMatch, List<Action> expectedApplyActions, MeterId expectedMeter, UUID groupCommandUuid) {
assertEquals(SWITCH_1.getSwitchId(), command.getSwitchId());
assertEquals(SWITCH_1.getOfVersion(), command.getOfVersion().toString());
assertEquals(MIRROR_COOKIE, command.getCookie());
assertEquals(expectedTable, command.getTable());
assertEquals(expectedPriority, command.getPriority());
assertEqualsMatch(expectedMatch, command.getMatch());
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).goToMeter(expectedMeter).build();
assertEquals(expectedInstructions, command.getInstructions());
assertEquals(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS), command.getFlags());
assertEquals(newArrayList(groupCommandUuid), new ArrayList<>(command.getDependsOn()));
}
use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterAndGroupForOf15.
@Test
public void shouldBuildCorrectRuleWithMeterAndGroupForOf15() {
sw = buildSwitch("OF_15", Sets.newHashSet(METERS, GROUP_PACKET_OUT_CONTROLLER, MATCH_UDP_PORT, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(3, 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);
GroupSpeakerData groupCommandData = getCommand(GroupSpeakerData.class, commands);
assertEquals(2, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
assertTrue(flowCommandData.getDependsOn().contains(groupCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(4, match.size());
checkEthDstMatch(match);
checkUpdDstMatch(match);
// Check flow command has correct instructions for OF 1.5
Instructions instructions = flowCommandData.getInstructions();
assertEquals(2, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof MeterAction);
MeterAction meterAction = (MeterAction) first;
assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
checkGroupAction(instructions.getApplyActions().get(1), groupCommandData.getGroupId());
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
// Check group command
checkGroupCommand(groupCommandData);
}
use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class Server42FlowRttTurningRuleGeneratorTest method testOutputRule.
private void testOutputRule(Switch sw, ActionType expectedSwapFieldType) {
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_FLOW_RTT_TURNING_COOKIE), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(SERVER_42_FLOW_RTT_TURNING_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch = Sets.newHashSet(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(SERVER_42_FLOW_RTT_FORWARD_UDP_PORT).build());
assertEquals(expectedMatch, flowCommandData.getMatch());
List<Action> expectedApplyActions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_REVERSE_UDP_PORT).build(), SwapFieldAction.builder().type(expectedSwapFieldType).numberOfBits(MAC_ADDRESS_SIZE_IN_BITS).srcOffset(0).dstOffset(0).oxmSrcHeader(OpenFlowOxms.ETH_SRC).oxmDstHeader(OpenFlowOxms.ETH_DST).build(), new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)));
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
use of org.openkilda.rulemanager.Instructions 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.Instructions 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);
}
Aggregations