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

@ -17,7 +17,7 @@ using namespace std;
// You will need to add private members to the class declaration in `router.hh` // You will need to add private members to the class declaration in `router.hh`
template <typename... Targs> template <typename... Targs>
void DUMMY_CODE(Targs &&... /* unused */) {} void DUMMY_CODE(Targs &&.../* unused */) {}
//! \param[in] route_prefix The "up-to-32-bit" IPv4 address prefix to match the datagram's destination address against //! \param[in] route_prefix The "up-to-32-bit" IPv4 address prefix to match the datagram's destination address against
//! \param[in] prefix_length For this route to be applicable, how many high-order (most-significant) bits of the route_prefix will need to match the corresponding bits of the datagram's destination address? //! \param[in] prefix_length For this route to be applicable, how many high-order (most-significant) bits of the route_prefix will need to match the corresponding bits of the datagram's destination address?
@ -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));
} }
@ -39,7 +40,7 @@ void Router::route_one_datagram(InternetDatagram &dgram) {
auto dst_ip = dgram.header().dst; auto dst_ip = dgram.header().dst;
auto best_match = _route_table.end(); auto best_match = _route_table.end();
int longest_prefix = 0; int longest_prefix = 0;
for (auto rule = _route_table.begin(); rule != _route_table.end(); ++ rule) { for (auto rule = _route_table.begin(); rule != _route_table.end(); ++rule) {
auto route_prefix = std::get<0>(*rule); auto route_prefix = std::get<0>(*rule);
auto prefix_length = std::get<1>(*rule); auto prefix_length = std::get<1>(*rule);
auto mask = std::get<4>(*rule); auto mask = std::get<4>(*rule);
@ -53,9 +54,8 @@ 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));
_interfaces[std::get<3>(*best_match)].send_datagram(dgram, next_hop); _interfaces[std::get<3>(*best_match)].send_datagram(dgram, next_hop);

View File

@ -48,7 +48,7 @@ class Router {
std::vector<AsyncNetworkInterface> _interfaces{}; std::vector<AsyncNetworkInterface> _interfaces{};
//! Internal routing table. Tuple(prefix, prefix_length, next_hop, interface, mask) //! Internal routing table. Tuple(prefix, prefix_length, next_hop, interface, mask)
std::vector<std::tuple<uint32_t, uint8_t,std::optional<Address>, size_t, uint32_t>> _route_table {}; std::vector<std::tuple<uint32_t, uint8_t, std::optional<Address>, size_t, uint32_t>> _route_table{};
//! Send a single datagram from the appropriate outbound interface to the next hop, //! Send a single datagram from the appropriate outbound interface to the next hop,
//! as specified by the route with the longest prefix_length that matches the //! as specified by the route with the longest prefix_length that matches the

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: [发的多少有点慢的离谱,不知道是哪里的问题]
完结撒花。虽然不知道以后这个实验的服务器会不会继续开着,因为有些实验,还不得不用它的服务器,如果没了就做不了了捏。