[Ns-developers] [ns3] socket API

George Riley riley at ece.gatech.edu
Mon Apr 14 18:07:35 PDT 2008


>
>  /**
> * return -1 if packet does not fit in tx buffer (current behavior is
> * to send the part of the packet which fits in the tx buffer).
> * If the packet does not fit, the caller can split the packet to send
> * (based on output by GetTxAvailable) and re-attempt to send the
> * packet.
> * If you want to provide a per-packet "to" address, store it as a
> * special tag in the outgoing packet.
> */
> int Send (Ptr<Packet> p, uint32_t flags);
I still contend, as I have from the beginning, that we need the
send calls that take buffer pointers and length values as arguments,
and still believe that.  The sockets API does not send packets, it
sends bytes, and we need this to stay.  I don't really understand
the pain you refer to.

>
>
> /**
> * returns the number of bytes which can be sent in a single call
> * to Send.
> */
> uint32_t GetTxAvailable (void) const;
>
> If we implement this, we should remove the SendTo method. Problem:  
> if we
> do this, we cannot specify the "to" address for
> int Socket::SendTo (uint8_t *buffer, uint32_t size);
> because there is no Ptr<Packet> to attach the "to" address to.
>
> Solution: get rid of the Socket::Send* methods which take raw buffers
> and implement them exclusively at the "synchronous" layer.
Disagree, per the above.
>
>
> 3) How should socket options and ioctls be supported ?
> Proposal:
>
> in src/node:
>
> class Ipv4SocketOptions
> {
>  /* Implement the linux IP_PKTINFO socket option. */
>  virtual void EnablePktInfo (void) = 0;
>  virtual void DisablePktInfo (void) = 0;
>  virtual bool IsPktInfoEnabled (void) = 0;
>
>  /* Implement the linux IP_OPTIONS socket option. */
>  virtual void SetOptions (const uint8_t [40] buffer, uint32_t size);
>  // return size of options data.
>  virtual uint32_t GetOptions (uint8_t [40] buffer);
>
>  /* implement IP_RECVTTL */
>  virtual void EnableRecvTtl (void) = 0;
>  virtual void DisableRecvTtl (void) = 0;
>  virtual uint32_t IsRecvTtlEnabled (void) = 0;
>
>  // all others...
> };
>
> class UdpSocketOptions : public Ipv4SocketOptions
> {
> public:
>  // udp-specific options.
> };
>
> class TcpSocketOptions : public Ipv4SocketOptions {...};
>
> All the above would be implemented in src/internet-node/ as aggregated
> classes to each Socket. i.e., user code:
>
> Ptr<Socket> sock = ...;
> Ptr<Ipv4SocketOptions> ipv4 = sock->GetObject<Ipv4SocketOptions> ();
> NS_ASSERT (ipv4 != 0);
> ipv4->EnableRecvTtl ();
>
> Another option here would be to just add all of the above methods to  
> the
> existing src/node/udp.h and src/node/tcp.h classes with an extra
> Ptr<Socket> argument:
>
> class Udp  ...
> {
> public:
>  /* Implement the linux IP_PKTINFO socket option. */
>  virtual void EnablePktInfo (Ptr<Socket> socket) = 0;
>  virtual void DisablePktInfo (Ptr<Socket> socket) = 0;
>  virtual bool IsPktInfoEnabled (Ptr<Socket> socket) = 0;
> };
>
> The former approach feels slightly more "right".
>
> 4) How is ancillary information supported ? It is attached as a tag to
> each packet whether it is sent or received.
>
> 5) posix sockets are extended with:
>
> int simu_recv (int fd, Ptr<Packet> packet, int flags);
> int simu_send (int fd, Ptr<Packet> packet, int flags);
> ssize_t simu_write (int fd, Ptr<Packet> packet);
> ssize_t simu_read (int fd, Ptr<Packet> packet);
>
>
> Mathieu
>



More information about the Ns-developers mailing list