blob: 8bbf983cd2441ffd1bb5b96f85c7b83944b19df5 [file] [log] [blame]
Thomas Gleixner25763b32019-05-28 10:10:09 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Andy Zhou96fbc132017-11-10 12:09:42 -08002/*
3 * Copyright (c) 2017 Nicira, Inc.
Andy Zhou96fbc132017-11-10 12:09:42 -08004 */
5
6#ifndef METER_H
7#define METER_H 1
8
9#include <linux/init.h>
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/netlink.h>
13#include <linux/openvswitch.h>
Andy Zhou96fbc132017-11-10 12:09:42 -080014#include <linux/skbuff.h>
Tonghao Zhangc7c4c442020-04-24 08:08:02 +080015#include <linux/bits.h>
Andy Zhou96fbc132017-11-10 12:09:42 -080016
17#include "flow.h"
18struct datapath;
19
20#define DP_MAX_BANDS 1
Tonghao Zhangc7c4c442020-04-24 08:08:02 +080021#define DP_METER_ARRAY_SIZE_MIN BIT_ULL(10)
Tonghao Zhangeb58eeb2020-04-24 08:08:03 +080022#define DP_METER_NUM_MAX (200000UL)
Andy Zhou96fbc132017-11-10 12:09:42 -080023
24struct dp_meter_band {
25 u32 type;
26 u32 rate;
27 u32 burst_size;
Tonghao Zhange5735882020-04-24 08:08:06 +080028 u64 bucket; /* 1/1000 packets, or in bits */
Andy Zhou96fbc132017-11-10 12:09:42 -080029 struct ovs_flow_stats stats;
30};
31
32struct dp_meter {
33 spinlock_t lock; /* Per meter lock */
34 struct rcu_head rcu;
Andy Zhou96fbc132017-11-10 12:09:42 -080035 u32 id;
36 u16 kbps:1, keep_stats:1;
37 u16 n_bands;
38 u32 max_delta_t;
39 u64 used;
40 struct ovs_flow_stats stats;
Kees Cook16ae53d2023-09-22 10:28:54 -070041 struct dp_meter_band bands[] __counted_by(n_bands);
Andy Zhou96fbc132017-11-10 12:09:42 -080042};
43
Tonghao Zhangc7c4c442020-04-24 08:08:02 +080044struct dp_meter_instance {
45 struct rcu_head rcu;
46 u32 n_meters;
Kees Cooke7b34822023-09-22 10:28:52 -070047 struct dp_meter __rcu *dp_meters[] __counted_by(n_meters);
Tonghao Zhangc7c4c442020-04-24 08:08:02 +080048};
49
50struct dp_meter_table {
51 struct dp_meter_instance __rcu *ti;
52 u32 count;
Tonghao Zhangeb58eeb2020-04-24 08:08:03 +080053 u32 max_meters_allowed;
Tonghao Zhangc7c4c442020-04-24 08:08:02 +080054};
55
Andy Zhou96fbc132017-11-10 12:09:42 -080056extern struct genl_family dp_meter_genl_family;
57int ovs_meters_init(struct datapath *dp);
58void ovs_meters_exit(struct datapath *dp);
59bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
60 struct sw_flow_key *key, u32 meter_id);
61
62#endif /* meter.h */