[Ns-developers] TCP and UDP layer refactoring
Mathieu Lacage
mathieu.lacage at sophia.inria.fr
Wed Jul 9 08:23:31 PDT 2008
On Tue, 2008-07-08 at 22:57 -0700, Tom Henderson wrote:
> >>> - When we *L4Protocol::CreateSocket(), it will give a socket that could
> >>> be bound in IPv4 or IPv6 so no need to add Udp6/Tcp6SocketFactory;
> >> this is an interesting point, I think. The SocketImpl classes can't
> >> have any explicit address family dependency because they are created
> >> before the family is known. So I agree with your point.
> >
> > I do not really understand that last point: why would you not know the
> > family at this point ? The caller of the CreateSocket function knows
> > what family it wants to get.
> >
>
> (getting back to this thread)
>
> If we make the SocketImpl class to be family independent, then when you
> create a socket, it can later become either a v4 or v6 socket depending
> on the addresses passed in. Right now, this information is not known at
> socket creation time.
It was my understanding that this information is available to you
already (albeit implicitely) because, my understanding is that each
socket factory can create a unique type of socket: "ipv4 tcp" or "ipv6
udp".
> In a later post, you suggested that this may be a bad idea; that we may
> want to explicitly either pass an address family parameter to
> CreateSocket() or else have separate factories for address families?
I do not think we need an extra argument to CreateSocket. I would go
with a separate factory for each family/domain because this is my
understanding of how the system is expected to be used.
Originally, I found the idea of using a special 'tcp' socket type which
can be bound to either ipv4 or ipv6 sockets ludicrous because I did not
see what kind of application would use it (and I don't know of any real
application using this).
I am also worried that this will make the tcp socket implementation
somewhat more complex because it will have to detect invalid
combinations (bind to ipv4 and connect to ipv6, but also, connect to
ipv6 without any prior bind which triggers an implicit bind () to ipv6,
and a couple of other combinations) and gracefully return error codes
for these.
I am also potentially worried that trying to implement the full posix
semantics on top of that special tcp socket in the ns-3-simu tree will
be painful because I will have to keep track of the family of my sockets
to make sure I return proper error codes if my user creates a tcp ipv4
socket but later tries to bind it to an ipv6 address.
The latter is really my main concern because, frankly, I am not going to
be the one to worry about the implementation complexity of the tcp
socket :) So, it is clear to me that I need a mode where I can create
sockets which belong to a specific family/domain _before_ bind and there
are two ways to do this: either add a domain argument to CreateSocket or
reuse our socket factory mechanism and create a specific socket factory
for each socket type. I clearly vote for the latter.
Note that this does not _require_ you to implement multiple tcp sockets
for ipv4 and ipv6. It just requires you to implement multiple socket
factories: TcpIpv4SocketFactory and TcpIpv6SocketFactory (and,
potentially, if you think it is useful, TcpSocketFactory). Each of these
factories could potentially create instances of the same object type if
it is easier from an implementation perspective but what matters is that
these different socket instances have very slightly different semantics
with regard to address type checking.
regards,
Mathieu
More information about the Ns-developers
mailing list