50 : TclClass(
"Module/UW/HERMES/PHY")
65 , pdr_file_name_(
"dbs/hermes/default.csv")
66 , pdr_token_separator_(
'\t')
69 bind(
"BCH_N", &
BCH_N);
70 bind(
"BCH_N", &
BCH_K);
71 bind(
"BCH_N", &
BCH_T);
84 if (strcasecmp(argv[1],
"initLUT") == 0) {
88 }
else if (argc == 3) {
89 if (strcasecmp(argv[1],
"setLUTFileName") == 0) {
90 string tmp_ = ((
char *) argv[2]);
91 if (tmp_.size() == 0) {
92 fprintf(stderr,
"Empty string for the file name");
97 }
else if (strcasecmp(argv[1],
"setLUTSeparator") == 0) {
98 string tmp_ = ((
char *) argv[2]);
99 if (tmp_.size() == 0) {
100 fprintf(stderr,
"Empty char for the file name");
113 ifstream input_file_;
117 input_file_.open(tmp_);
118 if (input_file_.is_open()) {
121 std::cout <<
"UwHermesPhy::initializeLUT()" << endl;
122 while (std::getline(input_file_, line_)) {
124 ::std::stringstream line_stream(line_);
131 std::cout << d <<
" " << p << endl;
143 cerr <<
"UwHermesPhy ERROR: FIRST INITIALIZE LUT!" << endl;
144 hdr_cmn *ch = HDR_CMN(p);
145 hdr_MPhy *ph = HDR_MPHY(p);
146 hdr_mac *mach = HDR_MAC(p);
148 static int mac_addr = -1;
149 ClMsgPhy2MacAddr msg;
151 mac_addr = msg.getAddr();
156 int nbits = ch->size() * 8;
157 double x = RNG::defaultrng()->uniform_double();
158 per_n =
getPER(ph->Pr / ph->Pn, nbits, p);
159 bool error_n = x <= per_n;
166 double interference =
168 per_ni = interference > 0;
172 if (per_ni and debug_)
173 std::cout <<
"INTERF" << interference << std::endl;
175 std::cerr <<
"Please choose only MEANPOWER as "
183 per_ni =
getPER(ph->Pr / (ph->Pn + ph->Pi),
186 error_ni = x <= per_ni;
191 Scheduler::instance().clock();
196 Scheduler::instance().clock() + ph->duration;
199 ch->error() = error_ni || error_n;
203 << NOW <<
" UwHermesPhy(" << mac_addr
204 <<
")::endRx() packet " << ch->uid()
205 <<
" contains errors due to noise and interference."
207 }
else if (error_n == 1) {
208 std::cout << NOW <<
" UwHermesPhy(" << mac_addr
209 <<
")::endRx() packet " << ch->uid()
210 <<
" contains errors due to noise." << std::endl;
214 incrErrorPktsNoise();
215 if (mach->ftype() != MF_CONTROL) {
217 }
else if (mach->ftype() == MF_CONTROL) {
220 }
else if (error_ni) {
221 if (mach->ftype() != MF_CONTROL) {
222 incrErrorPktsInterf();
224 if (interferent_pkts.second >= 1) {
227 if (interferent_pkts.first > 0) {
231 }
else if (mach->ftype() == MF_CONTROL) {
234 if (interferent_pkts.first > 0) {
253 return 1 -
matchPS(distance, _nbits);
259 hdr_MPhy *ph = HDR_MPHY(_p);
260 double x_src = (ph->srcPosition)->getX();
261 double y_src = (ph->srcPosition)->getY();
262 double z_src = (ph->srcPosition)->getZ();
263 double x_dst = (ph->dstPosition)->getX();
264 double y_dst = (ph->dstPosition)->getY();
265 double z_dst = (ph->dstPosition)->getZ();
266 return sqrt(pow(x_src - x_dst, 2.0) + pow(y_src - y_dst, 2.0) +
267 pow(z_src - z_dst, 2.0));
278 <<
" UwHermesPhy()::matchPS(double distance, int size)"
279 <<
"distance = " << distance <<
" packet size = " << size
284 PdrLut::iterator it =
range2pdr_.lower_bound(distance);
287 double l_sup = it->first;
288 double p_sup = it->second;
290 double l_inf = it->first;
291 double p_inf = it->second;
293 std::cout <<
" Distance between " << l_inf <<
" and " << l_sup;
294 std::cout <<
" Succ Prob between " << p_inf <<
" and " << p_sup;
296 double p_succ_frame =
299 std::cout <<
" Psucc_frame = " << p_succ_frame;
302 std::cout <<
" Ps = " << ps << std::endl;
308 double x,
double x1,
double y1,
double x2,
double y2)
310 double m = (y1 - y2) / (x1 - x2);
311 double q = y1 - m * x1;
317 std::cout << NOW <<
" UwHermesPhy::linearInterpolator( double x, "
318 "double x1, double y1, double x2, double y2 )"
319 <<
"m = " << m <<
" q= " <<
q << std::endl;
326 int n_chunck_coded_frame = ceil(
float(
FRAME_BIT) / 11);
327 int n_chunck_coded_packet = ceil(
float(size) / 11);
333 std::cout << NOW <<
" UwHermesPhy::chunckInterpolator( " << p <<
" "
334 << size <<
") n_chunck_coded_frame = " << n_chunck_coded_frame
335 <<
" n_chunck_coded_packet = " << n_chunck_coded_packet
337 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.
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 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