53 : TclClass(
"Module/UW/ICRPNode")
77 , timer_ack_waiting_(10)
78 , ackwaitingTmr_(this)
85 cout.setf(ios::floatfield, ios::fixed);
102 return Module::recvSyncClMsg(m);
112 return Module::recvAsyncClMsg(m);
120 sendSyncClMsgDown(m);
151 Tcl &tcl = Tcl::instance();
154 if (strcasecmp(argv[1],
"initialize") == 0) {
157 }
else if (strcasecmp(argv[1],
"clearhops") == 0) {
160 }
else if (strcasecmp(argv[1],
"printhops") == 0) {
163 }
else if (strcasecmp(argv[1],
"getackheadersize") == 0) {
166 }
else if (strcasecmp(argv[1],
"getdataheadersize") == 0) {
169 }
else if (strcasecmp(argv[1],
"getstatusheadersize") == 0) {
172 }
else if (strcasecmp(argv[1],
"getackpktcount") == 0) {
175 }
else if (strcasecmp(argv[1],
"getdatapktcount") == 0) {
178 }
else if (strcasecmp(argv[1],
"getstatuspktcount") == 0) {
182 }
else if (argc == 3) {
183 if (strcasecmp(argv[1],
"ipsink") == 0) {
184 ipSink_ =
static_cast<uint8_t
>(atoi(argv[2]));
186 fprintf(stderr,
"0 is not a valid IP address");
193 }
else if (strcasecmp(argv[1],
"addr") == 0) {
194 ipAddr_ =
static_cast<uint8_t
>(atoi(argv[2]));
197 fprintf(stderr,
"0 is not a valid IP address");
203 return Module::command(argc, argv);
209 hdr_cmn *ch = HDR_CMN(p);
221 if (ch->direction() == hdr_cmn::UP) {
226 cout <<
"@" << Scheduler::instance().clock()
228 <<
" - CP: " << ch->uid()
229 <<
" - UP - Status Packet for me." << endl;
236 cout <<
"@" << Scheduler::instance().clock()
238 <<
" - CP: " << ch->uid()
239 <<
" - UP - Status Packet, process and forward it."
244 Packet *p_new = Packet::alloc();
246 hdr_cmn *ch_new = HDR_CMN(p_new);
268 cout <<
"@" << Scheduler::instance().clock()
270 <<
" - CP: " << ch->uid()
271 <<
" - UP - Data Packet Received." << endl;
279 if (pointer_ != -1 &&
288 cout <<
"@" << Scheduler::instance().clock()
290 <<
" - CP: " << ch->uid()
291 <<
" - UP - Data Packet to Forward - IP "
314 cout <<
"@" << Scheduler::instance().clock()
316 <<
" - CP: " << ch->uid()
317 <<
" - UP - Data Packet in Bcast to "
318 "Forward - IP inserted."
329 cout <<
"@" << Scheduler::instance().clock()
331 <<
" - CP: " << ch->uid()
332 <<
" - UP - Data Packet already processed "
344 }
else if (ch->direction() ==
348 Packet *p_new = Packet::alloc();
351 hdr_cmn *ch_new = HDR_CMN(p_new);
354 if (pointer_ != -1 &&
route_table[pointer_].next_hop != 0) {
355 if (ch->next_hop() != 0) {
361 cout <<
"@" << Scheduler::instance().clock()
363 <<
" - CP: " << ch->uid()
364 <<
" - DOWN - New Data Packet. Next hop: "
365 <<
printIP(ch_new->next_hop()) << endl;
372 cout <<
"@" << Scheduler::instance().clock()
374 <<
" - P: " << ch->uid()
375 <<
" - ??? - NO_DIRECTION - Garbage." << endl;
386 hdr_cmn *ch = HDR_CMN(p);
390 ch->direction() = hdr_cmn::DOWN;
410 ch->timestamp() = Scheduler::instance().clock();
419 hdr_cmn *ch = HDR_CMN(p);
453 if ((Scheduler::instance().clock() -
route_table[i].creationtime) >
501 cout << i <<
" : " <<
'\t'
512 std::stringstream out;
513 out <<
"0.0.0." << ((_ip & 0x000000ff));
520 int level[4] = {0, 0, 0, 0};
522 strncpy(tmp, str, 19);
524 char *p = strtok(tmp,
".");
525 for (
int i = 0; p && i < 4; p = strtok(NULL,
"."), i++) {
529 else if (level[i] < 0)
533 for (
int i = 0; i < 4; i++) {
534 addr += (level[i] << 8 * (3 - i));
542 hdr_cmn *ch = HDR_CMN(p);
544 Packet *p_ack = Packet::alloc();
547 hdr_cmn *ch_ack = HDR_CMN(p_ack);
550 ch_ack->next_hop() = ch->prev_hop_;
551 iph_ack->
daddr() = ch->prev_hop_;
561 hdr_cmn *ch = HDR_CMN(p);
564 ch->direction() = hdr_cmn::DOWN;
576 ch->timestamp() = Scheduler::instance().clock();
packet_t PT_UWICRP_STATUS
ClMessage_t UWIP_CLMSG_SEND_ADDR
virtual void expire(Event *e)
Class that manages cross layer messages that require the IP of the node.
Class used to answer to UWIPClMsgReqAddr cross layer messages.
Adds the module for UwIcrpNodeModuleClass in ns2.
TclObject * create(int, const char *const *)
UwIcrpNode class is used to represent the routing layer of a node.
virtual void clearAllRouteTable()
Clears completely the routing table of the node.
virtual void addRouteEntry(Packet *)
Adds the information received from a Status packet in the routing table of the node.
virtual void sendBackAck(const Packet *p)
Creates an ack packet after the reception a data packet received correctly.
nsaddr_t str2addr(const char *)
Returns a nsaddr_t address from an IP written as a string in the form "x.x.x.x".
uint8_t ipSink_
IP of the sink associated.
virtual string printIP(const uint8_t)
Return a string with an IP in the classic form "x.x.x.x" converting an ns2 nsaddr_t address.
virtual void ackLost()
Resets all the routing information because the lost of an ack.
double max_validity_time_
Maximum validity time of a route.
virtual void initPktAck(Packet *p)
Initializes an Ack packet (previously allocated).
static const int getStatusPktHeaderSize()
Returns the size in byte of a hdr_uwicrp_status packet header.
virtual int command(int, const char *const *)
TCL command interpreter.
static long numberofstatuspkt_
Comulative number of Status packets processed by UwIcrpNode objects.
virtual bool addIpInList(Packet *, nsaddr_t)
Adds an IP passed as argument in the header of a Data packet passed as argument.
virtual void initialize()
Initializes a UwIcrpNode node.
uint8_t ipAddr_
IP of the current node.
static long numberofackpkt_
Comulative number of Ack packets processed by UwIcrpNode objects.
static const int getAckPktHeaderSize()
Returns the size in byte of a hdr_uwicrp_ack packet header.
routing_table_entry route_table[HOP_TABLE_LENGTH]
Node routing table.
virtual int recvAsyncClMsg(ClMessage *)
Initializes a UwIcrpSink node.
AckWaiting ackwaitingTmr_
AckWaiting object.
virtual void initPkt(Packet *)
Initializes a Data packet (previously allocated).
static long numberofdatapkt_
Comulative number of Data packets processed by UwIcrpNode objects.
virtual bool isIpInList(Packet *, nsaddr_t)
Checks if a specific IP is in the header of the packet passed as argument.
virtual void printHopTable()
Prints in the stdout the routing table of the current node.
virtual int findInRouteTable(nsaddr_t)
Seeks for an entry in the routing table that contains information to a specific address passed as arg...
static const int getDataPktHeaderSize()
Returns the size in byte of a hdr_uwicrp_data packet header.
UwIcrpNode()
Constructor of UwIcrpNode class.
~UwIcrpNode()
Destructor of UwIcrpNode class.
virtual int recvSyncClMsg(ClMessage *)
Cross-Layer messages synchronous interpreter.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
int printDebug_
Flag to enable or disable dirrefent levels of debug.
virtual void clearRouteTable(const int &)
Removes a specific entry in the routing table of the node.
double timer_ack_waiting_
Ack waiting timer.
hdr_uwicrp_ack describes acks packets used by UWICRP.
hdr_uwicrp_data describes data packets used by UWICRP
int & pointer_to_list_of_hops()
Reference to the pointer_to_list_of_hops_ variable.
int & list_of_hops_length()
Reference to the list_of_hops_length_ variable.
nsaddr_t * list_of_hops()
Pointer to the list_of_hops_ variable.
hdr_uwicrp_status describes status packets used by UWICRP
int & list_of_hops_length()
Reference to the list_of_hops_length_ variable.
nsaddr_t * list_of_hops()
Pointer to the list_of_hops_ variable.
int & pointer_to_list_of_hops()
Reference to the pointer_to_list_of_hops_ variable.
hdr_uwip describes UWIP packets.
uint8_t & daddr()
Reference to the daddr_ variable.
uint8_t & saddr()
Reference to the saddr_ variable.
double creationtime
Creation Time of the packet.
nsaddr_t destination
Address of the destination.
nsaddr_t next_hop
Address of the next hop.
bool isValid
Flag to check the validity of the packet.
static const int HOP_TABLE_LENGTH
Maximum length of the routing table of a node FOR UWICRP.
static const int MAX_HOP_NUMBER
Maximum number of hops contained in a SUN Path Establishment packet.
#define HDR_UWICRP_DATA(p)
#define HDR_UWICRP_STATUS(p)
packet_t PT_UWICRP_STATUS
UwIcrpNodeModuleClass class_module_uwicrp_node
Provides a module for nodes that needs a simple and dynamic routing protocol.
static const uint8_t UWIP_BROADCAST
Variable used to represent a broadcast UWIP.