Search in sources :

Example 21 with MeterSpeakerData

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;
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) ArrayList(java.util.ArrayList) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) MeterId(org.openkilda.model.MeterId)

Example 22 with MeterSpeakerData

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;
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData)

Example 23 with MeterSpeakerData

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;
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData)

Example 24 with MeterSpeakerData

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);
    }
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) ArrayList(java.util.ArrayList)

Example 25 with MeterSpeakerData

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);
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) MeterAction(org.openkilda.rulemanager.action.MeterAction) Action(org.openkilda.rulemanager.action.Action) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) Instructions(org.openkilda.rulemanager.Instructions) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Aggregations

MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)38 Test (org.junit.Test)30 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)30 SpeakerData (org.openkilda.rulemanager.SpeakerData)27 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)17 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)14 Action (org.openkilda.rulemanager.action.Action)13 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)11 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)9 Flow (org.openkilda.model.Flow)8 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)8 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)8 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)8 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)8 MeterId (org.openkilda.model.MeterId)7 Instructions (org.openkilda.rulemanager.Instructions)6 RoutingMetadata (org.openkilda.rulemanager.utils.RoutingMetadata)6 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)6 ValidationService (org.openkilda.wfm.topology.switchmanager.service.ValidationService)6 MeterAction (org.openkilda.rulemanager.action.MeterAction)5