2015年11月9日 星期一

3G 數據流量管理


成功不是「結果」,而是一種「習慣」!

See more at --  http://www.msn.com/zh-tw/news/living/

Terms:
BC:   Budget Control
TBD:  Time Budget Control
DBC:  Data Budget Control

The 3G logistic schema of the budget control function is designed in the way of dynamically presenting the 3G access statistics information by calling the Budget Control (BC) module to handle the budget of live 3G access.

When the 3G is running, then the cron daemon will periodically call the function, cron_3g_budget_control, a entry function of BC. The BC function is initiated by cron daemon if 3G access activities starts, and stops the BC function when no 3G access activities.

The 3G access information will then feed into BC data process and policy mechanism automatically.


1. Budget Control
One who first reaches the budget limit will have first priority to determine the policy behavior.

BC periodically evaluates per each update cycle (i.e. the period set in crontab) by dispatching 4 tasks sequentially, that is, pre-limited data budget, pre-limited time budget, over final-limited time budget, over final-limited data budget. They are all processed by TBC and DBC, respectively, according to passing the different argument content to do either pre-limited, or over final-limited budget control scheme.

The BC determines by means of getting the settings and policy from meta configuration (WEB UI settings) and pass to BC process, and finally call the function commit_policy, a policy execute unit, to execute either/both "Actions if over budget", or/and Trigger by Limit Budget. The schema is described as below.

The Policy 1:  “Actions if over budget”
It does some defined actions as below:
a). Logging the events, and message to system logger
b). Drop or keep current connection
c). Disallow or allow new connection
d). Light signaling:
Over Budget Limit: -- led_ctl 15
BC lights on the 3G LED if it has been over budget, and has the light signal of
very fast blinking.
   Pre-limited budget: -- led_ctl 14
BC lights on the 3G LED if it has reached pre-limit budget, and has the light
signal of fast blinking 5 seconds, and then Off 5 seconds.
e.) Send alert or notification by e-mail

The Policy 2:  “Trigger by Limit Budge”:
It does “warning in advance” if BC acknowledges this condition as occurred, and then just sends the warning message to system logger in advance when reaching pre-limited.

You can also determine to do most tasks by defining the policy schema at WEB UI setting time. The policy 1 behavior are described as below.

1.1. Keep current connection
     We only want the newest ram statistics report.
     - clean the flash report file
- generate this event file, and
- save live 3G access statistics report file to the flash, named the event file as report3G_BC_keep_current.$fnext.
If BC judges the situation as over budget when 3G connected, and the policy is un-checking the option “Drop current”, then BC will keep current connection while it is on-line, save 3G live statistics information as an event file. BC will consider this situation is the same connection, and continue to calculate the summation of the 3G access data plus old ones.

1.2. Drop current connection
There are two decision rules:
Drop, and Allow new connection
- When over budget, drop current connection, and allow user to re-start 3G connection.

Drop, and Disallow new connection
- When over budget, drop current connection, and disallow user to re-start 3G connection anymore.

1.2.1 Drop, and Allow new connection
Because BC has acknowledged when it is over budget under this policy rule when 3G connected, the 3G access statistics report on the flash will be reset for the new connection, and save live 3G access statistics report file to the flash, named the event file as report3G_BC_allow_new.$fnext, then finally stop 3G connection.

If it is over budget, and the policy is choosing the option “Drop”, and un-checking the option “Disallow new”, then BC will disconnect 3G while it is on-line, save statistics information as a new event file and replace the old one, and then stop 3G, except that the user re-dial or run into the billing cycle date.

At least, the user is capable of going into WEB UI to dial the 3g network if he/she determines to connect 3G again, in despite of having been exceeded the budget. BC will consider this situation is a new connection of having its own statistics report. The access statistics report is re-recorded from initial condition of billing zero point for the new connection.


1.2.2 Drop, and Disallow new connection
If BC judges the situation as over budget when 3G connected, and the policy is choosing the option “Drop”, and checking the option “Disallow”, then BC will drop current connection while it is on-line., and disallow any dialing trial action, except it is reaching next billing cycle. The next billing cycle is running cyclically from billing zero point.
The major considering is
a). Let this event file replace the old one stayed on the flash.
b). shutdown always if no state changed.
c). fobidden because it is over budget until it is reaching BC counter reset date.

Because BC has acknowledged when it is over budget under this policy rule, the 3G access statistics report on the flash will be deleted, and save live 3G access statistics report file to the flash, named the event file as report3G_BC_disallow_new.$fnext.

If it is over budget, and the policy is choosing the option “Drop”, and checking the option “Disallow new”, then BC will disconnect 3G, save statistics information as a new event file and replace the old one, and then stop 3G, except that next the billing cycle date will be coming.

At least, the user is unable to dial the 3g network anymore even if he/she determines to connect 3G again, because of having been exceeded the budget. BC will consider this situation is a forbidden situation within the same billing cycle.


2. Budget Counter Reset
The 3g billing cycle date is reaching, BC acknowledges, and then reset the 3G access statistics report, and set up a flag for BC to handle the affairs of zeroing BC counter.
    We have 4 budget counters,
    -  total elapsed time,
    -  total transferring of download and upload
    -  summated download transferring
    -  summated upload transferring
The reset mechanism for BC counter is working when it reaches the billing cycle date. The function will update 3g access information, and delete statistics report file on the flash, zero the BC counter and re-start 3G connection automatically while it is on-line.
So, in this situation, the statistics record is a new one for current billing cycle.
The old record will save to the flash named the event file as “report3G_BCreset_cycledate.$fnextcycle”, anyway, this is considering as an event.


BC treat new event as a replacement of old event. The flash will often keep one, and seldom keep two events, and depend on the program state at run-time.

3. Data Process
  The 3g access summarized statistics are periodically evaluated each minute, and do tasks as below,
3.1 Calculate total elapsed time from initial access time to now.
The calculation formula:
The flash base elapsed time + alive summated elapsed + this elapsed from re-start link. (we also consider the case of “dial on demand”)

3.2 Read signal strength from modem
It need some waiting time to get the signal quality from modem device.

3.3 get total data transfer(MB) from initial acess time to now.
The calculation formula:
The flash base transferring data + accumulated alive transfer from 3g network interface.  (including (1)sum_rcv_tx, (2)sum_rcv, and (3)sum_tx, respectively)

3.4 write the alive log
Write the live summated formatted string to customized 3G live statistics report log into the RAM named report3gStat per each update cycle, and copy this RAM report log to the flash according to every pre-defined number of update cycles by writer counter, that is to say, copy the live ram log to the flash when it reaches the write count.
The ram live report3gStat is with only one record and overwritten by new one periodically per update cycle.

If BC judges the 3G link as idle time when 3G connected, BC will save live 3G access statistics information to the flash only one time. BC stop itself activities if no any 3G access request while 3G is running on the dial-on-demand mode, BC will re-start link when there is any outgoing request via 3G network interface.

BC will create four event files for the sake of looking up who and what happened lately, and for further expanding request of data mining or restore.

4. Logging
The event item 2, 3 , 4, 5 is spawned individually only one time in the 3g alive time, moreover, they will be uniquely existing any time.

BC will just keep only and latest one event on the flash. Seldom appear two event files, depend on the program state at running time.

The files stored on to the directory, /flash/log/ , according to their occurring timing,  listed as below: (BTW, $fnext, $ fnextcycle both are file extention)

1. report3gStat
  Normally running time and stay on the flash and logging the 3g access statistics at running time.

2. report3G_BC_disallow_new.$fnext
  The BC generate this report if it identifies the disallow new event as occurred.

3. report3G_BCreset_cycledate.$fnextcycle
  The reset event of budget counter is occurred because the billing cycle date is reaching.

4. report3G_BC_keep_current.$fnext
  The BC identifies the keep current event as occurred.

5. report3G_BC_allow_new.$fnext
  The BC identifies the allow new event as occurred.

6. bc_disallow/bc_allow
  The flag only exists if the BC is over budget and use the “Disallow” or “allow” policy.


5. Message
5.1 The messages of event occurring and shown on console:

5.1.1. TIME BC - 0 PASS
TBC make sure that the pre-limmited time budget is not reaching yet.

5.1.2. TIME BC - 1 PASS
TBC make sure that the final limmited time budget is not over yet.

5.1.3. DATA BC - 0 PASS
DBC make sure that the pre-limmited data budget is not reaching yet.

5.1.4. DATA BC - 1 PASS
DBC make sure that the final limmited data budget is not over yet.

5.1.5. <Forbidden-data.BUDGET>
DBC make sure that the final limmited data budget has been exceeded.

5.1.6. <Forbidden-time.BUDGET>
DBC make sure that the final limmited time budget has been exceeded.

5.2 The messages of event occurring and shown on system logger:

5.2.1. The message: “Warning!  Over final limited data budget!!!”
  Meaning: DBC make sure that the final transfer data limited budget has been exceeded.

5.2.2. The message: “Warning!  Over final limited time budget!!!”
  Meaning: TBC make sure that the final total time limited budget has been exceeded.

5.2.3. The message: “Warning!  Reach pre-limited data budget!!!”
  Meaning: DBC make sure that the data pre-limited budget is reaching now.

5.2.4. The message: “Warning!  Reach pre-limited time budget!!!”
  Meaning: TBC make sure that the time pre-limited budget is reaching now.

5.2.5. Reaching the billing cycle, logging and reset budget counter
Meaning: BC logging and reset when it reaches the billing cycle.


沒有留言:

張貼留言