Public repo to distribute scripts and config's
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

80 regels
2.0 KiB

  1. #!/usr/bin/bash
  2. #
  3. NATNET=172.16.0.0/16
  4. NUMOFNS=254
  5. alias IPN='sudo ip net'
  6. alias IPL='sudo ip link'
  7. alias IPA='sudo ip addr add'
  8. peers='tcp://188.40.132.242:9651 tcp://65.21.231.58:9651'
  9. function IPNA() {
  10. local name=$1
  11. shift
  12. sudo ip -n ${name} addr add $@
  13. }
  14. function IPNL() {
  15. local name=$1
  16. shift
  17. sudo ip -n ${name} link $@
  18. }
  19. function IPNR() {
  20. local name=$1
  21. shift
  22. local defrtr=${1/\/24/}
  23. shift
  24. sudo ip -n ${name} route add default via ${defrtr}
  25. }
  26. function createns() {
  27. local iname=$1
  28. local in_ip=$2
  29. local out_ip=$3
  30. local name=n-${iname}
  31. IPN add $name
  32. IPL add in_${iname} type veth peer name out_${iname}
  33. IPL set in_${iname} netns ${name}
  34. IPNL ${name} set lo up
  35. IPNL ${name} set in_${iname} up
  36. IPL set out_${iname} up
  37. IPNA ${name} ${in_ip} dev in_${iname}
  38. IPA ${out_ip} dev out_${iname}
  39. IPNR ${name} ${out_ip}
  40. # start mycelium, relying on local discovery
  41. nohup sudo ip netns exec ${name} ./mycelium --key-file ${name}.bin --disable-peer-discovery --api-addr ${in_ip/\/24/}:8989 --peers ${peers} > ${iname}.out &
  42. }
  43. function dropns() {
  44. local iname=$1
  45. local name=n-${iname}
  46. IPL del out_${iname}
  47. IPN del ${name}
  48. }
  49. function doit() {
  50. nohup sudo ./mycelium --key-file host.bin --api-addr 127.0.0.1:8989 --peers ${peers}>host.out &
  51. for i in $(seq 1 $NUMOFNS); do
  52. createns ${i} 172.16.${i}.2/24 172.16.${i}.1/24
  53. done
  54. }
  55. function dropit() {
  56. sudo pkill -9 mycelium
  57. for i in $(seq 1 $NUMOFNS); do
  58. dropns ${i}
  59. done
  60. }
  61. function cleanit() {
  62. dropit
  63. sudo rm ./*.bin
  64. sudo rm ./*.out
  65. }
  66. function showit() {
  67. sudo killall -USR1 mycelium
  68. }
  69. function getmycelium(){
  70. wget https://github.com/threefoldtech/mycelium/releases/latest/download/mycelium-x86_64-unknown-linux-musl.tar.gz \
  71. -O- | gunzip -c | tar xvf - -C ${PWD}
  72. }