Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
praich
Ns 3 Dev
Commits
548b6842
Commit
548b6842
authored
2 years ago
by
Gabriel Ferreira
Browse files
Options
Download
Email Patches
Plain Diff
bindings: fix segmentation violation in python scripts
And move sample-rng-plot.py code to a main function
parent
78285da1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/wireless/mixed-wired-wireless.py
+9
-2
examples/wireless/mixed-wired-wireless.py
src/core/examples/sample-rng-plot.py
+33
-27
src/core/examples/sample-rng-plot.py
utils/python-unit-tests.py
+8
-0
utils/python-unit-tests.py
with
50 additions
and
29 deletions
+50
-29
examples/wireless/mixed-wired-wireless.py
View file @
548b6842
...
...
@@ -235,7 +235,7 @@ def main(argv):
# Reset the address base-- all of the 802.11 networks will be in
# the "10.0" address space
ipAddrs
.
SetBase
(
ns
.
network
.
Ipv4Address
(
"10.0.0.0"
),
ns
.
network
.
Ipv4Mask
(
"255.255.255.0"
))
tempRef
=
[]
# list of references to be held to prevent garbage collection
for
i
in
range
(
backboneNodes
):
print
(
"Configuring wireless network for backbone node "
,
i
)
#
...
...
@@ -279,11 +279,18 @@ def main(argv):
# the network mask initialized above
#
ipAddrs
.
NewNetwork
()
# This call returns an instance that needs to be stored in the outer scope
# not to be garbage collected when overwritten in the next iteration
subnetAlloc
=
ns
.
mobility
.
ListPositionAllocator
()
# Appending the object to a list is enough to prevent the garbage collection
tempRef
.
append
(
subnetAlloc
)
#
# The new wireless nodes need a mobility model so we aggregate one
# to each of the nodes we just finished building.
#
subnetAlloc
=
ns
.
mobility
.
ListPositionAllocator
()
for
j
in
range
(
infra
.
GetN
()):
subnetAlloc
.
Add
(
ns
.
core
.
Vector
(
0.0
,
j
,
0.0
))
...
...
This diff is collapsed.
Click to expand it.
src/core/examples/sample-rng-plot.py
View file @
548b6842
...
...
@@ -29,37 +29,43 @@ import sys
import
argparse
from
ns
import
ns
parser
=
argparse
.
ArgumentParser
(
"sample-rng-plot"
)
parser
.
add_argument
(
"--not-blocking"
,
action
=
"store_true"
,
default
=
False
)
args
=
parser
.
parse_args
(
sys
.
argv
[
1
:])
# mu, var = 100, 225
def
main
():
parser
=
argparse
.
ArgumentParser
(
"sample-rng-plot"
)
parser
.
add_argument
(
"--not-blocking"
,
action
=
"store_true"
,
default
=
False
)
args
=
parser
.
parse_args
(
sys
.
argv
[
1
:])
## Random number generator.
rng
=
ns
.
CreateObject
(
"NormalRandomVariable"
)
rng
.
SetAttribute
(
"Mean"
,
ns
.
DoubleValue
(
100.0
))
rng
.
SetAttribute
(
"Variance"
,
ns
.
DoubleValue
(
225.0
))
# mu, var = 100, 225
## Random number samples.
x
=
[
rng
.
GetValue
()
for
t
in
range
(
10000
)]
## Random number generator.
rng
=
ns
.
CreateObject
(
"NormalRandomVariable"
)
rng
.
SetAttribute
(
"Mean"
,
ns
.
DoubleValue
(
100.0
))
rng
.
SetAttribute
(
"Variance"
,
ns
.
DoubleValue
(
225.0
))
# the histogram of the data
## Random number samples.
x
=
[
rng
.
GetValue
()
for
t
in
range
(
10000
)]
## Make a probability density histogram
density
=
1
## Plot color
facecolor
=
'g'
## Plot alpha value (transparency)
alpha
=
0.75
# the histogram of the data
# We don't really need the plot results, we're just going to show it later.
# n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
n
,
bins
,
patches
=
plt
.
hist
(
x
,
50
,
density
=
True
,
facecolor
=
'g'
,
alpha
=
0.75
)
## Make a probability density histogram
density
=
1
## Plot color
facecolor
=
'g'
## Plot alpha value (transparency)
alpha
=
0.75
plt
.
title
(
'ns-3 histogram'
)
plt
.
text
(
60
,
.
025
,
r
'$\mu=100,\ \sigma=15$'
)
plt
.
axis
([
40
,
160
,
0
,
0.03
])
plt
.
grid
(
True
)
plt
.
show
(
block
=
not
args
.
not_blocking
)
# We don't really need the plot results, we're just going to show it later.
# n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
n
,
bins
,
patches
=
plt
.
hist
(
x
,
50
,
density
=
True
,
facecolor
=
'g'
,
alpha
=
0.75
)
plt
.
title
(
'ns-3 histogram'
)
plt
.
text
(
60
,
.
025
,
r
'$\mu=100,\ \sigma=15$'
)
plt
.
axis
([
40
,
160
,
0
,
0.03
])
plt
.
grid
(
True
)
plt
.
show
(
block
=
not
args
.
not_blocking
)
if
__name__
==
"__main__"
:
main
()
This diff is collapsed.
Click to expand it.
utils/python-unit-tests.py
View file @
548b6842
...
...
@@ -214,6 +214,8 @@ class TestSimulator(unittest.TestCase):
self
.
assertTrue
(
self
.
_received_packet
is
not
None
)
self
.
assertEqual
(
self
.
_received_packet
.
GetSize
(),
19
)
# Delete Ptr<>'s on the python side to let C++ clean them
del
internet
def
testAttributes
(
self
):
"""! Test attributes function
...
...
@@ -243,6 +245,9 @@ class TestSimulator(unittest.TestCase):
mobility
.
GetAttribute
(
"PositionAllocator"
,
ptr2
)
self
.
assertNotEqual
(
ptr
.
GetObject
(),
ns
.
core
.
Ptr
[
"Object"
](
ns
.
cppyy
.
nullptr
))
# Delete Ptr<>'s on the python side to let C++ clean them
del
queue
,
mobility
,
ptr
,
ptr2
def
testIdentity
(
self
):
"""! Test identify
@param self this object
...
...
@@ -257,6 +262,9 @@ class TestSimulator(unittest.TestCase):
self
.
assertEqual
(
c1
,
c2
)
# Delete Ptr<>'s on the python side to let C++ clean them
del
csma
,
channel
def
testTypeId
(
self
):
"""! Test type ID
@param self this object
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help