author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 19 Feb 2007 10:23:50 +0100 | |
changeset 304 | d8c9790ff263 |
parent 300 | 6b63789695a5 |
child 323 | ae826c265100 |
permissions | -rw-r--r-- |
299 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2007 University of Washington |
|
4 |
* All rights reserved. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License version 2 as |
|
8 |
* published by the Free Software Foundation; |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
*/ |
|
19 |
||
20 |
#include <string> |
|
21 |
#include "ns3/debug.h" |
|
304
d8c9790ff263
use new NS_ASSERT macro rather than assert. this makes the code build on my machine.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
300
diff
changeset
|
22 |
#include "ns3/assert.h" |
299 | 23 |
#include "ns3/packet.h" |
24 |
#include "ns3/drop-tail.h" |
|
25 |
#include "ns3/layer-connector.h" |
|
26 |
#include "ns3/channel.h" |
|
27 |
||
28 |
using namespace ns3; |
|
29 |
||
30 |
// =========================================================================== |
|
31 |
// Cook up a simplistic Internet Node |
|
32 |
// =========================================================================== |
|
33 |
class FakeInternetNode : public LayerConnectorUpper |
|
34 |
{ |
|
35 |
public: |
|
36 |
FakeInternetNode (); |
|
37 |
~FakeInternetNode (); |
|
38 |
||
39 |
void Doit (void); |
|
40 |
||
41 |
protected: |
|
42 |
bool UpperDoSendUp (Packet &p); |
|
43 |
bool UpperDoPull (Packet &p); |
|
44 |
||
45 |
DropTailQueue m_dtqOutbound; |
|
46 |
DropTailQueue m_dtqInbound; |
|
47 |
}; |
|
48 |
||
49 |
FakeInternetNode::FakeInternetNode () |
|
50 |
{ |
|
51 |
NS_DEBUG_UNCOND("FakeInternetNode::FakeInternetNode ()") |
|
52 |
} |
|
53 |
||
54 |
FakeInternetNode::~FakeInternetNode () |
|
55 |
{ |
|
56 |
NS_DEBUG_UNCOND("FakeInternetNode::~FakeInternetNode ()") |
|
57 |
} |
|
58 |
||
59 |
void |
|
60 |
FakeInternetNode::Doit (void) |
|
61 |
{ |
|
62 |
NS_DEBUG_UNCOND("FakeInternetNode::Doit ()") |
|
63 |
NS_DEBUG_UNCOND("FakeInternetNode::Doit (): **** Send outbound packet") |
|
64 |
Packet p; |
|
65 |
||
66 |
m_dtqOutbound.Enque(p); |
|
67 |
UpperNotify(); |
|
68 |
} |
|
69 |
||
70 |
bool |
|
71 |
FakeInternetNode::UpperDoSendUp (Packet &p) |
|
72 |
{ |
|
73 |
NS_DEBUG_UNCOND("FakeInternetNode::UpperDoSendUp (" << &p << ")") |
|
74 |
||
75 |
NS_DEBUG_UNCOND("FakeInternetNode::UpperDoSendUp (): **** Receive inbound packet") |
|
76 |
m_dtqInbound.Enque(p); |
|
77 |
return m_dtqInbound.Deque(p); |
|
78 |
} |
|
79 |
||
80 |
bool |
|
81 |
FakeInternetNode::UpperDoPull (Packet &p) |
|
82 |
{ |
|
83 |
NS_DEBUG_UNCOND("FakeInternetNode::DoPull (" << &p << ")") |
|
84 |
||
85 |
return m_dtqOutbound.Deque(p); |
|
86 |
} |
|
87 |
||
88 |
// =========================================================================== |
|
89 |
// Cook up a simplistic Physical Layer |
|
90 |
// =========================================================================== |
|
91 |
class FakePhysicalLayer : |
|
92 |
public LayerConnectorLower, |
|
93 |
public LayerConnectorUpper |
|
94 |
{ |
|
95 |
public: |
|
96 |
FakePhysicalLayer (); |
|
97 |
~FakePhysicalLayer (); |
|
98 |
||
99 |
protected: |
|
100 |
bool LowerDoNotify (LayerConnectorUpper *upper); |
|
101 |
bool UpperDoSendUp (Packet &p); |
|
102 |
bool UpperDoPull (Packet &p); |
|
103 |
||
104 |
DropTailQueue m_dtqInbound; |
|
105 |
DropTailQueue m_dtqOutbound; |
|
106 |
}; |
|
107 |
||
108 |
FakePhysicalLayer::FakePhysicalLayer () |
|
109 |
{ |
|
110 |
NS_DEBUG_UNCOND("FakePhysicalLayer::FakePhysicalLayer ()") |
|
111 |
} |
|
112 |
||
113 |
FakePhysicalLayer::~FakePhysicalLayer () |
|
114 |
{ |
|
115 |
NS_DEBUG_UNCOND("FakePhysicalLayer::~FakePhysicalLayer ()") |
|
116 |
} |
|
117 |
||
118 |
bool |
|
119 |
FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper) |
|
120 |
{ |
|
121 |
NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify ()") |
|
122 |
||
123 |
Packet p; |
|
124 |
||
125 |
NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify (): Starting pull") |
|
126 |
||
304
d8c9790ff263
use new NS_ASSERT macro rather than assert. this makes the code build on my machine.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
300
diff
changeset
|
127 |
NS_ASSERT(m_upperPartner); |
299 | 128 |
m_upperPartner->UpperPull(p); |
129 |
||
130 |
m_dtqOutbound.Enque(p); |
|
131 |
||
132 |
NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify (): Got bits, Notify lower") |
|
133 |
||
304
d8c9790ff263
use new NS_ASSERT macro rather than assert. this makes the code build on my machine.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
300
diff
changeset
|
134 |
NS_ASSERT(m_lowerPartner); |
299 | 135 |
return m_lowerPartner->LowerNotify(this); |
136 |
} |
|
137 |
||
138 |
bool |
|
139 |
FakePhysicalLayer::UpperDoSendUp (Packet &p) |
|
140 |
{ |
|
141 |
NS_DEBUG_UNCOND("FakePhysicalLayer::UpperDoSendUp (" << &p << ")") |
|
142 |
||
304
d8c9790ff263
use new NS_ASSERT macro rather than assert. this makes the code build on my machine.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
300
diff
changeset
|
143 |
NS_ASSERT(m_upperPartner); |
299 | 144 |
return m_upperPartner->UpperSendUp(p); |
145 |
} |
|
146 |
||
147 |
bool |
|
148 |
FakePhysicalLayer::UpperDoPull (Packet &p) |
|
149 |
{ |
|
150 |
NS_DEBUG_UNCOND("FakePhysicalLayer::DoPull (" << &p << ")") |
|
151 |
||
152 |
return m_dtqOutbound.Deque(p); |
|
153 |
} |
|
154 |
||
155 |
// =========================================================================== |
|
156 |
// Cook up a simplistic Channel, just to add any moby hack we feel like |
|
157 |
// =========================================================================== |
|
158 |
class FakeChannel : public Channel |
|
159 |
{ |
|
160 |
public: |
|
161 |
FakeChannel (); |
|
162 |
~FakeChannel (); |
|
163 |
}; |
|
164 |
||
165 |
FakeChannel::FakeChannel () |
|
166 |
{ |
|
167 |
NS_DEBUG_UNCOND("FakeChannel::FakeChannel ()") |
|
168 |
} |
|
169 |
||
170 |
FakeChannel::~FakeChannel () |
|
171 |
{ |
|
172 |
NS_DEBUG_UNCOND("FakeChannel::~FakeChannel ()") |
|
173 |
} |
|
174 |
||
175 |
int main (int argc, char *argv[]) |
|
176 |
{ |
|
177 |
NS_DEBUG_UNCOND("Channel Hackorama") |
|
178 |
||
300 | 179 |
#if 0 |
299 | 180 |
DebugComponentEnable("Queue"); |
181 |
DebugComponentEnable("DropTailQueue"); |
|
182 |
DebugComponentEnable("LayerConnector"); |
|
183 |
DebugComponentEnable("Channel"); |
|
300 | 184 |
#endif |
299 | 185 |
|
186 |
FakeInternetNode node1, node2, node3, node4; |
|
187 |
FakePhysicalLayer phys1, phys2, phys3, phys4; |
|
188 |
FakeChannel channel; |
|
189 |
Packet pkt; |
|
190 |
||
191 |
// all the hassle above lets us do something very simple here |
|
192 |
||
193 |
node1.ConnectToLower(phys1); |
|
194 |
phys1.ConnectToUpper(node1); |
|
195 |
phys1.ConnectToLower(channel); |
|
196 |
channel.ConnectToUpper(phys1); |
|
197 |
||
198 |
node2.ConnectToLower(phys2); |
|
199 |
phys2.ConnectToUpper(node2); |
|
200 |
phys2.ConnectToLower(channel); |
|
201 |
channel.ConnectToUpper(phys2); |
|
202 |
||
203 |
node3.ConnectToLower(phys3); |
|
204 |
phys3.ConnectToUpper(node3); |
|
205 |
phys3.ConnectToLower(channel); |
|
206 |
channel.ConnectToUpper(phys3); |
|
207 |
||
208 |
node4.ConnectToLower(phys4); |
|
209 |
phys4.ConnectToUpper(node4); |
|
210 |
phys4.ConnectToLower(channel); |
|
211 |
channel.ConnectToUpper(phys4); |
|
212 |
||
213 |
node1.Doit(); |
|
214 |
node2.Doit(); |
|
215 |
node3.Doit(); |
|
216 |
node4.Doit(); |
|
217 |
||
218 |
return 0; |
|
219 |
} |