+ bool opened;
+};
+\f
+/* Traffic control. */
+
+/* An instance of a traffic control class. Always associated with a particular
+ * network device.
+ *
+ * Each TC implementation subclasses this with whatever additional data it
+ * needs. */
+struct tc {
+ const struct tc_ops *ops;
+ struct hmap queues; /* Contains "struct tc_queue"s.
+ * Read by generic TC layer.
+ * Written only by TC implementation. */
+};
+
+/* One traffic control queue.
+ *
+ * Each TC implementation subclasses this with whatever additional data it
+ * needs. */
+struct tc_queue {
+ struct hmap_node hmap_node; /* In struct tc's "queues" hmap. */
+ unsigned int queue_id; /* OpenFlow queue ID. */
+};
+
+/* A particular kind of traffic control. Each implementation generally maps to
+ * one particular Linux qdisc class.
+ *
+ * The functions below return 0 if successful or a positive errno value on
+ * failure, except where otherwise noted. All of them must be provided, except
+ * where otherwise noted. */
+struct tc_ops {
+ /* Name used by kernel in the TCA_KIND attribute of tcmsg, e.g. "htb".
+ * This is null for tc_ops_default and tc_ops_other, for which there are no
+ * appropriate values. */
+ const char *linux_name;
+
+ /* Name used in OVS database, e.g. "linux-htb". Must be nonnull. */
+ const char *ovs_name;
+
+ /* Number of supported OpenFlow queues, 0 for qdiscs that have no
+ * queues. The queues are numbered 0 through n_queues - 1. */
+ unsigned int n_queues;
+
+ /* Called to install this TC class on 'netdev'. The implementation should
+ * make the Netlink calls required to set up 'netdev' with the right qdisc
+ * and configure it according to 'details'. The implementation may assume
+ * that the current qdisc is the default; that is, there is no need for it
+ * to delete the current qdisc before installing itself.
+ *
+ * The contents of 'details' should be documented as valid for 'ovs_name'
+ * in the "other_config" column in the "QoS" table in vswitchd/vswitch.xml
+ * (which is built as ovs-vswitchd.conf.db(8)).
+ *
+ * This function must return 0 if and only if it sets 'netdev->tc' to an
+ * initialized 'struct tc'.
+ *
+ * (This function is null for tc_ops_other, which cannot be installed. For
+ * other TC classes it should always be nonnull.) */
+ int (*tc_install)(struct netdev *netdev, const struct shash *details);
+
+ /* Called when the netdev code determines (through a Netlink query) that
+ * this TC class's qdisc is installed on 'netdev', but we didn't install
+ * it ourselves and so don't know any of the details.
+ *
+ * 'nlmsg' is the kernel reply to a RTM_GETQDISC Netlink message for
+ * 'netdev'. The TCA_KIND attribute of 'nlmsg' is 'linux_name'. The
+ * implementation should parse the other attributes of 'nlmsg' as
+ * necessary to determine its configuration. If necessary it should also
+ * use Netlink queries to determine the configuration of queues on
+ * 'netdev'.
+ *
+ * This function must return 0 if and only if it sets 'netdev->tc' to an
+ * initialized 'struct tc'. */
+ int (*tc_load)(struct netdev *netdev, struct ofpbuf *nlmsg);
+
+ /* Destroys the data structures allocated by the implementation as part of
+ * 'tc'. (This includes destroying 'tc->queues' by calling
+ * tc_destroy(tc).
+ *
+ * The implementation should not need to perform any Netlink calls. If
+ * desirable, the caller is responsible for deconfiguring the kernel qdisc.
+ * (But it may not be desirable.)
+ *
+ * This function may be null if 'tc' is trivial. */
+ void (*tc_destroy)(struct tc *tc);
+
+ /* Retrieves details of 'netdev->tc' configuration into 'details'.
+ *
+ * The implementation should not need to perform any Netlink calls, because
+ * the 'tc_install' or 'tc_load' that instantiated 'netdev->tc' should have
+ * cached the configuration.
+ *
+ * The contents of 'details' should be documented as valid for 'ovs_name'
+ * in the "other_config" column in the "QoS" table in vswitchd/vswitch.xml
+ * (which is built as ovs-vswitchd.conf.db(8)).
+ *
+ * This function may be null if 'tc' is not configurable.
+ */
+ int (*qdisc_get)(const struct netdev *netdev, struct shash *details);
+
+ /* Reconfigures 'netdev->tc' according to 'details', performing any
+ * required Netlink calls to complete the reconfiguration.
+ *
+ * The contents of 'details' should be documented as valid for 'ovs_name'
+ * in the "other_config" column in the "QoS" table in vswitchd/vswitch.xml
+ * (which is built as ovs-vswitchd.conf.db(8)).
+ *
+ * This function may be null if 'tc' is not configurable.
+ */
+ int (*qdisc_set)(struct netdev *, const struct shash *details);
+
+ /* Retrieves details of 'queue' on 'netdev->tc' into 'details'. 'queue' is
+ * one of the 'struct tc_queue's within 'netdev->tc->queues'.
+ *
+ * The contents of 'details' should be documented as valid for 'ovs_name'
+ * in the "other_config" column in the "Queue" table in
+ * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
+ *
+ * The implementation should not need to perform any Netlink calls, because
+ * the 'tc_install' or 'tc_load' that instantiated 'netdev->tc' should have
+ * cached the queue configuration.
+ *
+ * This function may be null if 'tc' does not have queues ('n_queues' is
+ * 0). */
+ int (*class_get)(const struct netdev *netdev, const struct tc_queue *queue,
+ struct shash *details);
+
+ /* Configures or reconfigures 'queue_id' on 'netdev->tc' according to
+ * 'details', perfoming any required Netlink calls to complete the
+ * reconfiguration. The caller ensures that 'queue_id' is less than
+ * 'n_queues'.
+ *
+ * The contents of 'details' should be documented as valid for 'ovs_name'
+ * in the "other_config" column in the "Queue" table in
+ * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
+ *
+ * This function may be null if 'tc' does not have queues or its queues are
+ * not configurable. */
+ int (*class_set)(struct netdev *, unsigned int queue_id,
+ const struct shash *details);
+
+ /* Deletes 'queue' from 'netdev->tc'. 'queue' is one of the 'struct
+ * tc_queue's within 'netdev->tc->queues'.
+ *
+ * This function may be null if 'tc' does not have queues or its queues
+ * cannot be deleted. */
+ int (*class_delete)(struct netdev *, struct tc_queue *queue);
+
+ /* Obtains stats for 'queue' from 'netdev->tc'. 'queue' is one of the
+ * 'struct tc_queue's within 'netdev->tc->queues'.
+ *
+ * On success, initializes '*stats'.
+ *
+ * This function may be null if 'tc' does not have queues or if it cannot
+ * report queue statistics. */
+ int (*class_get_stats)(const struct netdev *netdev,
+ const struct tc_queue *queue,
+ struct netdev_queue_stats *stats);
+
+ /* Extracts queue stats from 'nlmsg', which is a response to a
+ * RTM_GETTCLASS message, and passes them to 'cb' along with 'aux'.
+ *
+ * This function may be null if 'tc' does not have queues or if it cannot
+ * report queue statistics. */
+ int (*class_dump_stats)(const struct netdev *netdev,
+ const struct ofpbuf *nlmsg,
+ netdev_dump_queue_stats_cb *cb, void *aux);