+static void
+create_meter_policy(void)
+{
+ struct rte_mtr_error error;
+ int ret, port_id;
+ struct rte_mtr_meter_policy_params policy;
+ uint16_t nr_ports;
+ struct rte_flow_action actions[RTE_COLORS][MAX_ACTIONS_NUM];
+ int i;
+
+ memset(actions, 0, sizeof(actions));
+ memset(&policy, 0, sizeof(policy));
+ nr_ports = rte_eth_dev_count_avail();
+ for (port_id = 0; port_id < nr_ports; port_id++) {
+ for (i = 0; i < RTE_COLORS; i++)
+ fill_actions(actions[i], all_actions[i], 0, 0, 0,
+ 0, 0, 0, unique_data, rx_queues_count,
+ dst_ports[port_id]);
+ policy.actions[RTE_COLOR_GREEN] = actions[RTE_COLOR_GREEN];
+ policy.actions[RTE_COLOR_YELLOW] = actions[RTE_COLOR_YELLOW];
+ policy.actions[RTE_COLOR_RED] = actions[RTE_COLOR_RED];
+ policy_id[port_id] = port_id + 10;
+ ret = rte_mtr_meter_policy_add(port_id, policy_id[port_id],
+ &policy, &error);
+ if (ret) {
+ fprintf(stderr, "port %d: failed to create meter policy\n",
+ port_id);
+ policy_id[port_id] = UINT32_MAX;
+ }
+ memset(actions, 0, sizeof(actions));
+ }
+}
+
+static void
+destroy_meter_policy(void)
+{
+ struct rte_mtr_error error;
+ uint16_t nr_ports;
+ int port_id;
+
+ nr_ports = rte_eth_dev_count_avail();
+ for (port_id = 0; port_id < nr_ports; port_id++) {
+ /* If port outside portmask */
+ if (!((ports_mask >> port_id) & 0x1))
+ continue;
+
+ if (rte_mtr_meter_policy_delete
+ (port_id, policy_id[port_id], &error)) {
+ fprintf(stderr, "port %u: failed to delete meter policy\n",
+ port_id);
+ rte_exit(EXIT_FAILURE, "Error: Failed to delete meter policy.\n");
+ }
+ }
+}
+