meter.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017 Nicira, Inc.
  4. */
  5. #ifndef METER_H
  6. #define METER_H 1
  7. #include <linux/init.h>
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/netlink.h>
  11. #include <linux/openvswitch.h>
  12. #include <linux/genetlink.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/bits.h>
  15. #include "flow.h"
  16. struct datapath;
  17. #define DP_MAX_BANDS 1
  18. #define DP_METER_ARRAY_SIZE_MIN BIT_ULL(10)
  19. #define DP_METER_NUM_MAX (200000UL)
  20. struct dp_meter_band {
  21. u32 type;
  22. u32 rate;
  23. u32 burst_size;
  24. u64 bucket; /* 1/1000 packets, or in bits */
  25. struct ovs_flow_stats stats;
  26. };
  27. struct dp_meter {
  28. spinlock_t lock; /* Per meter lock */
  29. struct rcu_head rcu;
  30. u32 id;
  31. u16 kbps:1, keep_stats:1;
  32. u16 n_bands;
  33. u32 max_delta_t;
  34. u64 used;
  35. struct ovs_flow_stats stats;
  36. struct dp_meter_band bands[];
  37. };
  38. struct dp_meter_instance {
  39. struct rcu_head rcu;
  40. u32 n_meters;
  41. struct dp_meter __rcu *dp_meters[];
  42. };
  43. struct dp_meter_table {
  44. struct dp_meter_instance __rcu *ti;
  45. u32 count;
  46. u32 max_meters_allowed;
  47. };
  48. extern struct genl_family dp_meter_genl_family;
  49. int ovs_meters_init(struct datapath *dp);
  50. void ovs_meters_exit(struct datapath *dp);
  51. bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
  52. struct sw_flow_key *key, u32 meter_id);
  53. #endif /* meter.h */