Azinix

q.h

Go to the documentation of this file.
00001 /** \file q.h
00002                                                                                                          
00003   \brief Queueing  data structures
00004                                                                                                          
00005 ******************************************************************************/
00006 
00007 #ifndef _Q
00008 #define _Q
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 #include "nm.h"
00015 #include "pkt.h"
00016 
00017 /**
00018   * \brief  Boilerplate placeholder for enum decls.
00019   * 
00020   */
00021 
00022 typedef enum
00023 {
00024   QDrr_c
00025 } QTypes_c;
00026 
00027 /**
00028   * \brief  Data structure for differentiated service based on class
00029   * of service. 
00030   * 
00031   * The class of service identified by a contiguous set of  integers 
00032   * starting from 0. COS is strict: when sending packets 
00033   * on the egress, we consider packets of class k only when there
00034   * are no packets of class k+1 or more.
00035   * 
00036   */
00037 
00038 
00039 struct Q_Cos_t
00040 {
00041   int numClasses;
00042   lsList *packetQueueArray; // numClasses long array of lsList, 
00043   // each lsList contains pointers to a  Pkt_ProcessPkt_t
00044   // the beginning of the list is the head of the queue
00045   // the end of the list is the end of the queue
00046   int numPktsInQueue;
00047 };
00048 
00049 typedef struct Q_Cos_t Q_Cos_t;
00050 
00051 /**
00052   * \brief  Data structure for differentiated service based on DRR.
00053 
00054   * Arranged as a hashtable of individual queues; the hash
00055   * is from flow hashcodes to corresponding queues, which are just 
00056   * lists.  For now each queue is given a weight of 1, so there is
00057   * no weight information.
00058   * 
00059   */
00060 
00061 struct Q_Drr_t
00062 {
00063   st_table *flowToQueueTable;
00064   lsList qOfFlows;
00065   int numPktsInQueue;
00066   int numBytesInQueue;
00067 };
00068 
00069 typedef struct Q_Drr_t Q_Drr_t;
00070 
00071 
00072 /**
00073   * \brief Data structure for keeping flow
00074   *
00075   */
00076 
00077 struct Q_Flow_t
00078 {
00079   lsList queue;
00080   unsigned int numBytes;
00081   unsigned int numPkts;
00082   double rate;
00083   util_timing_t startOfCurrentWindow;
00084   double numBytesExitedInWindow;
00085 
00086 };
00087 
00088 typedef struct Q_Flow_t Q_Flow_t;
00089 
00090 // start of code that's being moved from rlp
00091 
00092 /**
00093   *     \brief  Enum for the drop policies
00094   *
00095   */
00096 
00097 typedef enum
00098 {
00099   Q_DropTail_c,
00100   Q_DropRed_c
00101 } Q_DropMethods_t;
00102 
00103 /**
00104   *     \brief Enum for types of queues
00105   */
00106 
00107 typedef enum
00108 {
00109   Q_QueueTypeUndef_c,
00110   Q_QueueTypeCos_c,
00111   Q_QueueTypeFlow_c
00112 } Q_QueueType_t;
00113 
00114 
00115 /**
00116   *     \brief  Cos Queue structure used for actions
00117   *
00118   *     Cos Queue structure used for actions
00119   *
00120   */
00121 
00122 struct Q_Q_t
00123 {
00124   char *name;
00125 
00126   // could be a class based or flow based
00127   Q_QueueType_t type;
00128 
00129   // this make sense only for flow-based queueing
00130   Pkt_FlowType_t flowType;
00131   int flowMaxRate;
00132   int maxFlows;
00133   int maxBytesPerFlow;
00134   Q_DropMethods_t flowDropMethod;
00135 
00136   int maxRate;          // in bits-per-second
00137 
00138   double currentRate;       // in bits-per-second
00139   util_timing_t lastEntryTime;  // basically a pair of u_int_32_t set by the rdtsc instruction
00140 
00141   int currentPriority;      // can be positive/0/negative, used to decide when to come back to this queue
00142   // dynamically updated based on assigned priority
00143   int assignedPriority;     // can be positive/0/negative, assigned by used in rule
00144 
00145   int numPktsInQueue;
00146   double numPktsProcessed;  // total number of packets we've processed so far
00147 
00148   int numBytesInQueue;
00149   int maxAllowedBytes;      // if we have this number in the queue, the queue is stopped
00150   double numBytesEntered;
00151   double numBytesExited;
00152 
00153   Q_DropMethods_t dropMethod;
00154 
00155   // actual queueing structure for cos case
00156   int numClasses;
00157   Q_Cos_t *cosQ;
00158 
00159   // actual queueing structure for flow-based queuing case
00160   Q_Drr_t *flowQ;
00161 
00162   double timeWindowDuration;
00163   double numBytesExitedInWindow;
00164   util_timing_t startOfCurrentWindow;
00165 
00166 };
00167 
00168 typedef struct Q_Q_t Q_Q_t;
00169 
00170 
00171 /**AutomaticStart*************************************************************/
00172 
00173 /*---------------------------------------------------------------------------*/
00174 /* Extern function prototypes                                                */
00175 /*---------------------------------------------------------------------------*/
00176 
00177 
00178 extern Q_Cos_t *Q_CosAlloc (int);
00179 extern int Q_CosFree (Q_Cos_t *);
00180 extern Q_Drr_t
00181   *Q_DrrAlloc (int (*flowCmp) (Pkt_EthernetHdr_t *, Pkt_EthernetHdr_t *),
00182            int (*flowHash) (Pkt_EthernetHdr_t *, int));
00183 extern int Q_DrrFree (Q_Drr_t * aDrrStruct);
00184 extern int Q_CosInsertPpBegin( Q_Cos_t *cosStruct, Pkt_ProcessPkt_t *anEthFrame, int classIndex );
00185 extern int Q_CosInsertPpEnd (Q_Cos_t *, Pkt_ProcessPkt_t *, int);
00186 extern int Q_CosInsertPpBeginEnd (Q_Cos_t *, Pkt_ProcessPkt_t *, int, int );
00187 extern Pkt_ProcessPkt_t *Q_CosReadPp (Q_Cos_t * cosStruct);
00188 extern Pkt_ProcessPkt_t *Q_CosReadHead (Q_Cos_t * cosStruct, int *classPtr);
00189 extern Pkt_ProcessPkt_t *Q_CosHead (Q_Cos_t * cosStruct, int *classPtr);
00190 extern Pkt_ProcessPkt_t *Q_CosHeadClass (Q_Cos_t * cosStruct, int classIndex);
00191 extern int Q_CosNumClasses (Q_Cos_t * cosStruct);
00192 extern int Q_DrrTestIsEmpty (Q_Drr_t * flowQueue);
00193 extern int Q_CosTestIsEmpty (Q_Cos_t * cosStruct);
00194 extern int Q_DrrInsertPpBegin (Q_Drr_t * drrStruct, Pkt_ProcessPkt_t * pp);
00195 extern int Q_DrrInsertPpEnd (Q_Drr_t * drrStruct, Pkt_ProcessPkt_t * pp);
00196 extern int Q_DrrInsertPpBeginEnd (Q_Drr_t * drrStruct, Pkt_ProcessPkt_t * pp,
00197                   int insertAtEnd);
00198 extern Q_Flow_t *Q_DrrReadFlow (Q_Drr_t * drrStruct, Pkt_EthernetHdr_t * pkt);
00199 extern Pkt_ProcessPkt_t *Q_DrrHead (Q_Drr_t * drrStruct);
00200 extern Pkt_ProcessPkt_t *Q_DrrReadHead (Q_Drr_t * drrStruct);
00201 extern st_table *Q_DrrReadFlowToQueueTable (Q_Drr_t * drrStruct);
00202 extern int Q_DrrNumFlows (Q_Drr_t * drrStruct);
00203 extern void Q_CosPrint (Q_Cos_t * cosData);
00204 extern void Q_DrrPrint (Q_Drr_t * drrData);
00205 extern Q_Flow_t *Q_AllocFlow ();
00206 extern double Q_ComputeRate (util_timing_t startOfWindow,
00207                  double timeWindowDuration,
00208                  int numBytesExitedInWindow, int pktLength);
00209 extern double Q_ComputeRateOld (util_timing_t lastTime,
00210                 Pkt_EthernetHdr_t * pkt);
00211 extern Q_Q_t *Q_AllocQ (char *name);
00212 
00213 /**AutomaticEnd***************************************************************/
00214 #ifdef __cplusplus
00215 }
00216 #endif
00217 
00218 #endif /* _Q */