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>
94 virtual void gettime (
unsigned int *,
unsigned int *);
107 m_prot->send_callback (data, datalen);
117 m_prot->gettime (sec,usec);
121 #undef NS_LOG_APPEND_CONTEXT
122 #define NS_LOG_APPEND_CONTEXT \
123 if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
130 .AddConstructor<NscTcpL4Protocol>()
131 .AddAttribute (
"SocketList",
"The list of sockets associated to this protocol.",
134 MakeObjectVectorChecker<NscTcpSocketImpl> ())
135 .AddAttribute (
"Library",
136 "Set the linux library to be used to create the stack",
140 MakeStringChecker ())
161 m_softTimer (
Timer::CANCEL_ON_DESTROY)
232 Ptr<Node>node = this->GetObject<Node> ();
241 tcpFactory->SetTcp (
this);
292 socket->SetTcp (
this);
329 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
331 peerAddress, peerPort);
348 uint32_t packetSize = packet->
GetSize ();
364 packetSize = packet->
GetSize ();
366 uint8_t *buf =
new uint8_t[packetSize];
368 const uint8_t *
data =
const_cast<uint8_t *
>(buf);
394 uint32_t ipv4Saddr, ipv4Daddr;
402 const uint8_t *rawdata =
reinterpret_cast<const uint8_t *
>(
data);
405 p = Create<Packet> (rawdata, datalen);
408 const uint32_t *ipheader =
reinterpret_cast<const uint32_t *
>(
data);
409 ipv4Saddr = *(ipheader+3);
410 ipv4Daddr = *(ipheader+4);
416 NS_ASSERT_MSG (ipv4,
"nsc callback invoked, but node has no ipv4 object");
430 endPoint != endPoints.end (); endPoint++) {
432 (*endPoint)->ForwardUp (NULL,
Ipv4Header (), 0, 0);
443 *sec = us / (1000*1000);
444 *usec = us - *sec * (1000*1000);
451 const uint32_t nInterfaces = ip->GetNInterfaces ();
453 NS_ASSERT_MSG (nInterfaces <= 2,
"nsc does not support multiple interfaces per node");
458 for (uint32_t i = 1; i < nInterfaces; i++)
463 uint16_t mtu = ip->GetMtu (i);
465 std::ostringstream addrOss, maskOss;
467 addr.
Print (addrOss);
468 mask.
Print (maskOss);
470 NS_LOG_LOGIC (
"if_attach " << addrOss.str ().c_str () <<
" " << maskOss.str ().c_str () <<
" " << mtu);
472 std::string addrStr = addrOss.str ();
473 std::string maskStr = maskOss.str ();
474 const char* addrCStr = addrStr.c_str ();
475 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
Deliver complete packet to the NSC network stack.
keep track of time values and allow control of global simulation resolution
void SoftInterrupt(void)
Provide a "soft" interrupt to NSC.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
Ipv4Mask GetMask(void) const
Get the network mask.
virtual void wakeup()
Called by the NSC stack whenever something of interest has happened.
Ipv4Address GetLocal(void) const
Get the local address.
hold variables of type string
a class to represent an Ipv4 address mask
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
bool IsNull(void) const
Check for null implementation.
std::string m_nscLibrary
path to the NSC library.
#define NS_ASSERT(condition)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
EndPoints GetAllEndPoints(void)
Get the entire list of end points registered.
Ptr< Socket > CreateSocket(void)
int external_rand()
External Random number generator.
uint32_t GetSize(void) const
static TypeId GetTypeId(void)
Get the type ID.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
The attribute can be written at construction-time.
void wakeup()
Called by the NSC stack whenever something of interest has happened.
virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
void SetNscLibrary(const std::string &lib)
Set the NSC library to be used.
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual void increment_ticks()=0
Increment the time ticks.
virtual int GetVersion(void) const
Get the NSC version.
Struct interface to NSC send capabilities.
NscInterfaceImpl * m_nscInterface
the NSC Interface.
Demultiplexes packets to various transport layer endpoints.
The attribute can be read.
NscInterfaceImpl(Ptr< NscTcpL4Protocol > prot)
Constructor.
virtual void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
void SetNode(Ptr< Node > node)
Set node associated with this stack.
int64_t GetMicroSeconds(void) const
virtual int get_hz()=0
Get the timer_interrupt frequency.
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
NS_LOG_COMPONENT_DEFINE("NscTcpL4Protocol")
virtual void NotifyNewAggregate()
This method is invoked whenever two sets of objects are aggregated together.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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
Get the NSC library being used.
Ptr< NscTcpL4Protocol > m_prot
the NSC TCP protocol
INetStack *(* FCreateStack)(ISendCallback *, IInterruptCallback *, FRandom)
void AggregateObject(Ptr< Object > other)
void SetDelay(const Time &delay)
#define NS_LOG_LOGIC(msg)
virtual void NotifyNewAggregate(void)
This method is invoked whenever two sets of objects are aggregated together.
Access to the Ipv4 forwarding table, interfaces, and configuration.
Struct interface to NSC soft interrupt capabilities.
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
void AddInterface(void)
Add an interface.
virtual void timer_interrupt()=0
The stack timer_interrupt function.
Implement the Ipv4 layer.
Nsc interface implementation class.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
INetStack * m_nscStack
the NSC stack.
virtual IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)
Called from lower-level layers to send the packet up in the stack.
L4 Protocol abstract base class.
static Time Now(void)
Return the "current simulation time".
void Print(std::ostream &os) const
Print this mask to the given output stream.
virtual void add_default_gateway(const char *addr)=0
Add a default gateway to the interface.
virtual ~NscTcpL4Protocol()
static const uint8_t PROT_NUMBER
protocol number (0x6)
Ptr< Node > m_node
the node this stack is associated with
#define NS_ASSERT_MSG(condition, message)
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
Ipv4 addresses are stored in host order in this class.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
std::vector< Ptr< NscTcpSocketImpl > > m_sockets
list of sockets
a class to store IPv4 address information on an interface
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
virtual int GetProtocolNumber(void) const
virtual void if_attach(const char *addr, const char *mask, int mtu)=0
Attach an interface to the stack.
void Nullify(void)
Discard the implementation, set it to null.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
virtual void if_send_finish(int if_id)=0
Signal the completion of send procedure to the NSC network stack.
virtual void init(int hz)=0
Initialize the stack.
contain a set of ns3::Object pointers.
virtual void gettime(unsigned int *, unsigned int *)
Called by the Linux stack RNG initialization.
Ptr< T > GetObject(void) const
a unique identifier for an interface.
void * m_dlopenHandle
dynamic library handle.
TypeId SetParent(TypeId tid)
void gettime(unsigned int *sec, unsigned int *usec)
Called by the Linux stack RNG initialization.
Timer m_softTimer
Soft interrupt timer.
void AddHeader(const Header &header)
Add header to this packet.
A representation of an internet endpoint/connection.
void send_callback(const void *data, int datalen)
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
virtual void send_callback(const void *data, int datalen)
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.