flow_table.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2007-2013 Nicira, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301, USA
  17. */
  18. #ifndef FLOW_TABLE_H
  19. #define FLOW_TABLE_H 1
  20. #include <linux/kernel.h>
  21. #include <linux/netlink.h>
  22. #include <linux/openvswitch.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/types.h>
  25. #include <linux/rcupdate.h>
  26. #include <linux/if_ether.h>
  27. #include <linux/in6.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/time.h>
  30. #include <linux/flex_array.h>
  31. #include <net/inet_ecn.h>
  32. #include <net/ip_tunnels.h>
  33. #include "flow.h"
  34. #define TBL_MIN_BUCKETS 1024
  35. struct flow_table {
  36. struct flex_array *buckets;
  37. unsigned int count, n_buckets;
  38. struct rcu_head rcu;
  39. struct list_head *mask_list;
  40. int node_ver;
  41. u32 hash_seed;
  42. bool keep_flows;
  43. };
  44. int ovs_flow_init(void);
  45. void ovs_flow_exit(void);
  46. struct sw_flow *ovs_flow_alloc(void);
  47. void ovs_flow_free(struct sw_flow *, bool deferred);
  48. static inline int ovs_flow_tbl_count(struct flow_table *table)
  49. {
  50. return table->count;
  51. }
  52. static inline int ovs_flow_tbl_need_to_expand(struct flow_table *table)
  53. {
  54. return (table->count > table->n_buckets);
  55. }
  56. struct flow_table *ovs_flow_tbl_alloc(int new_size);
  57. struct flow_table *ovs_flow_tbl_expand(struct flow_table *table);
  58. struct flow_table *ovs_flow_tbl_rehash(struct flow_table *table);
  59. void ovs_flow_tbl_destroy(struct flow_table *table, bool deferred);
  60. void ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow);
  61. void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
  62. struct sw_flow *ovs_flow_tbl_dump_next(struct flow_table *table,
  63. u32 *bucket, u32 *idx);
  64. struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
  65. const struct sw_flow_key *);
  66. bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
  67. struct sw_flow_match *match);
  68. struct sw_flow_mask *ovs_sw_flow_mask_alloc(void);
  69. void ovs_sw_flow_mask_add_ref(struct sw_flow_mask *);
  70. void ovs_sw_flow_mask_del_ref(struct sw_flow_mask *, bool deferred);
  71. void ovs_sw_flow_mask_insert(struct flow_table *, struct sw_flow_mask *);
  72. struct sw_flow_mask *ovs_sw_flow_mask_find(const struct flow_table *,
  73. const struct sw_flow_mask *);
  74. void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
  75. const struct sw_flow_mask *mask);
  76. #endif /* flow_table.h */