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
GetTypeId(void)32 TypeId WimaxConnection::GetTypeId (void)
33 {
34 static TypeId tid = TypeId ("ns3::WimaxConnection")
35
36 .SetParent<Object> ()
37
38 .SetGroupName("Wimax")
39
40 .AddAttribute ("Type",
41 "Connection type",
42 EnumValue (Cid::INITIAL_RANGING),
43 MakeEnumAccessor (&WimaxConnection::GetType),
44 MakeEnumChecker (Cid::BROADCAST,
45 "Broadcast",
46 Cid::INITIAL_RANGING,
47 "InitialRanging",
48 Cid::BASIC,
49 "Basic",
50 Cid::PRIMARY,
51 "Primary",
52 Cid::TRANSPORT,
53 "Transport",
54 Cid::MULTICAST,
55 "Multicast",
56 Cid::PADDING,
57 "Padding"))
58
59 .AddAttribute ("TxQueue",
60 "Transmit queue",
61 PointerValue (),
62 MakePointerAccessor (&WimaxConnection::GetQueue),
63 MakePointerChecker<WimaxMacQueue> ());
64 return tid;
65 }
66
WimaxConnection(Cid cid,enum Cid::Type type)67 WimaxConnection::WimaxConnection (Cid cid, enum Cid::Type type)
68 : m_cid (cid),
69 m_cidType (type),
70 m_queue (CreateObject<WimaxMacQueue> (1024)),
71 m_serviceFlow (0)
72 {
73 }
74
~WimaxConnection(void)75 WimaxConnection::~WimaxConnection (void)
76 {
77 }
78
79 void
DoDispose(void)80 WimaxConnection::DoDispose (void)
81 {
82 m_queue = 0;
83 // m_serviceFlow = 0;
84 }
85
86 Cid
GetCid(void) const87 WimaxConnection::GetCid (void) const
88 {
89 return m_cid;
90 }
91
92 enum Cid::Type
GetType(void) const93 WimaxConnection::GetType (void) const
94 {
95 return m_cidType;
96 }
97
98 Ptr<WimaxMacQueue>
GetQueue(void) const99 WimaxConnection::GetQueue (void) const
100 {
101 return m_queue;
102 }
103
104 void
SetServiceFlow(ServiceFlow * serviceFlow)105 WimaxConnection::SetServiceFlow (ServiceFlow *serviceFlow)
106 {
107 m_serviceFlow = serviceFlow;
108 }
109
110 ServiceFlow*
GetServiceFlow(void) const111 WimaxConnection::GetServiceFlow (void) const
112 {
113 return m_serviceFlow;
114 }
115
116 uint8_t
GetSchedulingType(void) const117 WimaxConnection::GetSchedulingType (void) const
118 {
119 return m_serviceFlow->GetSchedulingType ();
120 }
121
122 bool
Enqueue(Ptr<Packet> packet,const MacHeaderType & hdrType,const GenericMacHeader & hdr)123 WimaxConnection::Enqueue (Ptr<Packet> packet, const MacHeaderType &hdrType, const GenericMacHeader &hdr)
124 {
125
126 return m_queue->Enqueue (packet, hdrType, hdr);
127 }
128
129 Ptr<Packet>
Dequeue(MacHeaderType::HeaderType packetType)130 WimaxConnection::Dequeue (MacHeaderType::HeaderType packetType)
131 {
132 return m_queue->Dequeue (packetType);
133 }
134
135 Ptr<Packet>
Dequeue(MacHeaderType::HeaderType packetType,uint32_t availableByte)136 WimaxConnection::Dequeue (MacHeaderType::HeaderType packetType, uint32_t availableByte)
137 {
138 return m_queue->Dequeue (packetType, availableByte);
139 }
140
141 bool
HasPackets(void) const142 WimaxConnection::HasPackets (void) const
143 {
144 return !m_queue->IsEmpty ();
145 }
146
147 bool
HasPackets(MacHeaderType::HeaderType packetType) const148 WimaxConnection::HasPackets (MacHeaderType::HeaderType packetType) const
149 {
150 return !m_queue->IsEmpty (packetType);
151 }
152
153 std::string
GetTypeStr(void) const154 WimaxConnection::GetTypeStr (void) const
155 {
156 switch (m_cidType)
157 {
158 case Cid::BROADCAST:
159 return "Broadcast";
160 break;
161 case Cid::INITIAL_RANGING:
162 return "Initial Ranging";
163 break;
164 case Cid::BASIC:
165 return "Basic";
166 break;
167 case Cid::PRIMARY:
168 return "Primary";
169 break;
170 case Cid::TRANSPORT:
171 return "Transport";
172 break;
173 case Cid::MULTICAST:
174 return "Multicast";
175 break;
176 default:
177 NS_FATAL_ERROR ("Invalid connection type");
178 }
179
180 return "";
181 }
182
183 // Defragmentation Function
184 const
GetFragmentsQueue(void) const185 WimaxConnection::FragmentsQueue WimaxConnection::GetFragmentsQueue (void) const
186 {
187 return m_fragmentsQueue;
188 }
189
190 void
FragmentEnqueue(Ptr<const Packet> fragment)191 WimaxConnection::FragmentEnqueue (Ptr<const Packet> fragment)
192 {
193 m_fragmentsQueue.push_back (fragment);
194 }
195
196 void
ClearFragmentsQueue(void)197 WimaxConnection::ClearFragmentsQueue (void)
198 {
199 m_fragmentsQueue.clear ();
200 }
201 } // namespace ns3
202