author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 31 Oct 2007 16:26:18 +0100 | |
changeset 2058 | 1444e6708451 |
parent 1504 | 36ecc970ba96 |
child 1828 | 6ab68edddf45 |
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> |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
21 |
#include "ns3/log.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 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
30 |
NS_LOG_COMPONENT_DEFINE ("ChannelSample"); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
31 |
|
299 | 32 |
// =========================================================================== |
33 |
// Cook up a simplistic Internet Node |
|
34 |
// =========================================================================== |
|
35 |
class FakeInternetNode : public LayerConnectorUpper |
|
36 |
{ |
|
37 |
public: |
|
38 |
FakeInternetNode (); |
|
39 |
~FakeInternetNode (); |
|
40 |
||
41 |
void Doit (void); |
|
42 |
||
43 |
protected: |
|
44 |
bool UpperDoSendUp (Packet &p); |
|
45 |
bool UpperDoPull (Packet &p); |
|
46 |
||
47 |
DropTailQueue m_dtqOutbound; |
|
48 |
DropTailQueue m_dtqInbound; |
|
49 |
}; |
|
50 |
||
51 |
FakeInternetNode::FakeInternetNode () |
|
52 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
53 |
NS_LOG_FUNCTION; |
299 | 54 |
} |
55 |
||
56 |
FakeInternetNode::~FakeInternetNode () |
|
57 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
58 |
NS_LOG_FUNCTION; |
299 | 59 |
} |
60 |
||
61 |
void |
|
62 |
FakeInternetNode::Doit (void) |
|
63 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
64 |
NS_LOG_FUNCTION; |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
65 |
NS_LOG_INFO ("**** Send outbound packet"); |
299 | 66 |
Packet p; |
67 |
||
337
42102ed8ee3c
Fix bug 8: Enque/Deque misspelled
Tom Henderson <tomh@tomh.org>
parents:
323
diff
changeset
|
68 |
m_dtqOutbound.Enqueue(p); |
299 | 69 |
UpperNotify(); |
70 |
} |
|
71 |
||
72 |
bool |
|
73 |
FakeInternetNode::UpperDoSendUp (Packet &p) |
|
74 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
75 |
NS_LOG_FUNCTION; |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
76 |
NS_LOG_PARAM ("(" << &p << ")"); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
77 |
NS_LOG_INFO ("**** Receive inbound packet"); |
337
42102ed8ee3c
Fix bug 8: Enque/Deque misspelled
Tom Henderson <tomh@tomh.org>
parents:
323
diff
changeset
|
78 |
m_dtqInbound.Enqueue(p); |
42102ed8ee3c
Fix bug 8: Enque/Deque misspelled
Tom Henderson <tomh@tomh.org>
parents:
323
diff
changeset
|
79 |
return m_dtqInbound.Dequeue(p); |
299 | 80 |
} |
81 |
||
82 |
bool |
|
83 |
FakeInternetNode::UpperDoPull (Packet &p) |
|
84 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
85 |
NS_LOG_FUNCTION; |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
86 |
NS_LOG_PARAM ("(" << &p << ")"); |
299 | 87 |
|
337
42102ed8ee3c
Fix bug 8: Enque/Deque misspelled
Tom Henderson <tomh@tomh.org>
parents:
323
diff
changeset
|
88 |
return m_dtqOutbound.Dequeue(p); |
299 | 89 |
} |
90 |
||
91 |
// =========================================================================== |
|
92 |
// Cook up a simplistic Physical Layer |
|
93 |
// =========================================================================== |
|
94 |
class FakePhysicalLayer : |
|
95 |
public LayerConnectorLower, |
|
96 |
public LayerConnectorUpper |
|
97 |
{ |
|
98 |
public: |
|
99 |
FakePhysicalLayer (); |
|
100 |
~FakePhysicalLayer (); |
|
101 |
||
102 |
protected: |
|
103 |
bool LowerDoNotify (LayerConnectorUpper *upper); |
|
104 |
bool UpperDoSendUp (Packet &p); |
|
105 |
bool UpperDoPull (Packet &p); |
|
106 |
||
107 |
DropTailQueue m_dtqInbound; |
|
108 |
DropTailQueue m_dtqOutbound; |
|
109 |
}; |
|
110 |
||
111 |
FakePhysicalLayer::FakePhysicalLayer () |
|
112 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
113 |
NS_LOG_FUNCTION; |
299 | 114 |
} |
115 |
||
116 |
FakePhysicalLayer::~FakePhysicalLayer () |
|
117 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
118 |
NS_LOG_FUNCTION; |
299 | 119 |
} |
120 |
||
121 |
bool |
|
122 |
FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper) |
|
123 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
124 |
NS_LOG_FUNCTION; |
299 | 125 |
|
126 |
Packet p; |
|
127 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
128 |
NS_LOG_LOGIC ("Starting pull"); |
299 | 129 |
|
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
|
130 |
NS_ASSERT(m_upperPartner); |
299 | 131 |
m_upperPartner->UpperPull(p); |
132 |
||
337
42102ed8ee3c
Fix bug 8: Enque/Deque misspelled
Tom Henderson <tomh@tomh.org>
parents:
323
diff
changeset
|
133 |
m_dtqOutbound.Enqueue(p); |
299 | 134 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
135 |
NS_LOG_LOGIC ("Got bits, Notify lower"); |
299 | 136 |
|
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
|
137 |
NS_ASSERT(m_lowerPartner); |
299 | 138 |
return m_lowerPartner->LowerNotify(this); |
139 |
} |
|
140 |
||
141 |
bool |
|
142 |
FakePhysicalLayer::UpperDoSendUp (Packet &p) |
|
143 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
144 |
NS_LOG_FUNCTION; |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
145 |
NS_LOG_PARAM ("(" << &p << ")"); |
299 | 146 |
|
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
|
147 |
NS_ASSERT(m_upperPartner); |
299 | 148 |
return m_upperPartner->UpperSendUp(p); |
149 |
} |
|
150 |
||
151 |
bool |
|
152 |
FakePhysicalLayer::UpperDoPull (Packet &p) |
|
153 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
154 |
NS_LOG_FUNCTION; |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
155 |
NS_LOG_PARAM ("(" << &p << ")"); |
299 | 156 |
|
337
42102ed8ee3c
Fix bug 8: Enque/Deque misspelled
Tom Henderson <tomh@tomh.org>
parents:
323
diff
changeset
|
157 |
return m_dtqOutbound.Dequeue(p); |
299 | 158 |
} |
159 |
||
160 |
// =========================================================================== |
|
161 |
// Cook up a simplistic Channel, just to add any moby hack we feel like |
|
162 |
// =========================================================================== |
|
163 |
class FakeChannel : public Channel |
|
164 |
{ |
|
165 |
public: |
|
166 |
FakeChannel (); |
|
167 |
~FakeChannel (); |
|
168 |
}; |
|
169 |
||
170 |
FakeChannel::FakeChannel () |
|
171 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
172 |
NS_LOG_FUNCTION; |
299 | 173 |
} |
174 |
||
175 |
FakeChannel::~FakeChannel () |
|
176 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
177 |
NS_LOG_FUNCTION; |
299 | 178 |
} |
179 |
||
180 |
int main (int argc, char *argv[]) |
|
181 |
{ |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
337
diff
changeset
|
182 |
NS_LOG_INFO ("Channel Hackorama"); |
299 | 183 |
|
184 |
FakeInternetNode node1, node2, node3, node4; |
|
185 |
FakePhysicalLayer phys1, phys2, phys3, phys4; |
|
186 |
FakeChannel channel; |
|
187 |
Packet pkt; |
|
188 |
||
189 |
// all the hassle above lets us do something very simple here |
|
190 |
||
191 |
node1.ConnectToLower(phys1); |
|
192 |
phys1.ConnectToUpper(node1); |
|
193 |
phys1.ConnectToLower(channel); |
|
194 |
channel.ConnectToUpper(phys1); |
|
195 |
||
196 |
node2.ConnectToLower(phys2); |
|
197 |
phys2.ConnectToUpper(node2); |
|
198 |
phys2.ConnectToLower(channel); |
|
199 |
channel.ConnectToUpper(phys2); |
|
200 |
||
201 |
node3.ConnectToLower(phys3); |
|
202 |
phys3.ConnectToUpper(node3); |
|
203 |
phys3.ConnectToLower(channel); |
|
204 |
channel.ConnectToUpper(phys3); |
|
205 |
||
206 |
node4.ConnectToLower(phys4); |
|
207 |
phys4.ConnectToUpper(node4); |
|
208 |
phys4.ConnectToLower(channel); |
|
209 |
channel.ConnectToUpper(phys4); |
|
210 |
||
211 |
node1.Doit(); |
|
212 |
node2.Doit(); |
|
213 |
node3.Doit(); |
|
214 |
node4.Doit(); |
|
215 |
||
216 |
return 0; |
|
217 |
} |