[ovs-dev] [PATCH ovs V2 10/21] netdev-tc-offloads: Add ufid to tc/netdev map
Paul Blakey
paulb at mellanox.com
Sun Dec 25 11:39:38 UTC 2016
Flows offloaded to tc are identified by priority
and handle pair while OVS flows are identified by ufid.
Added a hash map to convert between the two for later
retrieval and deleting of offloaded flows.
Signed-off-by: Paul Blakey <paulb at mellanox.com>
Reviewed-by: Roi Dayan <roid at mellanox.com>
---
lib/netdev-tc-offloads.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
index 4ba6086..f470aa3 100644
--- a/lib/netdev-tc-offloads.c
+++ b/lib/netdev-tc-offloads.c
@@ -75,6 +75,104 @@
VLOG_DEFINE_THIS_MODULE(netdev_tc_offloads);
+static struct hmap ufid_to_tc = HMAP_INITIALIZER(&ufid_to_tc);
+static struct ovs_mutex ufid_lock = OVS_MUTEX_INITIALIZER;
+
+struct ufid_to_tc_data {
+ struct hmap_node node;
+ ovs_u128 ufid;
+ uint16_t prio;
+ uint32_t handle;
+ struct netdev *netdev;
+};
+
+static bool
+del_ufid_tc_mapping(ovs_u128 *ufid)
+{
+ size_t hash = hash_bytes(ufid, sizeof *ufid, 0);
+ struct ufid_to_tc_data *data;
+
+ ovs_mutex_lock(&ufid_lock);
+ HMAP_FOR_EACH_WITH_HASH(data, node, hash, &ufid_to_tc) {
+ if (ovs_u128_equals(*ufid, data->ufid)) {
+ break;
+ }
+ }
+ if (data) {
+ hmap_remove(&ufid_to_tc, &data->node);
+ ovs_mutex_unlock(&ufid_lock);
+ netdev_close(data->netdev);
+ free(data);
+ return true;
+ }
+ ovs_mutex_unlock(&ufid_lock);
+ return false;
+}
+
+static ovs_u128 *
+find_ufid(int prio, int handle, struct netdev *netdev)
+{
+ int ifindex = netdev_get_ifindex(netdev);
+ struct ufid_to_tc_data *data;
+
+ ovs_mutex_lock(&ufid_lock);
+ HMAP_FOR_EACH(data, node, &ufid_to_tc) {
+ if (data->prio == prio && data->handle == handle
+ && netdev_get_ifindex(data->netdev) == ifindex) {
+ break;
+ }
+ }
+ ovs_mutex_unlock(&ufid_lock);
+ if (data) {
+ return &data->ufid;
+ }
+ return NULL;
+}
+
+static int
+get_ufid_tc_mapping(ovs_u128 *ufid, int *prio, struct netdev **netdev)
+{
+ size_t hash = hash_bytes(ufid, sizeof *ufid, 0);
+ struct ufid_to_tc_data *data;
+
+ ovs_mutex_lock(&ufid_lock);
+ HMAP_FOR_EACH_WITH_HASH(data, node, hash, &ufid_to_tc) {
+ if (ovs_u128_equals(*ufid, data->ufid)) {
+ break;
+ }
+ }
+ ovs_mutex_unlock(&ufid_lock);
+ if (data) {
+ if (prio) {
+ *prio = data->prio;
+ }
+ if (netdev) {
+ *netdev = netdev_ref(data->netdev);
+ }
+ return data->handle;
+ }
+ return 0;
+}
+
+static bool
+add_ufid_tc_mapping(ovs_u128 *ufid, int prio, int handle, struct netdev *netdev)
+{
+ size_t hash = hash_bytes(ufid, sizeof *ufid, 0);
+ bool replace = del_ufid_tc_mapping(ufid);
+ struct ufid_to_tc_data *new_data = xzalloc(sizeof *new_data);
+
+ new_data->ufid = *ufid;
+ new_data->prio = prio;
+ new_data->handle = handle;
+ new_data->netdev = netdev_ref(netdev);
+
+ ovs_mutex_lock(&ufid_lock);
+ hmap_insert(&ufid_to_tc, &new_data->node, hash);
+ ovs_mutex_unlock(&ufid_lock);
+
+ return replace;
+}
+
int
netdev_tc_flow_flush(struct netdev *netdev)
{
--
1.8.3.1
More information about the dev
mailing list