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>
97 virtual void gettime (
unsigned int *sec,
unsigned int *usec);
120 m_prot->gettime (sec,usec);
124 #undef NS_LOG_APPEND_CONTEXT
125 #define NS_LOG_APPEND_CONTEXT \
126 if (m_node) { std::clog << Simulator::Now ().As (Time::S) << " [node " << m_node->GetId () << "] "; }
133 .SetGroupName (
"Internet")
135 .AddAttribute (
"SocketList",
"The list of sockets associated to this protocol.",
138 MakeObjectVectorChecker<NscTcpSocketImpl> ())
139 .AddAttribute (
"Library",
140 "Set the linux library to be used to create the stack",
165 m_softTimer (
Timer::CANCEL_ON_DESTROY)
236 Ptr<Node>node = this->GetObject<Node> ();
245 tcpFactory->SetTcp (
this);
296 socket->SetTcp (
this);
334 NS_LOG_FUNCTION (
this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
336 localAddress, localPort,
337 peerAddress, peerPort);
374 const uint8_t *
data =
const_cast<uint8_t *
>(buf);
400 uint32_t ipv4Saddr, ipv4Daddr;
408 const uint8_t *rawdata =
reinterpret_cast<const uint8_t *
>(
data);
411 p = Create<Packet> (rawdata, datalen);
414 const uint32_t *ipheader =
reinterpret_cast<const uint32_t *
>(
data);
415 ipv4Saddr = *(ipheader+3);
416 ipv4Daddr = *(ipheader+4);
422 NS_ASSERT_MSG (ipv4,
"nsc callback invoked, but node has no ipv4 object");
436 endPoint != endPoints.end (); endPoint++) {
438 (*endPoint)->ForwardUp (NULL,
Ipv4Header (), 0, 0);
449 *sec = us / (1000*1000);
450 *usec = us - *sec * (1000*1000);
457 const uint32_t nInterfaces = ip->GetNInterfaces ();
459 NS_ASSERT_MSG (nInterfaces <= 2,
"nsc does not support multiple interfaces per node");
464 for (uint32_t i = 1; i < nInterfaces; i++)
469 uint16_t mtu = ip->GetMtu (i);
471 std::ostringstream addrOss, maskOss;
473 addr.
Print (addrOss);
474 mask.
Print (maskOss);
476 NS_LOG_LOGIC (
"if_attach " << addrOss.str ().c_str () <<
" " << maskOss.str ().c_str () <<
" " << mtu);
478 std::string addrStr = addrOss.str ();
479 std::string maskStr = maskOss.str ();
480 const char* addrCStr = addrStr.c_str ();
481 const char* maskCStr = maskStr.c_str ();
bool IsNull(void) const
Check for null implementation.
void Nullify(void)
Discard the implementation, set it to null.
L4 Protocol abstract base class.
Ipv4 addresses are stored in host order in this class.
void Print(std::ostream &os) const
Print this address to the given output stream.
Demultiplexes packets to various transport layer endpoints.
EndPoints GetAllEndPoints(void)
Get the entire list of end points registered.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
A representation of an internet endpoint/connection.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Ipv4Mask GetMask(void) const
Get the network mask.
Ipv4Address GetLocal(void) const
Get the local address.
Implement the IPv4 layer.
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
a class to represent an Ipv4 address mask
void Print(std::ostream &os) const
Print this mask to the given output stream.
Nsc interface implementation class.
virtual void gettime(unsigned int *sec, unsigned int *usec)
Called by the Linux stack RNG initialization.
Ptr< NscTcpL4Protocol > m_prot
the NSC TCP protocol
NscInterfaceImpl(Ptr< NscTcpL4Protocol > prot)
Constructor.
virtual void send_callback(const void *data, int datalen)
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
virtual void wakeup()
Called by the NSC stack whenever something of interest has happened.
Nsc wrapper glue, to interface with the Ipv4 protocol underneath.
Timer m_softTimer
Soft interrupt timer.
Ptr< Node > m_node
the node this stack is associated with
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...
static TypeId GetTypeId(void)
Get the type ID.
std::string m_nscLibrary
path to the NSC library.
std::string GetNscLibrary(void) const
Get the NSC library being used.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
void AddInterface(void)
Add an interface.
Ptr< Socket > CreateSocket(void)
void SetNode(Ptr< Node > node)
Set node associated with this stack.
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...
virtual ~NscTcpL4Protocol()
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
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.
void send_callback(const void *data, int datalen)
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
void gettime(unsigned int *sec, unsigned int *usec)
Called by the Linux stack RNG initialization.
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...
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
void SoftInterrupt(void)
Provide a "soft" interrupt to NSC.
NscInterfaceImpl * m_nscInterface
the NSC Interface.
void SetNscLibrary(const std::string &lib)
Set the NSC library to be used.
virtual void DoDispose(void)
Destructor implementation.
std::vector< Ptr< NscTcpSocketImpl > > m_sockets
list of sockets
void wakeup()
Called by the NSC stack whenever something of interest has happened.
INetStack * m_nscStack
the NSC stack.
void * m_dlopenHandle
dynamic library handle.
virtual int GetVersion(void) const
Get the NSC version.
static const uint8_t PROT_NUMBER
protocol number (0x6)
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...
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
virtual void DoDispose(void)
Destructor implementation.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Container for a set of ns3::Object pointers.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Smart pointer class similar to boost::intrusive_ptr.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
static Time Now(void)
Return the current simulation virtual time.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
A simple virtual Timer class.
void SetDelay(const Time &delay)
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
a unique identifier for an interface.
@ ATTR_GET
The attribute can be read.
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeStringChecker(void)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int external_rand()
External Random number generator.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
INetStack *(* FCreateStack)(ISendCallback *, IInterruptCallback *, FRandom)
Struct interface to NSC soft interrupt capabilities.
virtual int get_hz()=0
Get the timer_interrupt frequency.
virtual void init(int hz)=0
Initialize the stack.
virtual void if_receive_packet(int if_id, const void *data, int datalen)=0
Deliver complete packet to the NSC network stack.
virtual void add_default_gateway(const char *addr)=0
Add a default gateway to the interface.
virtual void increment_ticks()=0
Increment the time ticks.
virtual void if_attach(const char *addr, const char *mask, int mtu)=0
Attach an interface to the stack.
virtual void timer_interrupt()=0
The stack timer_interrupt function.
virtual void if_send_finish(int if_id)=0
Signal the completion of send procedure to the NSC network stack.
Struct interface to NSC send capabilities.
static const uint32_t packetSize