Skip to content

Commit

Permalink
Fix division by zero crash when doing metering (#529)
Browse files Browse the repository at this point in the history
* Revert "Workaround for division by zero crash (#385)"

This reverts commit 103b198.

* Revert "QoS: Use params to profile map, carry pointer"

This reverts commit d2c0793.

Co-authored-by: Maximilian Pudelko <pudelkoM@users.noreply.github.com>
  • Loading branch information
amarsri28 and pudelkoM committed Mar 2, 2022
1 parent 318b049 commit 9cb736e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 62 deletions.
59 changes: 17 additions & 42 deletions core/modules/qos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,19 @@ void Qos::ProcessBatch(Context *ctx, bess::PacketBatch *batch) {

// meter if ogate is 0
if (ogate == METER_GATE) {
if (val[j]->p->cir_period == 0 || val[j]->p->pir_period == 0) {
// FIXME: https://github.com/omec-project/upf-epc/issues/376
DLOG(INFO) << "Detected pir/cir_period zero in rte_meter_trtcm_profile,"
<< " BUG? Setting METER_GREEN_GATE to prevent crash"
<< std::endl;
uint64_t time = rte_rdtsc();
uint32_t pkt_len = pkt->total_len() - val[j]->deduct_len;
uint8_t color = rte_meter_trtcm_color_blind_check(&val[j]->m, &val[j]->p,
time, pkt_len);

DLOG(INFO) << "color : " << color << std::endl;
// update ogate to color specific gate
if (color == RTE_COLOR_GREEN) {
ogate = METER_GREEN_GATE;
} else {
uint64_t time = rte_rdtsc();
uint32_t pkt_len = pkt->total_len() - val[j]->deduct_len;
uint8_t color = rte_meter_trtcm_color_blind_check(&val[j]->m, val[j]->p,
time, pkt_len);

DLOG(INFO) << "color : " << color << std::endl;
// update ogate to color specific gate
if (color == RTE_COLOR_GREEN) {
ogate = METER_GREEN_GATE;
} else if (color == RTE_COLOR_YELLOW) {
ogate = METER_YELLOW_GATE;
} else if (color == RTE_COLOR_RED) {
ogate = METER_RED_GATE;
}
} else if (color == RTE_COLOR_YELLOW) {
ogate = METER_YELLOW_GATE;
} else if (color == RTE_COLOR_RED) {
ogate = METER_RED_GATE;
}
}

Expand Down Expand Up @@ -386,28 +378,12 @@ CommandResponse Qos::CommandAdd(const bess::pb::QosCommandAddArg &arg) {
struct rte_meter_trtcm_params app_trtcm_params = {
.cir = cir, .pir = pir, .cbs = cbs, .pbs = pbs};

auto *result = params_map_.Find(app_trtcm_params);

if (result == nullptr) {
struct rte_meter_trtcm_profile p;

int ret = rte_meter_trtcm_profile_config(&p, &app_trtcm_params);
if (ret)
return CommandFailure(
ret,
"Insert Failed - rte_meter_trtcm_profile_config creation failed");

result = params_map_.Insert(app_trtcm_params, p);
if (result == nullptr) {
return CommandFailure(
ret,
"Insert Failed - rte_meter_trtcm_profile_config map insert failed");
}
}

v.p = &result->second;
int ret = rte_meter_trtcm_profile_config(&v.p, &app_trtcm_params);
if (ret)
return CommandFailure(
ret, "Insert Failed - rte_meter_trtcm_profile_config failed");

int ret = rte_meter_trtcm_config(&v.m, v.p);
ret = rte_meter_trtcm_config(&v.m, &v.p);
if (ret) {
return CommandFailure(ret,
"Insert Failed - rte_meter_trtcm_config failed");
Expand All @@ -433,7 +409,6 @@ CommandResponse Qos::CommandClear(__attribute__((unused))

void Qos::Clear() {
table_.Clear();
params_map_.Clear();
}

void Qos::DeInit() {
Expand Down
21 changes: 1 addition & 20 deletions core/modules/qos.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#include <rte_hash_crc.h>

#include "../pb/module_msg.pb.h"
#include "../utils/cuckoo_map.h"
#include "../utils/metering.h"

using bess::utils::CuckooMap;
using bess::utils::Metering;
using bess::utils::MeteringKey;

Expand All @@ -40,7 +38,7 @@ enum { FieldType = 0, ValueType };
struct value {
gate_idx_t ogate;
int64_t deduct_len;
struct rte_meter_trtcm_profile *p;
struct rte_meter_trtcm_profile p;
struct rte_meter_trtcm m;
MeteringKey Data;
} __attribute__((packed));
Expand All @@ -56,21 +54,6 @@ class Qos final : public Module {

static const Commands cmds;

struct Hash {
bess::utils::HashResult operator()(
const rte_meter_trtcm_params &key) const {
return rte_hash_crc(&key, sizeof(rte_meter_trtcm_params), 0);
}
};

struct EqualTo {
bool operator()(const rte_meter_trtcm_params &p1,
const rte_meter_trtcm_params &p2) const {
return (p1.cir == p2.cir) && (p1.pir == p2.pir) && (p1.cbs == p2.cbs) &&
(p1.pbs == p2.pbs);
}
};

Qos() : Module(), default_gate_(), total_key_size_(), fields_() {
max_allowed_workers_ = Worker::kMaxWorkers;
size_t len = sizeof(mask) / sizeof(uint64_t);
Expand Down Expand Up @@ -106,8 +89,6 @@ class Qos final : public Module {
std::vector<struct MeteringField> values_;
Metering<value> table_;
uint64_t mask[MAX_FIELDS];
CuckooMap<rte_meter_trtcm_params, rte_meter_trtcm_profile, Hash, EqualTo>
params_map_;
};

#endif // BESS_MODULES_QOS_H

0 comments on commit 9cb736e

Please sign in to comment.