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 *);
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 .SetGroupName (
"Internet")
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",
161 m_softTimer (
Timer::CANCEL_ON_DESTROY)
232 Ptr<Node>node = this->GetObject<Node> ();
241 tcpFactory->SetTcp (
this);
292 socket->SetTcp (
this);
330 NS_LOG_FUNCTION (
this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
332 localAddress, localPort,
333 peerAddress, peerPort);
370 const uint8_t *
data =
const_cast<uint8_t *
>(buf);
396 uint32_t ipv4Saddr, ipv4Daddr;
404 const uint8_t *rawdata =
reinterpret_cast<const uint8_t *
>(
data);
407 p = Create<Packet> (rawdata, datalen);
410 const uint32_t *ipheader =
reinterpret_cast<const uint32_t *
>(
data);
411 ipv4Saddr = *(ipheader+3);
412 ipv4Daddr = *(ipheader+4);
418 NS_ASSERT_MSG (ipv4,
"nsc callback invoked, but node has no ipv4 object");
432 endPoint != endPoints.end (); endPoint++) {
434 (*endPoint)->ForwardUp (NULL,
Ipv4Header (), 0, 0);
445 *sec = us / (1000*1000);
446 *usec = us - *sec * (1000*1000);
453 const uint32_t nInterfaces = ip->GetNInterfaces ();
455 NS_ASSERT_MSG (nInterfaces <= 2,
"nsc does not support multiple interfaces per node");
460 for (uint32_t i = 1; i < nInterfaces; i++)
465 uint16_t mtu = ip->GetMtu (i);
467 std::ostringstream addrOss, maskOss;
469 addr.
Print (addrOss);
470 mask.
Print (maskOss);
472 NS_LOG_LOGIC (
"if_attach " << addrOss.str ().c_str () <<
" " << maskOss.str ().c_str () <<
" " << mtu);
474 std::string addrStr = addrOss.str ();
475 std::string maskStr = maskOss.str ();
476 const char* addrCStr = addrStr.c_str ();
477 const char* maskCStr = maskStr.c_str ();
std::string GetNscLibrary(void) const
Get the NSC library being used.
Ptr< const AttributeChecker > MakeStringChecker(void)
virtual void if_receive_packet(int if_id, const void *data, int datalen)=0
Deliver complete packet to the NSC network stack.
Nsc wrapper glue, to interface with the Ipv4 protocol underneath.
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 "...
virtual void wakeup()
Called by the NSC stack whenever something of interest has happened.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold variables of type string.
a class to represent an Ipv4 address mask
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
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.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void DoDispose(void)
Destructor implementation.
The attribute can be written at construction-time.
void wakeup()
Called by the NSC stack whenever something of interest has happened.
void SetNscLibrary(const std::string &lib)
Set the NSC library to be used.
virtual void increment_ticks()=0
Increment the time ticks.
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.
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()
Notify all Objects aggregated to this one of a new Object being aggregated.
virtual void DoDispose(void)
Destructor implementation.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
Ptr< NscTcpL4Protocol > m_prot
the NSC TCP protocol
Ipv4Mask GetMask(void) const
Get the network mask.
void SetDelay(const Time &delay)
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
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...
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void AddInterface(void)
Add an interface.
virtual void timer_interrupt()=0
The stack timer_interrupt function.
Implement the IPv4 layer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
INetStack *(* FCreateStack)(ISendCallback *, IInterruptCallback *, FRandom)
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 virtual time.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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
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...
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.
virtual int GetVersion(void) const
Get the NSC version.
std::vector< Ptr< NscTcpSocketImpl > > m_sockets
list of sockets
a class to store IPv4 address information on an interface
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
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 void if_attach(const char *addr, const char *mask, int mtu)=0
Attach an interface to the stack.
Ipv4Address GetLocal(void) const
Get the local address.
void Nullify(void)
Discard the implementation, set it to null.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
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.
static const uint32_t packetSize
void Print(std::ostream &os) const
Print this address to the given output stream.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Container for a set of ns3::Object pointers.
virtual void gettime(unsigned int *, unsigned int *)
Called by the Linux stack RNG initialization.
bool IsNull(void) const
Check for null implementation.
a unique identifier for an interface.
void Print(std::ostream &os) const
Print this mask to the given output stream.
void * m_dlopenHandle
dynamic library handle.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
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 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.