sFlow实现可以分成4个部分:1)配置;2)流表生成(生成datapath的流表);3)datapath中的处理(已经分析);4)sFlow处理过程。本篇分析sFlow的配置过程。
1、bridge_configure_sflow函数
/* Set sFlow configuration on 'br'. */
static void
bridge_configure_sflow(struct bridge *br, int *sflow_bridge_number)
{
const struct ovsrec_sflow *cfg = br->cfg->sflow;
struct ovsrec_controller **controllers;
struct ofproto_sflow_options oso;
size_t n_controllers;
size_t i;
if (!cfg) {
ofproto_set_sflow(br->ofproto, NULL);
return;
}
memset(&oso, 0, sizeof oso);
sset_init(&oso.targets);
sset_add_array(&oso.targets, cfg->targets, cfg->n_targets); //sFlow统计信息接收器
oso.sampling_rate = SFL_DEFAULT_SAMPLING_RATE;
if (cfg->sampling) {
oso.sampling_rate = *cfg->sampling; //采样频率
}
oso.polling_interval = SFL_DEFAULT_POLLING_INTERVAL;
if (cfg->polling) {
oso.polling_interval = *cfg->polling;
}
oso.header_len = SFL_DEFAULT_HEADER_SIZE;
if (cfg->header) {
oso.header_len = *cfg->header;
}
oso.sub_id = (*sflow_bridge_number)++;
oso.agent_device = cfg->agent; //agent设备,可以提取本地IP地址
oso.control_ip = NULL;
n_controllers = bridge_get_controllers(br, &controllers);
for (i = 0; i < n_controllers; i++) {
if (controllers[i]->local_ip) {
oso.control_ip = controllers[i]->local_ip; //控制IP,作为本地IP使用
break;
}
}
ofproto_set_sflow(br->ofproto, &oso); //配置sflow
sset_destroy(&oso.targets);
}
2、ofproto_set_sflow函数
int
ofproto_set_sflow(struct ofproto *ofproto,
const struct of