20 #include "ns3/assert.h"
22 #include "ns3/nstime.h"
24 #include "ns3/packet.h"
26 #include "ns3/ipv4-route.h"
28 #include "ns3/object-vector.h"
29 #include "ns3/string.h"
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
64 virtual void gettime (
unsigned int *,
unsigned int *);
77 m_prot->send_callback (data, datalen);
87 m_prot->gettime (sec,usec);
91 #undef NS_LOG_APPEND_CONTEXT
92 #define NS_LOG_APPEND_CONTEXT \
93 if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
100 .AddConstructor<NscTcpL4Protocol>()
101 .AddAttribute (
"SocketList",
"The list of sockets associated to this protocol.",
104 MakeObjectVectorChecker<NscTcpSocketImpl> ())
105 .AddAttribute (
"Library",
106 "Set the linux library to be used to create the stack",
110 MakeStringChecker ())
124 m_softTimer (
Timer::CANCEL_ON_DESTROY)
195 Ptr<Node>node = this->GetObject<Node> ();
204 tcpFactory->SetTcp (
this);
255 socket->SetTcp (
this);
292 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
294 peerAddress, peerPort);
311 uint32_t packetSize = packet->
GetSize ();
327 packetSize = packet->
GetSize ();
329 uint8_t *buf =
new uint8_t[packetSize];
331 const uint8_t *
data =
const_cast<uint8_t *
>(buf);
357 uint32_t ipv4Saddr, ipv4Daddr;
365 const uint8_t *rawdata =
reinterpret_cast<const uint8_t *
>(
data);
368 p = Create<Packet> (rawdata, datalen);
371 const uint32_t *ipheader =
reinterpret_cast<const uint32_t *
>(
data);
372 ipv4Saddr = *(ipheader+3);
373 ipv4Daddr = *(ipheader+4);
379 NS_ASSERT_MSG (ipv4,
"nsc callback invoked, but node has no ipv4 object");
393 endPoint != endPoints.end (); endPoint++) {
395 (*endPoint)->ForwardUp (NULL,
Ipv4Header (), 0, 0);
406 *sec = us / (1000*1000);
407 *usec = us - *sec * (1000*1000);
414 const uint32_t nInterfaces = ip->GetNInterfaces ();
416 NS_ASSERT_MSG (nInterfaces <= 2,
"nsc does not support multiple interfaces per node");
421 for (uint32_t i = 1; i < nInterfaces; i++)
426 uint16_t mtu = ip->GetMtu (i);
428 std::ostringstream addrOss, maskOss;
430 addr.
Print (addrOss);
431 mask.
Print (maskOss);
433 NS_LOG_LOGIC (
"if_attach " << addrOss.str ().c_str () <<
" " << maskOss.str ().c_str () <<
" " << mtu);
435 std::string addrStr = addrOss.str ();
436 std::string maskStr = maskOss.str ();
437 const char* addrCStr = addrStr.c_str ();
438 const char* maskCStr = maskStr.c_str ();
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
virtual void if_receive_packet(int if_id, const void *data, int datalen)=0
keep track of time values and allow control of global simulation resolution
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
Ipv4Mask GetMask(void) const
Ipv4Address GetLocal(void) const
hold variables of type string
a class to represent an Ipv4 address mask
IpL4Protocol::DownTargetCallback m_downTarget
#define NS_ASSERT(condition)
EndPoints GetAllEndPoints(void)
#define NS_LOG_COMPONENT_DEFINE(name)
Ptr< Socket > CreateSocket(void)
uint32_t GetSize(void) const
static TypeId GetTypeId(void)
virtual void DoDispose(void)
virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
void SetNscLibrary(const std::string &lib)
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual void increment_ticks()=0
virtual int GetVersion(void) const
NscInterfaceImpl * m_nscInterface
Demultiplexes packets to various transport layer endpoints.
NscInterfaceImpl(Ptr< NscTcpL4Protocol > prot)
virtual void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb)
void SetNode(Ptr< Node > node)
int64_t GetMicroSeconds(void) const
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual void NotifyNewAggregate()
virtual void DoDispose(void)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
void Print(std::ostream &os) const
Print this address to the given output stream.
std::string GetNscLibrary(void) const
Ptr< NscTcpL4Protocol > m_prot
INetStack *(* FCreateStack)(ISendCallback *, IInterruptCallback *, FRandom)
void AggregateObject(Ptr< Object > other)
void SetDelay(const Time &delay)
#define NS_LOG_LOGIC(msg)
virtual void NotifyNewAggregate(void)
Access to the Ipv4 forwarding table, interfaces, and configuration.
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
virtual void timer_interrupt()=0
Implement the Ipv4 layer.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
virtual IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)
Receive a packet up the protocol stack.
NscTcpL4Protocol()
Constructor.
L4 Protocol abstract base class.
void Print(std::ostream &os) const
Print this mask to the given output stream.
virtual void add_default_gateway(const char *addr)=0
virtual ~NscTcpL4Protocol()
static const uint8_t PROT_NUMBER
#define NS_ASSERT_MSG(condition, message)
Ipv4EndPointDemux * m_endPoints
Ipv4 addresses are stored in host order in this class.
std::list< Ipv4EndPoint * > EndPoints
std::vector< Ptr< NscTcpSocketImpl > > m_sockets
a class to store IPv4 address information on an interface
void DeAllocate(Ipv4EndPoint *endPoint)
virtual int GetProtocolNumber(void) const
virtual void if_attach(const char *addr, const char *mask, int mtu)=0
std::list< Ipv4EndPoint * >::iterator EndPointsI
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Ipv4EndPoint * Allocate(void)
virtual void if_send_finish(int if_id)=0
virtual void init(int hz)=0
contain a set of ns3::Object pointers.
virtual void gettime(unsigned int *, unsigned int *)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void gettime(unsigned int *sec, unsigned int *usec)
void AddHeader(const Header &header)
A representation of an internet endpoint/connection.
void send_callback(const void *data, int datalen)
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
virtual void send_callback(const void *data, int datalen)
Ipv4EndPoint * Allocate(void)