Generating Exponential Distributed Inter-Contact Time Traces for ONE Simulator
1 #author: C. Liang (moc.liamg@tsuh.mcl, reverse it!)
2 #date: Dec. 2011
3 #function: generating a trace file with inter-contact time exponentially distributed.
4 #output format: {TIMESTAMP} CONN {NODE_ID_1} {NODE_ID_2} {LINK_STATUS}
5 #example: 3600 CONN n1 n2 up
6 # 4000 CONN n1 n2 down
7 #you can freely use this code. I hope it helps.
8 #ps: you should have Perl installed and included in the "PATH" enrioment variables.
9 use 5.010;
10 use strict;
11 use warnings;
12
13 #max time stamp
14 use constant MAX_TIMESTAMP => 21600;
15 #expected inter-contact time = 10,000s
16 use constant LAMBDA => 1/10000;
17 #minimum and maximum node IDs.
18 my $minNodeId = 1;
19 my $maxNodeId = 10;
20 #min & max contac duration, in seconds, uniformly distributed
21 use constant MIN_CONTACT_DURATION => 5;
22 use constant MAX_CONTACT_DURATION => 50;
23 use constant TRACE_FILE => "exp-trace.txt";
24
25 open FH, ">".TRACE_FILE || exit;
26
27 for(my $i = $minNodeId; $i < $maxNodeId; $i++)
28 {
29 for(my $j = $i + 1; $j < $maxNodeId; $j++){
30 my $cnt = 0;
31 my $is_up = 0;
32 my $link_status = "down";
33
34 while($cnt < MAX_TIMESTAMP){
35 my $val;
36
37 #FORMAT: 1642 CONN 1 0 up
38 if($is_up == 0){
39 #wait for a exponential time period and then turns up
40 $val = - ( 1/LAMBDA ) * log(1 - rand());
41 $val = int($val);
42 $cnt += $val;
43
44 $is_up = 1;
45 $link_status = "up";
46 }else{
47 #wait for a period of time [min, max]
48 $val = (MAX_CONTACT_DURATION - MIN_CONTACT_DURATION)*rand() + MIN_CONTACT_DURATION;
49 $val = int($val);
50 $cnt += $val;
51
52 $is_up = 0;
53 $link_status = "down";
54 }
55 say FH "$cnt CONN $i $j $link_status"
56 }#end of while
57 }
58 }
59 close FH;
60
61 #sort the contact schedule by timestamp
62 #sort
63 open FI,"<exp-trace.txt";
64 open FO, ">exp-one.txt";
65 my @lines = <FI>;
66 say FO map {$_->[-1]} sort {$a->[0] <=> $b->[0]} map {[(split)[0],$_]} @lines;
67 close FO;
68 close FI;
69
70 #here is an example setting file. You can comment them all and write it by yourself.
71 my $settings_file = "exp-settings.txt";
72 open EXP, ">".$settings_file;
73 say EXP "Scenario.name = %%Group.bufferSize%%-%%Group.router%%";
74 say EXP 'Scenario.simulateConnections = false';
75 say EXP "Scenario.endTime = 21600";
76 #Group settings
77 say EXP "Scenario.nrofHostGroups = 1";
78 say EXP "Group.nrofHosts = $maxNodeId";
79 say EXP "Group.nodeLocation = 10,10";
80 say EXP "Group.router = EpidemicRouter;
81 say EXP "Group.movementModel = StationaryMovement";
82 say EXP "Group.nodeLocation = 100,100";
83 say EXP "Group.bufferSize = [1M;2M;4M;8M;16M;32M;64M;128M;256M;512M;1024M]";
84
85 # how many reports to load
86 say EXP "Report.nrofReports = 3";
87 say EXP "Report.reportDir = traces/exp/";
88 # length of the warm up period (simulated seconds)
89 #Report.warmup = 0
90 # default directory of reports (can be overridden per Report with output setting)
91 #Report.reportDir = ../Reports/
92 # Report classes to load
93 say EXP "Report.report1 = MessageStatsReport";
94 say EXP "Report.report2 = AdjacencyGraphvizReport";
95 say EXP "Report.report3 = MessageGraphvizReport";
96 say EXP "GlobalRCRouter.secondsInTimeUnit = 60";
97
98 say EXP "Events.nrof = 2";
99 say EXP "Events1.class = ExternalEventsQueue";
100 say EXP "Events1.filePath = traces/exp-one.txt";
101
102 say EXP "Events2.class = MessageEventGenerator";
103 say EXP "Events2.interval = 10,30";
104 say EXP "Events2.size = 500k, 1M";
105 say EXP "Events2.hosts = $minNodeId,$maxNodeId";
106 # Message ID prefix
107 say EXP "Events2.prefix = M";
108 close EXP;
2 #date: Dec. 2011
3 #function: generating a trace file with inter-contact time exponentially distributed.
4 #output format: {TIMESTAMP} CONN {NODE_ID_1} {NODE_ID_2} {LINK_STATUS}
5 #example: 3600 CONN n1 n2 up
6 # 4000 CONN n1 n2 down
7 #you can freely use this code. I hope it helps.
8 #ps: you should have Perl installed and included in the "PATH" enrioment variables.
9 use 5.010;
10 use strict;
11 use warnings;
12
13 #max time stamp
14 use constant MAX_TIMESTAMP => 21600;
15 #expected inter-contact time = 10,000s
16 use constant LAMBDA => 1/10000;
17 #minimum and maximum node IDs.
18 my $minNodeId = 1;
19 my $maxNodeId = 10;
20 #min & max contac duration, in seconds, uniformly distributed
21 use constant MIN_CONTACT_DURATION => 5;
22 use constant MAX_CONTACT_DURATION => 50;
23 use constant TRACE_FILE => "exp-trace.txt";
24
25 open FH, ">".TRACE_FILE || exit;
26
27 for(my $i = $minNodeId; $i < $maxNodeId; $i++)
28 {
29 for(my $j = $i + 1; $j < $maxNodeId; $j++){
30 my $cnt = 0;
31 my $is_up = 0;
32 my $link_status = "down";
33
34 while($cnt < MAX_TIMESTAMP){
35 my $val;
36
37 #FORMAT: 1642 CONN 1 0 up
38 if($is_up == 0){
39 #wait for a exponential time period and then turns up
40 $val = - ( 1/LAMBDA ) * log(1 - rand());
41 $val = int($val);
42 $cnt += $val;
43
44 $is_up = 1;
45 $link_status = "up";
46 }else{
47 #wait for a period of time [min, max]
48 $val = (MAX_CONTACT_DURATION - MIN_CONTACT_DURATION)*rand() + MIN_CONTACT_DURATION;
49 $val = int($val);
50 $cnt += $val;
51
52 $is_up = 0;
53 $link_status = "down";
54 }
55 say FH "$cnt CONN $i $j $link_status"
56 }#end of while
57 }
58 }
59 close FH;
60
61 #sort the contact schedule by timestamp
62 #sort
63 open FI,"<exp-trace.txt";
64 open FO, ">exp-one.txt";
65 my @lines = <FI>;
66 say FO map {$_->[-1]} sort {$a->[0] <=> $b->[0]} map {[(split)[0],$_]} @lines;
67 close FO;
68 close FI;
69
70 #here is an example setting file. You can comment them all and write it by yourself.
71 my $settings_file = "exp-settings.txt";
72 open EXP, ">".$settings_file;
73 say EXP "Scenario.name = %%Group.bufferSize%%-%%Group.router%%";
74 say EXP 'Scenario.simulateConnections = false';
75 say EXP "Scenario.endTime = 21600";
76 #Group settings
77 say EXP "Scenario.nrofHostGroups = 1";
78 say EXP "Group.nrofHosts = $maxNodeId";
79 say EXP "Group.nodeLocation = 10,10";
80 say EXP "Group.router = EpidemicRouter;
81 say EXP "Group.movementModel = StationaryMovement";
82 say EXP "Group.nodeLocation = 100,100";
83 say EXP "Group.bufferSize = [1M;2M;4M;8M;16M;32M;64M;128M;256M;512M;1024M]";
84
85 # how many reports to load
86 say EXP "Report.nrofReports = 3";
87 say EXP "Report.reportDir = traces/exp/";
88 # length of the warm up period (simulated seconds)
89 #Report.warmup = 0
90 # default directory of reports (can be overridden per Report with output setting)
91 #Report.reportDir = ../Reports/
92 # Report classes to load
93 say EXP "Report.report1 = MessageStatsReport";
94 say EXP "Report.report2 = AdjacencyGraphvizReport";
95 say EXP "Report.report3 = MessageGraphvizReport";
96 say EXP "GlobalRCRouter.secondsInTimeUnit = 60";
97
98 say EXP "Events.nrof = 2";
99 say EXP "Events1.class = ExternalEventsQueue";
100 say EXP "Events1.filePath = traces/exp-one.txt";
101
102 say EXP "Events2.class = MessageEventGenerator";
103 say EXP "Events2.interval = 10,30";
104 say EXP "Events2.size = 500k, 1M";
105 say EXP "Events2.hosts = $minNodeId,$maxNodeId";
106 # Message ID prefix
107 say EXP "Events2.prefix = M";
108 close EXP;