2 var _
= require('lodash');
6 * rules - object with the monitoring param to simulator function mapping
9 SimMp = function(rules
) {
10 this.rules
= _
.clone(rules
, true);
13 //SimMp.prototype.map_rule = function(mp_id) {
14 // return this.rules['mp-mapper'][mp_id];
17 // Use the monitoring param id for now
18 SimMp
.prototype.createSimMonitorFunc = function(mp
) {
20 // Define our core simulation function here
23 var rand_func = function(min
, max
) {
24 return Math
.floor(Math
.random() * (max
-min
+1)) + min
;
28 // transmit and receive rate
29 tx_rc_rate: function(value
, elapsed_seconds
) {
30 // Ignore elapsed time for first implementation of transmit and
31 // receive rate simulation.
32 // This is just a quick and dirty and simple implementation to make
33 // the monitoring params change, stay within bounds, and not swing
35 var min_val
= mp
.min_value
;
36 var max_val
= mp
.max_value
;
37 // Set an outer bound of maxmium change from current value
38 // Tweak bin_count to set how much the value can swing from the
41 // Set the range we can generate the new value based on a function
42 // of the difference of the max and min values
43 var max_delta
= (max_val
- min_val
) / bin_count
;
44 console
.log('Setting max_delta = %s', max_delta
);
45 var new_val
= rand_func(
46 Math
.max(min_val
, value
-max_delta
),
47 Math
.min(max_val
, value
+max_delta
));
48 //console.log("Generated value: %s", new_val);
51 packet_size: function(value
, elapsed_seconds
) {
52 // Stub method just returns value unchanged
53 // TODO: Figure out how we want to vary packet sizes
56 accumulate: function(value
, elapsed_seconds
) {
57 // NOT TESTED. Basic idea. Will want to add variablility
58 // how fast we accumulate
59 var accumulate_rate
= 0.1;
60 var new_value
= value
+ (elapsed_seconds
* accumulate_rate
);
63 // add growth function
66 // Declare our monitoring param id to sim function mapping here
67 // TODO: Move out to a yaml/json file and make this function belong to
70 // 'tx-rate-pp1': funcs['tx_rc_rate'],
71 // 'rc-rate-pp1': funcs['tx_rc_rate']
74 var sim_func_name
= this.rules
['mp-mapper'][mp
.id
];
76 return funcs
[sim_func_name
];
78 console
.log('No time step sim function found for monitoring param with id "%s", using constant value', mp
.id
);
79 return function(value
, elapsed_seconds
) {