;;################################################################## ;; WSimunet - A Model for Simulating Large Wireless Networks ;; Author: Prof. Valério Rosset (PhD) ;; Contact: vrosset@unifesp.br ;; Version: v.6.26 - Basic (08/2018) ;; License: Open Source - Free Use for Academic Research/Teaching ;; All rights reserved to the author ;;################################################################### extensions [nw] ;; these are the metrics globals [simtime sim_rep total_simtime transmission_radius totaltx totalrx totalrxfailed totaltxfailed deliveryratio totaldeliverydelay totalnewmessages deliveryratioatsink totalnetworkdeliverydelay totalresidualenergy averageresidualenergy p_of_nodes_bellow_average p_of_nodes_bellow_threshold txdrain rxdrain sleepdrain processingdrain list_of_delays ticks_per_sec turnback rep_once sink_list] ;; nodes breed [nodes node] nodes-own [state txbuffer txcount rxcount txfailed rxfailed deffercount mytxlist myheaderlist destination nattempts CW acklist datarxcount deliverydelay delay samplecount localnetworkdeliverydelay msgpart residualenergy sqn packet_errors issink myneighborlist mysink mysinkdistance mylb mylt listA listB bfo_generation my_max_retry vs] ;; state: {tx,rx,idle} ;; event breed [events event] events-own [duration] ;; ;;breed [clinks link] links-own [capacity linktype] to reset_values reset-ticks clear-all-plots clear-globals end ;; this is the setup of simulation environment to setup clear-all set-default-shape nodes "circle" ;; SET the list of the sinks here with the respective coordinates ;; set sink_list [[100 400] [400 100]] ;; two sinks in the oposite corners ;; set sink_list [[250 250] [100 400] [400 100]] ;; three sinks ;; set sink_list [[250 250] [100 400] [400 100] [100 100] [400 400]] ;; five sinks .... set sink_list [[250 250]] ;; One sink in the center ;; creat sinks and coordinates acoording to the sink_list : sinks always are set as red foreach sink_list [a -> create-nodes 1 [setxy (item 0 a) (item 1 a) set color red set size 15 set issink true] ] ;; create n nodes and distribute them randomly in the field create-nodes number_of_nodes [setxy random-xcor random-ycor set color blue set size 8 ] set transmission_radius ( 10 ^ ( (1 / (pathLossExponent * 10)) * (( TxPower ) - ( rxSensibility ) - pld0) ) / range_scale ) set list_of_delays [] set simtime 0 set sim_rep 0 set rep_once 0 set total_simtime (max_tick * ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000))) ;; set the initial state of turtles ask turtles [ ;; the transmission radius depends on transmission power of RF device, therefore in this model this is not implemented yet ;; So we assume here the same communication range for every node create-links-with other turtles in-radius transmission_radius [set color blue] ;; Set initial state of nodes set state "rx" set txbuffer 0 set mytxlist [] set label who set CW Cwmin set acklist [] set myheaderlist [] set destination -1 ;;set rtable table:make set samplecount 0 set residualenergy (initialenergy) set nattempts -1 set sqn 0 set msgpart 0 set packet_errors 0 set datarxcount 0 set myneighborlist [] set mysink -1 set mysinkdistance -1 set mylb label set mylt False set listA [] set listB [] set bfo_generation 1 set my_max_retry max_retry set vs false ;;Set battery equations set txdrain ( (txcost / (3600) ) * (8 * message_size_bytes / (bit_rate_kbps * 1000)) ) set rxdrain ( (rxcost / (3600) ) * (8 * message_size_bytes / (bit_rate_kbps * 1000)) ) set sleepdrain (sleepcost / 3600) * (1 / (1 / ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)))) set processingdrain (processing_cost / (3600 * 1000)) set ticks_per_sec (1 / ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000))) set turnback false ] ;; set world background image import-pcolors backgroud_image_filename reset-ticks end ;;################################################## ;;################################################## ;; RESET procedure ;;################################################## ;;################################################## to reset set transmission_radius ( 10 ^ ( (1 / (pathLossExponent * 10)) * (( TxPower ) - ( rxSensibility ) - pld0) ) / range_scale ) ;; reactivate links of dead nodes if (count nodes with [state = "dead" or state = "faulty"] > 0)[ ask nodes with [state = "dead" or state = "faulty"] [ create-links-with other nodes in-radius transmission_radius [set color blue] ] ] ask nodes [ ;; node initial state set state "rx" set txbuffer 0 set mytxlist [] set label who set CW Cwmin set acklist [] set destination -1 set myheaderlist [] ;;set rtable table:make set samplecount 0 set residualenergy (initialenergy) set nattempts -1 set color blue set sqn 0 set packet_errors 0 set myneighborlist [] set mysink -1 set mysinkdistance -1 set mylb label set mylt False set listA [] set listB [] set bfo_generation 1 set my_max_retry max_retry set vs false set txcount 0 set rxcount 0 set txfailed 0 set rxfailed 0 set deffercount 0 set deliverydelay 0 set delay 0 set localnetworkdeliverydelay 0 set turnback false set msgpart 0 set datarxcount 0 ] clear-globals set transmission_radius ( 10 ^ ( (1 / (pathLossExponent * 10)) * (( TxPower ) - ( rxSensibility ) - pld0) ) / range_scale ) set txdrain ( (txcost / (3600) ) * (8 * message_size_bytes / (bit_rate_kbps * 1000)) ) set rxdrain ( (rxcost / (3600) ) * (8 * message_size_bytes / (bit_rate_kbps * 1000)) ) set sleepdrain (sleepcost / 3600) * (1 / (1 / ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)))) set processingdrain (processing_cost / (3600 * 1000)) set ticks_per_sec (1 / ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000))) set total_simtime (max_tick * ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000))) set list_of_delays [] ;; Reset links of Sink nodes ask nodes [ if (issink = True)[ set color red ask my-links [ die ] create-links-with other turtles in-radius transmission_radius [set color blue] ] ] ;; kill remaining event agents ask events [die] reset-ticks end ;;######################################################### ;; The aplication and network layer control implementation ;;######################################################### to application_layer ask nodes with [state != "dead" and state != "sleep" and state != "faulty"][ ifelse (issink != true)[ ;; ############ node's routing tasks needed for network configuration ##### ;; tasks wihtin setup period ifelse (ticks <= setup_period ) [ ;; ... none for now ][ ;; routing tasks after the setup period ;; Sink Selection if (routing_protocol = "direct")[ if (mysink = -1)[ set mysink [who] of one-of nodes with [issink = true] ] ] if (routing_protocol = "shortest-path")[ if (mysink = -1)[ let mindisttosink length (nw:path-to one-of (nodes with [issink = true])) let listofsinks [self] of nodes with [issink = true] foreach listofsinks [ a -> if (length (nw:path-to a) <= mindisttosink) [set mysink [who] of a] ] ] ] ] ;;end routing tasks after setup period ;;################## Data Generation in Application layer of non-sink nodes ##### if (ticks > setup_period )[ ;; reduce the energy for gathering data or pre-processing before transmission set residualenergy (residualenergy - processingdrain) ;; new data messages are created here ;; handle_message [typeofmsg acdelay sourceadd msgsqn msgdest hopcount payload msgrelaysrc] ;; Data generated by an exact rate per second if (exact_rate = true)[ if (ticks / ticks_per_sec <= max_msg_time)[ if ( floor ((ticks / ticks_per_sec) + (1 / ticks_per_sec)) > floor (ticks / ticks_per_sec))[ let ni 0.98 set msgpart (msgpart + message_psec) while [msgpart > ni] [ if (count link-neighbors >= 0) and (issink != true)[ handle_message 1 1 who sqn mysink 1 "data" who "data" set totalnewmessages (totalnewmessages + 1) ] ;; set ni (ni + 1) set msgpart (msgpart - 1) ] ] ] ] ;; Data generated by an specific rate per tick if (t_rate = true)[ if (ticks <= max_event_tick)[ let tx random-float 101 if (tx < (msg_rate)) [ if (count link-neighbors >= 0) and (issink != true)[ handle_message 1 1 who sqn mysink 1 "data" who "data" set totalnewmessages (totalnewmessages + 1) ] ] ] ] ;; Data Generated by an event detection if (t_event = true)[ if (any? events-on (turtles in-radius event_radius) ) and (samplecount = 0)[ if (count link-neighbors >= 0) and (issink != true)[ set totalnewmessages (totalnewmessages + 1) handle_message 1 1 who sqn mysink 1 "data" who "data" ] ] ] set samplecount ((samplecount + 1) mod sample_period) ] ;; ;; end of data generation by non sink nodes ][ ;;############### Procedures executed by sink nodes ##### ;; If the node is either a SINK or an Actuator ;; send the control messages to the network once if (ticks < 1 and setup_period >= 0)[ ifelse (routing_protocol = "mp-rings")[ ;; set one of neighbors to send a control message ;;let destnode [who] of one-of link-neighbors ;; handle_message [typeofmsg acdelay sourceadd msgsqn msgdest hopcount payload msgrelaysrc] handle_message 3 1 who sqn "broadcast" 1 "control" who "control" ][ ] ] ] ] end ;;################################################## ;;################################################## ;; Network Layer Receive Message procedure ;;################################################## ;;################################################## to receive_message ;; network layer call ;; put the received message in the txbuffer towards the sink ;; let msgrelaysource [item 0 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msgdest [item 1 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msgdelay [item 2 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msgsource [item 3 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msgsqn [item 4 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msgtype [item 5 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msghopcount [item 6 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let msgpayload [item 7 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] let ctrheader [item 8 (item 0 myheaderlist)] of one-of link-neighbors with [state = "tx"] ifelse (msgdest = who)[ ;; if (trace = true ) [show (sentence who " has received type " msgtype " from:" msgsource " with sqn: " msgsqn " hopcount:" msghopcount)] ;; msgtype: new data = 1; relayed data = 0 if(msgtype = 0 or msgtype = 1)[ ;; Data message delivered to the aplication layer of final destination let nodex one-of link-neighbors with [state = "tx"] set totaldeliverydelay (totaldeliverydelay + [item 2 (item 0 myheaderlist)] of nodex) ;; check this against msgdelay set list_of_delays lput (sentence msgsource msgdest msgdelay) list_of_delays set datarxcount (datarxcount + 1) ] ][ ;; this idicates if a sink received a data message ment for other synk - in this case the msg is droped if (issink = true) [ if (msgdest != "broadcast") [show (sentence "wrong dest" msgdest msgsource msgrelaysource msgtype msgpayload)]] ;; if the message is new set to relayed if ((msgtype = 1 or msgtype = 3) and who != msgsource)[set msgtype (msgtype - 1)] ;; Relay the message to the next hop towards the destination set msghopcount (msghopcount + 1) handle_message msgtype msgdelay msgsource msgsqn msgdest msghopcount msgpayload msgrelaysource ctrheader if (trace = true)[ show (sentence who " has received type " msgtype " from:" msgsource " with sqn: " msgsqn " hopcount:" msghopcount)] ] end ;;################################################## ;;################################################## ;; Network Layer Send Message procedure ;;################################################## ;;################################################## ;; Notice that the routing decision is made in this procedure to handle_message [typeofmsg acdelay sourceadd msgsqn msgdest hopcount payload msgrelaysrc ctrheader] ;; Types of Messages: 0: relayed data, 1:new data, 2: relayed control msg, 3: new control message let distancetodest 0 if (typeofmsg = 1 or typeofmsg = 3)[ set sqn (sqn + 1) ;; this is the update for the next sqn of this node ] ifelse (msgdest != "broadcast")[ if (issink = true) [show (sentence msgdest sourceadd msgrelaysrc typeofmsg payload ctrheader)] ifelse (msgdest = -1) [if (trace = true) [show (sentence "No sink set, new message drop" msgdest sourceadd msgrelaysrc typeofmsg payload)]] [set distancetodest length (nw:path-to turtle msgdest)] ;;msgdest ][ if (count my-links > 0)[set distancetodest length (nw:path-to one-of link-neighbors)] ] ;; if there is a path to the destination (check this to avoid droping messages) if (distancetodest > 0)[ ifelse (routing_protocol = "shortest-path")[ ;; the shortest path (perfect routing) let list_next_hop_sp nw:turtles-on-path-to turtle msgdest ifelse (list_next_hop_sp != nobody)[ let next_hop_sp item 1 list_next_hop_sp set destination [who] of next_hop_sp ;; show next_hop_sp set txbuffer (txbuffer + 1) set mytxlist lput (destination) mytxlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ][if (trace = true) [ show (sentence msgdest ": is out of range (no path found).")]] ][ ifelse(routing_protocol = "direct") [ ;;direct strategy set destination mysink set txbuffer (txbuffer + 1) set mytxlist lput (destination) mytxlist ;;set myheaderlist lput (destination) myheaderlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ][ ifelse (routing_protocol = "mp-rings")[ ifelse (typeofmsg = 2 or typeofmsg = 3)[ ifelse (issink != true) [ ;; update the routing tables ;; we do not need to do anything here actually we just need to forward the control message to occupate the medium ;; we just need to check if the hopcount is greater or equal to the sink distance ifelse (mysink != -1)[ ifelse (mysinkdistance > hopcount or empty? myneighborlist )[ set mysink sourceadd set mysinkdistance hopcount ;;length (nw:path-to turtle sourceadd) set myneighborlist fput (sentence sourceadd msgrelaysrc hopcount) myneighborlist ;; update the msg dest in the myheaderlist set txbuffer (txbuffer + 1) set mytxlist lput ("broadcast") mytxlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ][if (sourceadd != mysink) [set myneighborlist lput (sentence sourceadd msgrelaysrc hopcount) myneighborlist]] ][ set mysink sourceadd set mysinkdistance hopcount;;length (nw:path-to turtle sourceadd) set myneighborlist fput (sentence sourceadd msgrelaysrc hopcount) myneighborlist set txbuffer (txbuffer + 1) set mytxlist lput ("broadcast") mytxlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ] ][ ifelse (sourceadd = who and msgrelaysrc = who) [ set txbuffer (txbuffer + 1) set mytxlist lput ("broadcast") mytxlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ][ if (sourceadd != who)[ let sourceinthelist filter [s -> first s = sourceadd] myneighborlist if (empty? sourceinthelist) [set myneighborlist fput (sentence sourceadd msgrelaysrc hopcount) myneighborlist] ] ] ] ][ ;; check if the node has at least one item on the routing table before transmit data ifelse (length myneighborlist > 0)[ ;; send/relay data towards the sink (same of the shortestpath) let nexthop item 1 first filter [s -> first s = msgdest] myneighborlist let next_hop_sp one-of link-neighbors with [who = nexthop] if ((next_hop_sp = nobody))[ set nexthop one-of filter [s -> first s = msgdest] myneighborlist set next_hop_sp one-of link-neighbors with [who = nexthop] ] ifelse (next_hop_sp != nobody)[ set destination [who] of next_hop_sp set txbuffer (txbuffer + 1) set mytxlist lput (destination) mytxlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ][if (trace = true) [ show (sentence nexthop ": is out of range (probably dead).")]] ][if (trace = true) [ show (sentence who ": has nothing in the routing table")]] ] ][ ;; Other protocols ...... ] ] ] ] if (mobility_of_sink = true)[ let distancetosink length (nw:path-to turtle mysink) ;; If Sink is mobile if (distancetosink < 1 and issink != true) [ set destination mysink set txbuffer (txbuffer + 1) set mytxlist lput (destination) mytxlist set myheaderlist lput (sentence who msgdest acdelay sourceadd msgsqn typeofmsg hopcount payload ctrheader) myheaderlist ] ] end ;;################################################ ;;Link Layer implementation ;;################################################ to link_layer ;; This simulates the link layer operation of nodes ask nodes with [state != "dead" and state != "sleep" and state != "faulty"] [ ;; on every tick (round or slot-time) ;; all nodes start the round in rx set state "rx" ;; all nodes start in rx set acklist [] ;; always reset the acklist if (MAC_protocol = "CSMA-802.11-DCF") [ ; BACKOFF Rules of 802.11 STD ; When a STA has transmitted a frame other than an initial or intermediate fragment, that STA shall ; not transmit on the channel following the acknowledgment for that frame, without performing the ; backoff procedure. ; When an MSDU has been successfully delivered or all retransmission attempts have been ; exhausted, and the STA has a subsequent MSDU to transmit, then that STA shall perform a backoff ; procedure if ([deffercount] of self = 0) and (nattempts = -1) ;; set the CW and delay for a new message transmission [ set deffercount random (CW / 2) ;; initial backof of 802.11 ] ;; is something in the txbuffer then try to send it if ([deffercount] of self = 0)[ if (txbuffer > 0) [ set state "lst" set destination first mytxlist ] ] if ([state] of self = "rx")[set color gray] ] ;; Other Protocols if (MAC_protocol != "CSMA-802.11-DCF") [ if (txbuffer > 0) [ set state "lst" set destination first mytxlist ] if ([state] of self = "rx") [set color gray] ] ] ;; #### BACKOFF procedure #### ask nodes with [state != "dead" and state != "sleep" and state != "faulty"] [ if (MAC_protocol = "CSMA-802.11-DCF") [ ;; the CSMA 1-persitent with exponential backoff ask self [ if ([count link-neighbors] of self >= 1)[ ;; try tx only if backoff time is finished ifelse ([deffercount] of self <= 0) [ if ([state] of self = "lst") [ ;; if next is true the medium is in use ifelse (any? link-neighbors with [state = "tx"]) ;; channel is busy - Exposed node Problem [ set deffercount random (CW + 1) ;; this is the 802.11 backoff set state "rx" set color white ;; transmission delayed by backoff procedure ][ ;; transmits set state "tx" set color red ] ] ][ if (count link-neighbors with [state = "tx"] <= 0 ) ;; channel is idle [ set deffercount (deffercount - 1) ;; count down until 0 ] ] ] ] ] if (MAC_protocol = "CSMA-P-Persistent")[ ask self [ if ([count link-neighbors] of self >= 1)[ if ([state] of self = "lst") [ let p_tx random 101 ;; if next is true the medium is in use ifelse (any? link-neighbors with [state = "tx"]) or ((p_tx / 100) > p_persistence) ;; channel is busy - Exposed node Problem [ set state "rx" set color white ;; transmission delayed by CSMA procedure ;;set delay (delay + 1) ;;set totaldeliverydelay (totaldeliverydelay + 1) ][ ;; transmits set state "tx" set color red ] ] ] ] ] if (MAC_protocol = "None")[ if ([state] of self = "lst") [ set state "tx" set color red ] ] if (MAC_protocol = "TDMA")[ if ([state] of self = "lst") [ set state "tx" set color red ] ] ] ;; ##### RX procedure ##### ask nodes with [state != "dead" and state != "sleep" and state != "faulty"] [ if (MAC_protocol = "CSMA-802.11-DCF") [ ;; continue now with rx ask self [ ;; always check the rx if ([state] of self = "rx") [ ;; reduce the energy for one tx set residualenergy (residualenergy - rxdrain) ;;there is a colision here ;;hiden terminal ifelse (count link-neighbors with [state = "tx"] > 1) or ((count link-neighbors with [state = "tx"] = 1) and (random ( (1 / (Base))) < PER)) [ if (count link-neighbors with [state = "tx"] = 1) [set packet_errors (packet_errors + 1)] set color yellow ;; means that the transmision fails due to hiden terminal or frame corruption set rxfailed (rxfailed + 1) ;;set totalrxfailed (totalrxfailed + 1) set acklist lput -1 acklist ][ if (count link-neighbors with [state = "tx"] > 0)[ let dest [destination] of one-of link-neighbors with [state = "tx"] if (dest = [who] of self) or (dest = -1) or (dest = "broadcast");; must to include error rate in acks [ set color green ;; destination has received without errors set acklist lput ([who] of one-of link-neighbors with [state = "tx"]) acklist set rxcount (rxcount + 1) ;; increase the number of received the messages set totalrx (totalrx + 1) receive_message ] ] ] ] ] ] if (MAC_protocol = "CSMA-P-Persistent") [ ;; continue now with rx ask self [ ;; always check the rx if ([state] of self = "rx") [ ;; reduce the energy for one tx set residualenergy (residualenergy - rxdrain) ;;there is a colision here ;;hiden terminal ifelse (count link-neighbors with [state = "tx"] > 1) or (random ( (1 / (Base))) < PER) [ set color yellow ;; transmission fails due to hiden terminal or frame corruption set rxfailed (rxfailed + 1) set totalrxfailed (totalrxfailed + 1) set acklist lput -1 acklist ][ if (count link-neighbors with [state = "tx"] > 0)[ let dest [destination] of one-of link-neighbors with [state = "tx"] if (dest = [who] of self) or (dest = -1) or (dest = "broadcast") ;; must to include error rate in acks [ set color green ;; destination has received without errors set acklist lput ([who] of one-of link-neighbors with [state = "tx"]) acklist set rxcount (rxcount + 1) ;; increase the number of received the messages set totalrx (totalrx + 1) receive_message ] ] ] ] ] ] if (MAC_protocol = "TDMA")[ ;; continue now with rx ;; the abstraction here is that all nodes will have a slot of time every tick to send a message ;; therefore, there will be no colisions, no acks needed ask self [ ;; always check the rx if ([state] of self = "rx") [ ;; reduce the energy for one tx set residualenergy (residualenergy - rxdrain) ifelse (random-float ((1 / (Base))) < PER) [ set color yellow ;; fail due to frame corruption set rxfailed (rxfailed + 1) set totalrxfailed (totalrxfailed + 1) ][ if (count link-neighbors with [state = "tx"] > 0)[ let dest [destination] of link-neighbors with [state = "tx"] foreach dest[ a -> if (a = [who] of self) or (a = -1) or (a = "broadcast");; must to include error rate in acks [ set color green ;; destination has received without errors set rxcount (rxcount + 1) ;; increase the number of received the messages set totalrx (totalrx + 1) receive_message ] ] ] ] ] ] ] if (MAC_protocol = "None")[ ;; continue now with rx ask self [ ;; always check the rx if ([state] of self = "rx") [ ;; reduce the energy for one tx set residualenergy (residualenergy - rxdrain) ;;there is a colision here ;;hiden terminal problem ifelse (count link-neighbors with [state = "tx"] > 1) or (random ( (1 / (Base))) < PER) [ set color yellow ;; fail due to hiden terminal or frame corruption set rxfailed (rxfailed + 1) set totalrxfailed (totalrxfailed + 1) ][ if (count link-neighbors with [state = "tx"] > 0)[ let dest [destination] of one-of link-neighbors with [state = "tx"] ;;show dest if (dest = [who] of self) or (dest = -1) or (dest = "broadcast");; must to include error rate in acks [ set color green ;; destination has received without errors set rxcount (rxcount + 1) ;; increase the number of received the messages set totalrx (totalrx + 1) receive_message ] ] ] ] ] ] ] ;;###### ACKs confirmation procedure ####### ;; Test if tx nodes received a ack ask nodes with [state != "dead" and state != "sleep" and state != "faulty"] [ if (MAC_protocol = "CSMA-802.11-DCF")[ ask self[ if ([state] of self = "tx")[ ;; reduce the energy for one tx set residualenergy (residualenergy - txdrain) let dest [destination] of self ;;for broadcast no ack is sent ifelse (dest = "broadcast") [ set color blue ;; sucess in transmission confirmed by a received ack let myID who let txbcast count link-neighbors set txbuffer (txbuffer - 1) set txcount (txcount + txbcast) set totaltx (totaltx + txbcast) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set nattempts -1 set CW CWmin set destination -1 set txfailed (txfailed + count link-neighbors with [length acklist > 0 and first acklist = -1]) ][ ifelse (count link-neighbors with [who = dest] >= 1)[ let nodex [first acklist] of one-of link-neighbors with [who = dest] ifelse (nodex = who) [ set color blue ;; sucess in transmission confirmed by a received ack set txbuffer (txbuffer - 1) set txcount (txcount + 1) set totaltx (totaltx + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set nattempts -1 set CW CWmin set destination -1 ][ set nattempts (nattempts + 1) set CW (CW * 2) if (CW >= Cwmax) [set CW CWmax] ;If the source STA does not receive an acknowledgment frame, it shall attempt to retransmit the failed MPDU ;after performing the backoff procedure and the contention process set deffercount random (CW + 1) if (nattempts >= my_max_retry) [ set txbuffer (txbuffer - 1) set txcount (txcount + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set nattempts -1 set CW CWmin set destination -1 set txfailed (txfailed + 1) set totaltxfailed (totaltxfailed + 1) set color orange ;; packet discarded ] ] ][ ;; in this case the destination of the packet (in the buffer) is not active so the packet is discarded set txbuffer (txbuffer - 1) set txcount (txcount + 1) ;;set totaltx (totaltx + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set nattempts -1 set CW CWmin set destination -1 set txfailed (txfailed + 1) set totaltxfailed (totaltxfailed + 1) set color orange ;; packet discarded ] ] ] ] ] if (MAC_protocol = "CSMA-P-Persistent")[ ask self[ if ([state] of self = "tx")[ ;; reduce the energy for one tx set residualenergy (residualenergy - txdrain) let dest [destination] of self ;;for broadcast no ack is sent ifelse (dest = "broadcast") [ set color blue ;; sucess in transmission confirmed by a received ack let myID who let txbcast count link-neighbors set txbuffer (txbuffer - 1) set txcount (txcount + txbcast) set totaltx (totaltx + txbcast) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist ;;set nattempts -1 set destination -1 set txfailed (txfailed + count link-neighbors with [length acklist > 0 and first acklist = -1]) ][ if (count link-neighbors with [who = dest] >= 1)[ let nodex [first acklist] of one-of link-neighbors with [who = dest] ifelse (nodex = who) [ set color blue ;; sucess in transmission confirmed by a received ack set txbuffer (txbuffer - 1) set txcount (txcount + 1) set totaltx (totaltx + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set destination -1 ][ set txbuffer (txbuffer - 1) set txcount (txcount + 1) set totaltx (totaltx + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set destination -1 set txfailed (txfailed + 1) set totaltxfailed (totaltxfailed + 1) set color orange ;; packet discarded ] ] ] ] ] ] if ( MAC_protocol = "None" or MAC_protocol = "TDMA")[ ask self[ ;; if ([state] of self = "tx")[ ;; reduce the energy for one tx set residualenergy (residualenergy - txdrain) let dest [destination] of self ;;for broadcast no ack is sent ifelse (dest = "broadcast") [ set color blue ;; sucess in transmission confirmed by a received ack let myID who let txbcast count link-neighbors set txbuffer (txbuffer - 1) set txcount (txcount + txbcast) set totaltx (totaltx + txbcast) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set destination -1 ][ if (count link-neighbors with [who = dest] >= 1)[ let nodex_color [color] of one-of link-neighbors with [who = dest] ifelse (nodex_color = green or (MAC_protocol = "TDMA")) [ ;; sucess in transmission confirmed set txbuffer (txbuffer - 1) set txcount (txcount + 1) set totaltx (totaltx + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set destination -1 ][ set txbuffer (txbuffer - 1) set txcount (txcount + 1) set totaltx (totaltx + 1) set mytxlist remove-item 0 mytxlist set myheaderlist remove-item 0 myheaderlist set destination -1 set txfailed (txfailed + 1) set totaltxfailed (totaltxfailed + 1) ] ] ] ] ] ] ] end ;;################################################## ;;################################################## ;; The MOBILITY procedure ;;################################################## ;;################################################## to mobility_man ;; not working for multiple sinks if (mobility_of_sink = TRUE) [ ;; node 0 is the SINK ask nodes with [issink = true] [ if (mobility_strategy = "random_walk")[ ;; move ramdomly step 1 if (ycor > max-pycor - 1 or xcor > max-pxcor - 1 or ycor < min-pycor + 1 or xcor < min-pxcor + 1) [ right random 360] ifelse (walk_on_streets = true)[ ifelse (patch-ahead 1 != nobody and [pcolor] of patch-ahead 1 >= 9.0 and [pcolor] of patch-ahead 1 <= 9.9)[ forward (ground_speed / ticks_per_sec) ][ ifelse (patch-right-and-ahead 45 1 != nobody and [pcolor] of patch-right-and-ahead 45 1 >= 9.0 and [pcolor] of patch-right-and-ahead 45 1 <= 9.9)[ right 45 forward (ground_speed / ticks_per_sec) ][ ifelse (patch-left-and-ahead 45 1 != nobody and [pcolor] of patch-left-and-ahead 45 1 >= 9.0 and [pcolor] of patch-left-and-ahead 45 1 <= 9.9)[ left 45 forward (ground_speed / ticks_per_sec) ][left random 180 forward (ground_speed / ticks_per_sec)] ] ] ][ forward (air_speed / ticks_per_sec) ] ] if (mobility_strategy = "horizontal_walk")[ if (ticks = 1) [set heading 90] ifelse (heading = 90 and turnback = false)[ if (xcor >= max-pxcor - 1)[ if (xcor >= max-pxcor - 1 ) [right 90 forward 1 right 90] ] if (xcor >= max-pxcor - 1 and ycor <= min-pycor + 1)[set turnback not(turnback)] ][ ifelse (heading = 90 and turnback = true)[ if (xcor >= max-pxcor - 1 )[ if (xcor >= max-pxcor - 1 ) [left 90 forward 1 left 90] ] if (xcor >= max-pxcor - 1 and ycor >= max-pycor - 1 )[set turnback not(turnback)] ][ ifelse (heading = 270 and turnback = false) [ if (xcor <= min-pxcor + 1 )[ if (xcor <= min-pxcor + 1) [left 90 forward 1 left 90] ] if (xcor <= min-pxcor + 1 and ycor = min-pycor + 1)[set heading 90 set turnback not(turnback)] ][ if (xcor <= min-pxcor + 1 )[ if (xcor <= min-pxcor + 1) [right 90 forward 1 right 90] ] if (xcor <= min-pxcor + 1 and ycor = max-pycor - 1)[set heading 90 set turnback not(turnback)] ] ] ] forward ceiling (air_speed / ticks_per_sec) ] if (mobility_strategy = "other")[] ;;redefine links ask my-links [ die ] create-links-with other nodes in-radius transmission_radius ] ] end ;;################################################## ;;################################################## ;; The NODE MONITOR procedure ;;################################################## ;;################################################## to nodemonitor ask nodes with [state != "dead" and state != "faulty"][ if ([issink] of self != true)[ if (residualenergy <= 0) [ set txfailed (txfailed + txbuffer) set txbuffer 0 set state "dead" set color black ask my-links [ die ] ] let dutty_p random (100) ifelse (dutty_p > dutty_cycle)[ set state "sleep" set color cyan ;; reduce the energy for one sleep time set residualenergy (residualenergy - sleepdrain) ] [set state "rx"] if (count link-neighbors <= 0 and mobility_of_sink = FALSE) [ set state "dead" set txbuffer 0 set color black ] if (count link-neighbors > 0) and (nw:path-to one-of (nodes with [issink = true]) = false or (nw:path-to one-of (nodes with [issink = true])) = false) and (mobility_of_sink = FALSE) [ set state "dead" set txbuffer 0 set color black ] if (count link-neighbors > 0 and txbuffer > 0 ) [ SET_delay_ALL ;; set totaldeliverydelay (totaldeliverydelay + 1) ] if (ticks mod ticks_per_sec = 1 and random-float 1 < 1 / number_of_nodes)[ if (random-float 1 <= (node_fault_rate / (3600))) [ set txfailed (txfailed + txbuffer) set txbuffer 0 set state "faulty" set color black ask my-links [ die ] ] ] ] ] end ;;################################################## ;;################################################## ;; The Event Creation procedure ;;################################################## ;;################################################## to eventgenerator if (t_event = true)[ let eventprob random 101 if ( eventprob < event_rate) and (count events < max_events) and (ticks <= max_event_tick) [ create-events 1 [setxy random-xcor random-ycor set color red set duration event_duration set size 10] ] ] end ;;################################################## ;;################################################## ;; The Event Monitor procedure ;;################################################## ;;################################################## to eventmonitor if (any? events)[ ;; here ask events [ ifelse (duration > 0)[ set duration (duration - 1) ][ die ] ] ] end ;;################################################## ;;################################################## ;; The Delay Messurement procedure ;;################################################## ;;################################################## ;;node context to SET_delay_ALL let n 0 foreach myheaderlist [ ;;show item 2 (item n myheaderlist) + 1 set myheaderlist (replace-item n myheaderlist replace-item 2 (item n myheaderlist) ((item 2 (item n myheaderlist)) + 1)) ;;show item n myheaderlist set n (n + 1) ] end to plot_test set-current-plot "Total Simulation Time (s)" set-current-plot-pen "time" plot ticks / ticks_per_sec ;; set-current-plot "Individual Residual Energy (mAh)" ;; set-current-plot-pen "residualenergy" ;; plot histogram [residualenergy] of nodes ;; ask nodes [plot residualenergy] set-current-plot "Residual Energy (mAh)" set-current-plot-pen "default" ;;plotxy (simtime + total_simtime * sim_rep) 0 histogram [residualenergy] of nodes ;; set-current-plot "Total received Data" ;; set-current-plot-pen "pen1" ;; plot (([datarxcount] of node 0 * (message_size_bytes * 8)) / 1000) end to plot_demand ;; set-current-plot "demand" ;; set-current-plot-pen "default" ;; plotxy ticks who ;;show (sentence who ";" ticks) end ;;################################################## ;;################################################## ;; The MAIN procedure ;;################################################## ;;################################################## to go ;;############### Nodes monitor ##### nodemonitor ;;############### Event generator ##### eventgenerator ;;############### Call for application layer operation #### application_layer ;;############### Call for link layer operation #### link_layer ;;############### Stats #### set totaltx (sum ([txcount] of nodes)) set totalrx (sum ([rxcount] of nodes)) set totalrxfailed (sum ([rxfailed] of nodes)) set totaltxfailed (sum ([txfailed] of nodes)) set totalresidualenergy (sum ([residualenergy] of nodes with [state != "dead" and issink != true])) set averageresidualenergy ((totalresidualenergy) / (count nodes)) ;; ;;set p_of_nodes_bellow_energy_threshold ( (count nodes with [residualenergy < (averageresidualenergy) * (1 - energy_threshold)]) / count nodes ) set p_of_nodes_bellow_average (count nodes with [residualenergy < averageresidualenergy] / count nodes ) set p_of_nodes_bellow_threshold (count nodes with [residualenergy < (initialenergy * energy_threshold)] / count nodes ) if (totaltx > 0) or (totaltxfailed > 0) [ set deliveryratio (totalrx / (totaltx) ) ] if (totalnewmessages > 0) [ set deliveryratioatsink (sum ([datarxcount] of nodes with [issink = true])) / totalnewmessages ] ;;################ Monitors ##### ;;### EVENT monitor #### eventmonitor ;;### MOBILITY monitor #### mobility_man ;;################ Simulation Control ##### tick ;; icrease the clock: in this case the tick is the time used to complete the one frame transmission set simtime (ticks / (1 / ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)))) ;;if (ticks = max_event_tick)[ Set t_rate (False) ] ;;if (t_event = FALSE) [ if (ticks > max_tick) and (sum [txbuffer] of nodes = 0) [stop] ] ;;if (t_event = TRUE) [ if (ticks > max_tick) [stop] ] ifelse (run_until_clear_buffers)[ if (sum [txbuffer] of nodes = 0 and ticks > max_tick) [ plot_test stop] ] [if (ticks > max_tick) [plot_test stop]] ;;if (ticks > setup_period)[stop] end ;; This procedure performs several simulations calling the "go" procedure without changing of the world to go_repeatedly let i 0 + rep_once let t_rate_control t_rate let temp_sim_rep 0 let count_sim 1 while [number_of_simulations >= count_sim][ set temp_sim_rep sim_rep reset ifelse (run_until_clear_buffers)[ set sim_rep (i) ][ set sim_rep (i) ] ifelse (run_until_clear_buffers)[ while [not(sum [txbuffer] of nodes = 0 and ticks > max_tick)] [ go if (ticks >= max_tick)[ set rep_once (ticks / max_tick) ] ] ][ while [not(ticks > max_tick)] [ go if (ticks >= max_tick)[ set rep_once (ticks / max_tick) ] ] ] set i (i + rep_once) set count_sim (count_sim + 1) ] end ;;################################################## ;; RF Devices Config ;;################################################## to preset_rf_devices_config ifelse (preset_rf = "nRF24L01_TxPw=0dBm")[ ;; set some parametrs based on specs of "nRF24L01" for TxPower = 0 ;; set TxPower 0 set txcost 11.3 set rxcost 12.3 set bit_rate_kbps 250 set PER 1 set Base 1.0E-3 set rxSensibility -94 set frequency_radio 2.415 set message_size_bytes 41.125 ][ ] end ;;####################### REPORTS FOR OUTPUTS to-report throughput report ((sum [datarxcount] of nodes with [issink = true] * (message_size_bytes * 8)) / 1000) / ((ticks + 1) / ticks_per_sec) end to-report avdeliverydelay report (totaldeliverydelay / sum [datarxcount] of nodes with [issink = true]) * ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)) end @#$#@#$#@ GRAPHICS-WINDOW 338 10 847 520 -1 -1 1.0 1 10 1 1 1 0 0 0 1 0 500 0 500 1 1 1 ticks 30.0 BUTTON 11 198 142 237 NIL setup NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 1057 76 1136 109 go go\nif (ticks >= max_tick)[\n set rep_once (ticks / max_tick)\n]\n T 1 T OBSERVER NIL NIL NIL NIL 1 SLIDER 11 162 144 195 TxPower TxPower -20 30 0.0 1 1 dBm HORIZONTAL INPUTBOX 12 77 111 137 number_of_nodes 100.0 1 0 Number MONITOR 993 207 1109 252 Buffers of Nodes sum [txbuffer] of nodes 17 1 11 PLOT 875 318 1132 490 TX and RX Time (s) Total (Frames) 0.0 10.0 0.0 10.0 true true "" "" PENS "Total tx" 1.0 0 -2674135 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) totaltx]" "Total rx" 1.0 0 -13840069 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) totalrx]" MONITOR 935 207 992 252 NIL totaltx 17 1 11 MONITOR 875 207 932 252 NIL totalrx 17 1 11 MONITOR 1111 207 1206 252 Packet Errors sum ([packet_errors] of nodes) 17 1 11 INPUTBOX 335 898 412 958 max_retry 0.0 1 0 Number MONITOR 875 269 991 314 NIL totaltxfailed 17 1 11 TEXTBOX 14 31 96 77 The number of nodes (excluding the sink) 11 0.0 1 TEXTBOX 337 867 539 901 Maximum number of retramissions of a frame due to fail in tx (Retry Limit) 11 0.0 1 MONITOR 992 269 1109 314 Delivery ratio (%) deliveryratio * 100 17 1 11 TEXTBOX 996 254 1146 272 One-Hop Delivery Ratio 11 0.0 1 INPUTBOX 873 50 946 110 max_tick 1000.0 1 0 Number TEXTBOX 876 255 1026 273 Frames discarded 11 0.0 1 PLOT 1133 317 1389 490 Link Delivery Ratio Time (s) Delivery Ratio (%) 0.0 0.0 0.0 100.0 true true "" "" PENS "delivery" 1.0 0 -13345367 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) (deliveryratio * 100)]" INPUTBOX 545 925 604 985 CWmin 8.0 1 0 Number INPUTBOX 604 925 659 985 CWmax 30.0 1 0 Number PLOT 875 747 1134 888 Delivery Delay Time (s) Av. Delay (s) 0.0 10.0 0.0 1.0 true false "" "" PENS "Delay" 1.0 0 -16777216 true "" "if (ticks > 0 and sum [datarxcount] of nodes with [issink = true] > 0) [plotxy (simtime + (total_simtime * sim_rep)) ((totaldeliverydelay / sum [datarxcount] of nodes with [issink = true]) * ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)))]" TEXTBOX 15 426 321 459 Mark if new data messages are generated with a given transmission (%) per tick, during a max_tick interval. 11 0.0 1 TEXTBOX 583 909 642 927 CW limits 11 0.0 1 TEXTBOX 874 23 963 50 Total Simulation time (in Ticks) 11 0.0 1 INPUTBOX 7 987 62 1047 PER 1.0 1 0 Number INPUTBOX 62 987 139 1047 Base 0.001 1 0 Number MONITOR 990 521 1183 566 Data Messages Delivered (Goodput) sum [datarxcount] of nodes with [issink = true] 17 1 11 MONITOR 874 521 988 566 Data Msg. Generated totalnewmessages 17 1 11 PLOT 874 568 1134 744 End-to-End Delivery Ratio (Goodput) Time (s) Delivery Ratio 0.0 1.0 0.0 1.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) deliveryratioatsink]" MONITOR 1302 521 1413 566 Delivery Ratio % deliveryratioatsink * 100 17 1 11 TEXTBOX 10 957 192 986 The packet error rate in rx (BER + Termal noise + Multipath + Fading) 11 0.0 1 TEXTBOX 418 900 478 955 Value 0 means no retry and no ack 11 0.0 1 SWITCH 13 457 105 490 t_rate t_rate 0 1 -1000 SWITCH 10 549 128 582 t_event t_event 1 1 -1000 SLIDER 105 549 241 582 event_rate event_rate 0 100 10.0 1 1 % HORIZONTAL INPUTBOX 10 616 79 676 max_events 50.0 1 0 Number INPUTBOX 80 616 164 676 event_duration 50.0 1 0 Number INPUTBOX 166 616 245 676 sample_period 5.0 1 0 Number TEXTBOX 12 696 123 736 Set one of the following routing strategies 11 0.0 1 INPUTBOX 333 1133 384 1193 txcost 11.3 1 0 Number INPUTBOX 386 1133 436 1193 rxcost 12.3 1 0 Number INPUTBOX 332 1028 412 1088 initialenergy 200.0 1 0 Number MONITOR 883 935 1063 980 Av. Residual Energy (mA-h) averageresidualenergy 17 1 11 INPUTBOX 334 1249 436 1309 energy_threshold 0.3 1 0 Number MONITOR 1064 935 1207 980 % of nodes bellow Avarage p_of_nodes_bellow_average * 100 17 1 11 INPUTBOX 437 1133 527 1193 processing_cost 0.0 1 0 Number TEXTBOX 336 1090 601 1157 Tx, rx, processing and sleep costs specified in mA-h. Notice that these parameters depend on the TxPower chosen.\n 11 0.0 1 TEXTBOX 339 1200 606 1257 Minimum Energy Threshold sets the minimum residual energy to consider a given node with low battery. (0.1 = 10% of battery initial energy). 11 0.0 1 INPUTBOX 8 1109 119 1169 message_size_bytes 312.5 1 0 Number INPUTBOX 131 1109 206 1169 bit_rate_kbps 250.0 1 0 Number MONITOR 1209 980 1389 1025 tx energy drain (mA-h) txdrain 17 1 11 MONITOR 1209 935 1389 980 rx energy drain (mA-h) rxdrain 17 1 11 MONITOR 1064 981 1207 1026 % of live nodes ((count nodes with [state != \"dead\" and state != \"faulty\" and issink != true]) / number_of_nodes) * 100 17 1 11 MONITOR 883 981 1063 1026 % of nodes bellow energy threshold p_of_nodes_bellow_threshold * 100 17 1 11 TEXTBOX 20 9 321 37 ----------------- NETWORK MAIN SETUP ---------------------------- 11 0.0 1 TEXTBOX 10 316 335 344 -------- Application/Data/Event Generation Setup ---------------------- 11 0.0 1 TEXTBOX 10 520 257 545 Mark if events are ramdonly generated with a given event_rate (%) per tick 11 0.0 1 TEXTBOX 12 585 324 641 Set the Maximum number of concurrent events, the event duration and the period between each data gathering 11 0.0 1 TEXTBOX 5 681 857 709 ------- Network Layer Setup ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 11 0.0 1 TEXTBOX 7 821 863 849 --------- Link/Phy Layer Setup ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 11 0.0 1 TEXTBOX 10 1047 214 1101 Ex. if PER = 0.035 \nSet PER to 3.5\nSet Base to 1.0E-2 11 0.0 1 TEXTBOX 11 1094 137 1112 Max Frame Size (Bytes) 11 0.0 1 TEXTBOX 139 1094 289 1112 Bit Rate (kbps) 11 0.0 1 TEXTBOX 324 1003 344 1549 |\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n| 11 0.0 1 TEXTBOX 335 1011 485 1029 Battery Capacity in mA-h 11 0.0 1 TEXTBOX 866 12 881 1496 |\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n| 11 0.0 1 TEXTBOX 866 180 1592 208 -------------- Link Layer Outputs ---------------------------------------------------------------------------------------------------------------------------------------------- 11 0.0 1 TEXTBOX 875 504 1595 532 ----------- Application/Transport/Network Layer Outputs ----------------------------------------------------------------------------------------------------------------- 11 0.0 1 TEXTBOX 869 902 1592 930 --------- Energy Related Outputs ------------------------------------------------------------------------------------------------------------- 11 0.0 1 TEXTBOX 13 143 257 161 Set the transmission power of your radio in dBm. 11 0.0 1 INPUTBOX 106 458 201 518 msg_rate 0.2 1 0 Number TEXTBOX 10 1176 315 1232 ----Radio Config. ----------------------------------------------------- 11 0.0 1 TEXTBOX 19 1399 308 1539 Consider simetric links between nodes where the transmission radius (R) of a node is given by: \nR = 10^((1/(pathLossExponent*10))*((TxPower)\n-(rxSensibility)-pld0))\n\nPld0 is assumed to be the free space path loss considering the distance d0 = 1 m.\n\nPL(d0) = 20 * log(distance_d0)(10) + 20 * log(frequency_radio)(10) + 92.45 11 0.0 1 INPUTBOX 14 1242 124 1302 pld0 55.0 1 0 Number TEXTBOX 134 1216 254 1283 Rx Sensibility\ndBm 11 0.0 1 INPUTBOX 128 1243 202 1303 rxSensibility -94.0 1 0 Number INPUTBOX 204 1243 311 1303 pathLossExponent 2.4 1 0 Number MONITOR 146 162 277 207 Tx_radius (m) 10 ^ ((1 / (pathLossExponent * 10)) * ( ( TxPower ) - ( rxSensibility ) - pld0)) 17 1 11 INPUTBOX 114 77 184 137 range_scale 0.4 1 0 Number TEXTBOX 117 29 296 72 The field is set to 500m x 500m. \nYou can change the range_scale in order to change de field area. 11 0.0 1 CHOOSER 7 851 159 896 MAC_Protocol MAC_Protocol "CSMA-802.11-DCF" "CSMA-P-Persistent" "TDMA" "None" 1 INPUTBOX 8 896 159 956 p_persistence 0.6 1 0 Number TEXTBOX 336 839 540 867 These paramerts are needed only for 802.11-DCF 11 0.0 1 CHOOSER 10 740 116 785 routing_protocol routing_protocol "shortest-path" "direct" "mp-rings" "other" 0 TEXTBOX 550 842 861 908 In this simulation model every tick represents a slot of time large enough where a given node may transmit at least one frame. In the case of the 802.11 DCF every tick also encapsulates operations performed in the DIFS and SIFS intervals. 11 0.0 1 INPUTBOX 660 925 739 985 Sifs_size 0.001 1 0 Number TEXTBOX 671 910 734 928 SIFS Size (s) 11 0.0 1 MONITOR 216 1110 318 1155 Frame_tx_time (s) (message_size_bytes * 8) / (bit_rate_kbps * 1000) 17 1 11 MONITOR 740 940 832 985 DIFS Size (s) (message_size_bytes * 8) / (bit_rate_kbps * 1000) * 2 + Sifs_size 17 1 11 INPUTBOX 245 616 323 676 event_radius 10.0 1 0 Number MONITOR 198 1335 310 1380 Estimatted PL(d0) 20 * log(distance_d0)(10) + 20 * log(frequency_radio)(10) + 92.45 17 1 11 INPUTBOX 15 1333 93 1393 distance_d0 0.001 1 0 Number INPUTBOX 96 1334 194 1394 frequency_radio 2.415 1 0 Number TEXTBOX 20 1305 80 1333 Distance d0\nin Km 11 0.0 1 TEXTBOX 102 1305 334 1333 Frequency of the radio \nin Ghz 11 0.0 1 TEXTBOX 216 1200 277 1242 Path Loss\nExponent \n2.4 - 3.0 11 0.0 1 TEXTBOX 644 1127 864 1505 ------------------------------------------------------\nHere is an example of nRF24L01+ Specs:\n\nTx_Power <> Tx Cost \n0dBm <> 11.3mA\n-6dBm <> 9.0mA\n-12dBm <> 7.5mA\n-18dBm <> 7.0mA\n\nBit_rate <> Rx Cost\n2Mbps <> 13.5\n1Mbps <> 13.1\n250kbps <> 12.6\n\nBER = 1.0E-3\nOperation Frequency \n2.4 GHz\nChannel Bandwidth \n1 MHz at 250 - 1000 kbps \n2 Mhz at 2Mbps\n\n\nRx- Sensibility = -94 \nRadio Freq - 2.415 \n\nMax Frame Size - 41,125 bytes 11 0.0 1 BUTTON 1057 108 1136 141 reset \nlet itemp rep_once\nlet temp_sim_rep sim_rep\nreset\nset sim_rep (temp_sim_rep + itemp)\n\n NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 1146 82 1270 142 number_of_simulations 2.0 1 0 Number BUTTON 1146 143 1269 176 go repeatedly go_repeatedly\n\nlet itemp rep_once\nlet temp_sim_rep sim_rep\nreset\nset sim_rep (temp_sim_rep + itemp)\nset rep_once sim_rep NIL 1 T OBSERVER NIL NIL NIL NIL 1 TEXTBOX 871 10 1270 29 --------- Simulation Control Panel ----------------------------------------------------------- 11 0.0 1 PLOT 882 1028 1391 1199 Energy Outputs Time (s) Energy (mAh) 0.0 100.0 0.0 1.0 true true "" "" PENS "Av. Residual Energy" 1.0 1 -2674135 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) averageresidualenergy]" "E. Threshold " 1.0 0 -7500403 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) (initialenergy * (energy_threshold))]" SWITCH 1291 31 1418 64 mobility_of_sink mobility_of_sink 1 1 -1000 PLOT 1135 567 1395 744 Throughput of Sinks Time (s) Throughput (Kbps) 0.0 10.0 0.0 10.0 true false "" "" PENS "throughput " 1.0 0 -2674135 true "" "if ticks > 0 [plotxy (simtime + (total_simtime * sim_rep)) ((sum [datarxcount] of nodes with [issink = true] * (message_size_bytes * 8)) / 1000) / ((ticks + 1) / ticks_per_sec)]" BUTTON 339 578 580 611 Set background Image ;;set backgroud_image_filename user-file\nifelse backgroud_image_filename != \"\"[\nimport-pcolors-rgb backgroud_image_filename]\n[\n ask patches [ set pcolor black ]\n]\n;;import-pcolors backgroud_image_filename\n\n NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 205 459 296 519 max_event_tick 500.0 1 0 Number INPUTBOX 338 613 848 684 backgroud_image_filename recorte_jsc_openstreetmap.png 1 0 String BUTTON 338 543 412 576 Hide links ask links[hide-link] NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 418 543 496 576 Show Links ask links[ show-link] NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 586 544 662 611 select_node 2.0 1 0 Number INPUTBOX 662 544 725 611 set_cor_x 100.0 1 0 Number INPUTBOX 725 544 786 611 set_cor_y 10.0 1 0 Number BUTTON 789 544 849 610 Set Cord. ask turtle select_node [ setxy set_cor_x set_cor_y]\nreset NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 502 543 580 576 reset links ask links [die]\nset transmission_radius ( 10 ^ ( (1 / (pathLossExponent * 10)) * (( TxPower ) - ( rxSensibility ) - pld0) ) / range_scale )\nask turtles [create-links-with other turtles in-radius transmission_radius [set color blue]] NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 13 265 176 298 grid setup (only for sqr) setup\n\n\nask links [die]\n\nset set_cor_x 0\nset set_cor_y 0\nlet i1 0\nlet i2 0\nlet node_1 2\nlet dist abs sqrt number_of_nodes\nlet max_side max-pxcor ;;+ (50 / dist)\nwhile [i2 < dist][\n set i1 0\n set set_cor_x 0\n while [i1 < dist][\n ask turtle node_1 [setxy set_cor_x set_cor_y ]\n set set_cor_x set_cor_x + (max_side / (dist - 1))\n set i1 i1 + 1\n set node_1 node_1 + 1\n ]\n set set_cor_y set_cor_y + (max_side / (dist - 1))\n set i2 i2 + 1\n]\n\nset transmission_radius ( 10 ^ ( (1 / (pathLossExponent * 10)) * (( TxPower ) - ( rxSensibility ) - pld0) ) / range_scale )\nask turtles [create-links-with other turtles in-radius transmission_radius [set color blue]]\n\n\nset set_cor_x 0\nset set_cor_y 0 NIL 1 T OBSERVER NIL NIL NIL NIL 1 TEXTBOX 10 243 332 271 ------ Grid Auto Organize ------------------------------------------------- 11 0.0 1 TEXTBOX 181 267 331 295 The number of nodes must have an exact square root. 11 0.0 1 TEXTBOX 18 1199 112 1241 Use the value of estimated PL(d0) or any other 11 0.0 1 MONITOR 946 50 1047 95 total_sim_time (s) max_tick * ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)) 17 1 11 INPUTBOX 178 894 286 954 beacon_wind_size 0.01 1 0 Number TEXTBOX 182 861 274 889 Set the Beacon Window Lengh (s) 11 0.0 1 MONITOR 1413 521 1535 566 Av. Delivery Delay (s) (totaldeliverydelay / sum [datarxcount] of nodes with [issink = true]) * ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)) 17 1 11 SWITCH 1292 147 1419 180 walk_on_streets walk_on_streets 1 1 -1000 INPUTBOX 1418 49 1498 109 ground_speed 200.0 1 0 Number INPUTBOX 1499 49 1569 109 air_speed 200.0 1 0 Number TEXTBOX 1460 32 1580 50 Speed in m/s 11 0.0 1 MONITOR 873 112 946 157 ticks_per_sec 1 / ( beacon_wind_size + (message_size_bytes * 8) / (bit_rate_kbps * 1000)) 17 1 11 CHOOSER 1290 63 1418 108 mobility_strategy mobility_strategy "random_walk" "horizontal_walk" "other" 0 PLOT 1388 317 1563 490 Total Simulation Time (s) NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "time" 1.0 1 -16777216 true "" "" TEXTBOX 188 76 338 146 e.g. by setting the range_scale value to 0.5 the field area will be assumed to be 250m x 250m and so on. 11 0.0 1 TEXTBOX 1276 16 1291 184 |\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n| 11 0.0 1 TEXTBOX 1285 10 1606 38 --------- Mobility Control Panel ------------------------------------------ 11 0.0 1 PLOT 1331 195 1561 315 Av. Buffer Size (KBytes) NIL NIL 0.0 10.0 0.0 0.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "if (ticks > 0) [plotxy (simtime + (total_simtime * sim_rep)) ((sum [txbuffer] of nodes) / number_of_nodes) * message_size_bytes / 1024]" TEXTBOX 328 993 851 1011 --------- Energy Setup ------------------------------------------------------ Faults ----------------------------------------- 11 0.0 1 SWITCH 14 364 113 397 exact_rate exact_rate 1 1 -1000 INPUTBOX 115 364 199 424 message_psec 20.0 1 0 Number INPUTBOX 199 364 292 424 max_msg_time 1000.0 1 0 Number SWITCH 1147 49 1270 82 run_until_clear_buffers run_until_clear_buffers 1 1 -1000 TEXTBOX 13 333 341 376 Mark and set the number of new messages generated per second per node in the simulation, and the time limit for their generation. 11 0.0 1 TEXTBOX 324 842 339 996 |\n|\n|\n|\n|\n|\n|\n|\n|\n|\n| 11 0.0 1 MONITOR 946 96 1047 141 Simulation Time (s) simtime 17 1 11 INPUTBOX 201 988 296 1048 dutty_cycle 100.0 1 0 Number TEXTBOX 204 957 289 988 Set the dutty cycle in % 11 0.0 1 INPUTBOX 527 1133 606 1193 sleepcost 0.0 1 0 Number TEXTBOX 336 1491 1551 1509 ---- DEBUG Tools ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 11 0.0 1 BUTTON 1057 141 1136 174 clear_plots clear-all-plots NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 117 740 194 800 setup_period 0.0 1 0 Number SWITCH 331 1515 434 1548 trace trace 1 1 -1000 TEXTBOX 122 708 392 748 The setup_period determines the period of time that nodes are able to send only control messages, 11 0.0 1 CHOOSER 337 1418 517 1463 preset_rf preset_rf "nRF24L01_TxPw=0dBm" "cc1000 ..." "cc2420 ..." 0 BUTTON 528 1418 583 1464 Set preset_rf_devices_config NIL 1 T OBSERVER NIL NIL NIL NIL 1 TEXTBOX 204 740 392 823 after this period nodes will send data messages, it must be set in ticks. set to 0 if the routing strategy does note use any control message. 11 0.0 1 PLOT 883 1200 1392 1372 Residual Energy (mAh) NIL NIL 0.0 1000.0 0.0 10.0 true false "" "" PENS "default" 1.0 1 -16777216 true "" "" BUTTON 882 1375 1061 1408 Residual Energy Histogram ask nodes [\n \n if (residualenergy < 0)[set residualenergy 0]\n \n ]\n \n set-current-plot \"Residual Energy (mAh)\"\n set-current-plot-pen \"default\"\n clear-plot \n set-plot-x-range 0 (initialenergy + 1)\n histogram [residualenergy] of nodes NIL 1 T OBSERVER NIL NIL NIL NIL 1 MONITOR 1184 521 1301 566 Throughput (Kbps) ;;simtime\n;;((sum [datarxcount] of nodes with [issink = true] * (message_size_bytes * 8)) / 1000) / ((ticks + 0.000000001) / ticks_per_sec)\n((sum [datarxcount] of nodes with [issink = true] * (message_size_bytes * 8)) / 1000) / (simtime) 17 1 11 INPUTBOX 709 1028 824 1088 node_fault_rate 0.0 1 0 Number TEXTBOX 649 1012 833 1067 The rate of nodes' permanent fauts (per hour). 11 0.0 1 TEXTBOX 631 1003 646 1493 |\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n| 11 0.0 1 TEXTBOX 341 1387 612 1429 Set radio paramters based on the specs. \nchoose the radio model and click on the \"Set\" button. 11 0.0 1 TEXTBOX 444 1509 594 1551 If set some debug messages will appear in the comand center. 11 0.0 1 TEXTBOX 1295 117 1547 159 If set to true the sinks will move only over the white lanes in the map. 11 0.0 1 TEXTBOX 331 1358 627 1400 ---- Preset ------------------------------------------------------------ 11 0.0 1 BUTTON 1057 43 1136 76 one_step go\nif (ticks >= max_tick)[\n set rep_once (ticks / max_tick)\n]\n NIL 1 T OBSERVER NIL NIL NIL NIL 1 @#$#@#$#@ ![](file:wsimulnet.png) # WSimulNET - A Model for Simulating Large Wireless Networks # Short Guide ## INTRODUCTION WSimulNET is a simple and fast way to introduce the main concepts of wireless environments to (under)graduate students. The visual features of the model combined to the short learning curve of Netlogo’s environment and language make this tool suitable to be used in either introductory or advanced courses. Therefore, for many experiment setups, no prior knowledge about Netlogo’s programming language is needed to use this tool as they may not require modifying the source code. With this tool one may simulate several types of Wireless Networks, although mostly the model concentrates on Wireless Sensor Networks (WSNs) perspective. The tool provides the means to observe, and measure by several metrics, the behavior of nodes communicating on a wireless environment. Also, it is possible to simulate scenarios with multiple sinks, with or without mobility. Despite these basic features, the WSimulNET can also be used to simulate more sophisticated protocols considering large scale and high density networks, given to network’s practitioners and researchers very solid and realistic results. The model implements the CSMA/CA of IEEE 802.11-DCF, the CSMA(p-persistent) and TDMA abstraction as the medium access protocols. In the network layer, the model implements three routing strategies: 1. **direct:** Where nodes send messages directly to a sink, if there exists a link between them. 2. **shortest-path:** Nodes proceed with multi-hop routing considering the nest hop in the shortest path to the sink. However, this strategy does not use any control message to discover the path to the sinks. The path discovery is abstracted by the use of the “network” Netlogo extension. 3. **mp-rings:** this is a adaptation of the multipath rings protocol used in the Castalia Simulator (https://github.com/boulis/Castalia). In this protocol the paths are constructed considering the shortest distance (in hops) of each node to the sinks, every node will choose the nearby sink to join and include the ID of the next hop in the shortest path towards the chosen sink in the routing table. Differently of the former protocols this is a full implemented protocol, control messages are actually used in path discovery procedure executed during the setup period. This means that, due to failures, some nodes may not find the shortest path to the chosen sink or join to the actually nearby sink. At the beginning of protocol operation the sinks broadcast *discovery path messages* to the network and sensor nodes rebroadcast the control messages to their neighbors updating the *hopcount* field in the message header. Therefore, nodes may decide on the nearby sink and the next hop to it by observing the *hopcounts* received by their neighbors. After the setup period, nodes forward data messages through the chosen path. ## HOW IT WORKS The turtles act as network nodes of a wireless network or events, the links (between turtles) indicate the radio connectivity between network nodes, every pair of nodes sharing the same link is able to communicate to each other. However, this model supports only one network interface per node and all nodes share the same configuration. The model considers that links are symmetric and the communication range is calculated based on some chosen parameters. The transmission radius (R) of a node is given by Eq.1: R = 10 ^ ((1/(pathLossExponent*10))*((TxPower) -(rxSensibility)-pld0)) (Eq.1) The Pld0 is assumed to be the free space path loss (based on the Okumura model) considering the distance d0 = 1m, and is given by the Eq.2: PL(d0) = 20 * log(distance_d0)(10) + 20 * log(frequency_radio)(10) + 92.45 (Eq.2) These parameters may vary according to the radio technology used and the medium, and they must me adjusted properly to get more realistic results. In the main setup panel one may choose the number of network nodes, except the sinks, used in the simulation. Also, it is possible to determine the TXPower of the radio device, by observing the communication range (TxRadius). ## HOW TO USE IT Since the model simulates the many aspects of a WSN there are several parameters to be set. The setup panels are essentially separated considering parameters related to the application, network, link, radio model, energy and simulation control. ### Dealing with the parameters #### Application parameters: In the _Application/Data/Event Generation Setup_ section one may find three options for data message generation (switch buttons), namely: _exact_rate_, _t-rate_ and _t-event_. These three buttons can be set to _On_ at the same time. However, it is preferable to use them apart. 1. If the _exact_rate_ is set to _On_ data messages will be generated by nodes with the rate (number of messages per second) defined in the _message_psec_ input during the period (in seconds) defined in the _max_msg_time_ input. 2. If the _t_rate_ is set to _On_ data messages will be generated by nodes with the rate (number of messages per tick) defined in the _msg_rate_ input during the period (in ticks) defined in the _max_event_tick_ input. 3. If the _t-event_ is set to _On_ data messages will be generated by nodes when they detect a event nearby (a red triangle turtle), the events are generated with the rate defined in the _event_rate_ chooser during the period (in ticks) defined in the _max_event_tick_ input. For this latter option is is also possible to set some features of events: the maximum number of concurrent events that may appear in the world (max_events input); each event created will remain in the map by a period (in ticks) defined by the _ma_duration_ input; each node will sense the environment looking for any event in the _event_radius_ radius every period of _sample_period_ ticks. #### Network parameters: In the _Network Layer Setup_ section one may choose the routing protocol used in simulation as well as the size of the *setup_period* (in ticks) used by the protocol to exchange control messages,before starting the data generation by nodes. Is this model, only **mp-rings** actually generates and sends control messages, the others will not send any message during the *setup_period* interval. #### Link parameters: In the _Link/Phy Layer Setup_ section one may choose the MAC protocol used in simulation. The model provides three MAC strategies: the CSMA/CA strategy of IEEE 802.11-DCF including the backoff procedure, the CSMA(p-persistent) and a TDMA abstraction. In this section some parameters, such as *beacon_win_size*, *PER-Base*, *dutty_cycle*, *message_size_bytes* and the *bit _rate_kbps*, are shared by all MAC protocols and other parameters are specific of the IEEE 802.11-DCF and CSMA(p-persistent). A short description of each parameter is presented next. 1. Common parameters - *beacon_win_size*: the beacon window size in seconds. - *PER-Base*: the packet error rate (PER) of fail in rx procedure, this rate should include BER, Thermal noise, Multipath and Fading. Use the *PER* abd *Base* inputs to indicate the rate. For example, if rate = 0.035, set the *PER* to 3.5 and the *Base* to 1.0E-2. - *dutty_cycle*: indicates the ratio of activity of nodes (0-100). If 100 all nodes will perform their tasks during the total period of simulation. If less, nodes will randomly sleep with a probability of 100 - *dutty_cycle*. - *message_size_bytes*: the maximum size of a frame including all headers and preambles. Notice that, in this model, all frames have the same size. - *bit_rate_kbps*: the transmission rate of the network interface in kbps. This parameter is defined by the model of the radio device chosen for the simulation. 2. Specific parameters - *p-persitence*: the value of p in the CSMA-p-persistent protocol. - *max_retry*: the number of retransmissions attempts before dropping a frame (used in IEEE 802.11-DCF). - *CWmin* and *CWmax*: the CWmin and CWmax of IEEE 802.11-DCF. - *Sifs_size*: the sifs size of IEEE 802.11-DCF. #### Radio parameters: In the _Radio Config._ section one may set the radio parameters used in the Eq1. and Eq2 to defined transmission radius of nodes. The "rx_sensibility" and "frequency_radio" parameters are defined in the specifications of radio defvices. The other, are estimated based on the assumed simulated environment. #### Energy parameters: In the _Energy Setup_ section one may set the energy related parameters of nodes. In that section is possible to defined the initial energy capacity of nodes (in mAh), as well as the energy consumption (in mAh) for tx, rx, sleeping and processing tasks. Notice that this parameters may vary depending on the radio device configuration and the chosen TxPower. Here is an example of power consumption for several device configurations described in the [nRF24L01+ specification](https://www.nordicsemi.com/eng/content/download/2726/34069/file/nRF24L01P_Product_Specification_1_0.pdf): >Tx_Power <> Tx Cost 0dBm <> 11.3mA -6dBm <> 9.0mA -12dBm <> 7.5mA -18dBm <> 7.0mA >Bit_rate <> Rx Cost 2Mbps <> 13.5 1Mbps <> 13.1 250kbps <> 12.6 >BER = 1.0E-3 Operation Frequency 2.4 GHz Channel Bandwidth 1 MHz at 250 - 1000 kbps 2 Mhz at 2Mbps >Rx- Sensibility = -94 Radio Freq - 2.415 >Max Frame Size - 41,125 bytes The *energy_threshold* is the value used to define a node as a low battery state. #### Simulation Control parameters In the _Simulation Control_ section the *max_tick* sets the maximum number of ticks used in the simulation. However, depending on the network configuration, some nodes may have messages in the buffer at the end of simulation. In this case, if the option *run_until_clear_buffers* set to "On" the simulation will continue until all tx buffers of nodes be empty. Notice that when changing the *max_tick* the *total_simulation* A simulation is started by pressing the *go* button (or the *one-step* button for a step-by-step execution). Multiple simulations may be executed by seting the _number_of_simulation_ and pressing the *go_repeatedly* button. During the simulation, output monitors and plots are updated with intermediate results. #### Mobility Control parameters In the _Mobility Control_ section the *mobility_of_sink* option allows the sinks to walk through the world map. The mobility strategy is set by the _mobility_strategy_ chooser. The model implements two mobility strategies: the random walk and the horizontal walk. By setting the _walk_on_streets_ option "On" the sinks will only move over white (patches) lanes in the map. Sink nodes must be placed on the lanes otherwise they will get stuck. The speed of nodes can be set (in m/s) in the _ground_speed_ and _air_speed_ inputs. ### Faults By setting the *node_fault_rate* one may indicate the rate of permanent faults of nodes per hour. In this case whenever a node becomes faulty it will stop to work and lose all links with other nodes. Messages in the buffers of such nodes will be lost also. ### Outputs This model presents several output information to help the users to understand their simulation results. Therefore, such outputs are organized in three main groups with their distinct set of metrics: link layer outputs, application/transport/network outputs and energy outputs. ## THINGS TO NOTICE One may run multiple simulations with the same parameters by using the button "go repeatedly". The outputs will be plot in sequence for every execution. Multiple simulations with distinct parameters may be executed by using the Behaviorspace tool of the NetLogo environment. ## THINGS TO TRY The primarily focus of this model is to provide a way to simulate large-scale networks with minimum setup time. Therefore, one may test this model with high number of nodes in the network and verify how fast it goes in comparison to other simulation environments. ## EXTENDING THE MODEL The model is not exhaustive, there several points to be improved. ## CREDITS AND REFERENCES This model, and further improvements can be found in the author's site: https://sites.google.com/site/valeriorosset/wsimulnet Author: Valério Rosset (PhD), Associate Professor @ Federal University of São Paulo, Brazil. Contact: vrosset@unifesp.br Version: v.6.26 - Basic (08/2018) Netlogo Version: 6.0.2 License: Open Source - Free Use for Academic Research/Teaching All rights reserved to the author @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 sheep false 15 Circle -1 true true 203 65 88 Circle -1 true true 70 65 162 Circle -1 true true 150 105 120 Polygon -7500403 true false 218 120 240 165 255 165 278 120 Circle -7500403 true false 214 72 67 Rectangle -1 true true 164 223 179 298 Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 Circle -1 true true 3 83 150 Rectangle -1 true true 65 221 80 296 Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 Polygon -7500403 true false 276 85 285 105 302 99 294 83 Polygon -7500403 true false 219 85 210 105 193 99 201 83 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 wolf false 0 Polygon -16777216 true false 253 133 245 131 245 133 Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 6.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ setup go deliveryratioatsink * 100 (totalnetworkdeliverydelay - (max_ntemps * totaltxfailed)) / [rxcount] of node 0 setup go if (ticks >= max_tick)[ set rep_once (ticks / max_tick) ] totaltx totalrx totalrxfailed totaltxfailed totalresidualenergy averageresidualenergy p_of_nodes_bellow_average p_of_nodes_bellow_threshold deliveryratioatsink throughput avdeliverydelay simtime @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@