50 : TclClass(
"Module/UW/AHOI/PHY")
65 , pdr_file_name_(
"dbs/ahoi/default_pdr.csv")
66 , sir_file_name_(
"dbs/ahoi/default_sir.csv")
67 , pdr_token_separator_(
',')
83 if (strcasecmp(argv[1],
"initLUT") == 0) {
87 }
else if (argc == 3) {
88 if (strcasecmp(argv[1],
"setRangePDRFileName") == 0) {
89 string tmp_ = ((
char *) argv[2]);
90 if (tmp_.size() == 0) {
91 fprintf(stderr,
"Empty string for the file name");
96 }
else if (strcasecmp(argv[1],
"setSIRFileName") == 0) {
97 string tmp_ = ((
char *) argv[2]);
98 if (tmp_.size() == 0) {
99 fprintf(stderr,
"Empty string for the file name");
104 }
else if (strcasecmp(argv[1],
"setLUTSeparator") == 0) {
105 string tmp_ = ((
char *) argv[2]);
106 if (tmp_.size() == 0) {
107 fprintf(stderr,
"Empty char for the file name");
120 ifstream input_file_;
124 input_file_.open(tmp_);
125 if (input_file_.is_open()) {
128 std::cout <<
"UwAhoiPhy::initializeRangeLUT()" << endl;
129 while (std::getline(input_file_, line_)) {
131 std::istringstream line_stream(line_);
134 double d = stod(token);
136 double p = stod(token);
139 std::cout << d <<
" " << p << endl;
145 ifstream input_file_2;
148 input_file_2.open(tmp_);
149 if (input_file_2.is_open()) {
152 std::cout <<
"UwAhoiPhy::initializeSIRLUT()" << endl;
153 while (std::getline(input_file_2, line_)) {
155 std::istringstream line_stream(line_);
158 double sir = stod(token);
160 double p = stod(token);
163 std::cout << sir <<
" " << p << endl;
176 cerr <<
"UwAhoiPhy ERROR: FIRST INITIALIZE LUT!" << endl;
177 hdr_cmn *ch = HDR_CMN(p);
178 hdr_MPhy *ph = HDR_MPHY(p);
179 hdr_mac *mach = HDR_MAC(p);
181 static int mac_addr = -1;
182 ClMsgPhy2MacAddr msg;
184 mac_addr = msg.getAddr();
189 double x = RNG::defaultrng()->uniform_double();
190 per_n =
getPER(ph->Pr / ph->Pn, p);
191 bool error_n = x <= per_n;
197 per_ni = interference?
getPER(ph->Pr/interference,p):
getPER(0,p);
198 error_ni = x <= per_ni;
202 Scheduler::instance().clock();
207 Scheduler::instance().clock() + ph->duration;
210 ch->error() = error_ni || error_n;
214 << NOW <<
" UwAhoiPhy(" << mac_addr
215 <<
")::endRx() packet " << ch->uid()
216 <<
" contains errors due to noise and interference."
218 }
else if (error_n == 1) {
219 std::cout << NOW <<
" UwAhoiPhy(" << mac_addr
220 <<
")::endRx() packet " << ch->uid()
221 <<
" contains errors due to noise." << std::endl;
225 incrErrorPktsNoise();
226 if (mach->ftype() != MF_CONTROL) {
228 }
else if (mach->ftype() == MF_CONTROL) {
231 }
else if (error_ni) {
232 if (mach->ftype() != MF_CONTROL) {
233 incrErrorPktsInterf();
235 if (interferent_pkts.second >= 1) {
238 if (interferent_pkts.first > 0) {
242 }
else if (mach->ftype() == MF_CONTROL) {
245 if (interferent_pkts.first > 0) {
274 hdr_MPhy *ph = HDR_MPHY(_p);
275 double x_src = (ph->srcPosition)->getX();
276 double y_src = (ph->srcPosition)->getY();
277 double z_src = (ph->srcPosition)->getZ();
278 double x_dst = (ph->dstPosition)->getX();
279 double y_dst = (ph->dstPosition)->getY();
280 double z_dst = (ph->dstPosition)->getZ();
281 return sqrt(pow(x_src - x_dst, 2.0) + pow(y_src - y_dst, 2.0) +
282 pow(z_src - z_dst, 2.0));
290 <<
" UwAhoiPhy()::matchDistancePDR(double distance)"
291 <<
"distance = " << distance << std::endl;
295 PdrLut::iterator it =
range2pdr_.lower_bound(distance);
297 return (--it)->second;
298 double l_sup = it->first;
299 double p_sup = it->second;
301 double l_inf = it->first;
302 double p_inf = it->second;
304 std::cout <<
" Distance between " << l_inf <<
" and " << l_sup;
305 std::cout <<
" Succ Prob between " << p_inf <<
" and " << p_sup;
313 double sir_db = 10*log10(sir/10);
316 <<
" UwAhoiPhy()::matchSIR_PDR(double sir)"
317 <<
"sir = " << sir << std::endl;
318 if (sir_db <=
sir2pdr_.begin()->first)
321 PdrLut::iterator it =
sir2pdr_.lower_bound(sir_db);
323 return (--it)->second;
324 double l_sup = it->first;
325 double p_sup = it->second;
327 double l_inf = it->first;
328 double p_inf = it->second;
330 std::cout <<
" SIR between " << l_inf <<
" and " << l_sup;
331 std::cout <<
" Succ Prob between " << p_inf <<
" and " << p_sup;
338 double x,
double x1,
double y1,
double x2,
double y2)
340 double m = (y1 - y2) / (x1 - x2);
341 double q = y1 - m * x1;
343 std::cout << NOW <<
" UwAhoiPhy::linearInterpolator( double x, "
344 "double x1, double y1, double x2, double y2 )"
345 <<
"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.
virtual double consumedEnergyRx(const double &_duration)
Compute the energy (in Joule) spent by the modem in reception.
uwinterference * interference_
Pointer to the interference model module.
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 arrival time.
double Rx_Time_
Time (in seconds) spent by the node in reception.
virtual int command(int, const char *const *)
TCL command interpreter.
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