ofproto: fix compile warning of ofproto/ofproto.c
[openvswitch] / ofproto / ofproto-sflow.c
index f764dc4ecced1ce32f09097e7d44d87683e71665..60baf0e9e82c2f3bbba1ad351baaca5164c20244 100644 (file)
@@ -239,9 +239,6 @@ success:
 void
 ofproto_sflow_clear(struct ofproto_sflow *os)
 {
-    struct ofproto_sflow_port *osp;
-    unsigned int odp_port;
-
     if (os->sflow_agent) {
         sfl_agent_release(os->sflow_agent);
         os->sflow_agent = NULL;
@@ -251,11 +248,6 @@ ofproto_sflow_clear(struct ofproto_sflow *os)
     ofproto_sflow_options_destroy(os->options);
     os->options = NULL;
 
-    PORT_ARRAY_FOR_EACH (osp, &os->ports, odp_port) {
-        ofproto_sflow_del_port(os, odp_port);
-    }
-    port_array_clear(&os->ports);
-
     /* Turn off sampling to save CPU cycles. */
     dpif_set_sflow_probability(os->dpif, 0);
 }
@@ -282,7 +274,13 @@ void
 ofproto_sflow_destroy(struct ofproto_sflow *os)
 {
     if (os) {
+        struct ofproto_sflow_port *osp;
+        unsigned int odp_port;
+
         ofproto_sflow_clear(os);
+        PORT_ARRAY_FOR_EACH (osp, &os->ports, odp_port) {
+            ofproto_sflow_del_port(os, odp_port);
+        }
         port_array_destroy(&os->ports);
         free(os);
     }
@@ -301,12 +299,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 +336,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 +437,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);
     }
 }