-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscenario.sh
executable file
·61 lines (45 loc) · 1.83 KB
/
scenario.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#/bin/bash
# Creating the FIFO -----------------------------------------------------------#
echo "+ Deleting previous FIFO if they still exist"
\rm -f /tmp/in? /tmp/out? > /dev/null
echo "+ Creating one input FIFO per vehicle"
mkfifo /tmp/in1 /tmp/in2 /tmp/in3
echo "+ Creating one output FIFO per vehicle"
mkfifo /tmp/out1 /tmp/out2 /tmp/out3
# Launching the applications --------------------------------------------------#
echo "+ Launching one CAR application per vehicle"
./app.tk --ident=one --auto < /tmp/in1 > /tmp/out1 & pid_app1=$!
echo "id app1 : $pid_app1"
./app.tk --ident=two --auto < /tmp/in2 > /tmp/out2 & pid_app2=$!
echo "id app2 : $pid_app2"
./app.tk --ident=three --auto < /tmp/in3 > /tmp/out3 & pid_app3=$!
echo "id app3 : $pid_app3"
# Creating the network topology -----------------------------------------------#
# Connecting the vehicles in convoy:
# one <--> two <--> three
# one --> two
cat /tmp/out1 > /tmp/in2 & pid_com1=$!
echo "id com1 : $pid_com1"
# one <-- two --> three
cat /tmp/out2 | tee /tmp/in1 > /tmp/in3 & pid_com2=$!
echo "id com2 : $pid_com2"
# Two <-- three
cat /tmp/out3 > /tmp/in2 & pid_com3=$!
echo "id com3 : $pid_com3"
# Waiting for the end of the scenario -----------------------------------------#
echo "+ Waiting for the end of the scenario: type \"end\" for quitting. ";
# Reading stdin until "end" is typed
read -a foo
while ! [ "$foo" = "end" ]; do
echo "* reading $foo, not end. To terminate, type \"end\". ";
read -a foo
done
echo "+ Killing the applications"
kill -9 $pid_app1 $pid_app2 $pid_app3
echo "kill app : $pid_app1 $pid_app2 $pid_app3"
echo "+ Killing the communications"
kill -9 $pid_com1 $pid_com2 $pid_com3
echo "kill com : $pid_com1 $pid_com2 $pid_com3"
echo "+ Deleting the FIFO"
\rm -f /tmp/in? /tmp/out? > /dev/null
echo "+ End of the scenario"