From d11c05950200d91f559e0d159762bd51bc28593f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 6 Sep 2012 21:57:11 +0200 Subject: libosmogb: Port BSSGP flow control from openbsc/laforge/bssgp_fc branch This code is supposed to implement the BSSGP flow control algorithm, both for the per-BSS and for the per-MS flow control. The code currently has no test cases, they will come in a separate commit. --- include/osmocom/gprs/gprs_bssgp.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'include/osmocom') diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h index 8ca42bf9..0646ff79 100644 --- a/include/osmocom/gprs/gprs_bssgp.h +++ b/include/osmocom/gprs/gprs_bssgp.h @@ -2,6 +2,8 @@ #define _GPRS_BSSGP_H #include +#include +#include #include #include @@ -54,6 +56,25 @@ struct osmo_bssgp_prim { /* gprs_bssgp.c */ +/*! \brief BSSGP flow control (SGSN side) According to Section 8.2 */ +struct bssgp_flow_control { + uint32_t bucket_size_max; /*!< maximum size of the bucket */ + uint32_t bucket_leak_rate; /*!< leak rate of the bucket */ + + uint32_t bucket_counter; /*!< number of tokens in the bucket */ + struct timeval time_last_pdu; /*!< timestamp of last PDU sent */ + + /* the built-in queue */ + uint32_t max_queue_depth; /*!< how many packets to queue */ + uint32_t queue_depth; /*!< current length of queue */ + struct llist_head queue; /*!< linked list of msgb's */ + struct osmo_timer_list timer; /*!< timer-based dequeueing */ + + /*! callback to be called at output of flow control */ + int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, + uint32_t llc_pdu_len, void *priv); +}; + #define BVC_S_BLOCKED 0x0001 /* The per-BTS context that we keep on the SGSN side of the BSSGP link */ @@ -72,6 +93,10 @@ struct bssgp_bvc_ctx { struct rate_ctr_group *ctrg; + struct bssgp_flow_control fc; + uint32_t bmax_default_ms; + uint32_t r_default_ms; + /* we might want to add this as a shortcut later, avoiding the NSVC * lookup for every packet, similar to a routing cache */ //struct gprs_nsvc *nsvc; @@ -109,6 +134,7 @@ struct bssgp_lv { struct bssgp_dl_ud_par { uint32_t *tlli; char *imsi; + struct bssgp_flow_control *fc; uint16_t drx_parms; /* FIXME: priority */ struct bssgp_lv ms_ra_cap; @@ -157,6 +183,17 @@ struct bssgp_paging_info { int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, struct bssgp_paging_info *pinfo); +/* input function of the flow control implementation, called first + * for the MM flow control, and then as the MM flow control output + * callback in order to perform BVC flow control */ +int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, + uint32_t llc_pdu_len, void *priv); + +/* Initialize the Flow Control parameters for a new MS according to + * default values for the BVC specified by BVCI and NSEI */ +int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, + uint16_t nsei); + /* gprs_bssgp_vty.c */ int bssgp_vty_init(void); void bssgp_set_log_ss(int ss); -- cgit v1.2.3 From bb8262275f8bbf2b2264d68c5328a8c1a8c634d3 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 7 Sep 2012 10:22:01 +0200 Subject: BSSGP flow-control: various fixes * add more comments on units of struct members * make sure to parsre FC-BVC message correctly * add error message in case user passes PDU larger than bucket size * add new function to initialize flow control struct --- include/osmocom/gprs/gprs_bssgp.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'include/osmocom') diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h index 0646ff79..3a1b7613 100644 --- a/include/osmocom/gprs/gprs_bssgp.h +++ b/include/osmocom/gprs/gprs_bssgp.h @@ -58,15 +58,15 @@ struct osmo_bssgp_prim { /*! \brief BSSGP flow control (SGSN side) According to Section 8.2 */ struct bssgp_flow_control { - uint32_t bucket_size_max; /*!< maximum size of the bucket */ - uint32_t bucket_leak_rate; /*!< leak rate of the bucket */ + uint32_t bucket_size_max; /*!< maximum size of the bucket (octets) */ + uint32_t bucket_leak_rate; /*!< leak rate of the bucket (octets/sec) */ uint32_t bucket_counter; /*!< number of tokens in the bucket */ struct timeval time_last_pdu; /*!< timestamp of last PDU sent */ /* the built-in queue */ - uint32_t max_queue_depth; /*!< how many packets to queue */ - uint32_t queue_depth; /*!< current length of queue */ + uint32_t max_queue_depth; /*!< how many packets to queue (mgs) */ + uint32_t queue_depth; /*!< current length of queue (msgs) */ struct llist_head queue; /*!< linked list of msgb's */ struct osmo_timer_list timer; /*!< timer-based dequeueing */ @@ -94,7 +94,9 @@ struct bssgp_bvc_ctx { struct rate_ctr_group *ctrg; struct bssgp_flow_control fc; + /*! default maximum size of per-MS bucket in octets */ uint32_t bmax_default_ms; + /*! default bucket leak rate of per-MS bucket in octests/s */ uint32_t r_default_ms; /* we might want to add this as a shortcut later, avoiding the NSVC @@ -183,6 +185,12 @@ struct bssgp_paging_info { int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, struct bssgp_paging_info *pinfo); +void bssgp_fc_init(struct bssgp_flow_control *fc, + uint32_t bucket_size_max, uint32_t bucket_leak_rate, + uint32_t max_queue_depth, + int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, + uint32_t llc_pdu_len, void *priv)); + /* input function of the flow control implementation, called first * for the MM flow control, and then as the MM flow control output * callback in order to perform BVC flow control */ @@ -192,7 +200,7 @@ int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, /* Initialize the Flow Control parameters for a new MS according to * default values for the BVC specified by BVCI and NSEI */ int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, - uint16_t nsei); + uint16_t nsei, uint32_t max_queue_depth); /* gprs_bssgp_vty.c */ int bssgp_vty_init(void); -- cgit v1.2.3 From d8b476988d38f3ef2267594a46d0e4a9fc6eb6a1 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 7 Sep 2012 11:29:32 +0200 Subject: BSSGP: make bvc_ctx->fc a dynamic talloc allocation this ensures that we can talloc the flow-control queue entries as siblings off the bvc_ctx. --- include/osmocom/gprs/gprs_bssgp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/osmocom') diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h index 3a1b7613..eb4e7219 100644 --- a/include/osmocom/gprs/gprs_bssgp.h +++ b/include/osmocom/gprs/gprs_bssgp.h @@ -93,7 +93,7 @@ struct bssgp_bvc_ctx { struct rate_ctr_group *ctrg; - struct bssgp_flow_control fc; + struct bssgp_flow_control *fc; /*! default maximum size of per-MS bucket in octets */ uint32_t bmax_default_ms; /*! default bucket leak rate of per-MS bucket in octests/s */ -- cgit v1.2.3