From aeca9afe803c2f843acc20098f929d02c8d66f84 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 25 Aug 2009 08:52:57 +0200 Subject: [PATCH] export headers from internet-stack --- src/internet-stack/arp-l3-protocol.h | 3 +- src/internet-stack/nsc-tcp-l4-protocol.cc | 50 +++++++++++++++++------ src/internet-stack/nsc-tcp-l4-protocol.h | 44 ++++++++++---------- src/internet-stack/nsc-tcp-socket-impl.cc | 12 ------ src/internet-stack/nsc-tcp-socket-impl.h | 5 +-- src/internet-stack/tcp-l4-protocol.cc | 12 +++--- src/internet-stack/tcp-l4-protocol.h | 12 +++--- src/internet-stack/tcp-socket-impl.cc | 2 + src/internet-stack/tcp-test.cc | 11 ++--- src/internet-stack/udp-l4-protocol.h | 3 +- src/internet-stack/wscript | 10 ++++- 11 files changed, 92 insertions(+), 72 deletions(-) diff --git a/src/internet-stack/arp-l3-protocol.h b/src/internet-stack/arp-l3-protocol.h index 1256e8c40..7f0294e9f 100644 --- a/src/internet-stack/arp-l3-protocol.h +++ b/src/internet-stack/arp-l3-protocol.h @@ -26,14 +26,13 @@ #include "ns3/ptr.h" #include "ns3/traced-callback.h" -#include "ipv4-interface.h" - namespace ns3 { class ArpCache; class NetDevice; class Node; class Packet; +class Ipv4Interface; /** * \ingroup internetStack diff --git a/src/internet-stack/nsc-tcp-l4-protocol.cc b/src/internet-stack/nsc-tcp-l4-protocol.cc index f8af6ec79..1eda795b3 100644 --- a/src/internet-stack/nsc-tcp-l4-protocol.cc +++ b/src/internet-stack/nsc-tcp-l4-protocol.cc @@ -32,8 +32,10 @@ #include "ipv4-end-point.h" #include "ipv4-l3-protocol.h" #include "nsc-tcp-l4-protocol.h" +#include "nsc-tcp-socket-impl.h" #include "nsc-sysctl.h" #include "nsc-tcp-socket-factory-impl.h" +#include "sim_interface.h" #include "tcp-typedefs.h" @@ -54,13 +56,39 @@ NS_OBJECT_ENSURE_REGISTERED (NscTcpL4Protocol); /* see http://www.iana.org/assignments/protocol-numbers */ const uint8_t NscTcpL4Protocol::PROT_NUMBER = 6; -ObjectFactory -NscTcpL4Protocol::GetDefaultRttEstimatorFactory (void) +class NscInterfaceImpl : public ISendCallback, public IInterruptCallback { - ObjectFactory factory; - factory.SetTypeId (RttMeanDeviation::GetTypeId ()); - return factory; +public: + NscInterfaceImpl (Ptr prot); +private: + virtual void send_callback(const void *data, int datalen); + virtual void wakeup(); + virtual void gettime(unsigned int *, unsigned int *); +private: + Ptr m_prot; +}; + +NscInterfaceImpl::NscInterfaceImpl (Ptr prot) + : m_prot (prot) +{} + +void +NscInterfaceImpl::send_callback(const void *data, int datalen) +{ + m_prot->send_callback (data, datalen); } +void +NscInterfaceImpl::wakeup() +{ + m_prot->wakeup (); +} +void +NscInterfaceImpl::gettime(unsigned int *sec, unsigned int *usec) +{ + m_prot->gettime (sec,usec); +} + + TypeId NscTcpL4Protocol::GetTypeId (void) @@ -68,11 +96,6 @@ NscTcpL4Protocol::GetTypeId (void) static TypeId tid = TypeId ("ns3::NscTcpL4Protocol") .SetParent () .AddConstructor() - .AddAttribute ("RttEstimatorFactory", - "How RttEstimator objects are created.", - ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), - MakeObjectFactoryAccessor (&NscTcpL4Protocol::m_rttFactory), - MakeObjectFactoryChecker ()) .AddAttribute ("SocketList", "The list of sockets associated to this protocol.", ObjectVectorValue (), MakeObjectVectorAccessor (&NscTcpL4Protocol::m_sockets), @@ -95,6 +118,7 @@ int external_rand() NscTcpL4Protocol::NscTcpL4Protocol () : m_endPoints (new Ipv4EndPointDemux ()), m_nscStack (0), + m_nscInterface (new NscInterfaceImpl (this)), m_softTimer (Timer::CANCEL_ON_DESTROY) { m_dlopenHandle = NULL; @@ -139,7 +163,7 @@ NscTcpL4Protocol::SetNode (Ptr node) FCreateStack create = (FCreateStack)dlsym(m_dlopenHandle, "nsc_create_stack"); NS_ASSERT(create); - m_nscStack = create(this, this, external_rand); + m_nscStack = create(m_nscInterface, m_nscInterface, external_rand); int hzval = m_nscStack->get_hz(); NS_ASSERT(hzval > 0); @@ -212,6 +236,8 @@ NscTcpL4Protocol::DoDispose (void) m_endPoints = 0; } m_node = 0; + delete m_nscInterface; + m_nscInterface = 0; Ipv4L4Protocol::DoDispose (); } @@ -220,11 +246,9 @@ NscTcpL4Protocol::CreateSocket (void) { NS_LOG_FUNCTION (this); - Ptr rtt = m_rttFactory.Create (); Ptr socket = CreateObject (); socket->SetNode (m_node); socket->SetTcp (this); - socket->SetRtt (rtt); m_sockets.push_back (socket); return socket; } diff --git a/src/internet-stack/nsc-tcp-l4-protocol.h b/src/internet-stack/nsc-tcp-l4-protocol.h index c099dfc13..91ccd5963 100644 --- a/src/internet-stack/nsc-tcp-l4-protocol.h +++ b/src/internet-stack/nsc-tcp-l4-protocol.h @@ -23,27 +23,27 @@ #include "ns3/ipv4-address.h" #include "ns3/ptr.h" #include "ns3/object-factory.h" -#include "ipv4-end-point-demux.h" -#include "ipv4-l4-protocol.h" -#include "ipv4-interface.h" - -#include "tcp-header.h" - #include "ns3/timer.h" -#include "sim_interface.h" -#include "nsc-tcp-socket-impl.h" +#include "ipv4-l4-protocol.h" + +struct INetStack; namespace ns3 { class Node; class Socket; -class TcpHeader; +class Ipv4EndPointDemux; +class Ipv4Interface; +class NscTcpSocketImpl; +class Ipv4EndPoint; +class NscInterfaceImpl; + /** * \ingroup nsctcp * * \brief Nsc wrapper glue, to interface with the Ipv4 protocol underneath. */ -class NscTcpL4Protocol : public Ipv4L4Protocol, ISendCallback, IInterruptCallback { +class NscTcpL4Protocol : public Ipv4L4Protocol { public: static const uint8_t PROT_NUMBER; static TypeId GetTypeId (void); @@ -86,6 +86,10 @@ public: Ipv4Address const &destination, Ptr incomingInterface); +protected: + virtual void DoDispose (void); + virtual void NotifyNewAggregate (); +private: // NSC callbacks. // NSC invokes these hooks to interact with the simulator. // In any case, these methods are only to be called by NSC. @@ -93,29 +97,23 @@ public: // send_callback is invoked by NSCs 'ethernet driver' to re-inject // a packet (i.e. an octet soup consisting of an IP Header, TCP Header // and user payload, if any), into ns-3. - virtual void send_callback(const void *data, int datalen); + void send_callback(const void *data, int datalen); // This is called by the NSC stack whenever something of interest // has happened, e.g. when data arrives on a socket, a listen socket // has a new connection pending, etc. - virtual void wakeup(); + void wakeup(); // This is called by the Linux stack RNG initialization. // Its also used by the cradle code to add a timestamp to // printk/printf/debug output. - virtual void gettime(unsigned int *, unsigned int *); - -protected: - virtual void DoDispose (void); - virtual void NotifyNewAggregate (); -private: - Ptr m_node; - Ipv4EndPointDemux *m_endPoints; - ObjectFactory m_rttFactory; -private: + void gettime(unsigned int *sec, unsigned int *usec); void AddInterface (void); void SoftInterrupt (void); - static ObjectFactory GetDefaultRttEstimatorFactory (void); + friend class NscInterfaceImpl; friend class NscTcpSocketImpl; + Ptr m_node; + Ipv4EndPointDemux *m_endPoints; INetStack* m_nscStack; + NscInterfaceImpl *m_nscInterface; void *m_dlopenHandle; std::string m_nscLibrary; Timer m_softTimer; diff --git a/src/internet-stack/nsc-tcp-socket-impl.cc b/src/internet-stack/nsc-tcp-socket-impl.cc index 69f4a68b7..9718b3a35 100644 --- a/src/internet-stack/nsc-tcp-socket-impl.cc +++ b/src/internet-stack/nsc-tcp-socket-impl.cc @@ -74,7 +74,6 @@ NscTcpSocketImpl::GetTypeId () m_state (CLOSED), m_closeOnEmpty (false), m_txBufferSize (0), - m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)) { NS_LOG_FUNCTION (this); @@ -104,7 +103,6 @@ NscTcpSocketImpl::NscTcpSocketImpl(const NscTcpSocketImpl& sock) m_cWnd (sock.m_cWnd), m_ssThresh (sock.m_ssThresh), m_initialCWnd (sock.m_initialCWnd), - m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)), m_cnTimeout (sock.m_cnTimeout), m_cnCount (sock.m_cnCount), @@ -119,11 +117,6 @@ NscTcpSocketImpl::NscTcpSocketImpl(const NscTcpSocketImpl& sock) { m_txBuffer = sock.m_txBuffer; } - //copy the rtt if necessary - if (sock.m_rtt) - { - m_rtt = sock.m_rtt->Copy(); - } //can't "copy" the endpoint just yes, must do this when we know the peer info //too; this is in SYN_ACK_TX } @@ -165,11 +158,6 @@ NscTcpSocketImpl::SetTcp (Ptr tcp) m_nscTcpSocket = tcp->m_nscStack->new_tcp_socket(); m_tcp = tcp; } -void -NscTcpSocketImpl::SetRtt (Ptr rtt) -{ - m_rtt = rtt; -} enum Socket::SocketErrno diff --git a/src/internet-stack/nsc-tcp-socket-impl.h b/src/internet-stack/nsc-tcp-socket-impl.h index fa142615c..8269dc35f 100644 --- a/src/internet-stack/nsc-tcp-socket-impl.h +++ b/src/internet-stack/nsc-tcp-socket-impl.h @@ -30,7 +30,8 @@ #include "tcp-typedefs.h" #include "pending-data.h" #include "sequence-number.h" -#include "rtt-estimator.h" + +struct INetStreamSocket; namespace ns3 { @@ -63,7 +64,6 @@ public: void SetNode (Ptr node); void SetTcp (Ptr tcp); - void SetRtt (Ptr rtt); virtual enum SocketErrno GetErrno (void) const; virtual Ptr GetNode (void) const; @@ -158,7 +158,6 @@ private: uint32_t m_initialCWnd; //Initial cWnd value // Round trip time estimation - Ptr m_rtt; Time m_lastMeasuredRtt; // Timer-related members diff --git a/src/internet-stack/tcp-l4-protocol.cc b/src/internet-stack/tcp-l4-protocol.cc index 433ea7dbd..f67234a6b 100644 --- a/src/internet-stack/tcp-l4-protocol.cc +++ b/src/internet-stack/tcp-l4-protocol.cc @@ -34,7 +34,8 @@ #include "ipv4-end-point.h" #include "ipv4-l3-protocol.h" #include "tcp-socket-factory-impl.h" - +#include "tcp-socket-impl.h" +#include "rtt-estimator.h" #include "tcp-typedefs.h" #include @@ -558,17 +559,18 @@ TcpL4Protocol::Send (Ptr packet, } void -TcpL4Protocol::SendPacket (Ptr packet, TcpHeader outgoingHeader, +TcpL4Protocol::SendPacket (Ptr packet, const TcpHeader &outgoing, Ipv4Address saddr, Ipv4Address daddr) { NS_LOG_LOGIC("TcpL4Protocol " << this - << " sending seq " << outgoingHeader.GetSequenceNumber() - << " ack " << outgoingHeader.GetAckNumber() - << " flags " << std::hex << (int)outgoingHeader.GetFlags() << std::dec + << " sending seq " << outgoing.GetSequenceNumber() + << " ack " << outgoing.GetAckNumber() + << " flags " << std::hex << (int)outgoing.GetFlags() << std::dec << " data size " << packet->GetSize()); NS_LOG_FUNCTION (this << packet << saddr << daddr); // XXX outgoingHeader cannot be logged + TcpHeader outgoingHeader = outgoing; outgoingHeader.SetLength (5); //header length in units of 32bit words /* outgoingHeader.SetUrgentPointer (0); //XXX */ if(Node::ChecksumEnabled ()) diff --git a/src/internet-stack/tcp-l4-protocol.h b/src/internet-stack/tcp-l4-protocol.h index b610471c7..67a0645ee 100644 --- a/src/internet-stack/tcp-l4-protocol.h +++ b/src/internet-stack/tcp-l4-protocol.h @@ -27,19 +27,17 @@ #include "ns3/ipv4-address.h" #include "ns3/ptr.h" #include "ns3/object-factory.h" -#include "ipv4-end-point-demux.h" #include "ipv4-l4-protocol.h" -#include "ipv4-interface.h" - -#include "tcp-socket-impl.h" -#include "tcp-header.h" -#include "tcp-typedefs.h" namespace ns3 { class Node; class Socket; class TcpHeader; +class Ipv4EndPointDemux; +class Ipv4Interface; +class TcpSocketImpl; +class Ipv4EndPoint; /** * \ingroup tcp @@ -120,7 +118,7 @@ private: ObjectFactory m_rttFactory; private: friend class TcpSocketImpl; - void SendPacket (Ptr, TcpHeader, + void SendPacket (Ptr, const TcpHeader &, Ipv4Address, Ipv4Address); static ObjectFactory GetDefaultRttEstimatorFactory (void); diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index bdfb06ba5..3ca7ac8f0 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -36,6 +36,8 @@ #include "tcp-socket-impl.h" #include "tcp-l4-protocol.h" #include "ipv4-end-point.h" +#include "tcp-header.h" +#include "rtt-estimator.h" #include diff --git a/src/internet-stack/tcp-test.cc b/src/internet-stack/tcp-test.cc index 7bf53521a..870fe050b 100644 --- a/src/internet-stack/tcp-test.cc +++ b/src/internet-stack/tcp-test.cc @@ -31,17 +31,18 @@ #include "ns3/simple-net-device.h" #include "ns3/drop-tail-queue.h" #include "ns3/config.h" +#include "ns3/ipv4-static-routing.h" +#include "ns3/ipv4-list-routing.h" +#include "ns3/node.h" +#include "ns3/inet-socket-address.h" +#include "ns3/uinteger.h" + #include "ipv4-end-point.h" #include "arp-l3-protocol.h" #include "ipv4-l3-protocol.h" #include "icmpv4-l4-protocol.h" #include "udp-l4-protocol.h" #include "tcp-l4-protocol.h" -#include "ns3/ipv4-static-routing.h" -#include "ns3/ipv4-list-routing.h" - -#include "ns3/node.h" -#include "ns3/inet-socket-address.h" #include diff --git a/src/internet-stack/udp-l4-protocol.h b/src/internet-stack/udp-l4-protocol.h index 50794d2c2..4c44280a7 100644 --- a/src/internet-stack/udp-l4-protocol.h +++ b/src/internet-stack/udp-l4-protocol.h @@ -26,7 +26,6 @@ #include "ns3/packet.h" #include "ns3/ipv4-address.h" #include "ns3/ptr.h" -#include "ipv4-end-point-demux.h" #include "ipv4-l4-protocol.h" namespace ns3 { @@ -34,6 +33,8 @@ namespace ns3 { class Node; class Socket; class Ipv4Route; +class Ipv4EndPointDemux; +class Ipv4EndPoint; /** * \ingroup udp * \brief Implementation of the UDP protocol diff --git a/src/internet-stack/wscript b/src/internet-stack/wscript index 0f1396be4..dec9a0af4 100644 --- a/src/internet-stack/wscript +++ b/src/internet-stack/wscript @@ -121,11 +121,19 @@ def build(bld): 'sequence-number.h', 'icmpv4.h', 'icmpv6-header.h', - ] + 'ipv4-l3-protocol.h', + 'arp-l3-protocol.h', + 'udp-l4-protocol.h', + 'tcp-l4-protocol.h', + 'icmpv4-l4-protocol.h', + 'ipv4-l4-protocol.h', + 'arp-cache.h', + ] if bld.env['NSC_ENABLED']: obj.source.append ('nsc-tcp-socket-impl.cc') obj.source.append ('nsc-tcp-l4-protocol.cc') obj.source.append ('nsc-tcp-socket-factory-impl.cc') obj.source.append ('nsc-sysctl.cc') + headers.source.append('nsc-tcp-l4-protocol.h') obj.uselib = 'DL'