strange behavior with ns3 and ipython vs ns3 and python REPL

73 views
Skip to first unread message

catc...@bromberger.com

unread,
Oct 2, 2015, 6:17:49 PM10/2/15
to ns-3-users
Hi all,

I'm experiencing a very strange problem when running ns3's python bindings in an ipython REPL. Specifically, the results of an out-of-bounds access are different than in a regular python REPL.

Here's regular python:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ns.core
>>> import ns.network
>>> nodes = ns.network.NodeContainer()
>>> nodes.Create(2)
>>> z = nodes.Get(3)
>>> z is None
True

As expected, the invalid index to Get() returns None. However, in ipython:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python'
s own help system.
object?   -> Details about 'object', use 'object??' for extra details.


In [1]: import ns.network
In [2]: import ns.core
In [3]: nodes = ns.network.NodeContainer()
In [4]: nodes.Create(2)
In [5]: z = nodes.Get(3)
In [6]: z is None
Out[6]: False

In [7]: z
Out[7]: <network.Node at 0x108a173f8>

In [8]: y = nodes.Get(1)

In [9]: y
Out[9]: <network.Node at 0x108a173f8>  # same address?

In [10]: x = nodes.Get(0)

In [11]: x
Out[11]: <network.Node at 0x108a17ab8> # different address, as expected.

The reason I have to assign to variables is that when I don't, the call to nodes.Get(3) causes ipython to segfault.

I accept that this is likely an ipython issue, but I'm puzzled as to why I'd get different results from the call to nodes.Get(). Has anyone run into this before? (Can anyone else reproduce the issue?)

Also just FYI, using jupyter-console, I get a segfault with the above code.

Thanks.

catc...@bromberger.com

unread,
Oct 2, 2015, 6:37:29 PM10/2/15
to ns-3-users
Sorry for the followup, but I managed to get the segfault on a normal python REPL:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ns.network
>>> nodes = ns.network.NodeContainer()
>>> nodes.Create(2)
>>> nodes.Get(356)
Segmentation fault: 11

As it turns out, the segfaults in all 3 environments are not consistently reproducible. They seem to be more frequent in ipython/jupyter but multiple invalid accesses will eventually segfault any of the three.

Is this the expected response to an invalid indexing operation?

Tommaso Pecorella

unread,
Oct 3, 2015, 7:45:49 AM10/3/15
to ns-3-users
Hi,

what ns-3 version are you using ?

Cheers,

T

catc...@bromberger.com

unread,
Oct 3, 2015, 11:00:12 AM10/3/15
to ns-3-users
ns-3-dev, changeset:   11678:cf9f06803ccb

Thanks.

catc...@bromberger.com

unread,
Oct 6, 2015, 10:12:18 AM10/6/15
to ns-3-users
Reply all
Reply to author
Forward
0 new messages