?? bcast.h
字號:
/******************************************************************* Copyright (C) 2004 Thomas Kunz, CRC Canada, BCAST for IPv4. DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. See the GNU Library General Public License (file COPYING in the MANET_multicast directory) for conditions of use and redistribution.*********************************************************************//*Copyright (c) 1997, 1998 Carnegie Mellon University. All RightsReserved. Permission to use, copy, modify, and distribute thissoftware and its documentation is hereby granted (including forcommercial or for-profit use), provided that both the copyright notice and this permission notice appear in all copies of the software, derivative works, or modified versions, and any portions thereof, and that both notices appear in supporting documentation, and that credit is given to Carnegie Mellon University in all publications reporting on direct or indirect use of this code or its derivatives.ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMUMONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OFWHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THISSOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITYBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ORBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCEOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE ORINTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCHDAMAGE.Carnegie Mellon encourages (but does not require) users of thissoftware or intellectual property to return any improvements orextensions that they make, and to grant Carnegie Mellon the rights to redistribute these changes without encumbrance.The AODV code developed by the CMU/MONARCH group was optimized and tuned by Samir Das and Mahesh Marina, University of Cincinnati. The work was partially done in Sun Microsystems.*//* * The original AODV code was modified to support efficient broadcasting * (BCAST) by Thomas Kunz. */#ifndef __bcast_h__#define __bcast_h__#include <cmu-trace.h>#include <priqueue.h>#include <classifier/classifier-port.h>#include <MANET_multicast/mttable.h>#include <MANET_multicast/unique_id.h>#include <MANET_multicast/cache.h>#include <bcast/bcast_queue.h>class BCAST;// Should be set by the user using best guess (conservative) #define NETWORK_DIAMETER 30 // 30 hops// how much to delay packet retransmission (scaling factor)#define BCAST_DELAY 0.100 // in seconds/* Timers*//* The NackTimer is used to re-trigger NACKs up to MAX_NACK times for a specific packet that is deemed lost. After trying for MAX_NACK times, we will give up. The timer is cancelled when the requested packet is received. */#define MAX_NACK 3#define NACK_INITIAL_DELAY 1.0 // upper bound on initial delay for NACK #define NACK_TIMEOUT 1.0 // timeout and try again after x second// constants to control frequency of NACKs#define MIN_DIFF 0.7 // do not send too many NACKs per unit time#define PACKET_COUNT 30 // track back that many NACKsclass NackTimer_bcast : public Handler {public: NackTimer_bcast(BCAST* a) : agent(a) {count = 0; packet_ptr = 0; } void handle(Event*); void start_nack_timer(nsaddr_t p_src, unsigned int p_seqno, double delay); void cancel_nack_timer(nsaddr_t p_src, unsigned int p_seqno); void save_packet_time(double t_packet); int control_nack_flood(); // limit flooding of NACKsprivate: BCAST *agent; Event intr; int count; // how many NACKs have we tracked int packet_ptr; // next field to store tracked NACK double packet_times[PACKET_COUNT]; nsaddr_t src; // source address of missing packet unsigned int seqno; // sequence number of missing packet unsigned int retry_count; // number of retry attempts};/* The RetransmitTimer is used to delay the transmission of a duplicate packet P. Until the packet is retransmitted, a node listens for retransmissions by other nodes. If it overhears another node sending the same packet, it will cancel its own retransmission. */class RetransmitTimer_bcast : public Handler {public: RetransmitTimer_bcast(BCAST* a) : agent(a) {} void handle(Event*); void start_rtx_timer(Packet *pck, double delay); void cancel_rtx_timer(nsaddr_t p_src, unsigned int p_seqno);private: BCAST *agent; Event intr; nsaddr_t src; // source address of retransmitted packet unsigned int seqno; // sequence number of retransmitted packet Packet *p; // packet to be retransmitted};/* The HelloTimer periodically triggers the sending of HELLO messages to neighbors. Since this information is also available from other packets (i.e., piggybacked onto them), HELLO messages do get rescheduled whenever other data packets are transmitted. */#define HELLO_INTERVAL 2 // in seconds#define ALLOWED_HELLO_LOSS 1 // packets#define MaxHelloInterval (1.25 * HELLO_INTERVAL)#define MinHelloInterval (0.75 * HELLO_INTERVAL)class HelloTimer_bcast : public Handler {public: HelloTimer_bcast(BCAST* a) : agent(a) {} void handle(Event*); void reschedule(); // cancel and reschedule HELLO messageprivate: BCAST *agent; Event intr;};/* The NeighborTimer periodically cleans up the information about one-hop and two-hop neighbors. Unless this information is refreshed, it becomes stale and is removed. */class NeighborTimer_bcast : public Handler {public: NeighborTimer_bcast(BCAST* a) : agent(a) {} void handle(Event*);private: BCAST *agent; Event intr;};/* BCAST Neighbor Cache Entry*/class BCAST_Neighbor { friend class BCAST; public: BCAST_Neighbor(u_int32_t a) { nb_addr = a; nb_no_of_neighbors=0; } protected: LIST_ENTRY(BCAST_Neighbor) nb_link; nsaddr_t nb_addr; double nb_expire; // ALLOWED_HELLO_LOSS * HELLO_INTERVAL int nb_no_of_neighbors; nsaddr_t nb_neighbors[NEIGHBOR_COUNT];};LIST_HEAD(bcast_ncache, BCAST_Neighbor);#define CACHE_SIZE 10 // cache size for recently transmitted packets#define ILLEGAL_NODE 1000 // higher than the highest legal node number/* The Routing Agent*/class BCAST: public Agent { /* * make some friends first */ friend class NackTimer_bcast; friend class RetransmitTimer_bcast; friend class HelloTimer_bcast; friend class NeighborTimer_bcast; friend class BCASTHandler; public: BCAST(nsaddr_t id); void recv(Packet *p, Handler *); protected: int command(int, const char *const *); int initialized() { return 1 && target_; } /* * Neighbor Management */ void nb_insert(nsaddr_t id); BCAST_Neighbor* nb_lookup(nsaddr_t id); void nb_delete(nsaddr_t id); void nb_purge(void); void add_neighbors(BCAST_Neighbor *nb, int num_neigbors, nsaddr_t *one_hop_neighors); void nb_determine_degrees(int *max, int *n); /* * Packet TX Routines */ void forward(Packet *p); void sendHello(void); void sendNack(nsaddr_t id, u_int32_t bid); void sendPacket(Packet *p, double delay); /* * Packet RX Routines */ void recvBCAST(Packet *p); void recvHello(Packet *p); void recvNack(Packet *p); nsaddr_t index; // IP Address of this node mttable mtable; // Multicast Groups node joined /* * Handle duplicate packets */ UniqueIDHandler uid_handler; bcast_ncache nbhead; // Neighbor Cache /* * Timers */ NackTimer_bcast nacktimer; RetransmitTimer_bcast rtxtimer; HelloTimer_bcast htimer; NeighborTimer_bcast ntimer; /* * A queue used by the routing layer to buffer * packets before it broadcasts them. */ BCASTHandler bcast_queue; /* * A cache of recently transmitted packets */ PacketCache p_cache; /* * A mechanism for logging the contents of the routing * table. */ Trace *logtarget; /* * A pointer to the network interface queue that sits * between the "classifier" and the "link layer". */ PriQueue *ifqueue; /* for passing packets up to agents */ PortClassifier *dmux_;};#endif /* __bcast_h__ */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -