近期項目中要使用Ovs bond接口,Ovs Bond 隻有三種模式:balance-tcp,balance-slb,active-backup。這三種模式的工作方式如下:
1、active-backup:主備模式 2、balance-slb:負荷分擔,根據源MAC位址負荷分擔 3、balance-tcp:負荷分擔,根據IP位址+TCP端口進行負荷分擔。
虛拟交換機 bond支援以下幾種模式,根據實際組網需求進行選擇:
網絡類型 | 本端bond_mode | 本端 LACP | 對實體交換機 bond-mode | 對端 LACP |
vxlan | active-backup | Off | 不配 bond | |
balance-slb | Off | 不配 bond | ||
Balance-tcp | Active | 必須配bond | Active或者passive | |
Vlan | Active-backup | Off | 不配 bond | |
Balance-slb | Off | 不配 bond | ||
Balance-tcp | Active | 必須配bond | Active 或者passive |
重點說下,Balance-tcp模式和Lacp。Ovs Bond的部分代碼如下:
static struct bond_slave *
choose_output_slave(const struct bond *bond, const struct flow *flow,
struct flow_wildcards *wc, uint16_t vlan)
{
struct bond_entry *e;
int balance;
balance = bond->balance;
/*
判斷lacp的狀态,若配置了沒協商起來,狀态就是LACP_CONFIGURED
*/
if (bond->lacp_status == LACP_CONFIGURED) {
/* LACP has been configured on this bond but negotiations were
* unsuccussful. If lacp_fallback_ab is enabled use active-
* backup mode else drop all traffic.
若lacp_fallback_ab沒配置為active-backup(協商失敗使用),則直接丢包 */
if (!bond->lacp_fallback_ab) {
return NULL;
}
balance = BM_AB;
}
switch (balance) {
case BM_AB:
return bond->active_slave;
/* BM_TCP模式下,必然要協商起來,沒協商起來就要丢包 */
case BM_TCP:
if (bond->lacp_status != LACP_NEGOTIATED) {
/* Must have LACP negotiations for TCP balanced bonds. */
return NULL;
}
if (wc) {
flow_mask_hash_fields(flow, wc, NX_HASH_FIELDS_SYMMETRIC_L4);
}
/* Fall Through. */
case BM_SLB:
if (wc) {
flow_mask_hash_fields(flow, wc, NX_HASH_FIELDS_ETH_SRC);
}
e = lookup_bond_entry(bond, flow, vlan);
if (!e->slave || !e->slave->enabled) {
e->slave = get_enabled_slave(CONST_CAST(struct bond*, bond));
}
return e->slave;
default:
OVS_NOT_REACHED();
}
}