nsc: move nsc glue code from nsc-tcp-l4-protocol to node/nsc-glue.cc.
known problems:
- sim_interface.h is duplicated
- nsc-glue.cc adds hooks in node.cc, "hijacks" incoming packets
- nsc-glue exports NSCs INetStack (instead of wrapping it completely)
- nsc-tcp-l4-protocol and nsc-tcp-socket-impl make calls into nsc-glue
- nsc-tcp-socket-impl should really be "nsc-socket-core" (or something
like that)
needs fixing on nsc side:
- no support for multiple interfaces yet (also not yet supported
on nsc side)
- nsc initialisation still tied to IP (Adding an Interface and assigning the
IP address is a single step; it should be separate)
maybe there is more.
There is a NSC_NEXT define in nsc-glue.h, its main purpose is to flag
the places where the NSC API needs to be adapted to support multiple
interfaces in nsc.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
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;
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.
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
16 * based on earlier integration work by Tom Henderson and Sam Jansen.
17 * 2008 Florian Westphal <fw@strlen.de>
20 #include "ns3/assert.h"
23 #include "ns3/packet.h"
25 #include "ns3/ipv4-route.h"
27 #include "ns3/object-vector.h"
28 #include "ns3/string.h"
29 #include "tcp-header.h"
30 #include "ipv4-end-point-demux.h"
31 #include "ipv4-end-point.h"
32 #include "ipv4-l3-protocol.h"
33 #include "nsc-tcp-l4-protocol.h"
35 #include "nsc-tcp-socket-factory-impl.h"
37 #include "tcp-typedefs.h"
44 #include <netinet/in.h>
45 #include <arpa/inet.h>
47 NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol");
51 NS_OBJECT_ENSURE_REGISTERED (NscTcpL4Protocol);
53 /* see http://www.iana.org/assignments/protocol-numbers */
54 const uint8_t NscTcpL4Protocol::PROT_NUMBER = 6;
57 NscTcpL4Protocol::GetDefaultRttEstimatorFactory (void)
59 ObjectFactory factory;
60 factory.SetTypeId (RttMeanDeviation::GetTypeId ());
65 NscTcpL4Protocol::GetTypeId (void)
67 static TypeId tid = TypeId ("ns3::NscTcpL4Protocol")
68 .SetParent<Ipv4L4Protocol> ()
69 .AddConstructor<NscTcpL4Protocol>()
70 .AddAttribute ("RttEstimatorFactory",
71 "How RttEstimator objects are created.",
72 ObjectFactoryValue (GetDefaultRttEstimatorFactory ()),
73 MakeObjectFactoryAccessor (&NscTcpL4Protocol::m_rttFactory),
74 MakeObjectFactoryChecker ())
75 .AddAttribute ("SocketList", "The list of sockets associated to this protocol.",
77 MakeObjectVectorAccessor (&NscTcpL4Protocol::m_sockets),
78 MakeObjectVectorChecker<NscTcpSocketImpl> ())
79 .AddAttribute ("Library",
80 "Set the linux library to be used to create the stack",
81 TypeId::ATTR_GET|TypeId::ATTR_CONSTRUCT,
82 StringValue("liblinux2.6.26.so"),
83 MakeStringAccessor (&NscTcpL4Protocol::GetNscLibrary,&NscTcpL4Protocol::SetNscLibrary),
89 NscTcpL4Protocol::NscTcpL4Protocol ()
90 : m_endPoints (new Ipv4EndPointDemux ())
92 NS_LOG_LOGIC("Made a NscTcpL4Protocol "<<this);
96 NscTcpL4Protocol::SetNscLibrary(const std::string &soname)
100 m_nscLibrary = soname;
105 NscTcpL4Protocol::GetNscLibrary () const
112 NscTcpL4Protocol::SetNode (Ptr<Node> node)
115 m_node->SetNscLibrary (m_nscLibrary);
116 m_node->RegisterNscWakeupCallback (MakeCallback (&NscTcpL4Protocol::Wakeup , this));
120 NscTcpL4Protocol::NotifyNewAggregate ()
124 Ptr<Node>node = this->GetObject<Node> ();
127 Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
130 this->SetNode (node);
132 Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
133 tcpFactory->SetTcp (this);
134 node->AggregateObject (tcpFactory);
138 Object::NotifyNewAggregate ();
142 NscTcpL4Protocol::GetProtocolNumber (void) const
147 NscTcpL4Protocol::GetVersion (void) const
153 NscTcpL4Protocol::DoDispose (void)
155 NS_LOG_FUNCTION (this);
157 for (std::vector<Ptr<NscTcpSocketImpl> >::iterator i = m_sockets.begin (); i != m_sockets.end (); i++)
164 if (m_endPoints != 0)
170 Ipv4L4Protocol::DoDispose ();
174 NscTcpL4Protocol::CreateSocket (void)
176 NS_LOG_FUNCTION (this);
178 Ptr<RttEstimator> rtt = m_rttFactory.Create<RttEstimator> ();
179 Ptr<NscTcpSocketImpl> socket = CreateObject<NscTcpSocketImpl> ();
180 socket->SetNode (m_node);
181 socket->SetTcp (this);
182 socket->SetRtt (rtt);
183 m_sockets.push_back (socket);
188 NscTcpL4Protocol::Allocate (void)
190 NS_LOG_FUNCTION (this);
191 return m_endPoints->Allocate ();
195 NscTcpL4Protocol::Allocate (Ipv4Address address)
197 NS_LOG_FUNCTION (this << address);
198 return m_endPoints->Allocate (address);
202 NscTcpL4Protocol::Allocate (uint16_t port)
204 NS_LOG_FUNCTION (this << port);
205 return m_endPoints->Allocate (port);
209 NscTcpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
211 NS_LOG_FUNCTION (this << address << port);
212 return m_endPoints->Allocate (address, port);
216 NscTcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
217 Ipv4Address peerAddress, uint16_t peerPort)
219 NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
220 return m_endPoints->Allocate (localAddress, localPort,
221 peerAddress, peerPort);
225 NscTcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint)
227 NS_LOG_FUNCTION (this << endPoint);
228 m_endPoints->DeAllocate (endPoint);
231 void NscTcpL4Protocol::Wakeup()
234 // this should schedule a timer to read from all tcp sockets now... this is
235 // an indication that data might be waiting on the socket
237 Ipv4EndPointDemux::EndPoints endPoints = m_endPoints->GetAllEndPoints ();
238 for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
239 endPoint != endPoints.end (); endPoint++) {
240 // NSC HACK: (ab)use TcpSocket::ForwardUp for signalling
241 (*endPoint)->ForwardUp (NULL, Ipv4Address(), 0);
245 Ipv4L4Protocol::RxStatus
246 NscTcpL4Protocol::Receive (Ptr<Packet> p,
247 Ipv4Address const &source,
248 Ipv4Address const &destination,
249 Ptr<Ipv4Interface> incomingInterface)
250 { // STUB, RX happens in node/node.cc if NSC is in use.
251 return Ipv4L4Protocol::RX_OK;