use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class BfdCatchRuleGeneratorTest method shouldBuildCorrectRuleForOf13.
@Test
public void shouldBuildCorrectRuleForOf13() {
Switch sw = buildSwitch("OF_13", Sets.newHashSet(BFD));
BfdCatchRuleGenerator generator = new BfdCatchRuleGenerator();
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(CATCH_BFD_RULE_COOKIE), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(CATCH_BFD_RULE_PRIORITY, flowCommandData.getPriority());
FieldMatch ethDstMatch = getMatchByField(Field.ETH_DST, flowCommandData.getMatch());
assertEquals(sw.getSwitchId().toLong(), ethDstMatch.getValue());
assertFalse(ethDstMatch.isMasked());
FieldMatch ethTypeMatch = getMatchByField(Field.ETH_TYPE, flowCommandData.getMatch());
assertEquals(EthType.IPv4, ethTypeMatch.getValue());
assertFalse(ethTypeMatch.isMasked());
FieldMatch ipProtoMatch = getMatchByField(Field.IP_PROTO, flowCommandData.getMatch());
assertEquals(IpProto.UDP, ipProtoMatch.getValue());
assertFalse(ipProtoMatch.isMasked());
FieldMatch udpDstMatch = getMatchByField(Field.UDP_DST, flowCommandData.getMatch());
assertEquals(Constants.BDF_DEFAULT_PORT, udpDstMatch.getValue());
assertFalse(udpDstMatch.isMasked());
Instructions instructions = flowCommandData.getInstructions();
assertEquals(1, instructions.getApplyActions().size());
Action action = instructions.getApplyActions().get(0);
assertTrue(action instanceof PortOutAction);
PortOutAction portOutAction = (PortOutAction) action;
assertEquals(SpecialPortType.LOCAL, portOutAction.getPortNumber().getPortType());
}
use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class RoundTripLatencyRuleGeneratorTest method shouldBuildCorrectRuleForOf13.
@Test
public void shouldBuildCorrectRuleForOf13() {
Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
RoundTripLatencyRuleGenerator generator = RoundTripLatencyRuleGenerator.builder().config(config).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 Cookie(ROUND_TRIP_LATENCY_RULE_COOKIE), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(ROUND_TRIP_LATENCY_RULE_PRIORITY, flowCommandData.getPriority());
FieldMatch ethSrcMatch = getMatchByField(Field.ETH_SRC, flowCommandData.getMatch());
assertEquals(sw.getSwitchId().toLong(), ethSrcMatch.getValue());
assertFalse(ethSrcMatch.isMasked());
FieldMatch ethDstMatch = getMatchByField(Field.ETH_DST, flowCommandData.getMatch());
assertEquals(new SwitchId(config.getDiscoveryBcastPacketDst()).toLong(), ethDstMatch.getValue());
assertFalse(ethDstMatch.isMasked());
FieldMatch ethTypeMatch = getMatchByField(Field.ETH_TYPE, flowCommandData.getMatch());
assertEquals(EthType.IPv4, ethTypeMatch.getValue());
assertFalse(ethTypeMatch.isMasked());
FieldMatch ipProtoMatch = getMatchByField(Field.IP_PROTO, flowCommandData.getMatch());
assertEquals(IpProto.UDP, ipProtoMatch.getValue());
assertFalse(ipProtoMatch.isMasked());
FieldMatch udpDstMatch = getMatchByField(Field.UDP_DST, flowCommandData.getMatch());
assertEquals(Constants.LATENCY_PACKET_UDP_PORT, udpDstMatch.getValue());
assertFalse(udpDstMatch.isMasked());
Instructions instructions = flowCommandData.getInstructions();
assertEquals(2, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof CopyFieldAction);
CopyFieldAction copyFieldAction = (CopyFieldAction) first;
assertEquals(ROUND_TRIP_LATENCY_TIMESTAMP_SIZE, copyFieldAction.getNumberOfBits());
assertEquals(0, copyFieldAction.getSrcOffset());
assertEquals(ROUND_TRIP_LATENCY_T1_OFFSET, copyFieldAction.getDstOffset());
assertEquals(NOVIFLOW_RX_TIMESTAMP, copyFieldAction.getOxmSrcHeader());
assertEquals(NOVIFLOW_PACKET_OFFSET, copyFieldAction.getOxmDstHeader());
Action second = instructions.getApplyActions().get(1);
assertTrue(second instanceof PortOutAction);
PortOutAction portOutAction = (PortOutAction) second;
assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
}
use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class SingleTableServer42IngressRuleGeneratorTest method assertIngressCommand.
private void assertIngressCommand(FlowSpeakerData command, int expectedPriority, Set<FieldMatch> expectedMatch, List<Action> expectedApplyActions) {
assertEquals(SWITCH_1.getSwitchId(), command.getSwitchId());
assertEquals(SWITCH_1.getOfVersion(), command.getOfVersion().toString());
assertEquals(SERVER_42_INGRESS_COOKIE, command.getCookie());
assertEquals(OfTable.INPUT, command.getTable());
assertEquals(expectedPriority, command.getPriority());
assertEqualsMatch(expectedMatch, command.getMatch());
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
assertEquals(expectedInstructions, command.getInstructions());
assertEquals(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS), command.getFlags());
}
use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class TransitYRuleGeneratorTest method assertTransitCommand.
private void assertTransitCommand(List<SpeakerData> commands, OfTable table, FlowTransitEncapsulation encapsulation) {
assertEquals(1, commands.size());
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
assertEquals(SWITCH_1.getSwitchId(), flowCommandData.getSwitchId());
assertEquals(SWITCH_1.getOfVersion(), flowCommandData.getOfVersion().toString());
assertTrue(flowCommandData.getDependsOn().contains(SHARED_METER_UUID));
assertEquals(COOKIE, flowCommandData.getCookie());
assertEquals(table, flowCommandData.getTable());
assertEquals(Priority.Y_FLOW_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch;
if (encapsulation.getType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
expectedMatch = buildExpectedVlanMatch(PORT_NUMBER_1, encapsulation.getId());
} else {
expectedMatch = buildExpectedVxlanMatch(PORT_NUMBER_1, encapsulation.getId());
}
assertEqualsMatch(expectedMatch, flowCommandData.getMatch());
Instructions expectedInstructions = Instructions.builder().applyActions(Lists.newArrayList(new PortOutAction(new PortNumber(PORT_NUMBER_2)))).goToMeter(SHARED_METER_ID).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
assertEquals(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS), flowCommandData.getFlags());
}
use of org.openkilda.rulemanager.Instructions in project open-kilda by telstra.
the class TransitYRuleGenerator method buildTransitCommand.
private SpeakerData buildTransitCommand(Switch sw, int inPort, int outPort) {
Instructions instructions = Instructions.builder().applyActions(Lists.newArrayList(new PortOutAction(new PortNumber(outPort)))).build();
if (sharedMeterId != null && sharedMeterId.getValue() != 0L) {
addMeterToInstructions(sharedMeterId, sw, instructions);
}
FlowSpeakerDataBuilder<?, ?> builder = FlowSpeakerData.builder().switchId(sw.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(flowPath.getCookie().toBuilder().yFlow(true).build()).table(multiTable ? OfTable.TRANSIT : OfTable.INPUT).priority(Priority.Y_FLOW_PRIORITY).match(makeTransitMatch(sw, inPort, encapsulation)).instructions(instructions);
if (sw.getFeatures().contains(SwitchFeature.RESET_COUNTS_FLAG)) {
builder.flags(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS));
}
return builder.build();
}
Aggregations