Init ESDS repository

This commit is contained in:
Loic Guegan 2022-06-09 21:48:32 +02:00
commit c2e6aad09f
106 changed files with 2638 additions and 0 deletions

6
tests/README.md Normal file
View file

@ -0,0 +1,6 @@
# Tests
**Test folders names convention:**
- **m** senders and **n** receivers is written `<m>s<n>r` *(ex: 1s5r)*
- **n** nodes is written `<n>n` *(ex: 5n)*
- Tests names follow the following format `<title>_<m>s<n>r` or `<title>_<n>n` *(ex: simple_send_rcv_1s5r, ping_pong_2n)*
- Tests that test **elementary API functions** should start with the **simple** keyword

View file

@ -0,0 +1,4 @@
[t=0.000,src=n0] Send 1 bytes on wlan0
[t=0.000,src=n2] Send 1 bytes on wlan0
[t=0.000,src=n1] Interferences on wlan0
[t=1.000,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("wlan0","Hello World!",1,1)

View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),8)
# Hide the nodes from each others
B[0,2]=0
B[2,0]=0
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
s.create_node("sender")
s.run()

View file

@ -0,0 +1,4 @@
[t=0.000,src=n0] Send 1 bytes to n1 on eth0
[t=0.500,src=esds] Network update!
[t=0.750,src=n1] Receive 1 bytes on eth0
[t=0.750,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World!",1,1)

View file

@ -0,0 +1,38 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
########## Scenario ##########
# Notations:
# - Remaining communication duration (last communication ends minus current simulated time) = C
# - Last communication duration (previous row) = U
# - Last remaining data size (previous row) = D
# - Current remaining data (current row) = R
# - Initial data size (first row) = I
# - Bandwidth = BW
# - Latency = L
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communcation duration(s) | Communcation ends at(s) |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | 0 | 0 | 8 | 8 | 1 | 1 |
# | 0.5 | 0 | 16 | C/U*D = 4 | R/I * L + R/BW = 0.25 | 0.75 |
# | 0.75 | 0 | 16 | | | |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
##############################
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
simulator.update_network(simulator.B*2,simulator.L)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -0,0 +1,6 @@
[t=0.000,src=n0] Send 1 bytes to n2 on eth0
[t=0.000,src=n1] Send 1 bytes to n2 on eth0
[t=1.000,src=esds] Network update!
[t=1.500,src=n2] Receive 1 bytes on eth0
[t=1.500,src=n2] Receive 1 bytes on eth0
[t=1.500,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World!",1,2)

View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
########## Scenario ##########
# Notations:
# - Remaining communication duration (last communication ends minus current simulated time) = C
# - Last communication duration (previous row) = U
# - Last remaining data size (previous row) = D
# - Current remaining data (current row) = R
# - Initial data size (first row) = I
# - Bandwidth = BW
# - Latency = L
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | This table is the same for both sender | | | | | |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communication duration(s) | Communcation ends at(s) |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | 0 | 0 | 8/2 | 8 | 2 | 2 |
# | 1 | 0 | 16/2 | C/U*D = 4 | 0.5 | 1.5 |
# | 1.5 | 0 | 16/2 | 0 | | |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
##############################
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
simulator.update_network(simulator.B*2,simulator.L)
s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)

View file

@ -0,0 +1,37 @@
Python version 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0]
Simulation started at 1654802959.3233912
Number of nodes is 3
Manual breakpoints list: []
Breakpoints every 1s
-----------------------------------------------
Started since 0.04s
Simulated time 0.000s (or more precisely 0s)
Node number per state: pending=2 terminated=1
Node sharing: n2=2
Ids of node in timeout mode:
Sorted events list:
[[3 1 array(0, dtype=object) 0]
[0 2.0 array([0, 2, 'eth0', 'Hello World!', 1, 2.0, 1, 0], dtype=object)
1]
[0 2.0 array([1, 2, 'eth0', 'Hello World!', 1, 2.0, 1, 0], dtype=object)
1]]
-----------------------------------------------
Started since 0.04s
Simulated time 1.000s (or more precisely 1s)
Node number per state: pending=2 terminated=1
Node sharing: n2=2
Ids of node in timeout mode:
Sorted events list:
[[0 1.5
array([0, 2, 'eth0', 'Hello World!', 1, 0.5, 0.5, 0], dtype=object) 1]
[0 1.5
array([1, 2, 'eth0', 'Hello World!', 1, 0.5, 0.5, 0], dtype=object) 1]
[3 2 array(0, dtype=object) 0]]
-----------------------------------------------
Started since 0.05s
Simulated time 1.500s (or more precisely 1.5s)
Node number per state: terminated=3
Node sharing:
Ids of node in timeout mode:
Sorted events list:
[[3 2 array(0, dtype=object) 0]]

View file

@ -0,0 +1,5 @@
[t=0.000,src=n0] Send 1 bytes to n1 on eth0
[t=0.500,src=esds] Network update!
[t=1.000,src=esds] Network update!
[t=1.333,src=n1] Receive 1 bytes on eth0
[t=1.333,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World!",1,1)

View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
########## Scenario ##########
# Notations:
# - Remaining communication duration (last communication ends minus current simulated time) = C
# - Last communication duration (previous row) = U
# - Last remaining data size (previous row) = D
# - Current remaining data (current row) = R
# - Initial data size (first row) = I
# - Bandwidth = BW
# - Latency = L
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communcation duration(s) | Communcation ends at(s) |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | 0 | 0 | 8 | 8 | 1 | 1 |
# | 0.5 | 0.5 | 8 | C/U*D = 4 | R/I * L + R/BW = 0.75 | 1.25 |
# | 1 | 1 | 8 | C/U*D = 1.33 | R/I * L + R/BW = 0.33 | 1.33 |
# | 1.33 | 1 | 8 | | | |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
##############################
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
simulator.update_network(simulator.B,simulator.L+1/2)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -0,0 +1,7 @@
[t=0.000,src=n0] Send 1 bytes to n2 on eth0
[t=0.000,src=n1] Send 1 bytes to n2 on eth0
[t=1.000,src=esds] Network update!
[t=2.000,src=esds] Network update!
[t=2.300,src=n2] Receive 1 bytes on eth0
[t=2.300,src=n2] Receive 1 bytes on eth0
[t=2.300,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World!",1,2)

View file

@ -0,0 +1,42 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
########## Scenario ##########
# Notations:
# - Remaining communication duration (last communication ends minus current simulated time) = C
# - Last communication duration (previous row) = U
# - Last remaining data size (previous row) = D
# - Current remaining data (current row) = R
# - Initial data size (first row) = I
# - Bandwidth = BW
# - Latency = L
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | This table is the same for both sender | | | | | |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communication duration(s) | Communcation ends at(s) |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | 0 | 0 | 8/2 | 8 | 2 | 2 |
# | 1 | 0.5 | 8/2 | C/U*D=4 | R/BW + R/I*L = 1.25 | 2.25 |
# | 2 | 1 | 8/2 | C/U*D=0.8 | R/BW + R/I*L = 0.3 | 2.3 |
# | 2.3 | 1 | 8/2 | 0 | | |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
##############################
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
simulator.update_network(simulator.B,simulator.L+0.5)
s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)

View file

@ -0,0 +1,51 @@
Python version 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0]
Simulation started at 1654802960.9297695
Number of nodes is 3
Manual breakpoints list: []
Breakpoints every 1s
-----------------------------------------------
Started since 0.08s
Simulated time 0.000s (or more precisely 0s)
Node number per state: pending=2 terminated=1
Node sharing: n2=2
Ids of node in timeout mode:
Sorted events list:
[[3 1 array(0, dtype=object) 0]
[0 2.0 array([0, 2, 'eth0', 'Hello World!', 1, 2.0, 1, 0], dtype=object)
1]
[0 2.0 array([1, 2, 'eth0', 'Hello World!', 1, 2.0, 1, 0], dtype=object)
1]]
-----------------------------------------------
Started since 0.08s
Simulated time 1.000s (or more precisely 1s)
Node number per state: pending=2 terminated=1
Node sharing: n2=2
Ids of node in timeout mode:
Sorted events list:
[[3 2 array(0, dtype=object) 0]
[0 2.25
array([0, 2, 'eth0', 'Hello World!', 1, 1.25, 0.5, 0], dtype=object) 1]
[0 2.25
array([1, 2, 'eth0', 'Hello World!', 1, 1.25, 0.5, 0], dtype=object) 1]]
-----------------------------------------------
Started since 0.08s
Simulated time 2.000s (or more precisely 2s)
Node number per state: pending=2 terminated=1
Node sharing: n2=2
Ids of node in timeout mode:
Sorted events list:
[[0 2.3
array([0, 2, 'eth0', 'Hello World!', 1, 0.30000000000000004, 0.1, 0],
dtype=object) 1]
[0 2.3
array([1, 2, 'eth0', 'Hello World!', 1, 0.30000000000000004, 0.1, 0],
dtype=object) 1]
[3 3 array(0, dtype=object) 0]]
-----------------------------------------------
Started since 0.09s
Simulated time 2.300s (or more precisely 2.3s)
Node number per state: terminated=3
Node sharing:
Ids of node in timeout mode:
Sorted events list:
[[3 3 array(0, dtype=object) 0]]

View file

@ -0,0 +1,4 @@
[t=0.000,src=n0] Send 1 bytes on wlan0
[t=0.500,src=esds] Network update!
[t=0.750,src=n1] Receive 1 bytes on wlan0
[t=0.750,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("wlan0","Hello World!",1,1)

View file

@ -0,0 +1,38 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
########## Scenario ##########
# Notations:
# - Remaining communication duration (last communication ends minus current simulated time) = C
# - Last communication duration (previous row) = U
# - Last remaining data size (previous row) = D
# - Current remaining data (current row) = R
# - Initial data size (first row) = I
# - Bandwidth = BW
# - Latency = L
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communcation duration(s) | Communcation ends at(s) |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | 0 | 0 | 8 | 8 | 1 | 1 |
# | 0.5 | 0 | 16 | C/U*D = 4 | R/I * L + R/BW = 0.25 | 0.75 |
# | 0.75 | 0 | 16 | | | |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
##############################
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
simulator.update_network(simulator.B*2,simulator.L)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -0,0 +1,5 @@
[t=0.000,src=n0] Send 1 bytes on wlan0
[t=0.500,src=esds] Network update!
[t=1.000,src=esds] Network update!
[t=1.333,src=n1] Receive 1 bytes on wlan0
[t=1.333,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("wlan0","Hello World!",1,1)

View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
########## Scenario ##########
# Notations:
# - Remaining communication duration (last communication ends minus current simulated time) = C
# - Last communication duration (previous row) = U
# - Last remaining data size (previous row) = D
# - Current remaining data (current row) = R
# - Initial data size (first row) = I
# - Bandwidth = BW
# - Latency = L
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communcation duration(s) | Communcation ends at(s) |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
# | 0 | 0 | 8 | 8 | 1 | 1 |
# | 0.5 | 0.5 | 8 | C/U*D = 4 | R/I * L + R/BW = 0.75 | 1.25 |
# | 1 | 1 | 8 | C/U*D = 1.33 | R/I * L + R/BW = 0.33 | 1.33 |
# | 1.33 | 1 | 8 | | | |
# |-------------------+------------+----------------+----------------------+--------------------------+-------------------------|
##############################
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
simulator.update_network(simulator.B,simulator.L+1/2)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

48
tests/run.sh Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
wai=$(dirname $(readlink -f "$0")) # Current script directory
tests=$(find ${wai}/ -maxdepth 1 -mindepth 1 -type d) # Find tests
out=$(mktemp)
test_timeout=20
for test in ${tests}
do
printf "%-50s%s %s" "- $(basename $test)" "=>"
cd $test
timeout $test_timeout ./simulator.py &> "$out"
# Ensure timeout
if [ $? -eq 124 ]
then
echo -e "${RED}${BOLD}failed${NC}"
echo "------------- Test timeout (should not exceed ${test_timeout}s) -------------"
cat "$out";
rm "$out"
exit 2
fi
# Ensure test output
if $(diff "$out" ./out &>/dev/null)
then
echo -e "${GREEN}${BOLD}passed${NC}"
else
echo -e "${RED}${BOLD}failed${NC}"
echo "------------- Expected -------------"
cat out
echo "------------- Got -------------"
cat "$out";
rm "$out"
exit 1
fi
# Prepare for next test
cd - &>/dev/null
done
rm "$out"

View file

@ -0,0 +1,8 @@
#!/usr/bin/env python
def execute(api):
if api.node_id == 0:
api.send("eth0","Hello",5,1)
else:
api.receive("eth0")

View file

@ -0,0 +1,9 @@
[t=0.000,src=n0] Send 5 bytes to n1 on eth0
[t=3.300,src=esds] Hello Callback!
[t=6.600,src=esds] Hello Callback!
[t=9.900,src=esds] Hello Callback!
[t=13.200,src=esds] Hello Callback!
[t=16.500,src=esds] Hello Callback!
[t=19.800,src=esds] Hello Callback!
[t=20.000,src=n1] Receive 5 bytes on eth0
[t=20.000,src=esds] Simulation ends

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
n=2
B=np.full((2,2),n)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
def callback(simulator):
simulator.log("Hello Callback!")
s.run(breakpoints_every=3.3,breakpoint_callback=callback)

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.log("Running")

View file

@ -0,0 +1,7 @@
[t=0.000,src=n0] Running
[t=0.000,src=n1] Running
[t=1.000,src=esds] Hello Callback!
[t=2.000,src=esds] Hello Callback!
[t=3.000,src=esds] Hello Callback!
[t=10.000,src=esds] Hello Callback!
[t=10.000,src=esds] Simulation ends

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
n=2
B=np.full((n,n),n)
L=np.full((n,n),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
def callback(simulator):
simulator.log("Hello Callback!")
s.run(breakpoints=[1,2,3,10],breakpoint_callback=callback)

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.log("Running")

View file

@ -0,0 +1,3 @@
[t=0.000,src=n0] Running
[t=0.000,src=n1] Running
[t=10.000,src=esds] Simulation ends

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
n=2
B=np.full((n,n),n)
L=np.full((n,n),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
s.run(breakpoints=[1,2,3,10])

View file

@ -0,0 +1,7 @@
#!/usr/bin/env python
def execute(api):
api.log("A")
api.log("B")
api.log("C")
api.log("D")

21
tests/simple_log_5n/out Normal file
View file

@ -0,0 +1,21 @@
[t=0.000,src=n0] A
[t=0.000,src=n0] B
[t=0.000,src=n0] C
[t=0.000,src=n0] D
[t=0.000,src=n1] A
[t=0.000,src=n1] B
[t=0.000,src=n1] C
[t=0.000,src=n1] D
[t=0.000,src=n2] A
[t=0.000,src=n2] B
[t=0.000,src=n2] C
[t=0.000,src=n2] D
[t=0.000,src=n3] A
[t=0.000,src=n3] B
[t=0.000,src=n3] C
[t=0.000,src=n3] D
[t=0.000,src=n4] A
[t=0.000,src=n4] B
[t=0.000,src=n4] C
[t=0.000,src=n4] D
[t=0.000,src=esds] Simulation ends

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((5,5),5)
L=np.full((5,5),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
s.create_node("node")
s.create_node("node")
s.create_node("node")
s.run()

View file

@ -0,0 +1,7 @@
#!/usr/bin/env python
def execute(api):
api.log("Clock is {}s".format(api.read("clock")))
api.wait(5698.1256)
api.log("Clock is {}s".format(api.read("clock")))
api.log("Clock is {}s".format(api.read("clock")))

View file

@ -0,0 +1,7 @@
[t=0.000,src=n0] Clock is 0s
[t=0.000,src=n1] Clock is 0s
[t=5698.126,src=n0] Clock is 5698.1256s
[t=5698.126,src=n0] Clock is 5698.1256s
[t=5698.126,src=n1] Clock is 5698.1256s
[t=5698.126,src=n1] Clock is 5698.1256s
[t=5698.126,src=esds] Simulation ends

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((2,2),2)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
s.run()

View file

@ -0,0 +1,9 @@
[t=0.000,src=n2] eth0 is 0
[t=624.000,src=n2] eth0 is 0
[t=1248.000,src=n0] Send 50 bytes to n2 on eth0
[t=1249.000,src=n2] eth0 is 1
[t=1249.000,src=n1] Send 50 bytes to n2 on eth0
[t=1250.000,src=n2] eth0 is 2
[t=1513.667,src=n2] Receive 50 bytes on eth0
[t=1514.667,src=n2] Receive 50 bytes on eth0
[t=1514.667,src=esds] Simulation ends

View file

@ -0,0 +1,12 @@
#!/usr/bin/env python
def execute(api):
api.log("eth0 is {}".format(api.read("eth0_ncom")))
api.wait(624)
api.log("eth0 is {}".format(api.read("eth0_ncom")))
api.wait(624)
# Now we are at 624*2=1248 (first sender start a communication)
api.wait(1) # Let the communication starts
api.log("eth0 is {}".format(api.read("eth0_ncom"))) # Should print 1
api.wait(1) # Now second sender start a communication
api.log("eth0 is {}".format(api.read("eth0_ncom"))) # Should print 2

View file

@ -0,0 +1,9 @@
#!/usr/bin/env python
def execute(api):
api.wait(1248)
if api.node_id==0:
api.send("eth0","hello",50,2)
else:
api.wait(1)
api.send("eth0","hello",50,2)

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),3)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
s.run(interferences=False)

View file

@ -0,0 +1,11 @@
[t=0.000,src=n2] wlan0 is 0
[t=624.000,src=n2] wlan0 is 0
[t=1248.000,src=n0] Send 50 bytes on wlan0
[t=1249.000,src=n2] wlan0 is 1
[t=1249.000,src=n1] Send 50 bytes on wlan0
[t=1250.000,src=n2] wlan0 is 2
[t=1381.333,src=n1] Receive 50 bytes on wlan0
[t=1381.333,src=n2] Receive 50 bytes on wlan0
[t=1382.333,src=n0] Receive 50 bytes on wlan0
[t=1382.333,src=n2] Receive 50 bytes on wlan0
[t=1382.333,src=esds] Simulation ends

View file

@ -0,0 +1,12 @@
#!/usr/bin/env python
def execute(api):
api.log("wlan0 is {}".format(api.read("wlan0_ncom")))
api.wait(624)
api.log("wlan0 is {}".format(api.read("wlan0_ncom")))
api.wait(624)
# Now we are at 624*2=1248 (first sender start a communication)
api.wait(1) # Let the communication starts
api.log("wlan0 is {}".format(api.read("wlan0_ncom"))) # Should print 1
api.wait(1) # Second sender start a communication
api.log("wlan0 is {}".format(api.read("wlan0_ncom"))) # Should print 2

View file

@ -0,0 +1,9 @@
#!/usr/bin/env python
def execute(api):
api.wait(1248)
if api.node_id==0:
api.send("wlan0","hello",50,None)
else:
api.wait(1)
api.send("wlan0","hello",50,None)

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),3)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
s.run(interferences=False)

View file

@ -0,0 +1,8 @@
[t=0.000,src=n0] Send 1 bytes to n1 on eth0
[t=1.000,src=n1] Receive 1 bytes on eth0
[t=1.000,src=n1] Received: Hello World!
[t=1.000,src=n0] Send 1 bytes to n1 on eth0
[t=1.500,src=n1] Receive failed code=-1
[t=2.000,src=n1] Receive 1 bytes on eth0
[t=2.000,src=n1] Received: Hello World!
[t=2.000,src=esds] Simulation ends

View file

@ -0,0 +1,15 @@
#!/usr/bin/env python
def receivet(node,timeout):
##### Simple receive
code, data=node.receivet("eth0",timeout)
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
node.log(msg)
def execute(api):
# Should works
receivet(api,2)
# Should failed
receivet(api,0.5) # At t=1.5s
# Should works (priorities says that communications should occurs before timeout)
receivet(api,0.5) # At t=2s (timeout+receive should occur)

View file

@ -0,0 +1,6 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World!",1,1)
api.send("eth0","Hello World!",1,1)

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
s.run(debug=True)

View file

@ -0,0 +1,43 @@
Python version 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0]
Simulation started at 1654802960.7880125
Number of nodes is 2
Manual breakpoints list: []
Breakpoints every Nones
-----------------------------------------------
Started since 0.02s
Simulated time 0.000s (or more precisely 0s)
Node number per state: pending=1 request=1
Node sharing: n1=1
Ids of node in timeout mode:
Sorted events list:
[[0 1.0 array([0, 1, 'eth0', 'Hello World!', 1, 1.0, 1, 0], dtype=object)
1]
[1 2 array(1, dtype=object) 3]]
-----------------------------------------------
Started since 0.04s
Simulated time 1.000s (or more precisely 1.0s)
Node number per state: pending=1 request=1
Node sharing: n1=1
Ids of node in timeout mode:
Sorted events list:
[[1 1.5 array(1, dtype=object) 3]
[0 2.0
array([0, 1, 'eth0', 'Hello World!', 1, 1.0, 1, 1.0], dtype=object) 1]]
-----------------------------------------------
Started since 0.06s
Simulated time 1.500s (or more precisely 1.5s)
Node number per state: pending=1 request=1
Node sharing: n1=1
Ids of node in timeout mode:
Sorted events list:
[[0 2.0
array([0, 1, 'eth0', 'Hello World!', 1, 1.0, 1, 1.0], dtype=object) 1]
[1 2.0 array(1, dtype=object) 3]]
-----------------------------------------------
Started since 0.08s
Simulated time 2.000s (or more precisely 2.0s)
Node number per state: terminated=2
Node sharing:
Ids of node in timeout mode:
Sorted events list:
[]

View file

@ -0,0 +1,11 @@
[t=0.000,src=n0] Send 1 bytes to n1 on eth0
[t=1.000,src=n1] Receive 1 bytes on eth0
[t=1.000,src=n1] Received: Hello World!
[t=1.000,src=n0] Send 1 bytes to n1 on eth0
[t=2.000,src=n1] Receive 1 bytes on eth0
[t=3.000,src=n0] Send 1 bytes to n1 on eth0
[t=3.000,src=n1] Received: Hello World!
[t=3.000,src=n1] Turned off
[t=4.000,src=n1] Turned on
[t=5.000,src=n1] Receive failed code=-1
[t=5.000,src=esds] Simulation ends

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
def execute(api):
##### Simple receive
code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
api.log(msg)
##### Test if we still receive the data when we are not receiving
api.wait(2)
code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
api.log(msg)
##### Ensure data is not receive when turned off
api.turn_off()
api.wait(1)
api.turn_on()
code, data=api.receivet("eth0",1)
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
api.log(msg)

View file

@ -0,0 +1,7 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World!",1,1)
api.send("eth0","Hello World!",1,1)
api.wait(1) # Goto 3 seconds
api.send("eth0","Hello World!",1,1)

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,7 @@
[t=0.000,src=n0] Send 1 bytes to n2 on eth0
[t=0.000,src=n1] Send 1 bytes to n2 on eth0
[t=2.000,src=n2] Receive 1 bytes on eth0
[t=2.000,src=n2] Received: Hello World from 0!
[t=2.000,src=n2] Receive 1 bytes on eth0
[t=2.000,src=n2] Received: Hello World from 1!
[t=2.000,src=esds] Simulation ends

View file

@ -0,0 +1,13 @@
#!/usr/bin/env python
def execute(api):
##### Simple receive from node 0
code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
api.log(msg)
##### Simple receive from node 1
code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
api.log(msg)

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
api.send("eth0","Hello World from {}!".format(api.node_id),1,2)

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,40 @@
[t=0.000,src=n0] Send 1 bytes to n3 on eth0
[t=0.000,src=n1] Send 1 bytes to n3 on eth0
[t=0.000,src=n2] Send 1 bytes to n3 on eth0
[t=3.000,src=n3] Receive 1 bytes on eth0
[t=3.000,src=n3] Received: Hello World from 0!
[t=3.000,src=n3] Receive 1 bytes on eth0
[t=3.000,src=n3] Received: Hello World from 1!
[t=3.000,src=n3] Receive 1 bytes on eth0
[t=3.000,src=n3] Received: Hello World from 2!
[t=3.000,src=n0] Send 2 bytes to n3 on eth0
[t=3.000,src=n1] Send 1 bytes to n3 on eth0
[t=3.000,src=n2] Send 1 bytes to n3 on eth0
[t=6.000,src=n3] Receive 1 bytes on eth0
[t=6.000,src=n3] Received: Hello World from 1!
[t=6.000,src=n3] Receive 1 bytes on eth0
[t=6.000,src=n3] Received: Hello World from 2!
[t=7.000,src=n3] Receive 2 bytes on eth0
[t=7.000,src=n3] Received: Hello World from 0!
[t=7.000,src=n0] Send 2 bytes to n3 on eth0
[t=7.000,src=n1] Send 2 bytes to n3 on eth0
[t=7.000,src=n2] Send 1 bytes to n3 on eth0
[t=10.000,src=n3] Receive 1 bytes on eth0
[t=10.000,src=n3] Received: Hello World from 2!
[t=12.000,src=n3] Receive 2 bytes on eth0
[t=12.000,src=n3] Received: Hello World from 0!
[t=12.000,src=n3] Receive 2 bytes on eth0
[t=12.000,src=n3] Received: Hello World from 1!
[t=12.000,src=n0] Send 1 bytes to n3 on eth0
[t=12.000,src=n1] Send 2 bytes to n3 on eth0
[t=12.000,src=n2] Send 3 bytes to n3 on eth0
[t=15.000,src=n3] Receive 1 bytes on eth0
[t=15.000,src=n3] Received: Hello World from 0!
[t=17.000,src=n3] Receive 2 bytes on eth0
[t=17.000,src=n3] Received: Hello World from 1!
[t=18.000,src=n3] Receive 3 bytes on eth0
[t=18.000,src=n3] Received: Hello World from 2!
[t=18.000,src=n0] Send 5 bytes to n3 on eth0
[t=23.000,src=n3] Receive 5 bytes on eth0
[t=23.000,src=n3] Received: Hello World from 0!
[t=23.000,src=esds] Simulation ends

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
def receive(node, n):
for i in range(0,n):
code, data=node.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
node.log(msg)
def execute(api):
# Receive the first 3 send that should end at 3s
receive(api,3)
# Receive the first 3 send that should end at 7s
receive(api,3)
# Receive the first 3 send that should end at 12s
receive(api,3)
# Receive the first 3 send that should end at 18s
receive(api,3)
# Should ends at 23s
receive(api,1)

View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
# Node that bandwidths at setup in a way that 1 byte is send in 1 seconds with no sharing
def execute(api):
# Should be completed at 3s (bandwidth divided by 3)
api.send("eth0","Hello World from {}!".format(api.node_id),1,3) # Shoud lasts 3s
# These send should start at 3s and be completed at 7s
if api.node_id==0:
api.send("eth0","Hello World from {}!".format(api.node_id),2,3) # Should lasts 3s + 1s = 4s
else:
api.send("eth0","Hello World from {}!".format(api.node_id),1,3) # Should lasts 3s
api.wait(1) # Sync with node 0 at 7s
# Those sends should start at 7s and be completed at 12s
if api.node_id<=1:
api.send("eth0","Hello World from {}!".format(api.node_id),2,3) # Should last 3s + 2s = 5s
# Completed at 12s since 3 nodes are sharing the bandwidth up to 10s
# then the 2 two remaining node send their last byte up to 12s
else:
api.send("eth0","Hello World from {}!".format(api.node_id),1,3) # Should last 3s
# Completed at 10s (3 nodes are sharing the bandwidth)
api.wait(2) # Sync with node 0-1 at 12s
# Should start at 12s
# Node 0 sends 1 byte, node 1 sends 2 byte and node 2 sends 3
# These send should end at 18s
api.send("eth0","Hello World from {}!".format(api.node_id),api.node_id+1,3) # Should lasts 3s, 5s and 6s
# Finally a single send from node 0
if api.node_id==0:
api.wait(3) # Since node 0 send ends at 15s we sync it to 18s
api.send("eth0","Hello World from {}!".format(api.node_id),5,3) # Should takes 5 seconds (ends at 23s)

View file

@ -0,0 +1,18 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((4,4),8)
L=np.full((4,4),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,16 @@
[t=0.000,src=n0] Send 1 bytes on wlan0
[t=1.000,src=n1] Receive 1 bytes on wlan0
[t=1.000,src=n1] Received: Hello World!
[t=1.000,src=n2] Receive 1 bytes on wlan0
[t=1.000,src=n2] Received: Hello World!
[t=1.000,src=n2] Turned off
[t=1.000,src=n0] Send 1 bytes on wlan0
[t=2.000,src=n1] Receive 1 bytes on wlan0
[t=2.000,src=n1] Received: Hello World!
[t=2.000,src=n2] Turned on
[t=2.000,src=n0] Send 1 bytes on wlan0
[t=2.500,src=n2] Turned off
[t=3.000,src=n1] Receive 1 bytes on wlan0
[t=3.000,src=n1] Received: Hello World!
[t=3.000,src=n2] Turned on
[t=3.000,src=esds] Simulation ends

View file

@ -0,0 +1,29 @@
#!/usr/bin/env python
def receive(node):
##### Simple receive
code, data=node.receive("wlan0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
node.log(msg)
def execute(api):
# Should works for all receivers
receive(api)
if api.node_id == 1:
receive(api) # Should works
else:
api.turn_off()
api.wait(1) # Node 2 should not receive anything during 1s
api.turn_on()
if api.node_id == 1:
receive(api) # Should works
else:
api.wait(0.5) # Check if started communication get cancelled on turning off
api.turn_off() # Node 2 should not receive anything
api.wait(0.5) # Node 2 should not receive anything during 0.5s
api.turn_on()

View file

@ -0,0 +1,6 @@
#!/usr/bin/env python
def execute(api):
api.send("wlan0","Hello World!",1,1)
api.send("wlan0","Hello World!",1,1)
api.send("wlan0","Hello World!",1,1)

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,6 @@
[t=0.000,src=n0] Send 1 bytes on wlan0
[t=0.000,src=n1] Send 1 bytes on wlan0
[t=0.000,src=n0] Interferences on wlan0
[t=0.000,src=n1] Interferences on wlan0
[t=0.000,src=n2] Interferences on wlan0
[t=1.000,src=esds] Simulation ends

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
def execute(api):
pass

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
def execute(api):
api.send("wlan0","Hello World!",1,1)

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,11 @@
[t=0.000,src=n0] Send 1 bytes to n1 on eth0
[t=1.000,src=n1] Receive 1 bytes on eth0
[t=1.000,src=n1] Received: Hello World!
[t=1.000,src=n0] Send worked!
[t=1.000,src=n0] Send 1 bytes to n1 on eth0
[t=1.500,src=n0] Send failed
[t=1.500,src=n0] Send 1 bytes to n1 on eth0
[t=2.500,src=n1] Receive 1 bytes on eth0
[t=2.500,src=n1] Received: Hello World!
[t=2.500,src=n0] Send worked!
[t=2.500,src=esds] Simulation ends

View file

@ -0,0 +1,11 @@
#!/usr/bin/env python
def receive(node):
##### Simple receive
code, data=node.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
node.log(msg)
def execute(api):
receive(api)
receive(api)

View file

@ -0,0 +1,14 @@
#!/usr/bin/env python
def sendt(node,timeout):
code=node.sendt("eth0","Hello World!",1,1,timeout)
msg="Send worked!" if code == 0 else "Send failed"
node.log(msg)
def execute(api):
# Should work
sendt(api,2)
# Should not work
sendt(api,0.5)
# Should work
sendt(api,2)

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,7 @@
[t=0.000,src=n0] Send 1 bytes on wlan0
[t=1.000,src=n1] Receive 1 bytes on wlan0
[t=1.000,src=n1] Received: Hello World!
[t=1.000,src=n2] Receive 1 bytes on wlan0
[t=1.000,src=n2] Received: Hello World!
[t=1.000,src=n0] Send 1 bytes on wlan0
[t=1.500,src=esds] Simulation ends

View file

@ -0,0 +1,13 @@
#!/usr/bin/env python
def receive(node):
##### Simple receive
code, data=node.receive("wlan0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code)
node.log(msg)
def execute(api):
# Should works for all receivers
receive(api)

View file

@ -0,0 +1,8 @@
#!/usr/bin/env python
def execute(api):
# Should works
api.sendt("wlan0","Hello World!",1,1,2)
# Should not work
api.sendt("wlan0","Hello World!",1,1,0.5)

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("sender")
s.create_node("receiver")
s.create_node("receiver")
s.run()

View file

@ -0,0 +1,9 @@
#!/usr/bin/env python
def execute(api):
api.log("Before wait")
api.wait(2)
api.log("After wait")
api.log("Before wait")
api.wait(3)
api.log("After wait")

9
tests/simple_wait_2n/out Normal file
View file

@ -0,0 +1,9 @@
[t=0.000,src=n0] Before wait
[t=0.000,src=n1] Before wait
[t=2.000,src=n0] After wait
[t=2.000,src=n0] Before wait
[t=2.000,src=n1] After wait
[t=2.000,src=n1] Before wait
[t=5.000,src=n0] After wait
[t=5.000,src=n1] After wait
[t=5.000,src=esds] Simulation ends

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((2,2),2)
L=np.full((2,2),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
s.run()

View file

@ -0,0 +1,10 @@
#!/usr/bin/env python
def execute(api):
wait=api.node_id
api.log("Before wait for "+str(wait)+"s")
api.wait(wait) # Since 3 nodes max(wait)==2
# Ensure that wait end return back when simulation ends
api.wait_end()
api.log("Terminated")

View file

@ -0,0 +1,7 @@
[t=0.000,src=n0] Before wait for 0s
[t=0.000,src=n1] Before wait for 1s
[t=0.000,src=n2] Before wait for 2s
[t=2.000,src=n0] Terminated
[t=2.000,src=n1] Terminated
[t=2.000,src=n2] Terminated
[t=2.000,src=esds] Simulation ends

View file

@ -0,0 +1,17 @@
#!/usr/bin/env python
# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np
B=np.full((3,3),2)
L=np.full((3,3),0)
s=esds.Simulator(B,L)
s.create_node("node")
s.create_node("node")
s.create_node("node")
s.run()