-
Notifications
You must be signed in to change notification settings - Fork 0
/
rangen.sh
executable file
·130 lines (106 loc) · 3.23 KB
/
rangen.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# Input parameters for the number of UEs and gNBs
number_ues=$1
number_gnb=$2
nome_arquivo="docker-compose-setup.yaml"
imsi=208930000000000
imsi_f=208930000000000
link_gnb="gnb.free5gc.org"
# Copy the contents of the base file to the setup file to ensure a known initial state
cp docker-compose-base.yaml docker-compose-setup.yaml
# Network definitions to be added at the end of the setup file
final="
networks:
privnet:
ipam:
driver: default
config:
- subnet: 10.100.200.0/24
driver_opts:
com.docker.network.bridge.name: br-free5gc
volumes:
dbdata:
"
# Loop to add a container for each gNB+UEs pack
for ((i=0; i<$number_gnb; i++));
do
# Block that defines the service for each UE and gNB
service_block="
ueransim$i:
container_name: ueransim$i
build:
context: ./ueransim
volumes:
- ./config/gnbcfg$i.yaml:/ueransim/config/gnbcfg$i.yaml
- ./config/uecfg$i.yaml:/ueransim/config/uecfg$i.yaml
- ./config/gnbcfg.yaml:/ueransim/config/gnbcfg.yaml
- ./config/uecfg.yaml:/ueransim/config/uecfg.yaml
cap_add:
- NET_ADMIN
devices:
- "/dev/net/tun"
networks:
privnet:
aliases:
- ue$i.free5gc.org
depends_on:
- free5gc-amf
- free5gc-upf
command: ./start.sh $i $number_ues
ueransim-gnb$i:
container_name: ueransim-gnb$i
build:
context: ./ueransim
volumes:
- ./config/gnbcfg$i.yaml:/ueransim/config/gnbcfg$i.yaml
- ./config/gnbcfg.yaml:/ueransim/config/gnbcfg.yamll
cap_add:
- NET_ADMIN
devices:
- "/dev/net/tun"
networks:
privnet:
aliases:
- gnb$i.free5gc.org
depends_on:
- free5gc-amf
- free5gc-upf
command: ./nr-gnb -c ./config/gnbcfg$i.yaml &
"
# Append the service block to the docker-compose file
echo "$service_block" >> "$nome_arquivo"
# Create a uecfgx file based on the uecfg file starting with an imsi of 0
# Here x is the current number of gNB
cat config/uecfg.yaml > config/uecfg$i.yaml
# Calculate the imsi based on the configuration file (number of gNB)
sed -i "s#$imsi#$imsi_f#g" config/uecfg$i.yaml
imsi_f=$(( $number_ues * ($i + 1) + $imsi ))
# Change the network IP in the UE file based on the gNB
sed -i "s#$link_gnb#gnb$i.free5gc.org#g" config/uecfg$i.yaml
# Create a gnbcfgx file based on the gnbcfg file starting with IP gnb.free5gc.org
# Here x is the current number of gNB
cat config/gnbcfg.yaml > config/gnbcfg$i.yaml
# Change the network IP in the gNB file based on the gNB number
sed -i "s#$link_gnb#gnb$i.free5gc.org#g" config/gnbcfg$i.yaml
done
# Add network configurations at the end of the file
echo "$final" >> "$nome_arquivo"
# Build the ueransim containers
for ((j=0; j<$number_gnb; j++));
do
docker compose -f docker-compose-setup.yaml build ueransim$j
docker compose -f docker-compose-setup.yaml build ueransim-gnb$j
done
sleep 5
# Start the services
docker compose -f docker-compose-setup.yaml up
# At the end of the script execution, delete the generated configuration files.
for ((k=0; k< $number_gnb; k++));
do
file_name="config/uecfg$k.yaml"
rm -rf "${file_name}"
file_name="config/gnbcfg$k.yaml"
rm -rf "${file_name}"
done
file_name="docker-compose-setup.yaml"
rm -rf "${file_name}"