diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-05-13 12:55:20 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-05-13 12:55:20 +0200 |
commit | c1919866912d8106b522b9092641022ddaf31137 (patch) | |
tree | 975e1dff6823f30d5c356eacfd1cdc1d0e9a5960 | |
parent | 73b2359fb02d04ab76c512cb09660735c1306f87 (diff) |
[GPRS] NS: more rate counters for BLOCK / DEAD count
-rw-r--r-- | openbsc/src/db.c | 17 | ||||
-rw-r--r-- | openbsc/src/gprs/gprs_ns.c | 33 |
2 files changed, 37 insertions, 13 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c index f7fb3b457..57a7863c9 100644 --- a/openbsc/src/db.c +++ b/openbsc/src/db.c @@ -127,6 +127,13 @@ static char *create_stmts[] = { "value INTEGER NOT NULL, " "name TEXT NOT NULL " ")", + "CREATE TABLE IF NOT EXISTS RateCounters (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "timestamp TIMESTAMP NOT NULL, " + "value INTEGER NOT NULL, " + "name TEXT NOT NULL, " + "index INTEGER NOT NULL " + ")", "CREATE TABLE IF NOT EXISTS AuthKeys (" "id INTEGER PRIMARY KEY AUTOINCREMENT, " "subscriber_id INTEGER UNIQUE NOT NULL, " @@ -1194,10 +1201,10 @@ static int db_store_rate_ctr(struct rate_ctr_group *ctrg, unsigned int num, &q_name); result = dbi_conn_queryf(conn, - "Insert INTO Counters " - "(timestamp,name,value) VALUES " - "(datetime('now'),%s.%s,%"PRIu64")", - q_prefix, q_name, ctrg->ctr[num].current); + "Insert INTO RateCounters " + "(timestamp,name,index,value) VALUES " + "(datetime('now'),%s.%s,%u,%"PRIu64")", + q_prefix, q_name, ctrg->idx, ctrg->ctr[num].current); free(q_name); @@ -1213,7 +1220,7 @@ int db_store_rate_ctr_group(struct rate_ctr_group *ctrg) unsigned int i; char *q_prefix; - dbi_conn_quote_string_copy(conn, ctrg->name_prefix, &q_prefix); + dbi_conn_quote_string_copy(conn, ctrg->desc->group_name_prefix, &q_prefix); for (i = 0; i < ctrg->desc->num_ctr; i++) db_store_rate_ctr(ctrg, i, q_prefix); diff --git a/openbsc/src/gprs/gprs_ns.c b/openbsc/src/gprs/gprs_ns.c index 8530eb176..554e2ec38 100644 --- a/openbsc/src/gprs/gprs_ns.c +++ b/openbsc/src/gprs/gprs_ns.c @@ -74,15 +74,26 @@ static const struct tlv_definition ns_att_tlvdef = { }, }; +enum ns_ctr { + NS_CTR_PKTS_IN, + NS_CTR_PKTS_OUT, + NS_CTR_BYTES_IN, + NS_CTR_BYTES_OUT, + NS_CTR_BLOCKED, + NS_CTR_DEAD, +}; + static const struct rate_ctr_desc nsvc_ctr_description[] = { { "packets.in", "Packets at NS Level ( In)" }, - { "packets.out", "Packets at NS Level (Out)" }, - { "bytes.in", "Bytes at NS Level ( In)" }, - { "bytes.out", "Bytes at NS Level (Out)" }, + { "packets.out","Packets at NS Level (Out)" }, + { "bytes.in", "Bytes at NS Level ( In)" }, + { "bytes.out", "Bytes at NS Level (Out)" }, + { "blocked", "NS-VC Block count " }, + { "dead", "NS-VC gone dead count " }, }; static const struct rate_ctr_group_desc nsvc_ctrg_desc = { - .group_prefix_fmt = "ns.nsvc%u", + .group_name_prefix = "ns.nsvc", .group_description = "NSVC Peer Statistics", .num_ctr = ARRAY_SIZE(nsvc_ctr_description), .ctr_desc = nsvc_ctr_description, @@ -192,8 +203,8 @@ static int gprs_ns_tx(struct gprs_nsvc *nsvc, struct msgb *msg) int ret; /* Increment number of Uplink bytes */ - rate_ctr_inc(&nsvc->ctrg->ctr[1]); - rate_ctr_add(&nsvc->ctrg->ctr[3], msgb_l2len(msg)); + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_PKTS_OUT]); + rate_ctr_add(&nsvc->ctrg->ctr[NS_CTR_BYTES_OUT], msgb_l2len(msg)); switch (nsvc->nsi->ll) { case GPRS_NS_LL_UDP: @@ -310,6 +321,7 @@ int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause) /* be conservative and mark it as blocked even now! */ nsvc->state |= NSE_S_BLOCKED; + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); msg->l2h = msgb_put(msg, sizeof(*nsh)); nsh = (struct gprs_ns_hdr *) msg->l2h; @@ -392,6 +404,8 @@ static void gprs_ns_timer_cb(void *data) nsvc->nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { /* mark as dead and blocked */ nsvc->state = NSE_S_BLOCKED; + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_DEAD]); LOGP(DNS, LOGL_NOTICE, "NSEI=%u Tns-alive expired more then " "%u times, blocking NS-VC\n", nsvc->nsei, @@ -599,6 +613,7 @@ static int gprs_ns_rx_block(struct gprs_nsvc *nsvc, struct msgb *msg) //nsvci = (uint16_t *) TLVP_VAL(&tp, NS_IE_VCI); ns_dispatch_signal(nsvc, S_NS_BLOCK, *cause); + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); return gprs_ns_tx_simple(nsvc, NS_PDUT_BLOCK_ACK); } @@ -657,8 +672,9 @@ int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg, msgb_nsei(msg) = nsvc->nsei; /* Increment number of Incoming bytes */ - rate_ctr_inc(&nsvc->ctrg->ctr[0]); - rate_ctr_add(&nsvc->ctrg->ctr[2], msgb_l2len(msg)); + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_PKTS_IN]); + DEBUGP(DNS, "BYTES_IN msgb_l2len=%d\n", msgb_l2len(msg)); + rate_ctr_add(&nsvc->ctrg->ctr[NS_CTR_BYTES_IN], msgb_l2len(msg)); switch (nsh->pdu_type) { case NS_PDUT_ALIVE: @@ -697,6 +713,7 @@ int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg, /* mark NS-VC as blocked + active */ nsvc->state = NSE_S_BLOCKED | NSE_S_ALIVE; nsvc->remote_state = NSE_S_BLOCKED | NSE_S_ALIVE; + rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); if (nsvc->remote_end_is_sgsn) { /* stop RESET timer */ bsc_del_timer(&nsvc->timer); |