File: dsr-priqueue.h

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (129 lines) | stat: -rw-r--r-- 3,859 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* -*- c++ -*-
   dsr-priqueue.h
   
   A simple priority queue with a remove packet function
   exported from cmu
   The differentce between this and the ns version is that the ns priority 
   queue maintains one physical queue while giving priority to higher 
   priority packets.
   This priqueue on the other hand maintains separate physical queues
   for different priority levels.
   $Id: dsr-priqueue.h,v 1.1 2002/07/19 02:34:10 haldar Exp $
   */
#ifndef __dsrpriqueue_h__
#define __dsrpriqueue_h__

#include <object.h>
#include <queue.h>
#include <drop-tail.h>
#include <packet.h>
#include "lib/bsd-list.h"
#include <cmu-trace.h>

/* ======================================================================
   The BSD Interface Queues
   ====================================================================== */
struct  ifqueue {
        Packet	*ifq_head;
        Packet	*ifq_tail;
        int     ifq_len;
        int     ifq_maxlen;
        int     ifq_drops;
};
#define IFQ_MAXLEN	50

#define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
#define IF_DROP(ifq)            ((ifq)->ifq_drops++)
#define IF_ENQUEUE(ifq, p) {			                \
        (p)->next_ = 0;				                \
        if ((ifq)->ifq_tail == 0)		                \
                (ifq)->ifq_head = p;		                \
        else					                \
                (ifq)->ifq_tail->next_ = (p);	                \
        (ifq)->ifq_tail = (p);			                \
        (ifq)->ifq_len++;			                \
}
#define IF_DEQUEUE(ifq, p) {					\
        (p) = (ifq)->ifq_head;					\
        if (p) {						\
                if (((ifq)->ifq_head = (p)->next_) == 0)	\
                        (ifq)->ifq_tail = 0;			\
                (p)->next_ = 0;					\
                (ifq)->ifq_len--;				\
        }							\
}


/*
 * Control type and number of queues in PriQueue structure.
 */
#define IFQ_RTPROTO	0	/* Routing Protocol Traffic */
#define IFQ_REALTIME	1
#define IFQ_LOWDELAY	2
#define IFQ_NORMAL	3
#define IFQ_MAX		4

typedef int (*PacketFilter)(Packet *, void *);

class CMUPriQueue;

/* ======================================================================
   Handles callbacks for Priority Queues
   ====================================================================== */
class CMUPriQueueHandler : public Handler {
public:
  inline CMUPriQueueHandler(CMUPriQueue *ifq) : qh_ifq(ifq) {}
  void handle(Event*);
private: 
  CMUPriQueue *qh_ifq;
};

/* ======================================================================
   Priority Queues
   ====================================================================== */
class CMUPriQueue : public Connector {
  //friend class CMUPriQueueManager;
public:
  CMUPriQueue();

  int     command(int argc, const char*const* argv);

  /* called by upper layers to enque the packet */
  void    recv(Packet *p, Handler*);
  
  /* called by lower layers to get the next packet */
  void	prq_resume(void);
  
  void	Terminate(void);	/* called at end of simulation */
  
  Packet* prq_get_nexthop(nsaddr_t id);
  int	prq_isfull(Packet *p);
  int	prq_length(void);
  
private:
  int	prq_assign_queue(Packet *p);
  void	prq_enqueue(Packet *p);
  Packet*	prq_dequeue(void);
  void	prq_validate(void);
  
  struct ifqueue	prq_snd_[IFQ_MAX];
  nsaddr_t	prq_ipaddr_;	/* IP Address of this machine */
  Trace*		prq_logtarget_;	/* Used for logging */
  int		prq_blocked_;
  CMUPriQueueHandler	prq_qh_;
	
protected:
  void trace(char* fmt, ...);
  void log_stats(void);

  //TAILQ_ENTRY(CMUPriQueue) prq_list_;
  int qlen_logthresh_;	/* see run.tcl */
  int fw_logthresh_;	/* see run.tcl */
  
  int last_ifqlen_[IFQ_MAX];
  int stat_send_;		/* packets sent to lower layers */
  int stat_recv_;		/* packets received from upper layer */
  int stat_blocked_;	/* blocked on received */
};

#endif /* __priqueue_h__ */