|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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 ();
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
void * m_dlopenHandle
dynamic library handle.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
virtual void timer_interrupt()=0
The stack timer_interrupt function.
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
void AddHeader(const Header &header)
Add header to this packet.
NscInterfaceImpl * m_nscInterface
the NSC Interface.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void increment_ticks()=0
Increment the time ticks.
bool IsNull(void) const
Check for null implementation.
virtual void gettime(unsigned int *sec, unsigned int *usec)
Called by the Linux stack RNG initialization.
void Print(std::ostream &os) const
Print this mask to the given output stream.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
Ipv4Mask GetMask(void) const
Get the network mask.
Nsc interface implementation class.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void gettime(unsigned int *sec, unsigned int *usec)
Called by the Linux stack RNG initialization.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Ipv4 addresses are stored in host order in this class.
Container for a set of ns3::Object pointers.
void wakeup()
Called by the NSC stack whenever something of interest has happened.
@ ATTR_GET
The attribute can be read.
Ptr< Socket > CreateSocket(void)
INetStack * m_nscStack
the NSC stack.
Nsc wrapper glue, to interface with the Ipv4 protocol underneath.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
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...
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Struct interface to NSC soft interrupt capabilities.
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
virtual ~NscTcpL4Protocol()
A simple virtual Timer class.
Access to the IPv4 forwarding table, interfaces, and configuration.
Smart pointer class similar to boost::intrusive_ptr.
virtual int GetVersion(void) const
Get the NSC version.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static TypeId GetTypeId(void)
Get the type ID.
std::string GetNscLibrary(void) const
Get the NSC library being used.
INetStack *(* FCreateStack)(ISendCallback *, IInterruptCallback *, FRandom)
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
static const uint8_t PROT_NUMBER
protocol number (0x6)
a class to store IPv4 address information on an interface
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
virtual int get_hz()=0
Get the timer_interrupt frequency.
virtual void init(int hz)=0
Initialize the stack.
EndPoints GetAllEndPoints(void)
Get the entire list of end points registered.
Demultiplexes packets to various transport layer endpoints.
virtual void if_attach(const char *addr, const char *mask, int mtu)=0
Attach an interface to the 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.
Simulation virtual time values and global simulation resolution.
void AddInterface(void)
Add an interface.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
std::string m_nscLibrary
path to the NSC library.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.
L4 Protocol abstract base class.
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Hold variables of type string.
std::vector< Ptr< NscTcpSocketImpl > > m_sockets
list of sockets
virtual void DoDispose(void)
Destructor implementation.
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...
static const uint32_t packetSize
void SoftInterrupt(void)
Provide a "soft" interrupt to NSC.
void SetDelay(const Time &delay)
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...
Ptr< Node > m_node
the node this stack is associated with
virtual void if_send_finish(int if_id)=0
Signal the completion of send procedure to the NSC network stack.
virtual void send_callback(const void *data, int datalen)
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
Implement the IPv4 layer.
void send_callback(const void *data, int datalen)
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
a class to represent an Ipv4 address mask
Ipv4Address GetLocal(void) const
Get the local address.
virtual void if_receive_packet(int if_id, const void *data, int datalen)=0
Deliver complete packet to the NSC network stack.
Ptr< NscTcpL4Protocol > m_prot
the NSC TCP protocol
Ptr< const AttributeChecker > MakeStringChecker(void)
virtual void add_default_gateway(const char *addr)=0
Add a default gateway to the interface.
void SetNscLibrary(const std::string &lib)
Set the NSC library to be used.
virtual void wakeup()
Called by the NSC stack whenever something of interest has happened.
Struct interface to NSC send capabilities.
Timer m_softTimer
Soft interrupt timer.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
NscInterfaceImpl(Ptr< NscTcpL4Protocol > prot)
Constructor.
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
virtual void DoDispose(void)
Destructor implementation.
A representation of an internet endpoint/connection.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
int external_rand()
External Random number generator.
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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 Print(std::ostream &os) const
Print this address to the given output stream.
void Nullify(void)
Discard the implementation, set it to null.