X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fofproto-sflow.c;h=44c94a124ff1b9c102a903c7100d6cabc17f97fd;hb=02ef592c379d359bb447ae5fbb709e485dcb5103;hp=aa91460f66d7f31912675a19ec0b6960a55af9e8;hpb=5aafcfe30afc383e53d8345cc781c644964d0e91;p=openvswitch diff --git a/ofproto/ofproto-sflow.c b/ofproto/ofproto-sflow.c index aa91460f..44c94a12 100644 --- a/ofproto/ofproto-sflow.c +++ b/ofproto/ofproto-sflow.c @@ -212,7 +212,7 @@ sflow_choose_agent_address(const char *agent_device, const char *control_ip, if (agent_device) { struct netdev *netdev; - if (!netdev_open(agent_device, NETDEV_ETH_TYPE_NONE, &netdev)) { + if (!netdev_open_default(agent_device, &netdev)) { int error = netdev_get_in4(netdev, &in4, NULL); netdev_close(netdev); if (!error) { @@ -296,6 +296,17 @@ ofproto_sflow_add_poller(struct ofproto_sflow *os, sfl_poller_set_bridgePort(poller, odp_port); } +static void +ofproto_sflow_add_sampler(struct ofproto_sflow *os, + struct ofproto_sflow_port *osp, + u_int32_t sampling_rate, u_int32_t header_len) +{ + SFLSampler *sampler = sfl_agent_addSampler(os->sflow_agent, &osp->dsi); + sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, sampling_rate); + sfl_sampler_set_sFlowFsMaximumHeaderSize(sampler, header_len); + sfl_sampler_set_sFlowFsReceiver(sampler, RECEIVER_INDEX); +} + void ofproto_sflow_add_port(struct ofproto_sflow *os, uint16_t odp_port, const char *netdev_name) @@ -308,7 +319,7 @@ ofproto_sflow_add_port(struct ofproto_sflow *os, uint16_t odp_port, ofproto_sflow_del_port(os, odp_port); /* Open network device. */ - error = netdev_open(netdev_name, NETDEV_ETH_TYPE_NONE, &netdev); + error = netdev_open_default(netdev_name, &netdev); if (error) { VLOG_WARN_RL(&rl, "failed to open network device \"%s\": %s", netdev_name, strerror(error)); @@ -338,6 +349,7 @@ ofproto_sflow_del_port(struct ofproto_sflow *os, uint16_t odp_port) if (osp) { if (os->sflow_agent) { sfl_agent_removePoller(os->sflow_agent, &osp->dsi); + sfl_agent_removeSampler(os->sflow_agent, &osp->dsi); } netdev_close(osp->netdev); free(osp); @@ -350,14 +362,11 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, const struct ofproto_sflow_options *options) { struct ofproto_sflow_port *osp; - SFLDataSource_instance dsi; bool options_changed; - SFLSampler *sampler; SFLReceiver *receiver; unsigned int odp_port; SFLAddress agentIP; time_t now; - int error; if (!options->targets.n || !options->sampling_rate) { /* No point in doing any work if there are no targets or nothing to @@ -375,8 +384,8 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, if (options_changed || collectors_count(os->collectors) < options->targets.n) { collectors_destroy(os->collectors); - error = collectors_create(&options->targets, - SFL_DEFAULT_COLLECTOR_PORT, &os->collectors); + collectors_create(&options->targets, SFL_DEFAULT_COLLECTOR_PORT, + &os->collectors); if (os->collectors == NULL) { VLOG_WARN_RL(&rl, "no collectors could be initialized, " "sFlow disabled"); @@ -421,27 +430,14 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, sfl_receiver_set_sFlowRcvrOwner(receiver, "Open vSwitch sFlow"); sfl_receiver_set_sFlowRcvrTimeout(receiver, 0xffffffff); - /* Add a single sampler to represent the datapath (special :0 - * datasource). The alternative is to model a physical switch more closely - * and instantiate a separate sampler object for each interface, but then - * unicasts would have to be offered to two samplers, and - * broadcasts/multicasts would have to be offered to all of them. Doing it - * this way with a single :0 sampler is much more efficient for a - * virtual switch, and is allowed by the sFlow standard. - */ - SFL_DS_SET(dsi, 0, 0, 0); - sampler = sfl_agent_addSampler(os->sflow_agent, &dsi); - sfl_sampler_set_sFlowFsReceiver(sampler, RECEIVER_INDEX); - sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, options->sampling_rate); - sfl_sampler_set_sFlowFsMaximumHeaderSize(sampler, options->header_len); - /* Set the sampling_rate down in the datapath. */ dpif_set_sflow_probability(os->dpif, MAX(1, UINT32_MAX / options->sampling_rate)); - /* Add the currently known ports. */ + /* Add samplers and pollers for the currently known ports. */ PORT_ARRAY_FOR_EACH (osp, &os->ports, odp_port) { - ofproto_sflow_add_poller(os, osp, odp_port); + ofproto_sflow_add_sampler(os, osp, + options->sampling_rate, options->header_len); } } @@ -460,7 +456,7 @@ ofproto_sflow_received(struct ofproto_sflow *os, struct odp_msg *msg) SFLFlow_sample_element hdrElem; SFLSampled_header *header; SFLFlow_sample_element switchElem; - SFLSampler *sampler = os->sflow_agent->samplers; + SFLSampler *sampler; const struct odp_sflow_sample_header *hdr; const union odp_action *actions; struct ofpbuf payload; @@ -505,6 +501,16 @@ ofproto_sflow_received(struct ofproto_sflow *os, struct odp_msg *msg) fs.output = 0; /* Filled in correctly below. */ fs.sample_pool = hdr->sample_pool; + /* We are going to give it to the sampler that represents this input port. + * By implementing "ingress-only" sampling like this we ensure that we + * never have to offer the same sample to more than one sampler. */ + sampler = sfl_agent_getSamplerByIfIndex(os->sflow_agent, fs.input); + if (!sampler) { + VLOG_WARN_RL(&rl, "no sampler for input ifIndex (%"PRIu32")", + fs.input); + return; + } + /* Sampled header. */ memset(&hdrElem, 0, sizeof hdrElem); hdrElem.tag = SFLFLOW_HEADER;