From 1b137691320fbf0d1e545a146495d8988cd62200 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Tue, 12 Apr 2011 13:39:32 -0700 Subject: [PATCH] bond: New function bond_is_balanced(). As new bond modes are added, it will be nice to have the logic indicating whether or not a given bond mode requires rebalancing in one place. --- lib/bond.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/bond.c b/lib/bond.c index de71b9f1..dad34ada 100644 --- a/lib/bond.c +++ b/lib/bond.c @@ -682,23 +682,20 @@ bond_process_lacp(struct bond *bond, void *slave_, const struct ofpbuf *packet) /* Rebalancing. */ +static bool +bond_is_balanced(const struct bond *bond) +{ + return bond->balance == BM_SLB || bond->balance == BM_TCP; +} + /* Notifies 'bond' that 'n_bytes' bytes were sent in 'flow' within 'vlan'. */ void bond_account(struct bond *bond, const struct flow *flow, uint16_t vlan, uint64_t n_bytes) { - switch (bond->balance) { - case BM_AB: - /* Nothing to do. */ - break; - case BM_SLB: - case BM_TCP: + if (bond_is_balanced(bond)) { lookup_bond_entry(bond, flow, vlan)->tx_bytes += n_bytes; - break; - - default: - NOT_REACHED(); } } @@ -844,7 +841,7 @@ bond_rebalance(struct bond *bond, struct tag_set *tags) struct bond_entry *e; struct list bals; - if (bond->balance == BM_AB || time_msec() < bond->next_rebalance) { + if (!bond_is_balanced(bond) || time_msec() < bond->next_rebalance) { return; } bond->next_rebalance = time_msec() + bond->rebalance_interval; @@ -1020,7 +1017,7 @@ bond_unixctl_show(struct unixctl_conn *conn, ds_put_format(&ds, "updelay: %d ms\n", bond->updelay); ds_put_format(&ds, "downdelay: %d ms\n", bond->downdelay); - if (bond->balance != BM_AB) { + if (bond_is_balanced(bond)) { ds_put_format(&ds, "next rebalance: %lld ms\n", bond->next_rebalance - time_msec()); } @@ -1041,7 +1038,7 @@ bond_unixctl_show(struct unixctl_conn *conn, slave->delay_expires - time_msec()); } - if (bond->balance == BM_AB) { + if (!bond_is_balanced(bond)) { continue; } -- 2.30.2