⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flooding.h

📁 nRF24E1 sample sensor node code
💻 H
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************   @<title> A Flooding Routing Component </title>@**   @<!-- Copyright 2003 Gilbert (Gang) Chen, Boleslaw K. Szymanski*   and Rensselaer Polytechnic Institute. All worldwide rights*   reserved.  A license to use, copy, modify and distribute this*   software for non-commercial research purposes only is hereby*   granted, provided that this copyright notice and accompanying*   disclaimer is not modified or removed from the software.**   DISCLAIMER: The software is distributed "AS IS" without any*   express or implied warranty, including but not limited to, any*   implied warranties of merchantability or fitness for a particular*   purpose or any warranty of non-infringement of any current or*   pending patent rights. The authors of the software make no*   representations about the suitability of this software for any*   particular purpose. The entire risk as to the quality and*   performance of the software is with the user. Should the software*   prove defective, the user assumes the cost of all necessary*   servicing, repair or correction. In particular, neither Rensselaer*   Polytechnic Institute, nor the authors of the software are liable*   for any indirect, special, consequential, or incidental damages*   related to the software, to the maximum extent the law*   permits.-->@**   @<h1> A Flooding Routing Component </h1>@**   Flooding is a simple network layer component which*   rebroadcasts every received packet not destined to itself. This*   picture shows the inports and outports of this component.**   @<center><img src=flooding_routing.gif></center>@*************************************************************************/#ifndef flooding_h#define flooding_h#include <map>/******************************************************************* * Before building the flooding component, we must first have a structure that * contains all data structures and types used by the flooding component. * We have to use a separate class @Flooding_Struct for this purpose, because * @<a href=../compc++>CompC++</a>@ doesn't allow any intenally defined classes and types to be * accessed from outside.  For instance, if @Flooding@ is a component that * defines a packet type @packet_t@, we cannot use @Flooding::packet_t@ to * refer to @packet_t@. * * @Flooding_Struct@ is defined as a template class and the template parameter * is the type of the payload packets.  The Flooding component will pack * the payload packets into the network layer packets. *******************************************************************/template <class PLD>struct Flooding_Struct{/******************************************************************* * Here we define the network layer packet header, which includes the sequence number, * the size of the header, and the time the packet is sent by the network * layer. *******************************************************************/    struct hdr_struct    {		unsigned int seq_number;		unsigned int size;		double send_time;/******************************************************************* * The function @dump()@ is used to display the * content of the packet. The value it returns indicates whether the * payload is valid or not. If the payload is valid, the content of * the payload will be printed out automatically, and otherwise * ignored. In this example, this payload filed is always valid, so * a true value is returned every time @dump()@ is called. *******************************************************************/				bool dump(std::string& str) const 		{ 	    	char buffer[30];	    	sprintf(buffer,"%d %d",seq_number,size); 	    	str=buffer;	    	return true;		}    };/******************************************************************* * Here we define the packet types.  @payload_t@ is the type of the * payload, which could be a pointer to the payload packet or a  * reference to the payload packet.  We don't need to distinguish these * two cases, as the SENSE library handles this automatically for us. * @packet_t@ is the type of the network layer packet, with @hdr_struct@ * as the header and @PLD@ as the payload. *******************************************************************/	typedef PLD payload_t;    typedef smart_packet_t<hdr_struct,PLD> packet_t;};/******************************************************************* * Now we can build the Flooding component.  It must be derived from @TypeII@, * as it is a time-aware component in our simulation component classification. * It must also be derived from @Flooding_Struct@, as it is dependent on  * data strutures and types defined in @Flooding_Struct@. * Notice that both @TypeII@ and @Flooding_Struct@ are classes, not components. * In fact, in the current version of @<a href=../compc++>CompC++</a>@ a  * component cannot be subclassed * from any other component. *******************************************************************/template <class PLD>component Flooding : public TypeII, public Flooding_Struct<PLD>{ public:/******************************************************************* * Here we declare several component parameters. @MyEtherAddr@ is the * ethernet address of this component. @ForwardDelay@ is the period of * time that must elapse before this component can sent a packet to * the mac layer if the packet is to be rebroadcastm in order to avoid * collision caused by simultaneous transmissions.   * @DumpPackets@ indicates whether or not packet * content is dumped if the macro  * @<a href=manual.html#COST_DEBUG>COST_DEBUG</a>@ is defined. *******************************************************************/    ether_addr_t MyEtherAddr;    simtime_t ForwardDelay;    bool DumpPackets;/******************************************************************* * These are variables to record statistics. *******************************************************************/    int SentPackets;    int RecvPackets;    int RecvUniPackets;    double TotalDelay;/******************************************************************* * The inport * @from_mac_ack@ is used by the mac layer component to notify this * component that the transmission of a packet sent upon request has * been completed.  Whether or not the transmission is successful is * indicated by the argument of the inport. * The inport @from_transport@ is activated when there is a payload packet * from the transport layer or any layer above. * The inport @from_mac_data@ is activated when there is a packet * arriving from the mac layer. *******************************************************************/        inport inline void from_transport( payload_t& pld, ether_addr_t& dst, unsigned int size);    inport inline void from_mac_data (packet_t* pkt, ether_addr_t& dst);    inport inline void from_mac_ack (bool errflag);/******************************************************************* *  There are two outports, one to send the payload packet to the * transport layer and the other to send the packet to the mac layer *******************************************************************/	outport void to_transport ( payload_t& pld );	outport void to_mac (packet_t* pkt, ether_addr_t& dst, unsigned int size);/******************************************************************* *  This component needs a timer to delay packet retranmission to avoid possible *  collisions.  Since we don't know the number *  of events that could coexist (there is virtually no upper bound), *  so we can @<a href=manual.html#InfiTimer>InfiTimer</a>@.  The type of *  the @InfiTimer@ is just @packet_t@, but due to the implementation of  *  @<a href=../compc++>CompC++</a>@, the complete name including the *  class is required here. *  The @depart()@ inport will receive the pointer to the delayed packet  *  and the slot number which will be ignored.  This inport must be *  connected to the timer. *******************************************************************/	InfiTimer<Flooding_Struct<PLD>::packet_t*> delay;	inport inline void depart(packet_t* p, unsigned int i);	/******************************************************************* * @Start()@ will be called when the simulation is started, @Stop()@ when the * simulation is stopped. *******************************************************************/    void Start();    void Stop();    Flooding();    virtual ~Flooding();	 protected:    bool m_mac_busy;                  // if the mac layer is busy    unsigned int m_seq_number;        // current sequence number/******************************************************************* * In the original flooding protocol, whenever a node recieves a packet * it will rebroadcast it.  However, this would result in an exponential * increase on the number of packets being trasmitted.  Here we adopt * an optimization which would rebroadcast the received packet only when * it has never been seen before.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -