42#include <phymac-clmsg.h>
52 : TclClass(
"Module/UW/AHOI/PHY")
67 , pdr_file_name_(
"dbs/ahoi/default_pdr.csv")
68 , sir_file_name_(
"dbs/ahoi/default_sir.csv")
69 , pdr_token_separator_(
',')
85 if (strcasecmp(argv[1],
"initLUT") == 0) {
89 }
else if (argc == 3) {
90 if (strcasecmp(argv[1],
"setRangePDRFileName") == 0) {
91 string tmp_ = ((
char *) argv[2]);
92 if (tmp_.size() == 0) {
93 fprintf(stderr,
"Empty string for the file name");
98 }
else if (strcasecmp(argv[1],
"setSIRFileName") == 0) {
99 string tmp_ = ((
char *) argv[2]);
100 if (tmp_.size() == 0) {
101 fprintf(stderr,
"Empty string for the file name");
106 }
else if (strcasecmp(argv[1],
"setLUTSeparator") == 0) {
107 string tmp_ = ((
char *) argv[2]);
108 if (tmp_.size() == 0) {
109 fprintf(stderr,
"Empty char for the file name");
122 ifstream input_file_;
126 input_file_.open(tmp_);
127 if (input_file_.is_open()) {
130 std::cout <<
"UwAhoiPhy::initializeRangeLUT()" << endl;
131 while (std::getline(input_file_, line_)) {
133 std::istringstream line_stream(line_);
136 double d = stod(token);
138 double p = stod(token);
141 std::cout << d <<
" " << p << endl;
147 ifstream input_file_2;
150 input_file_2.open(tmp_);
151 if (input_file_2.is_open()) {
154 std::cout <<
"UwAhoiPhy::initializeSIRLUT()" << endl;
155 while (std::getline(input_file_2, line_)) {
157 std::istringstream line_stream(line_);
160 double sir = stod(token);
162 double p = stod(token);
165 std::cout << sir <<
" " << p << endl;
178 cerr <<
"UwAhoiPhy ERROR: FIRST INITIALIZE LUT!" << endl;
179 hdr_cmn *ch = HDR_CMN(p);
180 hdr_MPhy *ph = HDR_MPHY(p);
181 hdr_mac *mach = HDR_MAC(p);
183 static int mac_addr = -1;
184 ClMsgPhy2MacAddr msg;
186 mac_addr = msg.getAddr();
191 double x = RNG::defaultrng()->uniform_double();
192 per_n =
getPER(ph->Pr / ph->Pn, p);
193 bool error_n = x <= per_n;
199 per_ni = interference?
getPER(ph->Pr/interference,p):
getPER(0,p);
200 error_ni = x <= per_ni;
204 Scheduler::instance().clock();
209 Scheduler::instance().clock() + ph->duration;
212 ch->error() = error_ni || error_n;
216 << NOW <<
" UwAhoiPhy(" << mac_addr
217 <<
")::endRx() packet " << ch->uid()
218 <<
" contains errors due to noise and interference."
220 }
else if (error_n == 1) {
221 std::cout << NOW <<
" UwAhoiPhy(" << mac_addr
222 <<
")::endRx() packet " << ch->uid()
223 <<
" contains errors due to noise." << std::endl;
227 incrErrorPktsNoise();
228 if (mach->ftype() != MF_CONTROL) {
230 }
else if (mach->ftype() == MF_CONTROL) {
233 }
else if (error_ni) {
234 if (mach->ftype() != MF_CONTROL) {
235 incrErrorPktsInterf();
237 if (interferent_pkts.second >= 1) {
240 if (interferent_pkts.first > 0) {
244 }
else if (mach->ftype() == MF_CONTROL) {
247 if (interferent_pkts.first > 0) {
276 hdr_MPhy *ph = HDR_MPHY(_p);
277 double x_src = (ph->srcPosition)->getX();
278 double y_src = (ph->srcPosition)->getY();
279 double z_src = (ph->srcPosition)->getZ();
280 double x_dst = (ph->dstPosition)->getX();
281 double y_dst = (ph->dstPosition)->getY();
282 double z_dst = (ph->dstPosition)->getZ();
283 return sqrt(pow(x_src - x_dst, 2.0) + pow(y_src - y_dst, 2.0) +
284 pow(z_src - z_dst, 2.0));
292 <<
" UwAhoiPhy()::matchDistancePDR(double distance)"
293 <<
"distance = " << distance << std::endl;
297 PdrLut::iterator it =
range2pdr_.lower_bound(distance);
299 return (--it)->second;
300 double l_sup = it->first;
301 double p_sup = it->second;
303 double l_inf = it->first;
304 double p_inf = it->second;
306 std::cout <<
" Distance between " << l_inf <<
" and " << l_sup;
307 std::cout <<
" Succ Prob between " << p_inf <<
" and " << p_sup;
315 double sir_db = 10*log10(sir/10);
318 <<
" UwAhoiPhy()::matchSIR_PDR(double sir)"
319 <<
"sir = " << sir << std::endl;
320 if (sir_db <=
sir2pdr_.begin()->first)
323 PdrLut::iterator it =
sir2pdr_.lower_bound(sir_db);
325 return (--it)->second;
326 double l_sup = it->first;
327 double p_sup = it->second;
329 double l_inf = it->first;
330 double p_inf = it->second;
332 std::cout <<
" SIR between " << l_inf <<
" and " << l_sup;
333 std::cout <<
" Succ Prob between " << p_inf <<
" and " << p_sup;
340 double x,
double x1,
double y1,
double x2,
double y2)
342 double m = (y1 - y2) / (x1 - x2);
343 double q = y1 - m * x1;
345 std::cout << NOW <<
" UwAhoiPhy::linearInterpolator( double x, "
346 "double x1, double y1, double x2, double y2 )"
347 <<
"m = " << m <<
" q= " <<
q << std::endl;
void incrTot_pkts_lost()
Increment the number of packets discarded.
std::string Interference_Model
Interference calcuation mode chosen: CHUNK model or MEANPOWER model.
uwinterference * interference_
Pointer to the interference module.
virtual int command(int, const char *const *) override
TCL command interpreter.
void incrErrorCtrlPktsInterf()
Increment the number of CTRL packets discarded due to interference.
double Energy_Rx_
Energy (in Joule) spent by the node in transmission.
void incrCollisionCTRL()
Increment the number of CTRL pkts discarded due to a collision.
void incrCollisionDATAvsCTRL()
Increment the number of collisions DATA/CTRL.
double time_ready_to_end_rx_
Used to keep track of the rx time.
virtual double consumedEnergyRx(const double &_duration) const
Compute the energy (in Joule) spent by the modem in reception.
double Rx_Time_
Time (in seconds) spent by the node in reception.
void incrCollisionDATA()
Increment the number of DATA pkts discarded due to a collision.
void incrTotCrtl_pkts_lost()
Increment the number of CTRL packets discarded.
Adds the module for UwCbrModuleClass in ns2.
TclObject * create(int, const char *const *)
virtual int command(int, const char *const *)
TCL command interpreter.
virtual double matchSIR_PDR(double sir)
Return the PER via linear interpolation.
virtual double matchDistancePDR(double distance)
Return the PER via linear interpolation.
virtual void endRx(Packet *p)
Handles the end of a packet reception.
virtual double getPER(double snr, Packet *)
Returns the packet error rate by using the length of a packet and the information contained in the pa...
UwAhoiPhy()
Constructor of UwAhoiPhy class.
virtual double linearInterpolator(double x, double x1, double y1, double x2, double y2)
Return y via linear interpolation given two points.
virtual double getDistance(Packet *)
Return the distance between source and destination.
char pdr_token_separator_
virtual ~UwAhoiPhy()
Destructor of UwAhoiPhy class.
virtual void initializeLUT()
virtual double getInterferencePower(Packet *p)
Compute the average interference power for the given packet.
UwAhoiPhyClass class_module_UwAhoiPhy
Definition of UwAhoiPhy class.
std::pair< int, int > counter
counter of collisions