• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/queue/dsr-priqueue.h

00001 /* -*- c++ -*-
00002    dsr-priqueue.h
00003    
00004    A simple priority queue with a remove packet function
00005    exported from cmu
00006    The differentce between this and the ns version is that the ns priority 
00007    queue maintains one physical queue while giving priority to higher 
00008    priority packets.
00009    This priqueue on the other hand maintains separate physical queues
00010    for different priority levels.
00011    $Id: dsr-priqueue.h,v 1.1 2002/07/19 02:34:10 haldar Exp $
00012    */
00013 #ifndef __dsrpriqueue_h__
00014 #define __dsrpriqueue_h__
00015 
00016 #include <object.h>
00017 #include <queue.h>
00018 #include <drop-tail.h>
00019 #include <packet.h>
00020 #include "lib/bsd-list.h"
00021 #include <cmu-trace.h>
00022 
00023 /* ======================================================================
00024    The BSD Interface Queues
00025    ====================================================================== */
00026 struct  ifqueue {
00027         Packet  *ifq_head;
00028         Packet  *ifq_tail;
00029         int     ifq_len;
00030         int     ifq_maxlen;
00031         int     ifq_drops;
00032 };
00033 #define IFQ_MAXLEN      50
00034 
00035 #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
00036 #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
00037 #define IF_ENQUEUE(ifq, p) {                                    \
00038         (p)->next_ = 0;                                         \
00039         if ((ifq)->ifq_tail == 0)                               \
00040                 (ifq)->ifq_head = p;                            \
00041         else                                                    \
00042                 (ifq)->ifq_tail->next_ = (p);                   \
00043         (ifq)->ifq_tail = (p);                                  \
00044         (ifq)->ifq_len++;                                       \
00045 }
00046 #define IF_DEQUEUE(ifq, p) {                                    \
00047         (p) = (ifq)->ifq_head;                                  \
00048         if (p) {                                                \
00049                 if (((ifq)->ifq_head = (p)->next_) == 0)        \
00050                         (ifq)->ifq_tail = 0;                    \
00051                 (p)->next_ = 0;                                 \
00052                 (ifq)->ifq_len--;                               \
00053         }                                                       \
00054 }
00055 
00056 
00057 /*
00058  * Control type and number of queues in PriQueue structure.
00059  */
00060 #define IFQ_RTPROTO     0       /* Routing Protocol Traffic */
00061 #define IFQ_REALTIME    1
00062 #define IFQ_LOWDELAY    2
00063 #define IFQ_NORMAL      3
00064 #define IFQ_MAX         4
00065 
00066 typedef int (*PacketFilter)(Packet *, void *);
00067 
00068 class CMUPriQueue;
00069 
00070 /* ======================================================================
00071    Handles callbacks for Priority Queues
00072    ====================================================================== */
00073 class CMUPriQueueHandler : public Handler {
00074 public:
00075   inline CMUPriQueueHandler(CMUPriQueue *ifq) : qh_ifq(ifq) {}
00076   void handle(Event*);
00077 private: 
00078   CMUPriQueue *qh_ifq;
00079 };
00080 
00081 /* ======================================================================
00082    Priority Queues
00083    ====================================================================== */
00084 class CMUPriQueue : public Connector {
00085   //friend class CMUPriQueueManager;
00086 public:
00087   CMUPriQueue();
00088 
00089   int     command(int argc, const char*const* argv);
00090 
00091   /* called by upper layers to enque the packet */
00092   void    recv(Packet *p, Handler*);
00093   
00094   /* called by lower layers to get the next packet */
00095   void  prq_resume(void);
00096   
00097   void  Terminate(void);        /* called at end of simulation */
00098   
00099   Packet* prq_get_nexthop(nsaddr_t id);
00100   int   prq_isfull(Packet *p);
00101   int   prq_length(void);
00102   
00103 private:
00104   int   prq_assign_queue(Packet *p);
00105   void  prq_enqueue(Packet *p);
00106   Packet*       prq_dequeue(void);
00107   void  prq_validate(void);
00108   
00109   struct ifqueue        prq_snd_[IFQ_MAX];
00110   nsaddr_t      prq_ipaddr_;    /* IP Address of this machine */
00111   Trace*                prq_logtarget_; /* Used for logging */
00112   int           prq_blocked_;
00113   CMUPriQueueHandler    prq_qh_;
00114         
00115 protected:
00116   void trace(char* fmt, ...);
00117   void log_stats(void);
00118 
00119   //TAILQ_ENTRY(CMUPriQueue) prq_list_;
00120   int qlen_logthresh_;  /* see run.tcl */
00121   int fw_logthresh_;    /* see run.tcl */
00122   
00123   int last_ifqlen_[IFQ_MAX];
00124   int stat_send_;               /* packets sent to lower layers */
00125   int stat_recv_;               /* packets received from upper layer */
00126   int stat_blocked_;    /* blocked on received */
00127 };
00128 
00129 #endif /* __priqueue_h__ */

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1