use of org.openkilda.rulemanager.FlowSpeakerData 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.FlowSpeakerData in project open-kilda by telstra.
the class MultiTableIngressYRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
if (flow.isOneSwitchFlow()) {
throw new IllegalStateException("Y-Flow rules can't be created for one switch flow");
}
List<SpeakerData> result = new ArrayList<>();
FlowEndpoint ingressEndpoint = checkAndBuildIngressEndpoint(flow, flowPath, sw.getSwitchId());
FlowSpeakerData command = buildFlowIngressCommand(sw, ingressEndpoint);
if (command == null) {
return Collections.emptyList();
}
result.add(command);
if (generateMeterCommand) {
SpeakerData meterCommand = buildMeter(externalMeterCommandUuid, flowPath, config, sharedMeterId, sw);
if (meterCommand != null) {
result.add(meterCommand);
command.getDependsOn().add(externalMeterCommandUuid);
}
} else if (sw.getFeatures().contains(METERS) && sharedMeterId != null) {
command.getDependsOn().add(externalMeterCommandUuid);
}
return result;
}
use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class UniCastDiscoveryRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
List<SpeakerData> commands = new ArrayList<>();
Instructions instructions = Instructions.builder().applyActions(new ArrayList<>()).build();
FlowSpeakerData flowCommand = buildRule(sw, instructions);
if (flowCommand == null) {
return Collections.emptyList();
} else {
commands.add(flowCommand);
}
MeterId meterId = createMeterIdForDefaultRule(VERIFICATION_UNICAST_RULE_COOKIE);
SpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, config.getUnicastRateLimit(), config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
if (meterCommand != null) {
commands.add(meterCommand);
addMeterToInstructions(meterId, sw, instructions);
}
instructions.getApplyActions().add(new PortOutAction(new PortNumber(SpecialPortType.CONTROLLER)));
// todo remove useless set field action
instructions.getApplyActions().add(SetFieldAction.builder().field(Field.ETH_DST).value(sw.getSwitchId().toLong()).build());
if (meterCommand != null) {
flowCommand.getDependsOn().add(meterCommand.getUuid());
}
return commands;
}
use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class ArpRuleGenerator method buildCommands.
protected List<SpeakerData> buildCommands(Switch sw, Cookie cookie, OfTable table, int priority, Set<FieldMatch> match, Instructions instructions) {
FlowSpeakerData flowCommand = FlowSpeakerData.builder().switchId(sw.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(cookie).table(table).priority(priority).match(match).instructions(instructions).build();
List<SpeakerData> result = Lists.newArrayList(flowCommand);
MeterSpeakerData meterCommand = generateMeter(sw, cookie);
if (meterCommand != null) {
result.add(meterCommand);
addMeterToInstructions(meterCommand.getMeterId(), sw, instructions);
flowCommand.getDependsOn().add(meterCommand.getUuid());
}
return result;
}
use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.
the class MultiTableIngressRuleGeneratorTest method buildCommandsVlanEncapsulationDoubleVlanWithOuterVlanOverlappingTest.
@Test
public void buildCommandsVlanEncapsulationDoubleVlanWithOuterVlanOverlappingTest() {
Flow oneSwitchFlow = buildFlow(ONE_SWITCH_PATH, OUTER_VLAN_ID_1, 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(2, commands.size());
FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
MeterSpeakerData meterCommand = (MeterSpeakerData) commands.get(1);
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)));
assertIngressCommand(ingressCommand, Priority.DOUBLE_VLAN_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, METER_ID, null);
assertMeterCommand(meterCommand);
}
Aggregations