meter.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/skbuff.h>
  13. #include <linux/bits.h>
  14. #include "flow.h"
  15. struct datapath;
  16. #define DP_MAX_BANDS 1
  17. #define DP_METER_ARRAY_SIZE_MIN BIT_ULL(10)
  18. #define DP_METER_NUM_MAX (200000UL)
  19. struct dp_meter_band {
  20. u32 type;
  21. u32 rate;
  22. u32 burst_size;
  23. u64 bucket; /* 1/1000 packets, or in bits */
  24. struct ovs_flow_stats stats;
  25. };
  26. struct dp_meter {
  27. spinlock_t lock; /* Per meter lock */
  28. struct rcu_head rcu;
  29. u32 id;
  30. u16 kbps:1, keep_stats:1;
  31. u16 n_bands;
  32. u32 max_delta_t;
  33. u64 used;
  34. struct ovs_flow_stats stats;
  35. struct dp_meter_band bands[] __counted_by(n_bands);
  36. };
  37. struct dp_meter_instance {
  38. struct rcu_head rcu;
  39. u32 n_meters;
  40. struct dp_meter __rcu *dp_meters[] __counted_by(n_meters);
  41. };
  42. struct dp_meter_table {
  43. struct dp_meter_instance __rcu *ti;
  44. u32 count;
  45. u32 max_meters_allowed;
  46. };
  47. extern struct genl_family dp_meter_genl_family;
  48. int ovs_meters_init(struct datapath *dp);
  49. void ovs_meters_exit(struct datapath *dp);
  50. bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
  51. struct sw_flow_key *key, u32 meter_id);
  52. #endif /* meter.h */