Squashed 'components/mycelium/' content from commit afb32e0
git-subtree-dir: components/mycelium git-subtree-split: afb32e0cdb2d4cdd17f22a5693278068d061f08c
This commit is contained in:
58
scripts/README.md
Normal file
58
scripts/README.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Development / test scripts
|
||||
|
||||
## `setup_network.sh`
|
||||
|
||||
`setup_network.sh` is used as-is, and as_root :-/
|
||||
This little thing adds some LINUX network namespaces in which you can run mycelium
|
||||
U're a dev so deal with it
|
||||
|
||||
|
||||
## testing mycelium (`bigmush.sh`)
|
||||
This lill skrip will just start $NUMOFNS network namespaces in your LINUX box where you can SUDO (because I __know__ for a fact that you weren't root, of course), start a mycelium daemon in the main namespace and one in each NS.
|
||||
|
||||
### Usage :
|
||||
|
||||
Start with
|
||||
```bash
|
||||
source ./bigmush.sh
|
||||
getmycelium
|
||||
```
|
||||
will get the latest __release__ binary from github
|
||||
|
||||
Then
|
||||
```bash
|
||||
source ./bigmush.sh
|
||||
doit
|
||||
```
|
||||
|
||||
will create and start a 50 node mycelium with one central
|
||||
|
||||
```bash
|
||||
source ./bigmush
|
||||
dropit
|
||||
```
|
||||
will kill with little mercy mycelium daemons and delete the namespaces
|
||||
|
||||
|
||||
```bash
|
||||
source ./bigmush.sh
|
||||
cleanit
|
||||
```
|
||||
will do a `dropit` and clean `*.{bin,out}` files
|
||||
|
||||
```bash
|
||||
showit
|
||||
```
|
||||
|
||||
will send a USR1 signal to all mycelium daemons that will
|
||||
- send routing tables and peers to stdout
|
||||
- where stdout will be captured in `xx.out` for each NS
|
||||
|
||||
### logging
|
||||
every namespace has an `xx.out` file that is stout and stderr
|
||||
the `xx.bin` file is the namespace daemon's privkey.
|
||||
|
||||
### behaviour testing
|
||||
|
||||
1) verify if you can reach all mycelium namespaces
|
||||
2) also when running another machine in your net, verify if it's automatically detected
|
||||
90
scripts/bigmush.fish
Normal file
90
scripts/bigmush.fish
Normal file
@@ -0,0 +1,90 @@
|
||||
set NATNET 172.16.0.0/16
|
||||
set NUMOFNS 32
|
||||
|
||||
function IPN
|
||||
sudo ip net $argv
|
||||
end
|
||||
|
||||
function IPL
|
||||
sudo ip link $argv
|
||||
end
|
||||
|
||||
function IPA
|
||||
sudo ip addr add $argv
|
||||
end
|
||||
|
||||
set peers tcp://188.40.132.242:9651 quic://[2a01:4f8:212:fa6::2]:9651 tcp://185.69.166.7:9651 quic://[2a02:1802:5e:0:ec4:7aff:fe51:e36b]:9651 tcp://65.21.231.58:9651 quic://[2a01:4f9:5a:1042::2]:9651 tcp://[2604:a00:50:17b:9e6b:ff:fe1f:e054]:9651 quic://5.78.122.16:9651 tcp://[2a01:4ff:2f0:3621::1]:9651 quic://142.93.217.194:9651
|
||||
|
||||
function IPNA
|
||||
set name $argv[1]
|
||||
set -e argv[1]
|
||||
sudo ip -n $name addr add $argv
|
||||
end
|
||||
|
||||
function IPNL
|
||||
set name $argv[1]
|
||||
set -e argv[1]
|
||||
sudo ip -n $name link $argv
|
||||
end
|
||||
|
||||
function IPNR
|
||||
set name $argv[1]
|
||||
set defrtr (string replace -r '/24$' '' $argv[2])
|
||||
set -e argv[1]
|
||||
set -e argv[2]
|
||||
sudo ip -n $name route add default via $defrtr
|
||||
end
|
||||
|
||||
function createns
|
||||
set iname $argv[1]
|
||||
set in_ip $argv[2]
|
||||
set out_ip $argv[3]
|
||||
set name n-$iname
|
||||
IPN add $name
|
||||
IPL add in_$iname type veth peer name out_$iname
|
||||
IPL set in_$iname netns $name
|
||||
IPNL $name set lo up
|
||||
IPNL $name set in_$iname up
|
||||
IPL set out_$iname up
|
||||
IPNA $name $in_ip dev in_$iname
|
||||
IPA $out_ip dev out_$iname
|
||||
IPNR $name $out_ip
|
||||
nohup sudo ip netns exec $name ./mycelium --key-file $name.bin --api-addr (string replace -r '/24$' '' $in_ip):8989 --peers tcp://(string replace -r '/24$' '' $out_ip):9651 > $iname.out &
|
||||
end
|
||||
|
||||
function dropns
|
||||
set iname $argv[1]
|
||||
set name n-$iname
|
||||
IPL del out_$iname
|
||||
IPN del $name
|
||||
end
|
||||
|
||||
function doit
|
||||
nohup sudo ./mycelium --key-file host.bin --api-addr 127.0.0.1:8989 --peers $peers > host.out &
|
||||
for i in (seq 1 $NUMOFNS)
|
||||
createns $i 172.16.$i.2/24 172.16.$i.1/24
|
||||
end
|
||||
end
|
||||
|
||||
function dropit
|
||||
sudo pkill -9 mycelium
|
||||
for i in (seq 1 $NUMOFNS)
|
||||
dropns $i
|
||||
end
|
||||
end
|
||||
|
||||
function cleanit
|
||||
dropit
|
||||
sudo rm ./*.bin
|
||||
sudo rm ./*.out
|
||||
end
|
||||
|
||||
function showit
|
||||
sudo killall -USR1 mycelium
|
||||
end
|
||||
|
||||
function getmycelium
|
||||
wget https://github.com/threefoldtech/mycelium/releases/latest/download/mycelium-x86_64-unknown-linux-musl.tar.gz \
|
||||
-O- | gunzip -c | tar xvf - -C $PWD
|
||||
end
|
||||
|
||||
79
scripts/bigmush.sh
Executable file
79
scripts/bigmush.sh
Executable file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/bash
|
||||
#
|
||||
NATNET=172.16.0.0/16
|
||||
NUMOFNS=32
|
||||
alias IPN='sudo ip net'
|
||||
alias IPL='sudo ip link'
|
||||
alias IPA='sudo ip addr add'
|
||||
|
||||
peers='tcp://188.40.132.242:9651 quic://[2a01:4f8:212:fa6::2]:9651 tcp://185.69.166.7:9651 quic://[2a02:1802:5e:0:ec4:7aff:fe51:e36b]:9651 tcp://65.21.231.58:9651 quic://[2a01:4f9:5a:1042::2]:9651 tcp://[2604:a00:50:17b:9e6b:ff:fe1f:e054]:9651 quic://5.78.122.16:9651 tcp://[2a01:4ff:2f0:3621::1]:9651 quic://142.93.217.194:9651'
|
||||
|
||||
function IPNA() {
|
||||
local name=$1
|
||||
shift
|
||||
sudo ip -n ${name} addr add $@
|
||||
}
|
||||
function IPNL() {
|
||||
local name=$1
|
||||
shift
|
||||
sudo ip -n ${name} link $@
|
||||
}
|
||||
function IPNR() {
|
||||
local name=$1
|
||||
shift
|
||||
local defrtr=${1/\/24/}
|
||||
shift
|
||||
sudo ip -n ${name} route add default via ${defrtr}
|
||||
}
|
||||
function createns() {
|
||||
local iname=$1
|
||||
local in_ip=$2
|
||||
local out_ip=$3
|
||||
local name=n-${iname}
|
||||
IPN add $name
|
||||
IPL add in_${iname} type veth peer name out_${iname}
|
||||
IPL set in_${iname} netns ${name}
|
||||
IPNL ${name} set lo up
|
||||
IPNL ${name} set in_${iname} up
|
||||
IPL set out_${iname} up
|
||||
IPNA ${name} ${in_ip} dev in_${iname}
|
||||
IPA ${out_ip} dev out_${iname}
|
||||
IPNR ${name} ${out_ip}
|
||||
# start mycelium, relying on local discovery
|
||||
nohup sudo ip netns exec ${name} ./mycelium --key-file ${name}.bin --api-addr ${in_ip/\/24/}:8989 --peers tcp://${out_ip/\/24/}:9651 > ${iname}.out &
|
||||
}
|
||||
function dropns() {
|
||||
local iname=$1
|
||||
local name=n-${iname}
|
||||
IPL del out_${iname}
|
||||
IPN del ${name}
|
||||
}
|
||||
|
||||
function doit() {
|
||||
nohup sudo ./mycelium --key-file host.bin --api-addr 127.0.0.1:8989 --peers ${peers} >host.out &
|
||||
for i in $(seq 1 $NUMOFNS); do
|
||||
createns ${i} 172.16.${i}.2/24 172.16.${i}.1/24
|
||||
done
|
||||
}
|
||||
function dropit() {
|
||||
sudo pkill -9 mycelium
|
||||
for i in $(seq 1 $NUMOFNS); do
|
||||
dropns ${i}
|
||||
done
|
||||
}
|
||||
|
||||
function cleanit() {
|
||||
dropit
|
||||
sudo rm ./*.bin
|
||||
sudo rm ./*.out
|
||||
}
|
||||
|
||||
function showit() {
|
||||
sudo killall -USR1 mycelium
|
||||
}
|
||||
|
||||
function getmycelium() {
|
||||
wget https://github.com/threefoldtech/mycelium/releases/latest/download/mycelium-x86_64-unknown-linux-musl.tar.gz \
|
||||
-O- | gunzip -c | tar xvf - -C ${PWD}
|
||||
|
||||
}
|
||||
56
scripts/setup_network.sh
Executable file
56
scripts/setup_network.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# A simple shell script to setup a local network using network namespaces. This relies on the presence of the `ip` tool, part of `iproute2` package on linux.
|
||||
#
|
||||
# Note: this script requires root privilege
|
||||
|
||||
set -ex
|
||||
|
||||
# Create veth pairs
|
||||
ip l add p0 type veth peer p1
|
||||
ip l add p2 type veth peer p3
|
||||
ip l add p4 type veth peer p5
|
||||
ip l add p6 type veth peer p7
|
||||
|
||||
# Create bridge
|
||||
ip l add mycelium-br type bridge
|
||||
|
||||
# Add 1 part of every veth pair in the bridge
|
||||
ip l set p1 master mycelium-br
|
||||
ip l set p3 master mycelium-br
|
||||
ip l set p5 master mycelium-br
|
||||
ip l set p7 master mycelium-br
|
||||
|
||||
# Add network namespaces
|
||||
ip netns add net1
|
||||
ip netns add net2
|
||||
ip netns add net3
|
||||
|
||||
# Enable loopback devices in network namespaces
|
||||
ip -n net1 l set lo up
|
||||
ip -n net2 l set lo up
|
||||
ip -n net3 l set lo up
|
||||
|
||||
# Add 1 veth end to every network namespace
|
||||
ip l set p2 netns net1
|
||||
ip l set p4 netns net2
|
||||
ip l set p6 netns net3
|
||||
|
||||
# Set underlay IP addresses on the veth parts which are not in the bridge
|
||||
ip a add 10.0.2.1/24 dev p0
|
||||
ip -n net1 a add 10.0.2.2/24 dev p2
|
||||
ip -n net2 a add 10.0.2.3/24 dev p4
|
||||
ip -n net3 a add 10.0.2.4/24 dev p6
|
||||
|
||||
# Set all veth interface to up
|
||||
ip l set p0 up
|
||||
ip l set p1 up
|
||||
ip -n net1 l set p2 up
|
||||
ip l set p3 up
|
||||
ip -n net2 l set p4 up
|
||||
ip l set p5 up
|
||||
ip -n net3 l set p6 up
|
||||
ip l set p7 up
|
||||
|
||||
# Set bridge as up
|
||||
ip l set mycelium-br up
|
||||
Reference in New Issue
Block a user