42#include "phymac-clmsg.h"
53 : TclClass(
"Module/UW/HERMES/PHY")
68 , pdr_file_name_(
"dbs/hermes/default.csv")
69 , pdr_token_separator_(
'\t')
72 bind(
"BCH_N", &
BCH_N);
73 bind(
"BCH_N", &
BCH_K);
74 bind(
"BCH_N", &
BCH_T);
87 if (strcasecmp(argv[1],
"initLUT") == 0) {
91 }
else if (argc == 3) {
92 if (strcasecmp(argv[1],
"setLUTFileName") == 0) {
93 string tmp_ = ((
char *) argv[2]);
94 if (tmp_.size() == 0) {
95 fprintf(stderr,
"Empty string for the file name");
100 }
else if (strcasecmp(argv[1],
"setLUTSeparator") == 0) {
101 string tmp_ = ((
char *) argv[2]);
102 if (tmp_.size() == 0) {
103 fprintf(stderr,
"Empty char for the file name");
116 ifstream input_file_;
120 input_file_.open(tmp_);
121 if (input_file_.is_open()) {
124 std::cout <<
"UwHermesPhy::initializeLUT()" << endl;
125 while (std::getline(input_file_, line_)) {
127 ::std::stringstream line_stream(line_);
134 std::cout << d <<
" " << p << endl;
146 cerr <<
"UwHermesPhy ERROR: FIRST INITIALIZE LUT!" << endl;
147 hdr_cmn *ch = HDR_CMN(p);
148 hdr_MPhy *ph = HDR_MPHY(p);
149 hdr_mac *mach = HDR_MAC(p);
151 static int mac_addr = -1;
152 ClMsgPhy2MacAddr msg;
154 mac_addr = msg.getAddr();
159 int nbits = ch->size() * 8;
160 double x = RNG::defaultrng()->uniform_double();
161 per_n =
getPER(ph->Pr / ph->Pn, nbits, p);
162 bool error_n = x <= per_n;
169 double interference =
171 per_ni = interference > 0;
175 if (per_ni and debug_)
176 std::cout <<
"INTERF" << interference << std::endl;
178 std::cerr <<
"Please choose only MEANPOWER as "
186 per_ni =
getPER(ph->Pr / (ph->Pn + ph->Pi),
189 error_ni = x <= per_ni;
194 Scheduler::instance().clock();
199 Scheduler::instance().clock() + ph->duration;
202 ch->error() = error_ni || error_n;
206 << NOW <<
" UwHermesPhy(" << mac_addr
207 <<
")::endRx() packet " << ch->uid()
208 <<
" contains errors due to noise and interference."
210 }
else if (error_n == 1) {
211 std::cout << NOW <<
" UwHermesPhy(" << mac_addr
212 <<
")::endRx() packet " << ch->uid()
213 <<
" contains errors due to noise." << std::endl;
217 incrErrorPktsNoise();
218 if (mach->ftype() != MF_CONTROL) {
220 }
else if (mach->ftype() == MF_CONTROL) {
223 }
else if (error_ni) {
224 if (mach->ftype() != MF_CONTROL) {
225 incrErrorPktsInterf();
227 if (interferent_pkts.second >= 1) {
230 if (interferent_pkts.first > 0) {
234 }
else if (mach->ftype() == MF_CONTROL) {
237 if (interferent_pkts.first > 0) {
256 return 1 -
matchPS(distance, _nbits);
262 hdr_MPhy *ph = HDR_MPHY(_p);
263 double x_src = (ph->srcPosition)->getX();
264 double y_src = (ph->srcPosition)->getY();
265 double z_src = (ph->srcPosition)->getZ();
266 double x_dst = (ph->dstPosition)->getX();
267 double y_dst = (ph->dstPosition)->getY();
268 double z_dst = (ph->dstPosition)->getZ();
269 return sqrt(pow(x_src - x_dst, 2.0) + pow(y_src - y_dst, 2.0) +
270 pow(z_src - z_dst, 2.0));
281 <<
" UwHermesPhy()::matchPS(double distance, int size)"
282 <<
"distance = " << distance <<
" packet size = " << size
287 PdrLut::iterator it =
range2pdr_.lower_bound(distance);
290 double l_sup = it->first;
291 double p_sup = it->second;
293 double l_inf = it->first;
294 double p_inf = it->second;
296 std::cout <<
" Distance between " << l_inf <<
" and " << l_sup;
297 std::cout <<
" Succ Prob between " << p_inf <<
" and " << p_sup;
299 double p_succ_frame =
302 std::cout <<
" Psucc_frame = " << p_succ_frame;
305 std::cout <<
" Ps = " << ps << std::endl;
311 double x,
double x1,
double y1,
double x2,
double y2)
313 double m = (y1 - y2) / (x1 - x2);
314 double q = y1 - m * x1;
320 std::cout << NOW <<
" UwHermesPhy::linearInterpolator( double x, "
321 "double x1, double y1, double x2, double y2 )"
322 <<
"m = " << m <<
" q= " <<
q << std::endl;
329 int n_chunck_coded_frame = ceil(
float(
FRAME_BIT) / 11);
330 int n_chunck_coded_packet = ceil(
float(size) / 11);
336 std::cout << NOW <<
" UwHermesPhy::chunckInterpolator( " << p <<
" "
337 << size <<
") n_chunck_coded_frame = " << n_chunck_coded_frame
338 <<
" n_chunck_coded_packet = " << n_chunck_coded_packet
340 return pow(p, (
float(n_chunck_coded_packet) / n_chunck_coded_frame));
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 void initializeLUT()
virtual double matchPS(double distance, int size)
Return the PER via linear interpolation.
virtual void endRx(Packet *p)
Handles the end of a packet reception.
virtual int command(int, const char *const *)
TCL command interpreter.
virtual double linearInterpolator(double x, double x1, double y1, double x2, double y2)
Return y via linear interpolation given two points.
UwHermesPhy()
Constructor of UwHermesPhy class.
virtual double getDistance(Packet *)
Return the distance between source and destination.
virtual double getPER(double snr, int nbits, Packet *)
Returns the packet error rate by using the length of a packet and the information contained in the pa...
virtual double chunckInterpolator(double p, int size)
int BCH_N
BCH(n,k,t) : correction of t errors via BCH code new frame length= FRAME_BIT/k*n, example: 9152/11*15...
virtual ~UwHermesPhy()
Destructor of UwHermesPhy class.
char pdr_token_separator_
virtual counter getCounters(Packet *p)
Returns the counters of collisions.
virtual double getInterferencePower(Packet *p)
Compute the average interference power for the given packet.
UwHermesPhyClass class_module_uwhermesphy
Definition of UwHermesPhy class.
std::pair< int, int > counter
counter of collisions