Blame view

RIOT/dist/tools/ethos/start_network.sh 1 KB
a752c7ab   elopes   add first test an...
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
  #!/bin/sh
  
  ETHOS_DIR="$(dirname $(readlink -f $0))"
  
  create_tap() {
      ip tuntap add ${TAP} mode tap user ${USER}
      sysctl -w net.ipv6.conf.${TAP}.forwarding=1
      sysctl -w net.ipv6.conf.${TAP}.accept_ra=0
      ip link set ${TAP} up
      ip a a fe80::1/64 dev ${TAP}
      ip a a fd00:dead:beef::1/128 dev lo
      ip route add ${PREFIX} via fe80::2 dev ${TAP}
  }
  
  remove_tap() {
      ip tuntap del ${TAP} mode tap
  }
  
  cleanup() {
      echo "Cleaning up..."
      remove_tap
      ip a d fd00:dead:beef::1/128 dev lo
      kill ${UHCPD_PID}
      trap "" INT QUIT TERM EXIT
  }
  
  start_uhcpd() {
      ${UHCPD} ${TAP} ${PREFIX} > /dev/null &
      UHCPD_PID=$!
  }
  
  PORT=$1
  TAP=$2
  PREFIX=$3
  BAUDRATE=115200
  UHCPD="$(readlink -f "${ETHOS_DIR}/../uhcpd/bin")/uhcpd"
  
  [ -z "${PORT}" -o -z "${TAP}" -o -z "${PREFIX}" ] && {
      echo "usage: $0 <serial-port> <tap-device> <prefix> [baudrate]"
      exit 1
  }
  
  [ ! -z $4 ] && {
      BAUDRATE=$4
  }
  
  trap "cleanup" INT QUIT TERM EXIT
  
  
  create_tap && start_uhcpd && "${ETHOS_DIR}/ethos" ${TAP} ${PORT} ${BAUDRATE}