[Ns-developers] Students, Sockets and Smart Pointers

Joseph Kopena tjkopena at cs.drexel.edu
Fri Mar 28 06:10:43 PDT 2008


Craig wrote:
> There's a discussion going on in the context of ns-3 bug 154 that I think
> deserves a wider distribution.
>
> Gustavo has reported a student who wrote some code to use sockets directly
> which I reproduce at the end of the message. [If you happen to be the
> student who wrote this code, I'm not pointing fingers at you.  I'm more
> pointing fingers at the developers (me too) who led you down the path you
> found yourself in.]

A couple quick comments:

- This doesn't look like a sockets API problem to me.  That code shows
  a basic misunderstanding of the central paradigm:

  + There's a simulation context, the universe of the test
  + Within that universe are Nodes, which simulate computers
  + Nodes have NetDevices simulating network hardware
  + Nodes have Application objects corresponding to normal programs

The problem seems akin to setting up a GUI in Qt or GTK, applying a
very imperative-styled set of loops and functions, and complaining
that nothing happens (Qt & GTK are almost entirely event driven).


Craig, my reading of your first message here sounds like a new call
for a sockets API that could be (nearly) dropped in transparently for
the usual BSD sockets API.  That'd be awesome, but not for educational
reasons.  People could use that to run legacy code in NS3.  But,
they'd still have to do some sim setup.  More importantly, I would
argue strongly that people get just as confused by usual network
programming as this student seems to have gotten.  I argue that even
presented w/ a more typical API, they would get just as confused if
they kept expanding on the program, i.e. to implement a protocol.

I would be uneasy encouraging people not to fit protocols into
Application objects.  Stuffing everything into essentially a very
linear program from main() sounds like a recipe for disaster.  Without
some really silly fancyness, they'd still have to start the simulator,
you'd have to figure out how to interleave their execution w/ events,
etc.  I.e., worst case scenario I, Confused Student, am going to write
a program that creates a bunch of nodes, then runs a bunch of while ()
{ sleep(1); send(packet); } loops "on each one," and complain bitterly
when it doesn't work.

However, to alleviate some of that, what if there was an Application
class, instances of which take & execute a given method?  So, I could
write a couple methods representing programs to run on nodes and hand
off to those instances to execute.  A helper could make the whole
thing very simple, and avoid having to subclass Application.  There
would still be problems though, like the loop above.  Without a full
threading thing going on, you just can't do that much if people aren't
working within the event framework.

Thx

-- 
- joe kopena
right here and now


More information about the Ns-developers mailing list