-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwiredto154.cpp
More file actions
159 lines (139 loc) · 5.08 KB
/
wiredto154.cpp
File metadata and controls
159 lines (139 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Conditions Of Use
*
* This software was developed by employees of the National Institute of
* Standards and Technology (NIST), and others.
* This software has been contributed to the public domain.
* Pursuant to title 15 United States Code Section 105, works of NIST
* employees are not subject to copyright protection in the United States
* and are considered to be in the public domain.
* As a result, a formal license is not needed to use this software.
*
* This software is provided "AS IS."
* NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY. NIST does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* this software.
*/
/* Tony Cheneau <tony.cheneau@nist.gov> */
#include "core/simulation.hpp"
#include <boost/program_options.hpp>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
namespace po = boost::program_options;
using namespace std;
int main(int argc, char const* argv[])
{
string error_msg;
string simulation_file;
string modulation;
string pathloss;
string mcast_addr;
int mcast_port;
#ifdef DEBUG
cout << "This binary has been compiled with the \"debug\" flag!" << endl
<< "If you want performance, rebuild this program in \"release\" mode." << endl;
#endif /* DEBUG */
Simulation & sim = Simulation::get();
try {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce this help message")
("multicast-addr",
po::value<string>(&mcast_addr)->default_value("224.1.1.1"),
"multicast address used for sending outgoing frames")
("multicast-port",
po::value<int>(&mcast_port)->default_value(10000),
"multicast port used for sending outgoing frames")
("list-modulation", "list available modulation schemes")
("list-pathloss", "list available pathloss models")
("modulation", po::value<string>(&modulation), "modulation scheme")
("pathloss", po::value<string>(&pathloss), "path loss model for the simulation")
("simulation,s", po::value<string>(&simulation_file), "XML file that describes the simulation")
;
po::variables_map vm;
po::parsed_options parsed =
po::basic_command_line_parser<char>(argc, const_cast<char **>(argv)).
options(desc).allow_unregistered().run();
po::store(parsed, vm);
po::notify(vm);
vector<string> unrecognized_opt =
po::collect_unrecognized<char>(parsed.options, po::exclude_positional);
if (vm.count("help")) {
cout << "Usage: options_description [options]\n";
cout << desc;
return 0;
}
if (vm.count("list-modulation")) {
vector<string> modulations = Modulation::list_available_modulation();
cout << "List of available modulation schemes:" << endl;
for(vector<string>::const_iterator i = modulations.begin(); i != modulations.end(); ++i)
cout << *i << endl;
return 0;
}
if (vm.count("list-pathloss")) {
vector<string> pathlossmodels = PathLossModel::list_available_model();
cout << "List of available path loss models:" << endl;
for(vector<string>::const_iterator i = pathlossmodels.begin(); i != pathlossmodels.end(); ++i)
cout << *i << endl;
return 0;
}
if (vm.count("pathloss")) {
sim.set_pathloss_model(pathloss, unrecognized_opt);
}
else {
cerr << "no path loss model selected, you need to choose one using the --pathloss selector" << endl
<< "for the list of path loss model, try --list-pathloss." << endl
<< "use --help-pathloss to learn for model specific argument" << endl;
exit(EXIT_FAILURE);
}
if (vm.count("modulation")) {
sim.set_modulation(modulation);
}
else {
std::string default_mod("O-QPSK");
cout << "setting default modulation to " << default_mod << endl;
sim.set_modulation(default_mod);
}
if (!vm.count("simulation")) {
cerr << "\"simulation\" argument is mandatory" << endl;
cout << desc;
return 0;
}
sim.set_multicast_parameter(mcast_addr, mcast_port);
}
catch(std::exception& e)
{
cerr << e.what() << "\n";
return 1;
}
// read the topology from an XML file
try {
sim.load(simulation_file.c_str());
} catch (Simulation::exception_on_simulation_loading & e) {
cerr << "unable to load file " << simulation_file;
if (strlen(e.what()))
cerr << " (" << e.what() << ")";
cerr << endl;
return 1;
}
if (!sim.is_properly_configured(error_msg)) {
cerr << "simulation is not properly configured: "
<< error_msg
<< endl;
exit(EXIT_FAILURE);
}
// start the simulation engine
// (this should not exit unless the simulation ends)
// TODO: make it exit gracefully when ctrl+c is pressed
// TODO: send the simulation-end signal to the nodes
sim.start();
cout << "Sending \"simulation ending\" frame to all nodes" << endl;
// wait for the program to be interrupted
return 0;
}