diff options
Diffstat (limited to 'examples/std/README.md')
| -rw-r--r-- | examples/std/README.md | 125 |
1 files changed, 115 insertions, 10 deletions
diff --git a/examples/std/README.md b/examples/std/README.md index e3a59d6ea..ac2c2a1a6 100644 --- a/examples/std/README.md +++ b/examples/std/README.md | |||
| @@ -1,23 +1,128 @@ | |||
| 1 | 1 | ||
| 2 | ## Running the `embassy-net` examples | 2 | ## Running the `embassy-net` examples |
| 3 | 3 | ||
| 4 | First, create the tap0 interface. You only need to do this once. | 4 | To run `net`, `tcp_accept`, `net_udp` and `net_dns` examples you will need a tap interface. Before running these examples, create the tap99 interface. (The number was chosen to |
| 5 | hopefully not collide with anything.) You only need to do this once every time you reboot your computer. | ||
| 5 | 6 | ||
| 6 | ```sh | 7 | ```sh |
| 7 | sudo ip tuntap add name tap0 mode tap user $USER | 8 | cd $EMBASSY_ROOT/examples/std/ |
| 8 | sudo ip link set tap0 up | 9 | sudo sh tap.sh |
| 9 | sudo ip addr add 192.168.69.100/24 dev tap0 | ||
| 10 | sudo ip -6 addr add fe80::100/64 dev tap0 | ||
| 11 | sudo ip -6 addr add fdaa::100/64 dev tap0 | ||
| 12 | sudo ip -6 route add fe80::/64 dev tap0 | ||
| 13 | sudo ip -6 route add fdaa::/64 dev tap0 | ||
| 14 | ``` | 10 | ``` |
| 15 | 11 | ||
| 16 | Second, have something listening there. For example `nc -lp 8000` | 12 | The example `net_ppp` requires different steps that are detailed in its section. |
| 13 | |||
| 14 | ### `net` example | ||
| 15 | |||
| 16 | For this example, you need to have something listening in the correct port. For example `nc -lp 8000`. | ||
| 17 | 17 | ||
| 18 | Then run the example located in the `examples` folder: | 18 | Then run the example located in the `examples` folder: |
| 19 | 19 | ||
| 20 | ```sh | 20 | ```sh |
| 21 | cd $EMBASSY_ROOT/examples/std/ | 21 | cd $EMBASSY_ROOT/examples/std/ |
| 22 | cargo run --bin net -- --static-ip | 22 | cargo run --bin net -- --tap tap99 --static-ip |
| 23 | ``` | ||
| 24 | ### `tcp_accept` example | ||
| 25 | |||
| 26 | This example listen for a tcp connection. | ||
| 27 | |||
| 28 | First run the example located in the `examples` folder: | ||
| 29 | |||
| 30 | ```sh | ||
| 31 | cd $EMBASSY_ROOT/examples/std/ | ||
| 32 | cargo run --bin tcp_accept -- --tap tap99 --static-ip | ||
| 33 | ``` | ||
| 34 | |||
| 35 | Then open a connection to the port. For example `nc 192.168.69.2 9999`. | ||
| 36 | |||
| 37 | ### `net_udp` example | ||
| 38 | |||
| 39 | This example listen for a udp connection. | ||
| 40 | |||
| 41 | First run the example located in the `examples` folder: | ||
| 42 | |||
| 43 | ```sh | ||
| 44 | cd $EMBASSY_ROOT/examples/std/ | ||
| 45 | cargo run --bin net_udp -- --tap tap99 --static-ip | ||
| 46 | ``` | ||
| 47 | |||
| 48 | Then open a connection to the port. For example `nc -u 192.168.69.2 9400`. | ||
| 49 | |||
| 50 | ### `net_dns` example | ||
| 51 | |||
| 52 | This example queries a `DNS` for the IP address of `www.example.com`. | ||
| 53 | |||
| 54 | In order to achieve this, the `tap99` interface requires configuring tap99 as a gateway device temporarily. | ||
| 55 | |||
| 56 | For example, in Ubuntu you can do this by: | ||
| 57 | |||
| 58 | 1. Identifying your default route device. In the next example `eth0` | ||
| 59 | |||
| 60 | ```sh | ||
| 61 | ip r | grep "default" | ||
| 62 | default via 192.168.2.1 dev eth0 proto kernel metric 35 | ||
| 63 | ``` | ||
| 64 | |||
| 65 | 2. Enabling temporarily IP Forwarding: | ||
| 66 | |||
| 67 | ```sh | ||
| 68 | sudo sysctl -w net.ipv4.ip_forward=1 | ||
| 69 | ``` | ||
| 70 | |||
| 71 | 3. Configuring NAT to mascarade traffic from `tap99` to `eth0` | ||
| 72 | |||
| 73 | ```sh | ||
| 74 | sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
| 75 | sudo iptables -A FORWARD -i tap99 -j ACCEPT | ||
| 76 | sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT | ||
| 77 | ``` | ||
| 78 | |||
| 79 | 4. Then you can run the example located in the `examples` folder: | ||
| 80 | |||
| 81 | ```sh | ||
| 82 | cd $EMBASSY_ROOT/examples/std/ | ||
| 83 | cargo run --bin net_dns -- --tap tap99 --static-ip | ||
| 84 | ``` | ||
| 85 | |||
| 86 | ### `net_ppp` example | ||
| 87 | |||
| 88 | This example establish a Point-to-Point Protocol (PPP) connection that can be used, for example, for connecting to internet through a 4G modem via a serial channel. | ||
| 89 | |||
| 90 | The example creates a PPP bridge over a virtual serial channel between `pty1` and `pty2` for the example code and a PPP server running on the same computer. | ||
| 91 | |||
| 92 | To run this example you will need: | ||
| 93 | - ppp (pppd server) | ||
| 94 | - socat (socket CAT) | ||
| 95 | |||
| 96 | To run the examples you may follow the next steps: | ||
| 97 | |||
| 98 | 1. Save the PPP server configuration: | ||
| 99 | ```sh | ||
| 100 | sudo sh -c 'echo "myuser $(hostname) mypass 192.168.7.10" >> /etc/ppp/pap-secrets' | ||
| 101 | ``` | ||
| 102 | |||
| 103 | 2. Create a files `pty1` and `pty2` and link them | ||
| 104 | ```sh | ||
| 105 | cd $EMBASSY_ROOT/examples/std/ | ||
| 106 | socat -v -x PTY,link=pty1,rawer PTY,link=pty2,rawer | ||
| 107 | ``` | ||
| 108 | |||
| 109 | 3. open a second terminal and start the PPP server: | ||
| 110 | ```sh | ||
| 111 | cd $EMBASSY_ROOT/examples/std/ | ||
| 112 | sudo pppd $PWD/pty1 115200 192.168.7.1: ms-dns 8.8.4.4 ms-dns 8.8.8.8 nodetach debug local persist silent | ||
| 113 | ``` | ||
| 114 | |||
| 115 | 4. Open a third terminal and run the example | ||
| 116 | ```sh | ||
| 117 | cd $EMBASSY_ROOT/examples/std/ | ||
| 118 | RUST_LOG=trace cargo run --bin net_ppp -- --device pty2 | ||
| 119 | ``` | ||
| 120 | 5. Observe the output in the second and third terminal | ||
| 121 | 6. Open one last terminal to interact with `net_ppp` example through the PPP connection | ||
| 122 | ```sh | ||
| 123 | # ping the net_ppp client | ||
| 124 | ping 192.168.7.10 | ||
| 125 | # open an tcp connection | ||
| 126 | nc 192.168.7.10 1234 | ||
| 127 | # Type anything and observe the output in the different terminals | ||
| 23 | ``` | 128 | ``` |
