sflow: Always add poller and sampler together.
authorNeil McKee <neil.mckee@inmon.com>
Wed, 5 May 2010 20:26:23 +0000 (13:26 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 5 May 2010 20:27:11 +0000 (13:27 -0700)
he ofproto_sflow_add_poller() and ofproto_sflow_add_sampler() calls
should always be made together, either when a port is added
dynamically with ofproto_sflow_add_port() or when the sflow_agent is
first created in ofproto_sflow_set_options().  I was seeing odd
behavior where either the pollers or the samplers would never be
instantiated depending on the order that things happened.  (It's OK to
add the same sampler or poller again, because the library routines
sfl_agent_addPoller() and sfl_agent_addSampler() will just return the
existing one if it is there.  Perhaps we should add a comment to make
that clear?).

I changed the parameters to ofproto_sflow_add_sampler to make it work
the same way as ofproto_sflow_add_poller, where the options are
extracted from os->options within the function itself.

ofproto/ofproto-sflow.c

index f764dc4ecced1ce32f09097e7d44d87683e71665..22d99eb7cf87797a3f0ee39a8f3a1a6dbb284b4e 100644 (file)
@@ -301,12 +301,11 @@ ofproto_sflow_add_poller(struct ofproto_sflow *os,
 
 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)
+                         struct ofproto_sflow_port *osp)
 {
     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_sFlowFsPacketSamplingRate(sampler, os->options->sampling_rate);
+    sfl_sampler_set_sFlowFsMaximumHeaderSize(sampler, os->options->header_len);
     sfl_sampler_set_sFlowFsReceiver(sampler, RECEIVER_INDEX);
 }
 
@@ -339,9 +338,10 @@ ofproto_sflow_add_port(struct ofproto_sflow *os, uint16_t odp_port,
     SFL_DS_SET(osp->dsi, 0, ifindex, 0);
     port_array_set(&os->ports, odp_port, osp);
 
-    /* Add poller. */
+    /* Add poller and sampler. */
     if (os->sflow_agent) {
         ofproto_sflow_add_poller(os, osp, odp_port);
+        ofproto_sflow_add_sampler(os, osp);
     }
 }
 
@@ -439,8 +439,8 @@ ofproto_sflow_set_options(struct ofproto_sflow *os,
 
     /* Add samplers and pollers for the currently known ports. */
     PORT_ARRAY_FOR_EACH (osp, &os->ports, odp_port) {
-        ofproto_sflow_add_sampler(os, osp,
-                                  options->sampling_rate, options->header_len);
+        ofproto_sflow_add_poller(os, osp, odp_port);
+        ofproto_sflow_add_sampler(os, osp);
     }
 }