The Mannasim Framework ---------------------- The Manna Reseach Group e-mail: mannateam@gmail.com This file contains all file modifications made on ns-2.29 in order to Mannasim work. Modified files and changes are followed discussed. 1. NS-2.29 modified files The following ns-2.29 files were changed in some way to garantee that the simulator works: - ns-2.29/apps/udp.cc - ns-2.29/common/ns-process.h - ns-2.29/common/packet.cc - ns-2.29/common/packet.h - ns-2.29/mac/mac-802_11.cc - ns-2.29/tcl/lib/ns-lib.tcl - ns-2.29/tcl/lib/ns-default.tcl - ns-2.29/Makefile.in 1.1. ns-2.29/apps/udp.cc In method "void UdpAgent::sendmsg(int nbytes, AppData* data, const char* flags)" changed packet allocation method: allocpkt() substituted by allocpkt(sizeof(data)). ... while (n-- > 0) { // Alterated by The Manna Research Group // Used by mannasim - wireless sensor networks simulator. // p = allocpkt(); p = allocpkt(sizeof(data)); ... 1.2. ns-2.29/common/ns-process.h Added the following types in AppDataType enumeration: enum AppDataType { ... // Inserted by The Manna Research Group // ADUs used by mannasim - wireless sensor networks // simulator. SENSED_DATA, MANAGEMENT_DATA, ON_DEMAND_DATA, ON_DEMAND_PARAMETER, VIDEO_SENSED_DATA, TEMPERATURE_SENSED_DATA, CARBON_MONOXIDE_SENSED_DATA, ... }; Added two public functions in AppData class. class AppData{ ... public: ... // Inserted by The Manna Research Group // Data functions for On Demand Sensing - these functions should // be overwritten by specific application data types as temperatura // AppData for example. virtual bool compareData(AppData* data, int operation) {return false;} virtual bool checkEvent(AppData* data_) {return false;} }; 1.3. ns-2.29/common/packet.cc Added the static variable to PacketHeader class. #include "flags.h" ... // Inserted by MIT uAMPS project // Used by The Manna Research Group int hdr_rca::offset_; // static offset of rca header 1.4. ns-2.29/common/packet.h Several changes had to be made to this file. Changes are listed in the order they appear in the code. Created the following macros just after a list of macro definitions of ns-2.29: // Inserted by MIT uAMPS project // Used by The Manna Research Group #define HDR_RCA(p) ((struct hdr_rca*)(p)->access(hdr_rca::offset())) #define HDR_MACSensor(p) ((struct hdr_macSensor*)(p)->access(hdr_mac::offset_)) In packet_t enumaration added: enum packet_t{ ... // Inserted by MIT uAMPS project // Used by The Manna Research Group PT_RCA, ... }; In constructor of class p_info inserted the following default value: class p_info{ public: p_info() { ... // Inserted by MIT uAMPS project // Used by The Manna Research Group name_[PT_RCA] = "rca"; ... } }; In packet class inserted this static function in public section: class Packet : Event { ... public: ... // Inserted by MIT uAMPS project // Used by The Manna Research Group static void PrintRcHeader(Packet *p, char *layer); ... }; Inserted hdr_rca struct just after hdr_cmn struct: // Inserted by MIT uAMPS project // Used by The Manna Research Group struct hdr_rca { int msg_type_; char meta_[1000]; int meta_size_; float dist_to_dest_; int dist_est_; int rca_mac_src_; int rca_mac_dst_; int rca_link_src_; int rca_link_dst_; int code_; static int offset_; // offset for this header inline static int& offset() { return offset_; } inline static hdr_rca* access(Packet* p) { return (hdr_rca*) p->access(offset_); } /* per-field member functions */ inline int& msg_type() { return (msg_type_); } inline int& meta_size() { return (meta_size_); } inline float& get_dist() { return (dist_to_dest_); } inline int& dist_est() { return (dist_est_); } inline void set_meta(const char* data) { meta_size_ = strlen(data); if (meta_size_ > maxmetasize()) { printf("Error: Meta size %d too large (max = %d).\n", meta_size_, maxmetasize()); exit(1); } memcpy(meta_, data, meta_size_+1); } inline void set_meta(const char * data, int size) { if (size > maxmetasize()) { printf("Error: Meta size %d too large (max = %d).\n", size, maxmetasize()); exit(1); } memcpy(meta_, data, size); meta_size_ = size; } inline char* const meta() { return (meta_); } inline int maxmetasize() { return (sizeof(meta_)); } inline int& rca_mac_src() { return (rca_mac_src_); } inline int& rca_mac_dst() { return (rca_mac_dst_); } inline int& rca_link_src() { return (rca_link_src_); } inline int& rca_link_dst() { return (rca_link_dst_); } inline int& get_code() { return (code_); } int base_X; int base_Y; inline int& get_base_X() { return (base_X); } inline int& get_base_Y() { return (base_Y); } }; In implementation of alloc method of Packet class added this: inline Packet * Packet::alloc(){ ... // Inserted by MIT uAMPS project // Used by The Manna Research Group hdr_rca* rca_hdr = HDR_RCA(p); rca_hdr->meta_size_ = 0; } In implementation of copy method of Packet class added this: inline Packet * Packet::copy() const { ... // Inserted by MIT uAMPS project // Used by The Manna Research Group hdr_rca* rca_hdr = HDR_RCA(p); rca_hdr->meta_size_ = 0; ... } Implemented at the end of the file the static method define in Packet class: // Inserted by MIT uAMPS project // Used by The Manna Research Group inline void Packet::PrintRcHeader(Packet *p, char *layer) { hdr_cmn *hdr = HDR_CMN(p); hdr_rca *rca_hdr = HDR_RCA(p); printf("%s Layer received: Type=%d data_size=%d\n\tMeta = %s\n\tSource = %x\n\tTarget = %x\n\tLink_target =%x\n",layer,rca_hdr->msg_type(), hdr->size(), rca_hdr->meta(),rca_hdr->rca_mac_src(), rca_hdr->rca_mac_dst(), rca_hdr->rca_link_dst()); } 1.5. ns-2.29/mac/mac-802_11.cc The code that follows was added to 802.11 MAC "void Mac802_11::send (Packet *p, Handler *h)" function in orther to garantee that in an On Demand network simulation the sensor nodes don't loose broadcast messages. ... if(mhBackoff_.busy() == 0) { if(is_idle()) { ... /// Inserted by the Manna Research Group /// /// This code permits that MAC still uses backoff in the case of /// MAC idles and broadcasting. /// IMPORTANT: NS-2 still works well after added this code, but /// we don't know if it is consistent with other cases. /// /// Added by Fabricio Silva Aguiar - do not loose broadcast messages. /// if((u_int32_t)ETHER_ADDR(dh->dh_ra) == MAC_BROADCAST){ mhBackoff_.start(cw_, is_idle()); }else{ if(mhDefer_.busy() == 0) { rTime = (Random::random() % cw_) * (phymib_.getSlotTime()); mhDefer_.start(phymib_.getDIFS() + rTime); } } ... 1.6. ns-2.29/tcl/lib/ns-lib.tcl Added sensorNode as a global node configuration parameter # # Inserted by The Manna Research Group Simulator instproc sensorNode {val} {$self set sensorNode_ $val} also inserted the following procedure: # Inserted by The Manna Research Group # Used by mannasim - wireless sensor network simulator Simulator instproc create-node-instance args { $self instvar routingAgent_ sensorNode_ # DSR is a special case if {$routingAgent_ == "DSR"} { set nodeclass [$self set-dsr-nodetype] } elseif { [info exists sensorNode_] && $sensorNode_ == "ON"} { set nodeclass Node/MobileNode/SensorNode } else { set nodeclass Node/MobileNode } return [eval new $nodeclass $args] } 1.7. ns-2.29/tcl/lib/ns-default.tcl Inserted default values for each of the Mannasim parameter configurable by a TCL script. These values are as follows: DataGenerator/TemperatureDataGenerator set sensing_interval_ 0.0 DataGenerator/TemperatureDataGenerator set sensing_type_ 0 DataGenerator/TemperatureDataGenerator set avg_measure 25.0 DataGenerator/TemperatureDataGenerator set std_deviation 1.0 DataGenerator/TemperatureDataGenerator set maximumTemperatureValue 00.0 DataGenerator/CarbonMonoxideDataGenerator set sensing_interval_ 0.0 DataGenerator/CarbonMonoxideDataGenerator set sensing_type_ 0 DataGenerator/CarbonMonoxideDataGenerator set avg_measure 3000.0 DataGenerator/CarbonMonoxideDataGenerator set std_deviation 100.0 DataGenerator/CarbonMonoxideDataGenerator set maximumCarbonMonoxideValue 0.0 Application/SensorBaseApp set disseminating_type_ 0 Application/SensorBaseApp set disseminating_interval_ 0.0 Application/SensorBaseApp set destination_id_ 0 Application/SensorBaseApp/CommonNodeApp set disseminating_type_ 0 Application/SensorBaseApp/CommonNodeApp set disseminating_interval_ 0.0 Application/SensorBaseApp/CommonNodeApp set destination_id_ 0 Node/MobileNode/SensorNode set sensingPower_ 0.5 Node/MobileNode/SensorNode set processingPower_ 0.5 Node/MobileNode/SensorNode set instructionsPerSecond_ 100000000 Application/AccessPointApp set outside_network_ 0 Application/AccessPointApp set request_type_ 0 Application/AccessPointApp set destination_id_ 0 Application/AccessPointApp set node_id_ 0 Application/AccessPointApp set diretorio 0 1.8. ns-2.29/Makefile.in The Mannasim objects location were inserted in the OBJ_CC directive of Makefile.in. This instructs the compiler to build Mannasim within the ns-2. mannasim/accessPointApp.o \ mannasim/aggregateProcessing.o \ mannasim/battery.o \ mannasim/carbonMonoxideAppData.o \ mannasim/carbonMonoxideDataGenerator.o\ mannasim/clusterHeadApp.o \ mannasim/commonNodeApp.o \ mannasim/dataGenerator.o \ mannasim/onDemandData.o \ mannasim/onDemandParameter.o \ mannasim/processing.o \ mannasim/sensedData.o \ mannasim/sensorBaseApp.o \ mannasim/sensorNode.o \ mannasim/temperatureAppData.o \ mannasim/temperatureDataGenerator.o\ mannasim/diffusion/nrAttributes.o\ mannasim/diffusion/commonNodeDiffApp.o \ mannasim/diffusion/accessPointDiffApp.o \ mannasim/leach/mac/leach-wireless-phy.o \ mannasim/leach/mac/mac-sensor.o \ mannasim/leach/mac/mac-sensor-timers.o \ mannasim/leach/rca/rca-ll.o \ mannasim/leach/rca/rcagent.o \ mannasim/leach/app/leachApp.o \ mannasim/leach/leachAgent.o \ mannasim/leach/app/accessPointLeachApp.o \ 2. Building Mannasim After unpacking Mannasim source code, replacing modified files and Makefile.in just go to ns-2.29 main folder an type: ./configure ./make to compile Mannasim and integrate it to ns-2.29.