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>
93 virtual void gettime (
unsigned int *,
unsigned int *);
106 m_prot->send_callback (data, datalen);
116 m_prot->gettime (sec,usec);
120 #undef NS_LOG_APPEND_CONTEXT
121 #define NS_LOG_APPEND_CONTEXT \
122 if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
129 .AddConstructor<NscTcpL4Protocol>()
130 .AddAttribute (
"SocketList",
"The list of sockets associated to this protocol.",
133 MakeObjectVectorChecker<NscTcpSocketImpl> ())
134 .AddAttribute (
"Library",
135 "Set the linux library to be used to create the stack",
139 MakeStringChecker ())
160 m_softTimer (
Timer::CANCEL_ON_DESTROY)
231 Ptr<Node>node = this->GetObject<Node> ();
240 tcpFactory->SetTcp (
this);
291 socket->SetTcp (
this);
328 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
330 peerAddress, peerPort);
347 uint32_t packetSize = packet->
GetSize ();
363 packetSize = packet->
GetSize ();
365 uint8_t *buf =
new uint8_t[packetSize];
367 const uint8_t *
data =
const_cast<uint8_t *
>(buf);
393 uint32_t ipv4Saddr, ipv4Daddr;
401 const uint8_t *rawdata =
reinterpret_cast<const uint8_t *
>(
data);
404 p = Create<Packet> (rawdata, datalen);
407 const uint32_t *ipheader =
reinterpret_cast<const uint32_t *
>(
data);
408 ipv4Saddr = *(ipheader+3);
409 ipv4Daddr = *(ipheader+4);
415 NS_ASSERT_MSG (ipv4,
"nsc callback invoked, but node has no ipv4 object");
429 endPoint != endPoints.end (); endPoint++) {
431 (*endPoint)->ForwardUp (NULL,
Ipv4Header (), 0, 0);
442 *sec = us / (1000*1000);
443 *usec = us - *sec * (1000*1000);
450 const uint32_t nInterfaces = ip->GetNInterfaces ();
452 NS_ASSERT_MSG (nInterfaces <= 2,
"nsc does not support multiple interfaces per node");
457 for (uint32_t i = 1; i < nInterfaces; i++)
462 uint16_t mtu = ip->GetMtu (i);
464 std::ostringstream addrOss, maskOss;
466 addr.
Print (addrOss);
467 mask.
Print (maskOss);
469 NS_LOG_LOGIC (
"if_attach " << addrOss.str ().c_str () <<
" " << maskOss.str ().c_str () <<
" " << mtu);
471 std::string addrStr = addrOss.str ();
472 std::string maskStr = maskOss.str ();
473 const char* addrCStr = addrStr.c_str ();
474 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.
Simulation virtual time values and 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)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ipv4Mask GetMask(void) const
Get the network mask.
virtual void wakeup()
Called by the NSC stack whenever something of interest has happened.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
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)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
EndPoints GetAllEndPoints(void)
Get the entire list of end points registered.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< Socket > CreateSocket(void)
int external_rand()
External Random number generator.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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...
#define NS_FATAL_ERROR(msg)
fatal error handling
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.
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
Get an approximation of the time stored in this instance in the indicated unit.
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.
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)
Use NS_LOG to output a message of level LOG_LOGIC.
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)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
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.