+/* Returns whether a IPFIX row is valid. */
+static bool
+ovsrec_ipfix_is_valid(const struct ovsrec_ipfix *ipfix)
+{
+ return ipfix && ipfix->n_targets > 0;
+}
+
+/* Returns whether a Flow_Sample_Collector_Set row is valid. */
+static bool
+ovsrec_fscs_is_valid(const struct ovsrec_flow_sample_collector_set *fscs,
+ const struct bridge *br)
+{
+ return ovsrec_ipfix_is_valid(fscs->ipfix) && fscs->bridge == br->cfg;
+}
+
+/* Set IPFIX configuration on 'br'. */
+static void
+bridge_configure_ipfix(struct bridge *br)
+{
+ const struct ovsrec_ipfix *be_cfg = br->cfg->ipfix;
+ bool valid_be_cfg = ovsrec_ipfix_is_valid(be_cfg);
+ const struct ovsrec_flow_sample_collector_set *fe_cfg;
+ struct ofproto_ipfix_bridge_exporter_options be_opts;
+ struct ofproto_ipfix_flow_exporter_options *fe_opts = NULL;
+ size_t n_fe_opts = 0;
+
+ OVSREC_FLOW_SAMPLE_COLLECTOR_SET_FOR_EACH(fe_cfg, idl) {
+ if (ovsrec_fscs_is_valid(fe_cfg, br)) {
+ n_fe_opts++;
+ }
+ }
+
+ if (!valid_be_cfg && n_fe_opts == 0) {
+ ofproto_set_ipfix(br->ofproto, NULL, NULL, 0);
+ return;
+ }
+
+ if (valid_be_cfg) {
+ memset(&be_opts, 0, sizeof be_opts);
+
+ sset_init(&be_opts.targets);
+ sset_add_array(&be_opts.targets, be_cfg->targets, be_cfg->n_targets);
+
+ if (be_cfg->sampling) {
+ be_opts.sampling_rate = *be_cfg->sampling;
+ } else {
+ be_opts.sampling_rate = SFL_DEFAULT_SAMPLING_RATE;
+ }
+ if (be_cfg->obs_domain_id) {
+ be_opts.obs_domain_id = *be_cfg->obs_domain_id;
+ }
+ if (be_cfg->obs_point_id) {
+ be_opts.obs_point_id = *be_cfg->obs_point_id;
+ }
+ if (be_cfg->cache_active_timeout) {
+ be_opts.cache_active_timeout = *be_cfg->cache_active_timeout;
+ }
+ if (be_cfg->cache_max_flows) {
+ be_opts.cache_max_flows = *be_cfg->cache_max_flows;
+ }
+ }
+
+ if (n_fe_opts > 0) {
+ struct ofproto_ipfix_flow_exporter_options *opts;
+ fe_opts = xcalloc(n_fe_opts, sizeof *fe_opts);
+ opts = fe_opts;
+ OVSREC_FLOW_SAMPLE_COLLECTOR_SET_FOR_EACH(fe_cfg, idl) {
+ if (ovsrec_fscs_is_valid(fe_cfg, br)) {
+ opts->collector_set_id = fe_cfg->id;
+ sset_init(&opts->targets);
+ sset_add_array(&opts->targets, fe_cfg->ipfix->targets,
+ fe_cfg->ipfix->n_targets);
+ opts->cache_active_timeout = fe_cfg->ipfix->cache_active_timeout
+ ? *fe_cfg->ipfix->cache_active_timeout : 0;
+ opts->cache_max_flows = fe_cfg->ipfix->cache_max_flows
+ ? *fe_cfg->ipfix->cache_max_flows : 0;
+ opts++;
+ }
+ }
+ }
+
+ ofproto_set_ipfix(br->ofproto, valid_be_cfg ? &be_opts : NULL, fe_opts,
+ n_fe_opts);
+
+ if (valid_be_cfg) {
+ sset_destroy(&be_opts.targets);
+ }
+
+ if (n_fe_opts > 0) {
+ struct ofproto_ipfix_flow_exporter_options *opts = fe_opts;
+ size_t i;
+ for (i = 0; i < n_fe_opts; i++) {
+ sset_destroy(&opts->targets);
+ opts++;
+ }
+ free(fe_opts);
+ }
+}
+