1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  *         Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  */
21 
22 #ifndef SERVICE_FLOW_H
23 #define SERVICE_FLOW_H
24 
25 #include <stdint.h>
26 #include "wimax-phy.h"
27 #include "wimax-connection.h"
28 #include "cs-parameters.h"
29 
30 namespace ns3 {
31 
32 class ServiceFlowRecord;
33 class WimaxConnection;
34 
35 /**
36  * \ingroup wimax
37  * This class implements service flows as described by the IEEE-802.16 standard
38  */
39 class ServiceFlow
40 {
41 public:
42   /// Direction enumeration
43   enum Direction
44   {
45     SF_DIRECTION_DOWN,
46     SF_DIRECTION_UP
47   };
48 
49   /// Type enumeration
50   enum Type
51   {
52     SF_TYPE_PROVISIONED,
53     SF_TYPE_ADMITTED,
54     SF_TYPE_ACTIVE
55   };
56 
57   /// section 11.13.11 Service flow scheduling type, page 701
58   enum SchedulingType
59   {
60     SF_TYPE_NONE = 0,
61     SF_TYPE_UNDEF = 1,
62     SF_TYPE_BE = 2,
63     SF_TYPE_NRTPS = 3,
64     SF_TYPE_RTPS = 4,
65     SF_TYPE_UGS = 6,
66     SF_TYPE_ALL = 255
67   };
68   /// section 11.13.19.2 CS parameter encoding rules, page 707
69   enum CsSpecification
70   {
71     ATM = 99,
72     IPV4 = 100,
73     IPV6 = 101,
74     ETHERNET = 102,
75     VLAN = 103,
76     IPV4_OVER_ETHERNET = 104,
77     IPV6_OVER_ETHERNET = 105,
78     IPV4_OVER_VLAN = 106,
79     IPV6_OVER_VLAN = 107
80   };
81   /// Modulation type enumeration, Table 356 and 362
82   enum ModulationType
83   {
84     MODULATION_TYPE_BPSK_12,
85     MODULATION_TYPE_QPSK_12,
86     MODULATION_TYPE_QPSK_34,
87     MODULATION_TYPE_QAM16_12,
88     MODULATION_TYPE_QAM16_34,
89     MODULATION_TYPE_QAM64_23,
90     MODULATION_TYPE_QAM64_34
91   };
92 
93   /**
94    * \brief creates a TLV from this service flow
95    * \return the created tlv
96    */
97   Tlv ToTlv (void) const;
98   /**
99    * \brief creates a service flow from a TLV
100    * \param tlv the tlv from which the service flow will be created
101    */
102   ServiceFlow (Tlv tlv);
103   /**
104    * \return true if the passed parameters match the classifier of the service flow, false otherwise
105    * \param srcAddress the source ip address
106    * \param dstAddress the destination ip address
107    * \param srcPort the source port
108    * \param dstPort the destination port
109    * \param proto the layer 4 protocol
110    */
111   bool CheckClassifierMatch (Ipv4Address srcAddress,
112                              Ipv4Address dstAddress,
113                              uint16_t srcPort,
114                              uint16_t dstPort,
115                              uint8_t proto) const;
116   /// default constructor
117   ServiceFlow ();
118   /**
119    * Constructor
120    *
121    * \param direction the direction
122    */
123   ServiceFlow (enum Direction direction);
124   /**
125    * Constructor
126    *
127    * \param sf service flow
128    */
129   ServiceFlow (const ServiceFlow & sf);
130   /**
131    * Constructor
132    *
133    * \param sfid the SFID
134    * \param direction the direction
135    * \param connection the connection object
136    */
137   ServiceFlow (uint32_t sfid,
138                enum Direction direction,
139                Ptr<WimaxConnection> connection);
140   ~ServiceFlow (void);
141   /**
142    * assignment operator
143    * \param o the service flow to assign
144    * \returns the service flow
145    */
146   ServiceFlow & operator = (ServiceFlow const& o);
147 
148   /// Initial values
149   void InitValues (void);
150   /**
151    * Set direction
152    * \param direction the direction value
153    */
154   void SetDirection (enum Direction direction);
155   /**
156    * Get direction
157    * \returns the direction
158    */
159   enum Direction GetDirection (void) const;
160   /**
161    * Copy parameters from another service flow
162    * \param sf the service flow
163    */
164   void CopyParametersFrom (ServiceFlow sf);
165 
166   /**
167    * Set type of service flow
168    * \param type the type value
169    */
170   void SetType (enum Type type);
171   /**
172    * Get type of service flow
173    * \returns the type
174    */
175   enum Type GetType (void) const;
176   /**
177    * Set connection
178    * \param connection the connection
179    */
180   void SetConnection (Ptr<WimaxConnection> connection);
181   /**
182    * Can return a null connection is this service flow has not
183    * been associated yet to a connection.
184    * \returns pointer to the WimaxConnection
185    */
186   Ptr<WimaxConnection> GetConnection (void) const;
187 
188   /**
189    * Set is enabled flag
190    * \param isEnabled is enabled flag
191    */
192   void SetIsEnabled (bool isEnabled);
193   /**
194    * Get is enabled flag
195    * \returns is enabled
196    */
197   bool GetIsEnabled (void) const;
198 
199   /**
200    * Set service flow record
201    * \param record pointer to the service flow record
202    */
203   void SetRecord (ServiceFlowRecord *record);
204   /**
205    * Get service flow record
206    * \returns pointer to the service flow record
207    */
208   ServiceFlowRecord* GetRecord (void) const;
209 
210   // wrapper functions
211   /**
212    * Get pointer to queue
213    * \returns pointer to the wimax mac queue
214    */
215   Ptr<WimaxMacQueue> GetQueue (void) const;
216   /**
217    * Get scheduling type
218    * \returns the scheduling type
219    */
220   enum ServiceFlow::SchedulingType GetSchedulingType (void) const;
221   /**
222    * Check if packets are present
223    * \returns true if there are packets
224    */
225   bool HasPackets (void) const;
226   /**
227    * Check if packets of particular type are present
228    * \param packetType the packet type to select
229    * \returns true if there are packets of the packet type
230    */
231   bool HasPackets (MacHeaderType::HeaderType packetType) const;
232 
233   /// shall be called only by BS
234   void CleanUpQueue (void);
235 
236   /// Print QOS parameters
237   void PrintQoSParameters (void) const;
238 
239   /**
240    * Get scheduling type string
241    * \returns the name of the scheduling type
242    */
243   char* GetSchedulingTypeStr (void) const;
244 
245   /**
246    * Get SFID
247    * \returns the SFID
248    */
249   uint32_t GetSfid (void) const;
250   /**
251    * Get CID
252    * \returns the CID
253    */
254   uint16_t GetCid (void) const;
255   /**
256    * Get service class name
257    * \returns the service class name
258    */
259   std::string GetServiceClassName () const;
260   /**
261    * Get QOS parameter set type
262    * \returns the QOS parameter set type
263    */
264   uint8_t GetQosParamSetType (void) const;
265   /**
266    * Get traffic priority
267    * \returns the traffic priority
268    */
269   uint8_t GetTrafficPriority (void) const;
270   /**
271    * Get max sustained traffic rate
272    * \returns the maximum sustained traffic rate
273    */
274   uint32_t GetMaxSustainedTrafficRate (void) const;
275   /**
276    * Get max traffic burst
277    * \returns the maximum traffic burst
278    */
279   uint32_t GetMaxTrafficBurst (void) const;
280   /**
281    * Get minimum reserved traffic rate
282    * \returns the minimum reserved traffic rate
283    */
284   uint32_t GetMinReservedTrafficRate (void) const;
285   /**
286    * Get minimum tolerable traffic rate
287    * \returns the minimum tolerable traffic rate
288    */
289   uint32_t GetMinTolerableTrafficRate (void) const;
290   /**
291    * Get service scheduling type
292    * \returns the scheduling type
293    */
294   enum ServiceFlow::SchedulingType GetServiceSchedulingType (void) const;
295   /**
296    * Get request transmission policy
297    * \returns the request transmission policy
298    */
299   uint32_t GetRequestTransmissionPolicy (void) const;
300   /**
301    * Get tolerated jitter
302    * \returns the tolerated jitter
303    */
304   uint32_t GetToleratedJitter (void) const;
305   /**
306    * Get maximum latency
307    * \returns the maximum latency
308    */
309   uint32_t GetMaximumLatency (void) const;
310   /**
311    * Get fixed versus varaiable SDU indicator
312    * \returns the fixed vs variable SDU indicator
313    */
314   uint8_t GetFixedversusVariableSduIndicator (void) const;
315   /**
316    * Get SDU size
317    * \returns the SDU size
318    */
319   uint8_t GetSduSize (void) const;
320   /**
321    * Get target SAID
322    * \returns the target SAID
323    */
324   uint16_t GetTargetSAID (void) const;
325   /**
326    * Get ARQ enable
327    * \returns the ARQ enable
328    */
329   uint8_t GetArqEnable (void) const;
330   /**
331    * Get ARQ retry timeout transmit
332    * \returns the ARQ retry timeout
333    */
334   uint16_t GetArqWindowSize (void) const;
335   /**
336    * Get ARQ retry timeout transmit
337    * \returns the ARQ retry timeout transmit
338    */
339   uint16_t GetArqRetryTimeoutTx (void) const;
340   /**
341    * Get ARQ retry timeout receive
342    * \returns the ARQ retry timeout receive
343    */
344   uint16_t GetArqRetryTimeoutRx (void) const;
345   /**
346    * Get ARQ block lifetime
347    * \returns the ARQ block lifetime
348    */
349   uint16_t GetArqBlockLifeTime (void) const;
350   /**
351    * Get ARQ sync loss
352    * \returns the ARQ sync loss value
353    */
354   uint16_t GetArqSyncLoss (void) const;
355   /**
356    * Get ARQ deliver in order
357    * \returns the ARQ deliver in order
358    */
359   uint8_t GetArqDeliverInOrder (void) const;
360   /**
361    * Get ARQ purge timeout
362    * \returns the ARQ purge timeout value
363    */
364   uint16_t GetArqPurgeTimeout (void) const;
365   /**
366    * Get ARQ block size
367    * \returns the ARQ block size
368    */
369   uint16_t GetArqBlockSize (void) const;
370   /**
371    * Get CS specification
372    * \returns the CS specification
373    */
374   enum CsSpecification GetCsSpecification (void) const;
375   /**
376    * Get convergence sublayer
377    * \returns the convergence sublayer
378    */
379   CsParameters GetConvergenceSublayerParam (void) const;
380   /**
381    * Get unsolicited grant interval
382    * \returns the unsolicited grant interval
383    */
384   uint16_t GetUnsolicitedGrantInterval (void) const;
385   /**
386    * Get unsolicited polling interval
387    * \returns the unsolicited polling interval
388    */
389   uint16_t GetUnsolicitedPollingInterval (void) const;
390   /**
391    * Get is multicast
392    * \returns the is multicast flag
393    */
394   bool GetIsMulticast (void) const;
395   /**
396    * Get modulation
397    * \returns the modulation
398    */
399   enum WimaxPhy::ModulationType GetModulation (void) const;
400 
401   /**
402    * Set SFID
403    * \param sfid the SFID
404    */
405   void SetSfid (uint32_t sfid);
406   /** Set service class name
407    * \param name the service class name
408    */
409   void SetServiceClassName (std::string name);
410   /**
411    * Set QOS parameter set type
412    * \param type the QOS paraneter set type
413    */
414   void SetQosParamSetType (uint8_t type);
415   /**
416    * Set traffic priority
417    * \param priority the traffic priority
418    */
419   void SetTrafficPriority (uint8_t priority);
420   /**
421    * Set max sustained traffic rate
422    * \param maxSustainedRate the maximum sustained traffic rate
423    */
424   void SetMaxSustainedTrafficRate (uint32_t maxSustainedRate);
425   /**
426    * Set maximum traffic burst
427    * \param maxTrafficBurst the maximum traffic burst
428    */
429   void SetMaxTrafficBurst (uint32_t maxTrafficBurst);
430   /**
431    * Set minimum reserved traffic rate
432    * \param minResvRate the minimum reserved traffic rate
433    */
434   void SetMinReservedTrafficRate (uint32_t minResvRate);
435   /**
436    * Set minimum tolerable traffic rate
437    * \param minJitter the minimum tolerable traffic rate
438    */
439   void SetMinTolerableTrafficRate (uint32_t minJitter);
440   /**
441    * Set service scheduling type
442    * \param schedType the service scheduling type
443    */
444   void SetServiceSchedulingType (enum ServiceFlow::SchedulingType schedType);
445   /**
446    * Set request transmission policy
447    * \param policy the request transmission policy
448    */
449   void SetRequestTransmissionPolicy (uint32_t policy);
450   /**
451    * Set tolerated jitter
452    * \param jitter the tolerated jitter
453    */
454   void SetToleratedJitter (uint32_t jitter);
455   /**
456    * Set maximum latency
457    * \param MaximumLatency the maximjum latency
458    */
459   void SetMaximumLatency (uint32_t MaximumLatency);
460   /**
461    * Set fixed versus variable SDU indicator
462    * \param sduIndicator fixed vs variable SDU indicator
463    */
464   void SetFixedversusVariableSduIndicator (uint8_t sduIndicator);
465   /**
466    * Set SDU size
467    * \param sduSize the SDU size
468    */
469   void SetSduSize (uint8_t sduSize);
470   /**
471    * Set target SAID
472    * \param targetSaid the target SAID value
473    */
474   void SetTargetSAID (uint16_t targetSaid);
475   /**
476    * Set ARQ enable
477    * \param arqEnable the ARQ enable setting
478    */
479   void SetArqEnable (uint8_t arqEnable);
480   /**
481    * Set ARQ retry timeout transmit
482    * \param arqWindowSize the ARQ retry timeout transmit
483    */
484   void SetArqWindowSize (uint16_t arqWindowSize);
485   /**
486    * Set ARQ retry timeout transmit
487    * \param timeout the ARQ retry timeout transmit
488    */
489   void SetArqRetryTimeoutTx (uint16_t timeout);
490   /**
491    * Set ARQ retry timeout receive
492    * \param timeout the timeout
493    */
494   void SetArqRetryTimeoutRx (uint16_t timeout);
495   /**
496    * Set ARQ block lifetime
497    * \param lifeTime the ARQ block life time
498    */
499   void SetArqBlockLifeTime (uint16_t lifeTime);
500   /**
501    * Set ARQ sync loss
502    * \param syncLoss the ARQ sync loss
503    */
504   void SetArqSyncLoss (uint16_t syncLoss);
505   /**
506    * Set ARQ deliver in order
507    * \param inOrder the deliver in order setting
508    */
509   void SetArqDeliverInOrder (uint8_t inOrder);
510   /**
511    * Set ARQ purge timeout
512    * \param timeout the timeout value
513    */
514   void SetArqPurgeTimeout (uint16_t timeout);
515   /**
516    * Set ARQ block size
517    * \param size the size
518    */
519   void SetArqBlockSize (uint16_t size);
520   /**
521    * Set CS specification
522    * \param spec the CS specification
523    */
524   void SetCsSpecification (enum CsSpecification spec);
525   /**
526    * Set convergence sublayer parameters
527    * \param csparam the convergence sublayer parameters
528    */
529   void SetConvergenceSublayerParam (CsParameters csparam);
530 
531   /**
532    * Set unsolicied grant interval
533    * \param unsolicitedGrantInterval the unsolicited grant interval
534    */
535   void SetUnsolicitedGrantInterval (uint16_t unsolicitedGrantInterval);
536   /**
537    * Set unsolicited polling interval
538    * \param unsolicitedPollingInterval the unsolicited polling interval
539    */
540   void SetUnsolicitedPollingInterval (uint16_t unsolicitedPollingInterval);
541   /**
542    * Set is multicast
543    * \param isMulticast the is multicast flag
544    */
545   void SetIsMulticast (bool isMulticast);
546   /**
547    * Set modulation
548    * \param modulationType the modulation type
549    */
550   void SetModulation (enum WimaxPhy::ModulationType modulationType);
551 
552 
553 
554 private:
555   uint32_t m_sfid; ///< SFID
556   std::string m_serviceClassName; ///< service class name
557   uint8_t m_qosParamSetType; ///< QOS parameter type
558   uint8_t m_trafficPriority; ///< traffic priority
559   uint32_t m_maxSustainedTrafficRate; ///< maximum sustained traffic rate
560   uint32_t m_maxTrafficBurst; ///< maximum traffic burst
561   uint32_t m_minReservedTrafficRate; ///< minimum reserved traffic rate
562   uint32_t m_minTolerableTrafficRate; ///< minimum tolerable traffic rate
563   enum ServiceFlow::SchedulingType m_schedulingType; ///< scheduling type
564   uint32_t m_requestTransmissionPolicy; ///< request transmission policy
565   uint32_t m_toleratedJitter; ///< tolerated jitter
566   uint32_t m_maximumLatency; ///< maximum latency
567   uint8_t m_fixedversusVariableSduIndicator; ///< fixed versus variable SDI indicator
568   uint8_t m_sduSize; ///< SDU size
569   uint16_t m_targetSAID; ///< traget SAID
570   uint8_t m_arqEnable; ///< ARQ enable
571   uint16_t m_arqWindowSize; ///< ARQ window size
572   uint16_t m_arqRetryTimeoutTx; ///< ARQ retry timeout transmit
573   uint16_t m_arqRetryTimeoutRx; ///< ARQ retry timeout receive
574   uint16_t m_arqBlockLifeTime; ///< ARQ block life time
575   uint16_t m_arqSyncLoss; ///< ARQ sync loss
576   uint8_t m_arqDeliverInOrder; ///< ARQ deliver in order
577   uint16_t m_arqPurgeTimeout; ///< ARQ purge timeout
578   uint16_t m_arqBlockSize; ///< ARQ block size
579   enum CsSpecification m_csSpecification; ///< CS specification
580   CsParameters m_convergenceSublayerParam; ///< convergence sublayer parameters
581   uint16_t m_unsolicitedGrantInterval; ///< unsolicited grant interval
582   uint16_t m_unsolicitedPollingInterval; ///< unsolicited polling interval
583   Direction m_direction; ///< direction
584   Type m_type; ///< type
585   Ptr<WimaxConnection> m_connection; ///< connection
586   bool m_isEnabled; ///< is enabled?
587   bool m_isMulticast; ///< is multicast?
588   enum WimaxPhy::ModulationType m_modulationType; ///< modulation type
589   // will be used by the BS
590   ServiceFlowRecord *m_record; ///< service flow record
591 };
592 
593 } // namespace ns3
594 
595 #endif /* SERVICE_FLOW_H */
596