use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
// should be replaced with fair feature detection based on ActionId's during handshake
if (!(sw.getFeatures().contains(NOVIFLOW_PUSH_POP_VXLAN) || sw.getFeatures().contains(KILDA_OVS_PUSH_POP_MATCH_VXLAN))) {
return Collections.emptyList();
}
Cookie cookie = new Cookie(VERIFICATION_UNICAST_VXLAN_RULE_COOKIE);
FlowSpeakerData flowCommand = buildUnicastVerificationRuleVxlan(sw, cookie);
List<SpeakerData> result = new ArrayList<>();
result.add(flowCommand);
MeterId meterId = createMeterIdForDefaultRule(cookie.getValue());
long meterRate = config.getUnicastRateLimit();
MeterSpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, meterRate, config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
if (meterCommand != null) {
addMeterToInstructions(meterId, sw, flowCommand.getInstructions());
flowCommand.getDependsOn().add(meterCommand.getUuid());
result.add(meterCommand);
}
return result;
}
use of org.openkilda.rulemanager.MeterSpeakerData 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.MeterSpeakerData in project open-kilda by telstra.
the class LldpRuleGenerator 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.MeterSpeakerData in project open-kilda by telstra.
the class OfBatchExecutor method verifyMeters.
private void verifyMeters() {
log.debug("Verify meters with key: {} (hasMeters={})", kafkaKey, hasMeters);
if (!hasMeters) {
return;
}
boolean inaccurate = switchFeatures.contains(SwitchFeature.INACCURATE_METER);
try {
List<OFMeterConfigStatsReply> replies = meterStats.get();
List<MeterSpeakerData> switchMeters = new ArrayList<>();
replies.forEach(reply -> switchMeters.addAll(OfMeterConverter.INSTANCE.convertToMeterSpeakerData(reply, inaccurate)));
for (MeterSpeakerData switchMeter : switchMeters) {
MeterSpeakerData expectedMeter = holder.getByMeterId(switchMeter.getMeterId());
if (expectedMeter != null) {
if (switchMeter.equals(expectedMeter)) {
holder.recordSuccessUuid(expectedMeter.getUuid());
} else {
holder.recordFailedUuid(expectedMeter.getUuid(), format("Failed to validate meter on a switch. Expected: %s, actual: %s. " + "Switch features: %s.", expectedMeter, switchMeter, switchFeatures));
}
}
}
} catch (Exception e) {
log.error("Failed to verify meters for message", e);
}
}
use of org.openkilda.rulemanager.MeterSpeakerData 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