author | Tom Henderson <tomh@tomh.org> |
Mon, 04 Jan 2016 14:11:51 -0800 | |
changeset 11800 | bd9c9abd5d6e |
parent 11463 | 60d4486a863a |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Mileti? <rivanvx@gmail.com>
parents:
7256
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
3578 | 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" |
|
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
35 |
#include "nsc-tcp-socket-impl.h" |
3578 | 36 |
#include "nsc-sysctl.h" |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
37 |
#include "nsc-tcp-socket-factory-impl.h" |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
38 |
#include "sim_interface.h" |
3578 | 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 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
48 |
namespace ns3 { |
3578 | 49 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
50 |
NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol"); |
3578 | 51 |
|
10652
dc18deba4502
[doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10440
diff
changeset
|
52 |
NS_OBJECT_ENSURE_REGISTERED (NscTcpL4Protocol); |
3578 | 53 |
|
54 |
/* see http://www.iana.org/assignments/protocol-numbers */ |
|
55 |
const uint8_t NscTcpL4Protocol::PROT_NUMBER = 6; |
|
56 |
||
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
57 |
/** |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
58 |
* \ingroup nsctcp |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
59 |
* \brief Nsc interface implementation class. |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
60 |
*/ |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
61 |
class NscInterfaceImpl : public ISendCallback, public IInterruptCallback |
3578 | 62 |
{ |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
63 |
public: |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
64 |
/** |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
65 |
* Constructor |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
66 |
* \param prot the NSC TCP protocol |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
67 |
*/ |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
68 |
NscInterfaceImpl (Ptr<NscTcpL4Protocol> prot); |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
69 |
private: |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
70 |
/** |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
71 |
* \brief Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3. |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
72 |
* |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
73 |
* A packet is an octet soup consisting of an IP Header, TCP Header |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
74 |
* and user payload, if any |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
75 |
* |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
76 |
* \param data the data |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
77 |
* \param datalen the data length |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
78 |
*/ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
79 |
virtual void send_callback (const void *data, int datalen); |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
80 |
/** |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
81 |
* \brief Called by the NSC stack whenever something of interest has happened |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
82 |
* |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
83 |
* Examples: when data arrives on a socket, a listen socket |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
84 |
* has a new connection pending, etc. |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
85 |
*/ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
86 |
virtual void wakeup (); |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
87 |
/** |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
88 |
* \brief Called by the Linux stack RNG initialization |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
89 |
* |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
90 |
* Its also used by the cradle code to add a timestamp to |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
91 |
* printk/printf/debug output. |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
92 |
*/ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
93 |
virtual void gettime (unsigned int *, unsigned int *); |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
94 |
private: |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
95 |
Ptr<NscTcpL4Protocol> m_prot; //!< the NSC TCP protocol |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
96 |
}; |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
97 |
|
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
98 |
NscInterfaceImpl::NscInterfaceImpl (Ptr<NscTcpL4Protocol> prot) |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
99 |
: m_prot (prot) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
100 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
101 |
} |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
102 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
103 |
void |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
104 |
NscInterfaceImpl::send_callback (const void *data, int datalen) |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
105 |
{ |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
106 |
m_prot->send_callback (data, datalen); |
3578 | 107 |
} |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
108 |
void |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
109 |
NscInterfaceImpl::wakeup () |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
110 |
{ |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
111 |
m_prot->wakeup (); |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
112 |
} |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
113 |
void |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
114 |
NscInterfaceImpl::gettime (unsigned int *sec, unsigned int *usec) |
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
115 |
{ |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
116 |
m_prot->gettime (sec,usec); |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
117 |
} |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
118 |
|
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
119 |
|
5887 | 120 |
#undef NS_LOG_APPEND_CONTEXT |
121 |
#define NS_LOG_APPEND_CONTEXT \ |
|
122 |
if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; } |
|
3578 | 123 |
|
124 |
TypeId |
|
125 |
NscTcpL4Protocol::GetTypeId (void) |
|
126 |
{ |
|
127 |
static TypeId tid = TypeId ("ns3::NscTcpL4Protocol") |
|
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
128 |
.SetParent<IpL4Protocol> () |
11259
ea2f6a3ed14e
SetGroupName for internet module
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
129 |
.SetGroupName ("Internet") |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
130 |
.AddConstructor<NscTcpL4Protocol>() |
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
131 |
.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
|
132 |
ObjectVectorValue (), |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
133 |
MakeObjectVectorAccessor (&NscTcpL4Protocol::m_sockets), |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
134 |
MakeObjectVectorChecker<NscTcpSocketImpl> ()) |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
135 |
.AddAttribute ("Library", |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
136 |
"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
|
137 |
TypeId::ATTR_GET|TypeId::ATTR_CONSTRUCT, |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
138 |
StringValue ("liblinux2.6.26.so"), |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
139 |
MakeStringAccessor (&NscTcpL4Protocol::GetNscLibrary,&NscTcpL4Protocol::SetNscLibrary), |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
140 |
MakeStringChecker ()) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
141 |
; |
3578 | 142 |
return tid; |
143 |
} |
|
144 |
||
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
145 |
/** |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
146 |
* \brief External Random number generator |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
147 |
* |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
148 |
* \todo make it random... |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
149 |
* |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
150 |
* \returns a random number |
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
151 |
*/ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
152 |
int external_rand () |
3578 | 153 |
{ |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
154 |
return 1; |
3578 | 155 |
} |
156 |
||
157 |
NscTcpL4Protocol::NscTcpL4Protocol () |
|
158 |
: m_endPoints (new Ipv4EndPointDemux ()), |
|
159 |
m_nscStack (0), |
|
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
160 |
m_nscInterface (new NscInterfaceImpl (this)), |
3578 | 161 |
m_softTimer (Timer::CANCEL_ON_DESTROY) |
162 |
{ |
|
163 |
m_dlopenHandle = NULL; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
164 |
NS_LOG_LOGIC ("Made a NscTcpL4Protocol "<<this); |
3578 | 165 |
} |
166 |
||
167 |
NscTcpL4Protocol::~NscTcpL4Protocol () |
|
168 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
169 |
NS_LOG_FUNCTION (this); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
170 |
dlclose (m_dlopenHandle); |
3578 | 171 |
} |
172 |
||
173 |
void |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
174 |
NscTcpL4Protocol::SetNscLibrary (const std::string &soname) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
175 |
{ |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
176 |
if (soname!="") |
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 |
m_nscLibrary = soname; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
179 |
NS_ASSERT (!m_dlopenHandle); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
180 |
m_dlopenHandle = dlopen (soname.c_str (), RTLD_NOW); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
181 |
if (m_dlopenHandle == NULL) |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
182 |
NS_FATAL_ERROR (dlerror ()); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
183 |
} |
3578 | 184 |
} |
185 |
||
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
186 |
std::string |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
187 |
NscTcpL4Protocol::GetNscLibrary () const |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
188 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
189 |
return m_nscLibrary; |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
190 |
} |
3578 | 191 |
void |
192 |
NscTcpL4Protocol::SetNode (Ptr<Node> node) |
|
193 |
{ |
|
194 |
m_node = node; |
|
195 |
||
196 |
if (m_nscStack) |
|
197 |
{ // stack has already been loaded... |
|
198 |
return; |
|
199 |
} |
|
200 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
201 |
NS_ASSERT (m_dlopenHandle); |
3578 | 202 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
203 |
FCreateStack create = (FCreateStack)dlsym (m_dlopenHandle, "nsc_create_stack"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
204 |
NS_ASSERT (create); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
205 |
m_nscStack = create (m_nscInterface, m_nscInterface, external_rand); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
206 |
int hzval = m_nscStack->get_hz (); |
3578 | 207 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
208 |
NS_ASSERT (hzval > 0); |
3578 | 209 |
|
210 |
m_softTimer.SetFunction (&NscTcpL4Protocol::SoftInterrupt, this); |
|
211 |
m_softTimer.SetDelay (MilliSeconds (1000/hzval)); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
212 |
m_nscStack->init (hzval); |
3578 | 213 |
// This enables stack and NSC debug messages |
214 |
// m_nscStack->set_diagnostic(1000); |
|
215 |
||
216 |
Ptr<Ns3NscStack> nscStack = Create<Ns3NscStack> (); |
|
217 |
nscStack->SetStack (m_nscStack); |
|
218 |
node->AggregateObject (nscStack); |
|
219 |
||
220 |
m_softTimer.Schedule (); |
|
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
221 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
222 |
// 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
|
223 |
// 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
|
224 |
Simulator::ScheduleNow (&NscTcpL4Protocol::AddInterface, this); |
3578 | 225 |
} |
226 |
||
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
227 |
void |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
228 |
NscTcpL4Protocol::NotifyNewAggregate () |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
229 |
{ |
4669
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
230 |
if (m_node == 0) |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
231 |
{ |
4669
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
232 |
Ptr<Node>node = this->GetObject<Node> (); |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
233 |
if (node != 0) |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
234 |
{ |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
235 |
Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> (); |
8835
414acb8683ce
Do not overwrite transport protocol downtarget callback in NotifyNewAggregate()
Tom Henderson <tomh@tomh.org>
parents:
7801
diff
changeset
|
236 |
if (ipv4 != 0 && m_downTarget.IsNull ()) |
4669
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
237 |
{ |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
238 |
this->SetNode (node); |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
239 |
ipv4->Insert (this); |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
240 |
Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> (); |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
241 |
tcpFactory->SetTcp (this); |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
242 |
node->AggregateObject (tcpFactory); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
243 |
this->SetDownTarget (MakeCallback (&Ipv4L3Protocol::Send, ipv4)); |
4669
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
244 |
} |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4472
diff
changeset
|
245 |
} |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
246 |
} |
11463
60d4486a863a
bug 2125: subclasses must chain up to their base class NotifyNewAggregate() method (patch due to nlmills)
Tom Henderson <tomh@tomh.org>
parents:
11259
diff
changeset
|
247 |
IpL4Protocol::NotifyNewAggregate (); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
248 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
249 |
|
3578 | 250 |
int |
251 |
NscTcpL4Protocol::GetProtocolNumber (void) const |
|
252 |
{ |
|
253 |
return PROT_NUMBER; |
|
254 |
} |
|
255 |
int |
|
256 |
NscTcpL4Protocol::GetVersion (void) const |
|
257 |
{ |
|
258 |
return 2; |
|
259 |
} |
|
260 |
||
261 |
void |
|
262 |
NscTcpL4Protocol::DoDispose (void) |
|
263 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
264 |
NS_LOG_FUNCTION (this); |
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
265 |
|
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
266 |
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
|
267 |
{ |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
268 |
*i = 0; |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
269 |
} |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
270 |
m_sockets.clear (); |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
271 |
|
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
272 |
|
3578 | 273 |
if (m_endPoints != 0) |
274 |
{ |
|
275 |
delete m_endPoints; |
|
276 |
m_endPoints = 0; |
|
277 |
} |
|
278 |
m_node = 0; |
|
4740
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
279 |
delete m_nscInterface; |
34acfd7ad508
export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4669
diff
changeset
|
280 |
m_nscInterface = 0; |
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
281 |
m_downTarget.Nullify (); |
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
282 |
IpL4Protocol::DoDispose (); |
3578 | 283 |
} |
284 |
||
285 |
Ptr<Socket> |
|
286 |
NscTcpL4Protocol::CreateSocket (void) |
|
287 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
288 |
NS_LOG_FUNCTION (this); |
3578 | 289 |
|
290 |
Ptr<NscTcpSocketImpl> socket = CreateObject<NscTcpSocketImpl> (); |
|
291 |
socket->SetNode (m_node); |
|
292 |
socket->SetTcp (this); |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
3820
diff
changeset
|
293 |
m_sockets.push_back (socket); |
3578 | 294 |
return socket; |
295 |
} |
|
296 |
||
297 |
Ipv4EndPoint * |
|
298 |
NscTcpL4Protocol::Allocate (void) |
|
299 |
{ |
|
3710
ad0c222a18be
nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents:
3578
diff
changeset
|
300 |
NS_LOG_FUNCTION (this); |
3578 | 301 |
return m_endPoints->Allocate (); |
302 |
} |
|
303 |
||
304 |
Ipv4EndPoint * |
|
305 |
NscTcpL4Protocol::Allocate (Ipv4Address address) |
|
306 |
{ |
|
307 |
NS_LOG_FUNCTION (this << address); |
|
308 |
return m_endPoints->Allocate (address); |
|
309 |
} |
|
310 |
||
311 |
Ipv4EndPoint * |
|
312 |
NscTcpL4Protocol::Allocate (uint16_t port) |
|
313 |
{ |
|
314 |
NS_LOG_FUNCTION (this << port); |
|
315 |
return m_endPoints->Allocate (port); |
|
316 |
} |
|
317 |
||
318 |
Ipv4EndPoint * |
|
319 |
NscTcpL4Protocol::Allocate (Ipv4Address address, uint16_t port) |
|
320 |
{ |
|
321 |
NS_LOG_FUNCTION (this << address << port); |
|
322 |
return m_endPoints->Allocate (address, port); |
|
323 |
} |
|
324 |
||
325 |
Ipv4EndPoint * |
|
326 |
NscTcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
327 |
Ipv4Address peerAddress, uint16_t peerPort) |
3578 | 328 |
{ |
329 |
NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort); |
|
330 |
return m_endPoints->Allocate (localAddress, localPort, |
|
331 |
peerAddress, peerPort); |
|
332 |
} |
|
333 |
||
334 |
void |
|
335 |
NscTcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) |
|
336 |
{ |
|
337 |
NS_LOG_FUNCTION (this << endPoint); |
|
338 |
// NSC m_endPoints->DeAllocate (endPoint); |
|
339 |
} |
|
340 |
||
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
341 |
IpL4Protocol::RxStatus |
3578 | 342 |
NscTcpL4Protocol::Receive (Ptr<Packet> packet, |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
343 |
Ipv4Header const &header, |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
344 |
Ptr<Ipv4Interface> incomingInterface) |
3578 | 345 |
{ |
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
5971
diff
changeset
|
346 |
NS_LOG_FUNCTION (this << packet << header << incomingInterface); |
3578 | 347 |
Ipv4Header ipHeader; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
348 |
uint32_t packetSize = packet->GetSize (); |
3578 | 349 |
|
350 |
// The way things work at the moment, the IP header has been removed |
|
351 |
// by the ns-3 IPv4 processing code. However, the NSC stack expects |
|
352 |
// a complete IP packet, so we add the IP header back. |
|
353 |
// Since the original header is already gone, we create a new one |
|
354 |
// based on the information we have. |
|
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
5971
diff
changeset
|
355 |
ipHeader.SetSource (header.GetSource ()); |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
5971
diff
changeset
|
356 |
ipHeader.SetDestination (header.GetDestination ()); |
3578 | 357 |
ipHeader.SetProtocol (PROT_NUMBER); |
358 |
ipHeader.SetPayloadSize (packetSize); |
|
359 |
ipHeader.SetTtl (1); |
|
360 |
// all NSC stacks check the IP checksum |
|
361 |
ipHeader.EnableChecksum (); |
|
362 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
363 |
packet->AddHeader (ipHeader); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
364 |
packetSize = packet->GetSize (); |
3578 | 365 |
|
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6442
diff
changeset
|
366 |
uint8_t *buf = new uint8_t[packetSize]; |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6442
diff
changeset
|
367 |
packet->CopyData (buf, packetSize); |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6442
diff
changeset
|
368 |
const uint8_t *data = const_cast<uint8_t *>(buf); |
3578 | 369 |
|
370 |
// deliver complete packet to the NSC network stack |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
371 |
m_nscStack->if_receive_packet (0, data, packetSize); |
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6442
diff
changeset
|
372 |
delete[] buf; |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6442
diff
changeset
|
373 |
|
3578 | 374 |
wakeup (); |
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
375 |
return IpL4Protocol::RX_OK; |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
376 |
} |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
377 |
|
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
378 |
IpL4Protocol::RxStatus |
9146
1bc2026bc8b4
complete TOS patch for NSC code
Tom Henderson <tomh@tomh.org>
parents:
8835
diff
changeset
|
379 |
NscTcpL4Protocol::Receive(Ptr<Packet>, Ipv6Header const &, Ptr<Ipv6Interface>) |
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
380 |
{ |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
381 |
return IpL4Protocol::RX_ENDPOINT_UNREACH; |
3578 | 382 |
} |
383 |
||
384 |
void NscTcpL4Protocol::SoftInterrupt (void) |
|
385 |
{ |
|
386 |
m_nscStack->timer_interrupt (); |
|
387 |
m_nscStack->increment_ticks (); |
|
388 |
m_softTimer.Schedule (); |
|
389 |
} |
|
390 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
391 |
void NscTcpL4Protocol::send_callback (const void* data, int datalen) |
3578 | 392 |
{ |
393 |
Ptr<Packet> p; |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
394 |
uint32_t ipv4Saddr, ipv4Daddr; |
3578 | 395 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
396 |
NS_ASSERT (datalen > 20); |
3578 | 397 |
|
398 |
||
399 |
// create packet, without IP header. The TCP header is not touched. |
|
400 |
// Not using the IP header makes integration easier, but it destroys |
|
401 |
// eg. ECN. |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
datalen -= 20; |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
405 |
p = Create<Packet> (rawdata, datalen); |
3578 | 406 |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
407 |
// 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
|
408 |
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
|
409 |
ipv4Saddr = *(ipheader+3); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
410 |
ipv4Daddr = *(ipheader+4); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3710
diff
changeset
|
411 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
412 |
Ipv4Address saddr (ntohl (ipv4Saddr)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
413 |
Ipv4Address daddr (ntohl (ipv4Daddr)); |
3578 | 414 |
|
415 |
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
|
416 |
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
|
417 |
|
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
418 |
m_downTarget (p, saddr, daddr, PROT_NUMBER, 0); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
419 |
m_nscStack->if_send_finish (0); |
3578 | 420 |
} |
421 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
422 |
void NscTcpL4Protocol::wakeup () |
3578 | 423 |
{ |
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
424 |
// \todo |
3578 | 425 |
// this should schedule a timer to read from all tcp sockets now... this is |
426 |
// an indication that data might be waiting on the socket |
|
427 |
||
428 |
Ipv4EndPointDemux::EndPoints endPoints = m_endPoints->GetAllEndPoints (); |
|
429 |
for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin (); |
|
430 |
endPoint != endPoints.end (); endPoint++) { |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
431 |
// NSC HACK: (ab)use TcpSocket::ForwardUp for signalling |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
432 |
(*endPoint)->ForwardUp (NULL, Ipv4Header (), 0, 0); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
433 |
} |
3578 | 434 |
} |
435 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
436 |
void NscTcpL4Protocol::gettime (unsigned int* sec, unsigned int* usec) |
3578 | 437 |
{ |
438 |
// Only used by the Linux network stack, e.g. during ISN generation |
|
439 |
// and in the kernel rng initialization routine. Also used in Linux |
|
440 |
// printk output. |
|
441 |
Time t = Simulator::Now (); |
|
442 |
int64_t us = t.GetMicroSeconds (); |
|
443 |
*sec = us / (1000*1000); |
|
444 |
*usec = us - *sec * (1000*1000); |
|
445 |
} |
|
446 |
||
447 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
448 |
void NscTcpL4Protocol::AddInterface (void) |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
449 |
{ |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
450 |
Ptr<Ipv4> ip = m_node->GetObject<Ipv4> (); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
451 |
const uint32_t nInterfaces = ip->GetNInterfaces (); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
452 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
453 |
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
|
454 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
455 |
// 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
|
456 |
// 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
|
457 |
// 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
|
458 |
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
|
459 |
{ |
4375
db81fdcb06e7
Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
460 |
Ipv4InterfaceAddress ifAddr = ip->GetAddress (i, 0); |
db81fdcb06e7
Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
461 |
Ipv4Address addr = ifAddr.GetLocal (); |
db81fdcb06e7
Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
462 |
Ipv4Mask mask = ifAddr.GetMask (); |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
463 |
uint16_t mtu = ip->GetMtu (i); |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
464 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
465 |
std::ostringstream addrOss, maskOss; |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
466 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
467 |
addr.Print (addrOss); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
468 |
mask.Print (maskOss); |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
469 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
470 |
NS_LOG_LOGIC ("if_attach " << addrOss.str ().c_str () << " " << maskOss.str ().c_str () << " " << mtu); |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
471 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
472 |
std::string addrStr = addrOss.str (); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
473 |
std::string maskStr = maskOss.str (); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
474 |
const char* addrCStr = addrStr.c_str (); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
475 |
const char* maskCStr = maskStr.c_str (); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
476 |
m_nscStack->if_attach (addrCStr, maskCStr, mtu); |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
477 |
|
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
478 |
if (i == 1) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
479 |
{ |
7801
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
480 |
// The NSC stack requires a default gateway and only supports |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
481 |
// single-interface nodes. The below is a hack, but |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
482 |
// it turns out that we can pass the interface address to nsc as |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
483 |
// a default gateway. Bug 1398 has been opened to track this |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
484 |
// issue (NSC's limitation to single-interface nodes) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
485 |
// |
7801
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
486 |
// Previous versions of this code tried to assign the "next" |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
487 |
// IP address of the subnet but this was found to fail for |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
488 |
// some use cases in /30 subnets. |
c4c585d16c68
repair broken nsc workaround that was uncovered by the fix in changeset 62dee74123ca
Tom Henderson <tomh@tomh.org>
parents:
7775
diff
changeset
|
489 |
|
10440
1e48ff9185f1
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10410
diff
changeset
|
490 |
// \todo \bugid{1398} NSC's limitation to single-interface nodes |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
491 |
m_nscStack->add_default_gateway (addrOss.str ().c_str ()); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
492 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
493 |
} |
3717
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
494 |
} |
36bddd3732c7
nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents:
3711
diff
changeset
|
495 |
|
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
496 |
void |
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
497 |
NscTcpL4Protocol::SetDownTarget (IpL4Protocol::DownTargetCallback callback) |
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
498 |
{ |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
499 |
m_downTarget = callback; |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
500 |
} |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
501 |
|
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
502 |
void |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
503 |
NscTcpL4Protocol::SetDownTarget6 (IpL4Protocol::DownTargetCallback6 callback) |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
504 |
{ |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
505 |
} |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
506 |
|
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
507 |
IpL4Protocol::DownTargetCallback |
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
508 |
NscTcpL4Protocol::GetDownTarget (void) const |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
509 |
{ |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
510 |
return m_downTarget; |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
511 |
} |
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6694
diff
changeset
|
512 |
|
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
513 |
IpL4Protocol::DownTargetCallback6 |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
514 |
NscTcpL4Protocol::GetDownTarget6 (void) const |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
515 |
{ |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
516 |
return (IpL4Protocol::DownTargetCallback6)0; |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
517 |
} |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7386
diff
changeset
|
518 |
|
7386
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Mileti? <rivanvx@gmail.com>
parents:
7385
diff
changeset
|
519 |
} // namespace ns3 |
3578 | 520 |