A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wimax-connection.cc
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  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  */
21 
22 #include "wimax-connection.h"
23 #include "ns3/pointer.h"
24 #include "ns3/enum.h"
25 #include "ns3/uinteger.h"
26 #include "service-flow.h"
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (WimaxConnection);
31 
32 TypeId WimaxConnection::GetTypeId (void)
33 {
34  static TypeId tid = TypeId ("ns3::WimaxConnection")
35 
36  .SetParent<Object> ()
37 
38  .AddAttribute ("Type",
39  "Connection type",
40  EnumValue (Cid::INITIAL_RANGING),
41  MakeEnumAccessor (&WimaxConnection::GetType),
42  MakeEnumChecker (Cid::BROADCAST,
43  "Broadcast",
44  Cid::INITIAL_RANGING,
45  "InitialRanging",
46  Cid::BASIC,
47  "Basic",
48  Cid::PRIMARY,
49  "Primary",
50  Cid::TRANSPORT,
51  "Transport",
52  Cid::MULTICAST,
53  "Multicast",
54  Cid::PADDING,
55  "Padding"))
56 
57  .AddAttribute ("TxQueue",
58  "Transmit queue",
59  PointerValue (),
60  MakePointerAccessor (&WimaxConnection::GetQueue),
61  MakePointerChecker<WimaxMacQueue> ());
62  return tid;
63 }
64 
65 WimaxConnection::WimaxConnection (Cid cid, enum Cid::Type type)
66  : m_cid (cid),
67  m_cidType (type),
68  m_queue (CreateObject<WimaxMacQueue> (1024)),
69  m_serviceFlow (0)
70 {
71 }
72 
73 WimaxConnection::~WimaxConnection (void)
74 {
75 }
76 
77 void
79 {
80  m_queue = 0;
81  // m_serviceFlow = 0;
82 }
83 
84 Cid
85 WimaxConnection::GetCid (void) const
86 {
87  return m_cid;
88 }
89 
90 enum Cid::Type
91 WimaxConnection::GetType (void) const
92 {
93  return m_cidType;
94 }
95 
96 Ptr<WimaxMacQueue>
98 {
99  return m_queue;
100 }
101 
102 void
104 {
105  m_serviceFlow = serviceFlow;
106 }
107 
110 {
111  return m_serviceFlow;
112 }
113 
114 uint8_t
116 {
117  return m_serviceFlow->GetSchedulingType ();
118 }
119 
120 bool
122 {
123 
124  return m_queue->Enqueue (packet, hdrType, hdr);
125 }
126 
129 {
130  return m_queue->Dequeue (packetType);
131 }
132 
134 WimaxConnection::Dequeue (MacHeaderType::HeaderType packetType, uint32_t availableByte)
135 {
136  return m_queue->Dequeue (packetType, availableByte);
137 }
138 
139 bool
141 {
142  return !m_queue->IsEmpty ();
143 }
144 
145 bool
147 {
148  return !m_queue->IsEmpty (packetType);
149 }
150 
151 std::string
152 WimaxConnection::GetTypeStr (void) const
153 {
154  switch (m_cidType)
155  {
156  case Cid::BROADCAST:
157  return "Broadcast";
158  break;
159  case Cid::INITIAL_RANGING:
160  return "Initial Ranging";
161  break;
162  case Cid::BASIC:
163  return "Basic";
164  break;
165  case Cid::PRIMARY:
166  return "Primary";
167  break;
168  case Cid::TRANSPORT:
169  return "Transport";
170  break;
171  case Cid::MULTICAST:
172  return "Multicast";
173  break;
174  default:
175  NS_FATAL_ERROR ("Invalid connection type");
176  }
177 
178  return "";
179 }
180 
181 // Defragmentation Function
182 const
183 WimaxConnection::FragmentsQueue WimaxConnection::GetFragmentsQueue (void) const
184 {
185  return m_fragmentsQueue;
186 }
187 
188 void
190 {
191  m_fragmentsQueue.push_back (fragment);
192 }
193 
194 void
196 {
197  m_fragmentsQueue.clear ();
198 }
199 } // namespace ns3
HeaderType
this class implements the mac header type field.
void FragmentEnqueue(Ptr< const Packet > fragment)
enqueue a received packet (that is a fragment) into the fragments queue
uint8_t GetSchedulingType(void) const
ServiceFlow * GetServiceFlow(void) const
this class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
Ptr< WimaxMacQueue > GetQueue(void) const
const FragmentsQueue GetFragmentsQueue(void) const
get a queue of received fragments
virtual void DoDispose(void)
bool HasPackets(void) const
Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
void ClearFragmentsQueue(void)
delete all enqueued fragments
bool Enqueue(Ptr< Packet > packet, const MacHeaderType &hdrType, const GenericMacHeader &hdr)
enqueue a packet in the queue of the connection
Definition: cid.h:35
Ptr< Packet > Dequeue(MacHeaderType::HeaderType packetType=MacHeaderType::HEADER_TYPE_GENERIC)
dequeue a packet from the queue of the connection
void SetServiceFlow(ServiceFlow *serviceFlow)
set the service flow associated to this connection