// We may want to account for the length of headers in len // calculation, like ETH header + overhead, specially if it // is a gso packet. But I am not doing it right now.
// Begin critical section
bpf_spin_lock(&qdp->lock);
credit = qdp->credit;
delta = curtime - qdp->lasttime; /* delta < 0 implies that another process with a curtime greater *thanoursbeatustothecriticalsectionandalreadyadded *thenewcredit,soweshouldnotadditourselves
*/ if (delta > 0) {
qdp->lasttime = curtime;
new_credit = credit + CREDIT_PER_NS(delta, qdp->rate); if (new_credit > MAX_CREDIT)
credit = MAX_CREDIT; else
credit = new_credit;
}
credit -= len;
qdp->credit = credit;
bpf_spin_unlock(&qdp->lock); // End critical section
// Check if we should update rate if (qsp != NULL && (qsp->rate * 128) != qdp->rate) {
qdp->rate = qsp->rate * 128;
bpf_printk("Updating rate: %d (1sec:%llu bits)\n",
(int)qdp->rate,
CREDIT_PER_NS(1000000000, qdp->rate) * 8);
}
// Set flags (drop, congestion, cwr) // Dropping => we are congested, so ignore congestion flag if (credit < -DROP_THRESH ||
(len > LARGE_PKT_THRESH && credit < -LARGE_PKT_DROP_THRESH)) { // Very congested, set drop packet
drop_flag = true; if (pkti.ecn)
congestion_flag = true; elseif (pkti.is_tcp)
cwr_flag = true;
} elseif (credit < 0) { // Congested, set congestion flag if (pkti.ecn || pkti.is_tcp) { if (credit < -MARK_THRESH)
congestion_flag = true; else
congestion_flag = false;
} else {
congestion_flag = true;
}
}
if (congestion_flag) { if (bpf_skb_ecn_set_ce(skb)) {
ecn_ce_flag = true;
} else { if (pkti.is_tcp) { unsignedint rand = bpf_get_prandom_u32();
if (-credit >= MARK_THRESH +
(rand % MARK_REGION_SIZE)) { // Do congestion control
cwr_flag = true;
}
} elseif (len > LARGE_PKT_THRESH) { // Problem if too many small packets?
drop_flag = true;
}
}
}
if (qsp != NULL) if (qsp->no_cn)
cwr_flag = false;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.