[Ns-developers] NS-3 UDP / TCP refactoring
mathieu.lacage at sophia.inria.fr
Fri Aug 8 14:58:50 PDT 2008
On Fri, 2008-08-08 at 13:58 -0700, Mathieu Lacage wrote:
> In ns-3, sockets are created with subclasses of the SocketFactory base
> class. Each instance of a SocketFactory creates one type of socket and,
> we get a socket factory by writing:
> Ptr<Socket> socket = Socket::CreateSocket (node, socketType);
> How can we encode the type of socket to create in the socketType ?
> We discussed that briefly in our first thread on that topic in june and
> I think that the version we seemed to converge upon is to map pairs
> family+type to a single string:
> - PF_INET+SOCK_DGRAM = "ns3::Ipv4UdpSocketFactory"
> - PF_INET+SOCK_STREAM = "ns3::Ipv4TcpSocketFactory"
> - PF_INET6+SOCK_DGRAM = "ns3::Ipv6UdpSocketFactory"
> - PF_INET6+SOCK_STREAM = "ns3::Ipv6TcpSocketFactory"
> For compatibility, we could easily rename "ns3::Ipv4UdpSocketFactory" to
> "ns3::UdpSocketFactory" as an exception but I have to confess that I
> don't find this especially exciting.
> What the above does not solve, though, is what happens of the protocol
> argument which, unfortunately, will be needed if you want to be able to
> create ICMP sockets. We could keep extending the above proposal:
> - PF_INET+SOCK_RAW+IPPROTO_ICMP = "ns3::Ipv4RawIcmpSocketFactory"
> - PF_INET6+SOCK_RAW+IPPROTO_ICMP = "ns3::Ipv6RawIcmpSocketFactory"
> - etc.
I should have realized earlier that the above cannot work because the
whole point of a raw socket is to allow the user to freely specify an
arbitrary protocol number, not hardcode it in a string. So, there are
two options here:
- define a RawSocket base class and add a SetProtocol method there.
- add an int protocol argument to SocketFactory::Create and
In the interest of avoiding too much breakage, the former would be the
way to go but it would make it impossible to use these raw sockets with
the OnOffApplication for example. The latter seems more in line with the
socket API but it would have a lot of fallout everywhere we specify the
type of socket to create (especially in the applications and their
I don't know if adding support for raw sockets nicely integrated in our
system is worth all this breakage though, so, the former option could be
the way to go. And, in case someone wonders, yes, I would like to
actually implement these raw sockets because I need them at least for
the ns-3-simu branch.
More information about the Ns-developers