39#include <phymac-clmsg.h>
46#define DEFAULT_PSDU 32
55 : TclClass(
"Module/UW/AL")
76 , interframe_period(0)
77 , frame_set_validity(0)
80 , has_tap_clmsg(false)
83 dummyStr +=
" DEFAULT DUMMY STRING ";
87 bind(
"nodeID", (
int *) &
nodeID);
88 bind(
"PSDU", (
int *) &
PSDU);
89 bind(
"debug_", (
int *) &
debug_);
106 if (strcmp(argv[1],
"Reset_PER_List") == 0) {
112 if (strcmp(argv[1],
"linkPacker") == 0) {
119 if (strcmp(argv[1],
"setDummyStr") ==
129 if (strcmp(argv[1],
"Set_PER_List") == 0) {
130 for (
int i = 2; i < argc - 1; i = i + 2) {
131 int id = atoi(argv[i]);
132 double per = atof(argv[i + 1]);
136 for (list<pl_element>::iterator it =
PERList.begin();
139 if (it->node_ID == pl.
node_ID) {
147 if (strcmp(argv[1],
"Clear_PER_List") == 0) {
148 for (
int i = 2; i < argc; i++) {
149 int id = atoi(argv[i]);
150 for (list<pl_element>::iterator it =
PERList.begin();
153 if (it->node_ID ==
id) {
161 return Module::command(argc, argv);
169 for (list<PERListElement>::iterator it =
PERList.begin();
172 if (it->node_ID == mac_addr) {
184 for (list<PERListElement>::iterator it =
PERList.begin();
187 if (it->node_ID == mac_addr) {
189 cout <<
"getPER! " << it->per << endl;
199 hdr_cmn *ch = HDR_CMN(p);
201 if (ch->direction() == hdr_cmn::UP) {
203 std::cout << NOW <<
" UW-AL(" <<
nodeID
204 <<
") : received pkt UP ****" << endl;
212 std::cout << NOW <<
" UW-AL(" <<
nodeID
213 <<
") : received pkt DOWN ****" << endl;
281 hal->
pktID() = pkt_counter_;
297 hdr_cmn *ch = HDR_CMN(p);
301 printf(
"\033[0;0;31m WARNING: \033[0m ");
302 cout <<
"in Uwal::fragmentPkt -> pPacker set to NULL (i.e., no UW "
303 "AL packer added from tcl with linkPacker). No "
304 "serialization neither fragmentation can be performed! "
305 "(i.e., packet just sent to lower layers)."
314 size_t payload_length =
315 pkt_length - hdr_length;
317 if (
PSDU < hdr_length) {
318 printf(
"\033[0;0;31m ERROR: \033[0m ");
319 cout <<
"in packer::ALfragmenter PSDU: " <<
PSDU
320 <<
" but hdr_length; " << hdr_length
321 <<
". Packet fragmentation is not possible since the hdr "
322 "cannot fit in the PSDU."
327 if (pkt_length <=
PSDU) {
338 size_t framePayloadLength =
PSDU - hdr_length;
339 size_t frameNumber = payload_length / framePayloadLength;
347 std::cout <<
"------ ch->size_: " << ch->size()
348 <<
" hdr_length: " << hdr_length
349 <<
", payload_length: " << payload_length
350 <<
", pkt_length: " << pkt_length
351 <<
", framePayloadLength: " << framePayloadLength
352 <<
", frameNumber: " << frameNumber
353 <<
" lastFramePayloadLength: "
354 << lastFramePayloadLength << std::endl;
357 for (uint i = 0; i < frameNumber; i++) {
362 ch_tmp = HDR_CMN(f_tmp);
366 if (!(i == (frameNumber - 1) && lastFramePayloadLength == 0))
382 if (i == (frameNumber - 1) && lastFramePayloadLength == 0)
383 std::cout <<
"TX frame (last) num: " << i << endl;
385 std::cout <<
"TX frame num: " << i << endl;
386 std::cout <<
"Header: "
390 std::cout <<
"Payload: "
398 ch_tmp->size_ =
PSDU;
402 if (lastFramePayloadLength > 0) {
408 ch_tmp = HDR_CMN(f_tmp);
422 ch_tmp->size_ =
PSDU;
428 lastFramePayloadLength);
435 std::cout <<
"TX (last) frame num: " << frameNumber << endl;
436 std::cout <<
"Header: "
440 std::cout <<
"Payload: "
460 hdr_cmn *ch = HDR_CMN(p);
464 printf(
"\033[0;0;31m WARNING: \033[0m ");
465 cout <<
"in Uwal::fragmentPkt -> pPacker set to NULL (i.e., no UW "
466 "AL packer added from tcl with linkPacker). No "
467 "serialization neither reassembling of fragmented packets "
468 "can be performed! (i.e., frame just sent to upper layers)."
474 std::map<RxFrameSetKey, RxFrameSet>::iterator it =
477 size_t framePayloadOffset =
493 Scheduler::instance().clock());
506 Scheduler::instance().clock());
511 std::cout << NOW <<
" UW-AL(" <<
nodeID
512 <<
") - Received frame in error" << std::endl;
514 (it->second).setError();
528 Scheduler::instance().clock());
540 Scheduler::instance().clock());
545 std::cout << NOW <<
" UW-AL(" <<
nodeID
546 <<
") - Received frame in error" << std::endl;
552 std::pair<RxFrameSetKey, RxFrameSet>(newKey, newSet));
558 std::cout << NOW <<
" UW-AL(" <<
nodeID
559 <<
") Generated map of RxFrameSets. Number of elements: "
562 for (std::map<RxFrameSetKey, RxFrameSet>::iterator it =
566 std::cout <<
"Element num: " << i++ << endl;
567 std::cout <<
"Key: " << it->first.displayKey() << endl;
569 std::cout <<
"Set: " << it->second.displaySet() << endl;
579 if (m->type() == CLMSG_PHY2MAC_ENDTX && !
force_endTx_) {
582 Phy2MacEndTx(((ClMsgPhy2MacEndTx *) m)->pkt);
585 }
else if (m->type() == CLMSG_MAC2PHY_GETTXDURATION
586 && m->direction() == DOWN) {
587 Packet *p = ((ClMsgMac2PhyGetTxDuration *) m)->pkt;
588 hdr_cmn *ch = HDR_CMN(p);
590 if (ch->direction() == hdr_cmn::DOWN) {
599 std::cout << NOW <<
" UW-AL(" <<
nodeID
600 <<
") : received ClMsg pkt DOWN ****"
607 sendSyncClMsgDown(m);
611 return Module::recvSyncClMsg(m);
618 std::map<RxFrameSetKey, RxFrameSet>::iterator it =
sendUpFrameSet.begin();
620 for (
int i = 0; i < fs_size; i++) {
621 if (it->second.tot_length() == it->second.curr_length()) {
624 << NOW <<
" UW-AL(" <<
nodeID
625 <<
")::checkRxFrameSet() - COMPLETE pkt RECEIVED! ****"
627 std::cout <<
"Number of elements in sendUpFrameSet: "
629 std::cout <<
"Key: " << it->first.displayKey() << endl;
631 std::cout <<
"Set: " << it->second.displaySet() << endl;
634 Packet *p = Packet::alloc();
638 hdr_cmn *ch = HDR_CMN(p);
640 hal->
srcID() = it->first.srcID();
647 (it->second.binPayload()).c_str(),
648 (it->second.binPayload()).size());
649 hal->
binPktLength() += (it->second.binPayload()).size();
659 ch->size() = it->second.tot_length();
661 std::cout <<
"Packet size = " << ch->size() << std::endl;
666 hdr_mac *mach = HDR_MAC(p);
668 double x = RNG::defaultrng()->uniform_double();
669 cout <<
"x = " << x << endl;
671 cout <<
"PER = " << per << endl;
672 bool error = x <= per;
677 if (it->second.getError()) {
679 std::cout << NOW <<
" UW-AL(" <<
nodeID
680 <<
") - Packet in error" << std::endl;
688 }
else if (Scheduler::instance().clock() -
689 it->second.t_last_rx_frame() >
692 printf(
"\033[0;0;31m WARNING: \033[0m ");
693 std::cout <<
"**** Uwal::checkRxFrameSet() - INCOMPLETE pkt "
694 "DISCARDED! - frame_set_validity elapsed! ****"
696 std::cout <<
"Number of elements in sendUpFrameSet: "
void UpdateRxFrameSet(char *, size_t, size_t, int, double)
virtual void expire(Event *e)
Method to handle the expiration of a given event.
Uwal * pUwal_
Pointer to an Uwal object.
Class to create the Otcl shadow object for an object of the class Uwal.
TclObject * create(int, const char *const *)
The main class implementing the module used to implement the adaptation layer between ns2/NS-Miracle ...
virtual void endRx(Packet *)
Method to end a packet reception.
void checkRxFrameSet()
Method responsible to check for errors the received frames.
std::queue< Packet * > sendUpPkts
queue of the packets to send up to the upper protocols
int debug_
String containing dummy characters to be used as padding chars if necessary.
virtual int recvSyncClMsg(ClMessage *m)
Method to handle the reception of a synchronous crosslayer message.
virtual int command(int, const char *const *)
Method to map tcl commands into c++ methods.
packer * pPacker
Pointer to the packer of the protocol headers.
std::queue< Packet * > sendDownPkts
queue of the packet to send down to the modem
virtual void endTx(Packet *)
Method to end a packet transmission.
double interframe_period
Time period [s] between two successive frame to be sent down.
void ALqueueManager()
Method responsible to manage the queueing system of Adaptation Layer.
void initializeHdr(Packet *, unsigned int)
Method responsible to initialize the headers of the packet.
TxFrameTimer InterframeTmr
Object of the class TxFrameTimer.
unsigned int pkt_counter
Counter for the pktID to set in TX.
std::queue< Packet * > sendUpFrames
queue of the frames to send up to the upper protocols
bool has_tap_clmsg
True if received a ClMessage from uwTAP.
int force_endTx_
0 not force, otherwise force endTx
virtual double getPERfromID(int mac_addr)
Method to search for the PER associated with a particular MAC address.
list< PERListElement > PERList
PER list (couple of ID of the node and Packet Error Rate associated )
int frame_padding
Flag to determine if perfoming bit padding up to PSDU size.
std::queue< Packet * > sendDownFrames
queue of the frames to send down
virtual void recv(Packet *)
Method to handle the reception of packets arriving from the upper layers of the network simulator.
virtual void startRx(Packet *)
Method to start a packet reception.
void fragmentPkt(Packet *)
Method responsible to fragment the packet.
void reassembleFrames(Packet *)
Method responsible to reassemble the various fragments in a unique packets.
std::map< RxFrameSetKey, RxFrameSet > sendUpFrameSet
map of the frames to send up
double frame_set_validity
Time of validity of a frame set.
virtual bool isInPERList(int mac_addr)
Method to search a MAC address in the PER List.
virtual void startTx(Packet *)
Method to start the packet transmission.
size_t PSDU
size of the PSDU
Class exploited by the Uwal module to map an NS-Miracle packet into a bit stream, and vice-versa.
Packet * unpackHdr(Packet *)
size_t getHdrBytesLength()
std::string packPayload(Packet *)
Method to map an NS-Miracle packet into a legal modem payload (i.e., a string of binary characters) w...
static std::string hexdump(std::string)
Packet * unpackPayload(Packet *)
Method to de-map a legal modem payload (i.e., a string of binary characters) into an NS-Miracle packe...
std::string packHdr(Packet *)
#define MAX_BIN_PKT_ARRAY_LENGTH
#define MAX_DUMMY_STRING_LENGTH
hdr_uwal describes the packet header used by Uwal objects.
char * dummyStr()
Return the pointer to the dummyStr_ array.
uint8_t & Mbit()
Reference to the Mbit_ variable.
uint32_t & binHdrLength()
Reference to the binHdrLength_ variable.
uint16_t & framePayloadOffset()
Reference to the frameOffset_ variable.
unsigned int & pktID()
Reference to the pktID_ variable.
char * binPkt()
Return to the binPkt_ array pointer.
uint8_t & srcID()
Reference to the srcID_ variable.
uint32_t & binPktLength()
Reference to the binPktLength_ variable.
UwalClass class_module_uwal
#define DEFAULT_PSDU
The size, in bytes, of the default Physical Service Data Unit (i.e., the maximum length of a packet c...
Header of the main class that implements the adaptation layer between ns2/NS-Miracle and binary data ...