| 278 | |
| 279 | |
| 280 | def sn_establish_GSL(container_id_list, matrix, GS_num, constellation_size, bw, |
| 281 | loss): |
| 282 | # starting links among satellites and ground stations |
| 283 | for i in range(1, constellation_size + 1): |
| 284 | for j in range(constellation_size + 1, |
| 285 | constellation_size + GS_num + 1): |
| 286 | # matrix[i-1][j-1])==1 means a link between node i and node j |
| 287 | if ((float(matrix[i - 1][j - 1])) <= 0.01): |
| 288 | continue |
| 289 | # IP address (there is a link between i and j) |
| 290 | delay = str(matrix[i - 1][j - 1]) |
| 291 | address_16_23 = (j - constellation_size) & 0xff |
| 292 | address_8_15 = i & 0xff |
| 293 | GSL_name = "GSL_" + str(i) + "-" + str(j) |
| 294 | # Create internal network in docker. |
| 295 | os.system('docker network create ' + GSL_name + " --subnet 9." + |
| 296 | str(address_16_23) + "." + str(address_8_15) + ".0/24") |
| 297 | print('[Create GSL:]' + 'docker network create ' + GSL_name + |
| 298 | " --subnet 9." + str(address_16_23) + "." + |
| 299 | str(address_8_15) + ".0/24") |
| 300 | os.system('docker network connect ' + GSL_name + " " + |
| 301 | str(container_id_list[i - 1]) + " --ip 9." + |
| 302 | str(address_16_23) + "." + str(address_8_15) + ".50") |
| 303 | with os.popen( |
| 304 | "docker exec -it " + str(container_id_list[i - 1]) + |
| 305 | " ip addr | grep -B 2 9." + str(address_16_23) + "." + |
| 306 | str(address_8_15) + |
| 307 | ".50 | head -n 1 | awk -F: '{ print $2 }' | tr -d [:blank:]" |
| 308 | ) as f: |
| 309 | ifconfig_output = f.readline() |
| 310 | target_interface = str(ifconfig_output).split("@")[0] |
| 311 | os.system("docker exec -d " + str(container_id_list[i - 1]) + |
| 312 | " ip link set dev " + target_interface + " down") |
| 313 | os.system("docker exec -d " + str(container_id_list[i - 1]) + |
| 314 | " ip link set dev " + target_interface + " name " + |
| 315 | "B" + str(i - 1 + 1) + "-eth" + str(j)) |
| 316 | os.system("docker exec -d " + str(container_id_list[i - 1]) + |
| 317 | " ip link set dev B" + str(i - 1 + 1) + "-eth" + |
| 318 | str(j) + " up") |
| 319 | os.system("docker exec -d " + str(container_id_list[i - 1]) + |
| 320 | " tc qdisc add dev B" + str(i - 1 + 1) + "-eth" + |
| 321 | str(j) + " root netem delay " + str(delay) + "ms loss " + str(loss) + "% rate " + str(bw) + "Gbit") |
| 322 | print('[Add current node:]' + 'docker network connect ' + |
| 323 | GSL_name + " " + str(container_id_list[i - 1]) + " --ip 9." + |
| 324 | str(address_16_23) + "." + str(address_8_15) + ".50") |
| 325 | |
| 326 | os.system('docker network connect ' + GSL_name + " " + |
| 327 | str(container_id_list[j - 1]) + " --ip 9." + |
| 328 | str(address_16_23) + "." + str(address_8_15) + ".60") |
| 329 | with os.popen( |
| 330 | "docker exec -it " + str(container_id_list[j - 1]) + |
| 331 | " ip addr | grep -B 2 9." + str(address_16_23) + "." + |
| 332 | str(address_8_15) + |
| 333 | ".60 | head -n 1 | awk -F: '{ print $2 }' | tr -d [:blank:]" |
| 334 | ) as f: |
| 335 | ifconfig_output = f.readline() |
| 336 | target_interface = str(ifconfig_output).split("@")[0] |
| 337 | os.system("docker exec -d " + str(container_id_list[j - 1]) + |