author | Tom Henderson <tomh@tomh.org> |
Thu, 28 May 2009 21:37:25 -0700 | |
changeset 4472 | e20a31541404 |
parent 4375 | db81fdcb06e7 |
child 4669 | 8aaa5e83939e |
permissions | -rw-r--r-- |
3578 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
* |
|
16 |
* based on earlier integration work by Tom Henderson and Sam Jansen. |
|
17 |
* 2008 Florian Westphal <fw@strlen.de> |
|
18 |
*/ |
|
19 |
||
20 |
#include "ns3/assert.h" |
|
21 |
#include "ns3/log.h" |
|
22 |
#include "ns3/nstime.h" |
|
23 |
||
24 |
#include "ns3/packet.h" |
|
25 |
#include "ns3/node.h" |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
26 |
#include "ns3/ipv4-route.h" |
3578 | 27 |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
28 |
#include "ns3/object-vector.h" |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
29 |
#include "ns3/string.h" |
3578 | 30 |
#include "tcp-header.h" |
31 |
#include "ipv4-end-point-demux.h" |
|
32 |
#include "ipv4-end-point.h" |
|
33 |
#include "ipv4-l3-protocol.h" |
|
34 |
#include "nsc-tcp-l4-protocol.h" |
|
35 |
#include "nsc-sysctl.h" |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
36 |
#include "nsc-tcp-socket-factory-impl.h" |
3578 | 37 |
|
38 |
#include "tcp-typedefs.h" |
|
39 |
||
40 |
#include <vector> |
|
41 |
#include <sstream> |
|
42 |
#include <dlfcn.h> |
|
43 |
#include <iomanip> |
|
44 |
||
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
45 |
#include <netinet/in.h> |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
46 |
#include <arpa/inet.h> |
3578 | 47 |
|
48 |
NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol"); |
|
49 |
||
50 |
namespace ns3 { |
|
51 |
||
52 |
NS_OBJECT_ENSURE_REGISTERED (NscTcpL4Protocol); |
|
53 |
||
54 |
/* see http://www.iana.org/assignments/protocol-numbers */ |
|
55 |
const uint8_t NscTcpL4Protocol::PROT_NUMBER = 6; |
|
56 |
||
57 |
ObjectFactory |
|
58 |
NscTcpL4Protocol::GetDefaultRttEstimatorFactory (void) |
|
59 |
{ |
|
60 |
ObjectFactory factory; |
|
61 |
factory.SetTypeId (RttMeanDeviation::GetTypeId ()); |
|
62 |
return factory; |
|
63 |
} |
|
64 |
||
65 |
TypeId |
|
66 |
NscTcpL4Protocol::GetTypeId (void) |
|
67 |
{ |
|
68 |
static TypeId tid = TypeId ("ns3::NscTcpL4Protocol") |
|
69 |
.SetParent<Ipv4L4Protocol> () |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
70 |
.AddConstructor<NscTcpL4Protocol>() |
3578 | 71 |
.AddAttribute ("RttEstimatorFactory", |
72 |
"How RttEstimator objects are created.", |
|
73 |
ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), |
|
74 |
MakeObjectFactoryAccessor (&NscTcpL4Protocol::m_rttFactory), |
|
75 |
MakeObjectFactoryChecker ()) |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
76 |
.AddAttribute ("SocketList", "The list of sockets associated to this protocol.", |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
77 |
ObjectVectorValue (), |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
78 |
MakeObjectVectorAccessor (&NscTcpL4Protocol::m_sockets), |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
79 |
MakeObjectVectorChecker<NscTcpSocketImpl> ()) |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
80 |
.AddAttribute ("Library", |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
81 |
"Set the linux library to be used to create the stack", |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
82 |
TypeId::ATTR_GET|TypeId::ATTR_CONSTRUCT, |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
83 |
StringValue("liblinux2.6.26.so"), |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
84 |
MakeStringAccessor (&NscTcpL4Protocol::GetNscLibrary,&NscTcpL4Protocol::SetNscLibrary), |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
85 |
MakeStringChecker ()) |
3578 | 86 |
; |
87 |
return tid; |
|
88 |
} |
|
89 |
||
90 |
int external_rand() |
|
91 |
{ |
|
92 |
return 1; // TODO |
|
93 |
} |
|
94 |
||
95 |
NscTcpL4Protocol::NscTcpL4Protocol () |
|
96 |
: m_endPoints (new Ipv4EndPointDemux ()), |
|
97 |
m_nscStack (0), |
|
98 |
m_softTimer (Timer::CANCEL_ON_DESTROY) |
|
99 |
{ |
|
100 |
m_dlopenHandle = NULL; |
|
101 |
NS_LOG_LOGIC("Made a NscTcpL4Protocol "<<this); |
|
102 |
} |
|
103 |
||
104 |
NscTcpL4Protocol::~NscTcpL4Protocol () |
|
105 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
106 |
NS_LOG_FUNCTION (this); |
3578 | 107 |
dlclose(m_dlopenHandle); |
108 |
} |
|
109 |
||
110 |
void |
|
111 |
NscTcpL4Protocol::SetNscLibrary(const std::string &soname) |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
112 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
113 |
if (soname!="") |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
114 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
115 |
m_nscLibrary = soname; |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
116 |
NS_ASSERT(!m_dlopenHandle); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
117 |
m_dlopenHandle = dlopen(soname.c_str (), RTLD_NOW); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
118 |
if (m_dlopenHandle == NULL) |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
119 |
NS_FATAL_ERROR (dlerror()); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
120 |
} |
3578 | 121 |
} |
122 |
||
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
123 |
std::string |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
124 |
NscTcpL4Protocol::GetNscLibrary () const |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
125 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
126 |
return m_nscLibrary; |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
127 |
} |
3578 | 128 |
void |
129 |
NscTcpL4Protocol::SetNode (Ptr<Node> node) |
|
130 |
{ |
|
131 |
m_node = node; |
|
132 |
||
133 |
if (m_nscStack) |
|
134 |
{ // stack has already been loaded... |
|
135 |
return; |
|
136 |
} |
|
137 |
||
138 |
NS_ASSERT(m_dlopenHandle); |
|
139 |
||
140 |
FCreateStack create = (FCreateStack)dlsym(m_dlopenHandle, "nsc_create_stack"); |
|
141 |
NS_ASSERT(create); |
|
142 |
m_nscStack = create(this, this, external_rand); |
|
143 |
int hzval = m_nscStack->get_hz(); |
|
144 |
||
145 |
NS_ASSERT(hzval > 0); |
|
146 |
||
147 |
m_softTimer.SetFunction (&NscTcpL4Protocol::SoftInterrupt, this); |
|
148 |
m_softTimer.SetDelay (MilliSeconds (1000/hzval)); |
|
149 |
m_nscStack->init(hzval); |
|
150 |
// This enables stack and NSC debug messages |
|
151 |
// m_nscStack->set_diagnostic(1000); |
|
152 |
||
153 |
Ptr<Ns3NscStack> nscStack = Create<Ns3NscStack> (); |
|
154 |
nscStack->SetStack (m_nscStack); |
|
155 |
node->AggregateObject (nscStack); |
|
156 |
||
157 |
m_softTimer.Schedule (); |
|
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
158 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
159 |
// its likely no ns-3 interface exits at this point, so |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
160 |
// we dealy adding the nsc interface until the start of the simulation. |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
161 |
Simulator::ScheduleNow (&NscTcpL4Protocol::AddInterface, this); |
3578 | 162 |
} |
163 |
||
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
164 |
void |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
165 |
NscTcpL4Protocol::NotifyNewAggregate () |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
166 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
167 |
bool is_not_initialized = (m_node == 0); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
168 |
Ptr<Node>node = this->GetObject<Node> (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
169 |
Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
170 |
if (is_not_initialized && node!= 0 && ipv4 != 0) |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
171 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
172 |
this->SetNode (node); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
173 |
ipv4->Insert (this); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
174 |
Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
175 |
tcpFactory->SetTcp (this); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
176 |
node->AggregateObject (tcpFactory); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
177 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
178 |
Object::NotifyNewAggregate (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
179 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
180 |
|
3578 | 181 |
int |
182 |
NscTcpL4Protocol::GetProtocolNumber (void) const |
|
183 |
{ |
|
184 |
return PROT_NUMBER; |
|
185 |
} |
|
186 |
int |
|
187 |
NscTcpL4Protocol::GetVersion (void) const |
|
188 |
{ |
|
189 |
return 2; |
|
190 |
} |
|
191 |
||
192 |
void |
|
193 |
NscTcpL4Protocol::DoDispose (void) |
|
194 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
195 |
NS_LOG_FUNCTION (this); |
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
196 |
|
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
197 |
for (std::vector<Ptr<NscTcpSocketImpl> >::iterator i = m_sockets.begin (); i != m_sockets.end (); i++) |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
198 |
{ |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
199 |
*i = 0; |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
200 |
} |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
201 |
m_sockets.clear (); |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
202 |
|
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
203 |
|
3578 | 204 |
if (m_endPoints != 0) |
205 |
{ |
|
206 |
delete m_endPoints; |
|
207 |
m_endPoints = 0; |
|
208 |
} |
|
209 |
m_node = 0; |
|
210 |
Ipv4L4Protocol::DoDispose (); |
|
211 |
} |
|
212 |
||
213 |
Ptr<Socket> |
|
214 |
NscTcpL4Protocol::CreateSocket (void) |
|
215 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
216 |
NS_LOG_FUNCTION (this); |
3578 | 217 |
|
218 |
Ptr<RttEstimator> rtt = m_rttFactory.Create<RttEstimator> (); |
|
219 |
Ptr<NscTcpSocketImpl> socket = CreateObject<NscTcpSocketImpl> (); |
|
220 |
socket->SetNode (m_node); |
|
221 |
socket->SetTcp (this); |
|
222 |
socket->SetRtt (rtt); |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
223 |
m_sockets.push_back (socket); |
3578 | 224 |
return socket; |
225 |
} |
|
226 |
||
227 |
Ipv4EndPoint * |
|
228 |
NscTcpL4Protocol::Allocate (void) |
|
229 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
230 |
NS_LOG_FUNCTION (this); |
3578 | 231 |
return m_endPoints->Allocate (); |
232 |
} |
|
233 |
||
234 |
Ipv4EndPoint * |
|
235 |
NscTcpL4Protocol::Allocate (Ipv4Address address) |
|
236 |
{ |
|
237 |
NS_LOG_FUNCTION (this << address); |
|
238 |
return m_endPoints->Allocate (address); |
|
239 |
} |
|
240 |
||
241 |
Ipv4EndPoint * |
|
242 |
NscTcpL4Protocol::Allocate (uint16_t port) |
|
243 |
{ |
|
244 |
NS_LOG_FUNCTION (this << port); |
|
245 |
return m_endPoints->Allocate (port); |
|
246 |
} |
|
247 |
||
248 |
Ipv4EndPoint * |
|
249 |
NscTcpL4Protocol::Allocate (Ipv4Address address, uint16_t port) |
|
250 |
{ |
|
251 |
NS_LOG_FUNCTION (this << address << port); |
|
252 |
return m_endPoints->Allocate (address, port); |
|
253 |
} |
|
254 |
||
255 |
Ipv4EndPoint * |
|
256 |
NscTcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, |
|
257 |
Ipv4Address peerAddress, uint16_t peerPort) |
|
258 |
{ |
|
259 |
NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort); |
|
260 |
return m_endPoints->Allocate (localAddress, localPort, |
|
261 |
peerAddress, peerPort); |
|
262 |
} |
|
263 |
||
264 |
void |
|
265 |
NscTcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) |
|
266 |
{ |
|
267 |
NS_LOG_FUNCTION (this << endPoint); |
|
268 |
// NSC m_endPoints->DeAllocate (endPoint); |
|
269 |
} |
|
270 |
||
3820 | 271 |
Ipv4L4Protocol::RxStatus |
3578 | 272 |
NscTcpL4Protocol::Receive (Ptr<Packet> packet, |
273 |
Ipv4Address const &source, |
|
274 |
Ipv4Address const &destination, |
|
275 |
Ptr<Ipv4Interface> incomingInterface) |
|
276 |
{ |
|
277 |
NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface); |
|
278 |
Ipv4Header ipHeader; |
|
279 |
uint32_t packetSize = packet->GetSize(); |
|
280 |
||
281 |
// The way things work at the moment, the IP header has been removed |
|
282 |
// by the ns-3 IPv4 processing code. However, the NSC stack expects |
|
283 |
// a complete IP packet, so we add the IP header back. |
|
284 |
// Since the original header is already gone, we create a new one |
|
285 |
// based on the information we have. |
|
286 |
ipHeader.SetSource (source); |
|
287 |
ipHeader.SetDestination (destination); |
|
288 |
ipHeader.SetProtocol (PROT_NUMBER); |
|
289 |
ipHeader.SetPayloadSize (packetSize); |
|
290 |
ipHeader.SetTtl (1); |
|
291 |
// all NSC stacks check the IP checksum |
|
292 |
ipHeader.EnableChecksum (); |
|
293 |
||
294 |
packet->AddHeader(ipHeader); |
|
295 |
packetSize = packet->GetSize(); |
|
296 |
||
297 |
const uint8_t *data = const_cast<uint8_t *>(packet->PeekData()); |
|
298 |
||
299 |
// deliver complete packet to the NSC network stack |
|
300 |
m_nscStack->if_receive_packet(0, data, packetSize); |
|
301 |
wakeup (); |
|
3820 | 302 |
return Ipv4L4Protocol::RX_OK; |
3578 | 303 |
} |
304 |
||
305 |
void NscTcpL4Protocol::SoftInterrupt (void) |
|
306 |
{ |
|
307 |
m_nscStack->timer_interrupt (); |
|
308 |
m_nscStack->increment_ticks (); |
|
309 |
m_softTimer.Schedule (); |
|
310 |
} |
|
311 |
||
312 |
void NscTcpL4Protocol::send_callback(const void* data, int datalen) |
|
313 |
{ |
|
314 |
Ptr<Packet> p; |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
315 |
uint32_t ipv4Saddr, ipv4Daddr; |
3578 | 316 |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
317 |
NS_ASSERT(datalen > 20); |
3578 | 318 |
|
319 |
||
320 |
// create packet, without IP header. The TCP header is not touched. |
|
321 |
// Not using the IP header makes integration easier, but it destroys |
|
322 |
// eg. ECN. |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
323 |
const uint8_t *rawdata = reinterpret_cast<const uint8_t *>(data); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
324 |
rawdata += 20; // skip IP header. IP options aren't supported at this time. |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
325 |
datalen -= 20; |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
326 |
p = Create<Packet> (rawdata, datalen); |
3578 | 327 |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
328 |
// we need the real source/destination ipv4 addresses for Send (). |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
329 |
const uint32_t *ipheader = reinterpret_cast<const uint32_t *>(data); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
330 |
ipv4Saddr = *(ipheader+3); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
331 |
ipv4Daddr = *(ipheader+4); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
332 |
|
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
333 |
Ipv4Address saddr(ntohl(ipv4Saddr)); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
334 |
Ipv4Address daddr(ntohl(ipv4Daddr)); |
3578 | 335 |
|
336 |
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> (); |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
337 |
NS_ASSERT_MSG (ipv4, "nsc callback invoked, but node has no ipv4 object"); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
338 |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
339 |
ipv4->Send (p, saddr, daddr, PROT_NUMBER, 0); |
3578 | 340 |
m_nscStack->if_send_finish(0); |
341 |
} |
|
342 |
||
343 |
void NscTcpL4Protocol::wakeup() |
|
344 |
{ |
|
345 |
// TODO |
|
346 |
// this should schedule a timer to read from all tcp sockets now... this is |
|
347 |
// an indication that data might be waiting on the socket |
|
348 |
||
349 |
Ipv4EndPointDemux::EndPoints endPoints = m_endPoints->GetAllEndPoints (); |
|
350 |
for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin (); |
|
351 |
endPoint != endPoints.end (); endPoint++) { |
|
352 |
// NSC HACK: (ab)use TcpSocket::ForwardUp for signalling |
|
353 |
(*endPoint)->ForwardUp (NULL, Ipv4Address(), 0); |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
void NscTcpL4Protocol::gettime(unsigned int* sec, unsigned int* usec) |
|
358 |
{ |
|
359 |
// Only used by the Linux network stack, e.g. during ISN generation |
|
360 |
// and in the kernel rng initialization routine. Also used in Linux |
|
361 |
// printk output. |
|
362 |
Time t = Simulator::Now (); |
|
363 |
int64_t us = t.GetMicroSeconds (); |
|
364 |
*sec = us / (1000*1000); |
|
365 |
*usec = us - *sec * (1000*1000); |
|
366 |
} |
|
367 |
||
368 |
||
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
369 |
void NscTcpL4Protocol::AddInterface(void) |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
370 |
{ |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
371 |
Ptr<Ipv4> ip = m_node->GetObject<Ipv4> (); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
372 |
const uint32_t nInterfaces = ip->GetNInterfaces (); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
373 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
374 |
NS_ASSERT_MSG (nInterfaces <= 2, "nsc does not support multiple interfaces per node"); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
375 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
376 |
// start from 1, ignore the loopback interface (HACK) |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
377 |
// we really don't need the loop, but its here to illustrate |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
378 |
// how things _should_ be (once nsc can deal with multiple interfaces...) |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
379 |
for (uint32_t i = 1; i < nInterfaces; i++) |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
380 |
{ |
4375
db81fdcb06e7
Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
381 |
Ipv4InterfaceAddress ifAddr = ip->GetAddress (i, 0); |
db81fdcb06e7
Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
382 |
Ipv4Address addr = ifAddr.GetLocal (); |
db81fdcb06e7
Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
383 |
Ipv4Mask mask = ifAddr.GetMask (); |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
384 |
uint16_t mtu = ip->GetMtu (i); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
385 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
386 |
std::ostringstream addrOss, maskOss; |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
387 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
388 |
addr.Print(addrOss); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
389 |
mask.Print(maskOss); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
390 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
391 |
NS_LOG_LOGIC ("if_attach " << addrOss.str().c_str() << " " << maskOss.str().c_str() << " " << mtu); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
392 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
393 |
std::string addrStr = addrOss.str(); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
394 |
std::string maskStr = maskOss.str(); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
395 |
const char* addrCStr = addrStr.c_str(); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
396 |
const char* maskCStr = maskStr.c_str(); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
397 |
m_nscStack->if_attach(addrCStr, maskCStr, mtu); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
398 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
399 |
if (i == 1) |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
400 |
{ |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
401 |
// We need to come up with a default gateway here. Can't guarantee this to be |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
402 |
// correct really... |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
403 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
404 |
uint8_t addrBytes[4]; |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
405 |
addr.Serialize(addrBytes); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
406 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
407 |
// XXX: this is all a bit of a horrible hack |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
408 |
// |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
409 |
// Just increment the last octet, this gives a decent chance of this being |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
410 |
// 'enough'. |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
411 |
// |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
412 |
// All we need is another address on the same network as the interface. This |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
413 |
// will force the stack to output the packet out of the network interface. |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
414 |
addrBytes[3]++; |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
415 |
addr.Deserialize(addrBytes); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
416 |
addrOss.str(""); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
417 |
addr.Print(addrOss); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
418 |
m_nscStack->add_default_gateway(addrOss.str().c_str()); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
419 |
} |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
420 |
} |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
421 |
} |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
422 |
|
3578 | 423 |
}; // namespace ns3 |
424 |