Lab7 Done Right. 完结撒花!

This commit is contained in:
ridethepig 2023-02-18 16:37:55 +00:00
parent 7dd3fed217
commit 892e613b72
7 changed files with 146 additions and 18 deletions

View File

@ -30,7 +30,8 @@ void Router::add_route(const uint32_t route_prefix,
cerr << "DEBUG: adding route " << Address::from_ipv4_numeric(route_prefix).ip() << "/" << int(prefix_length) cerr << "DEBUG: adding route " << Address::from_ipv4_numeric(route_prefix).ip() << "/" << int(prefix_length)
<< " => " << (next_hop.has_value() ? next_hop->ip() : "(direct)") << " on interface " << interface_num << "\n"; << " => " << (next_hop.has_value() ? next_hop->ip() : "(direct)") << " on interface " << interface_num << "\n";
uint32_t mask = 0; uint32_t mask = 0;
if (prefix_length > 0) mask = (1 << 31) >> (prefix_length - 1); if (prefix_length > 0)
mask = (1 << 31) >> (prefix_length - 1);
_route_table.push_back(std::make_tuple(route_prefix, prefix_length, next_hop, interface_num, mask)); _route_table.push_back(std::make_tuple(route_prefix, prefix_length, next_hop, interface_num, mask));
} }
@ -53,8 +54,7 @@ void Router::route_one_datagram(InternetDatagram &dgram) {
if (best_match != _route_table.end()) { if (best_match != _route_table.end()) {
if (dgram.header().ttl <= 1) { if (dgram.header().ttl <= 1) {
return; return;
} } else {
else {
dgram.header().ttl--; dgram.header().ttl--;
} }
auto next_hop = std::get<2>(*best_match).value_or(Address::from_ipv4_numeric(dgram.header().dst)); auto next_hop = std::get<2>(*best_match).value_or(Address::from_ipv4_numeric(dgram.header().dst));

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

View File

@ -1,23 +1,149 @@
Lab 7 Writeup Lab 7 Writeup
============= =============
My name: [your name here] My name: Catfood
My SUNet ID: [your sunetid here] My SUNet ID: 998244353
My lab partner's SUNet ID: [your sunetid here] I collaborated with: An orange cat
I also worked with or collaborated with: [their sunetids here] This lab took me about `1` hours to do.
I would like to thank/reward these classmates for their help: [list sunetids here]
This lab took me about [n] hours to do. I [did/did not] attend the lab session.
Solo portion: Solo portion:
[]
就,照着敲命令就好了。不过不知道为啥,好像有点慢而且有概率会失败,需要耐心一点。
Section 3
---------
**server** run first
```
➜ build git:(master) ./apps/lab7 server cs144.keithw.org 3000
DEBUG: Network interface has Ethernet address 02:00:00:09:60:3c and IP address 172.16.0.1
DEBUG: Network interface has Ethernet address 02:00:00:0c:50:e4 and IP address 10.0.0.172
DEBUG: adding route 172.16.0.0/12 => (direct) on interface 0
DEBUG: adding route 10.0.0.0/8 => (direct) on interface 1
DEBUG: adding route 192.168.0.0/16 => 10.0.0.192 on interface 1
DEBUG: Network interface has Ethernet address 8a:0e:de:4e:97:19 and IP address 172.16.0.100
DEBUG: Listening for incoming connection...
New connection from 192.168.0.50:16828.
hello world
hello client
Oh!!!!!!!
DEBUG: Inbound stream from 192.168.0.50:16828 finished cleanly.
DEBUG: Waiting for clean shutdown... DEBUG: Outbound stream to 192.168.0.50:16828 finished (1 byte still in flight).
DEBUG: Outbound stream to 192.168.0.50:16828 has been fully acknowledged.
DEBUG: TCP connection finished cleanly.
done.
Exiting... done.
```
**client**
```
➜ build git:(master) ./apps/lab7 client cs144.keithw.org 3001
DEBUG: Network interface has Ethernet address 02:00:00:32:12:73 and IP address 192.168.0.1
DEBUG: Network interface has Ethernet address 02:00:00:da:5c:7d and IP address 10.0.0.192
DEBUG: adding route 192.168.0.0/16 => (direct) on interface 0
DEBUG: adding route 10.0.0.0/8 => (direct) on interface 1
DEBUG: adding route 172.16.0.0/12 => 10.0.0.172 on interface 1
DEBUG: Network interface has Ethernet address 6e:18:17:8b:27:38 and IP address 192.168.0.50
DEBUG: Connecting from 192.168.0.50:16828...
DEBUG: Connecting to 172.16.0.100:1234...
Successfully connected to 172.16.0.100:1234.
hello world
hello client
Oh!!!!!!!
DEBUG: Outbound stream to 172.16.0.100:1234 finished (1 byte still in flight).
DEBUG: Outbound stream to 172.16.0.100:1234 has been fully acknowledged.
DEBUG: Inbound stream from 172.16.0.100:1234 finished cleanly.
DEBUG: Waiting for lingering segments (e.g. retransmissions of FIN) from peer...
DEBUG: Waiting for clean shutdown... DEBUG: TCP connection finished cleanly.
done.
Exiting... done.
```
Section 4
----------
server启动后会等待连接到来才发送数据因此可以先执行。但是有个巨大的问题就是不是很稳定而且发送极其缓慢只能耐心了。
**server**
```
➜ build git:(master) ✗ dd if=/dev/urandom bs=1M count=1 of=/tmp/big.txt
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00460547 s, 228 MB/s
➜ build git:(master) ✗ ./apps/lab7 server cs144.keithw.org 3000 < /tmp/big.txt
DEBUG: Network interface has Ethernet address 02:00:00:f0:8f:3f and IP address 172.16.0.1
DEBUG: Network interface has Ethernet address 02:00:00:82:df:65 and IP address 10.0.0.172
DEBUG: adding route 172.16.0.0/12 => (direct) on interface 0
DEBUG: adding route 10.0.0.0/8 => (direct) on interface 1
DEBUG: adding route 192.168.0.0/16 => 10.0.0.192 on interface 1
DEBUG: Network interface has Ethernet address 86:87:fa:05:41:74 and IP address 172.16.0.100
DEBUG: Listening for incoming connection...
New connection from 192.168.0.50:25255.
DEBUG: Inbound stream from 192.168.0.50:25255 finished cleanly.
DEBUG: Waiting for clean shutdown... DEBUG: Outbound stream to 192.168.0.50:25255 finished (64000 bytes still in flight).
DEBUG: Outbound stream to 192.168.0.50:25255 has been fully acknowledged.
DEBUG: TCP connection finished cleanly.
done.
Exiting... done.
```
**client**
```
➜ build git:(master) ✗ </dev/null ./apps/lab7 client cs144.keithw.org 3001 > /tmp/big-received.txt
DEBUG: Network interface has Ethernet address 02:00:00:fe:a0:99 and IP address 192.168.0.1
DEBUG: Network interface has Ethernet address 02:00:00:31:4a:3c and IP address 10.0.0.192
DEBUG: adding route 192.168.0.0/16 => (direct) on interface 0
DEBUG: adding route 10.0.0.0/8 => (direct) on interface 1
DEBUG: adding route 172.16.0.0/12 => 10.0.0.172 on interface 1
DEBUG: Network interface has Ethernet address 3e:6d:08:df:93:af and IP address 192.168.0.50
DEBUG: Connecting from 192.168.0.50:25255...
DEBUG: Connecting to 172.16.0.100:1234...
Successfully connected to 172.16.0.100:1234.
DEBUG: Outbound stream to 172.16.0.100:1234 finished (1 byte still in flight).
DEBUG: Outbound stream to 172.16.0.100:1234 has been fully acknowledged.
DEBUG: Inbound stream from 172.16.0.100:1234 finished cleanly.
DEBUG: Waiting for lingering segments (e.g. retransmissions of FIN) from peer...
DEBUG: Waiting for clean shutdown... DEBUG: TCP connection finished cleanly.
done.
Exiting... done.
➜ sponge git:(master) ✗ sha256sum /tmp/big.txt
f2c54a920a34e125ea4478735f5f07af926c40abe9f0f695272b689370ce6782 /tmp/big.txt
➜ sponge git:(master) ✗ sha256sum /tmp/big-received.txt
f2c54a920a34e125ea4478735f5f07af926c40abe9f0f695272b689370ce6782 /tmp/big-received.txt
```
**离谱的发送时间**
发了快8分钟才发完下面的log显示发600K花了4分多钟大概重传了不知道多少次了已经本来打算分析一波原因的但是这网卡都是走的自己写的压根没办法抓包啊只能看他打印的 debug过于抽象所以就没分析了。不过大概率是外部设备的问题国内网络环境比较的复杂不过能发完应该就问题不大了大雾
```
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 451K Feb 18 15:42 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 528K Feb 18 15:42 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 654K Feb 18 15:44 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 875K Feb 18 15:45 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 922K Feb 18 15:45 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 985K Feb 18 15:46 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
➜ sponge git:(master) ✗ ls -lh /tmp | grep big
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:46 big-received.txt
-rw-rw-r-- 1 catfood catfood 1.0M Feb 18 15:29 big.txt
```
Group portion: Group portion:
[]
没有人和我一起玩(哇哇大哭~
Creative portion (optional): Creative portion (optional):
[] []
@ -31,4 +157,6 @@ Other remarks:
- Optional: I was surprised by: [describe] - Optional: I was surprised by: [describe]
- Optional: I'm not sure about: [describe] - Optional: I'm not sure about: [发的多少有点慢的离谱,不知道是哪里的问题]
完结撒花。虽然不知道以后这个实验的服务器会不会继续开着,因为有些实验,还不得不用它的服务器,如果没了就做不了了捏。