use of org.openkilda.rulemanager.action.PortOutAction in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGeneratorTest method checkGroupCommand.
private void checkGroupCommand(GroupSpeakerData groupCommandData) {
assertEquals(GroupId.ROUND_TRIP_LATENCY_GROUP_ID, groupCommandData.getGroupId());
assertEquals(GroupType.ALL, groupCommandData.getType());
List<Bucket> buckets = groupCommandData.getBuckets();
assertEquals(2, buckets.size());
Bucket first = buckets.get(0);
assertEquals(2, first.getWriteActions().size());
SetFieldAction setEthDstAction = getActionByType(SetFieldAction.class, first.getWriteActions());
assertEquals(Field.ETH_DST, setEthDstAction.getField());
assertEquals(sw.getSwitchId().toLong(), setEthDstAction.getValue());
PortOutAction sendToControllerAction = getActionByType(PortOutAction.class, first.getWriteActions());
assertEquals(SpecialPortType.CONTROLLER, sendToControllerAction.getPortNumber().getPortType());
Bucket second = buckets.get(1);
assertEquals(2, second.getWriteActions().size());
SetFieldAction setUdpDstAction = getActionByType(SetFieldAction.class, second.getWriteActions());
assertEquals(Field.UDP_DST, setUdpDstAction.getField());
assertEquals(LATENCY_PACKET_UDP_PORT, setUdpDstAction.getValue());
PortOutAction sendToPortInAction = getActionByType(PortOutAction.class, second.getWriteActions());
assertEquals(SpecialPortType.IN_PORT, sendToPortInAction.getPortNumber().getPortType());
}
use of org.openkilda.rulemanager.action.PortOutAction in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterAndWithoutGroupForOf13.
@Test
public void shouldBuildCorrectRuleWithMeterAndWithoutGroupForOf13() {
sw = buildSwitch("OF_13", Sets.newHashSet(METERS, MATCH_UDP_PORT, 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);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(4, match.size());
checkEthDstMatch(match);
checkUpdDstMatch(match);
Instructions instructions = flowCommandData.getInstructions();
assertEquals(1, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof PortOutAction);
PortOutAction portOutAction = (PortOutAction) first;
assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
assertNull(instructions.getWriteActions());
assertEquals(meterCommandData.getMeterId(), instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
}
use of org.openkilda.rulemanager.action.PortOutAction in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithoutMeterAndGroupForOf13.
@Test
public void shouldBuildCorrectRuleWithoutMeterAndGroupForOf13() {
sw = buildSwitch("OF_13", Sets.newHashSet(MATCH_UDP_PORT, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(1, 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);
assertTrue(flowCommandData.getDependsOn().isEmpty());
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(4, match.size());
checkEthDstMatch(match);
checkUpdDstMatch(match);
// Check flow command has correct instructions without meter and group
Instructions instructions = flowCommandData.getInstructions();
assertEquals(1, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof PortOutAction);
PortOutAction portOutAction = (PortOutAction) first;
assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
}
use of org.openkilda.rulemanager.action.PortOutAction in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGenerator method getRoundTripLatencyGroup.
private static GroupSpeakerData getRoundTripLatencyGroup(Switch sw) {
List<Bucket> buckets = new ArrayList<>();
buckets.add(Bucket.builder().writeActions(Sets.newHashSet(// todo: remove useless set ETH_DST action
actionSetDstMac(sw.getSwitchId().toLong()), new PortOutAction(new PortNumber(SpecialPortType.CONTROLLER)))).build());
buckets.add(Bucket.builder().writeActions(Sets.newHashSet(SetFieldAction.builder().field(Field.UDP_DST).value(LATENCY_PACKET_UDP_PORT).build(), new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)))).build());
return GroupSpeakerData.builder().switchId(sw.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).groupId(GroupId.ROUND_TRIP_LATENCY_GROUP_ID).type(GroupType.ALL).buckets(buckets).build();
}
use of org.openkilda.rulemanager.action.PortOutAction in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
List<SpeakerData> commands = new ArrayList<>();
List<Action> actions = new ArrayList<>();
Instructions instructions = Instructions.builder().applyActions(actions).build();
FlowSpeakerData flowCommand = buildRule(sw, instructions);
commands.add(flowCommand);
MeterId meterId = createMeterIdForDefaultRule(VERIFICATION_BROADCAST_RULE_COOKIE);
SpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, config.getBroadcastRateLimit(), config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
if (meterCommand != null) {
commands.add(meterCommand);
addMeterToInstructions(meterId, sw, instructions);
}
GroupSpeakerData groupCommand = null;
if (sw.getFeatures().contains(SwitchFeature.GROUP_PACKET_OUT_CONTROLLER)) {
groupCommand = getRoundTripLatencyGroup(sw);
actions.add(new GroupAction(groupCommand.getGroupId()));
commands.add(groupCommand);
} else {
actions.add(new PortOutAction(new PortNumber(SpecialPortType.CONTROLLER)));
}
if (meterCommand != null) {
flowCommand.getDependsOn().add(meterCommand.getUuid());
}
if (groupCommand != null) {
flowCommand.getDependsOn().add(groupCommand.getUuid());
}
return commands;
}
Aggregations