diff --git a/libsponge/router.cc b/libsponge/router.cc index 1964374..6b471b7 100644 --- a/libsponge/router.cc +++ b/libsponge/router.cc @@ -17,7 +17,7 @@ using namespace std; // You will need to add private members to the class declaration in `router.hh` template -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] 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) << " => " << (next_hop.has_value() ? next_hop->ip() : "(direct)") << " on interface " << interface_num << "\n"; 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)); } @@ -39,7 +40,7 @@ void Router::route_one_datagram(InternetDatagram &dgram) { auto dst_ip = dgram.header().dst; auto best_match = _route_table.end(); 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 prefix_length = std::get<1>(*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 (dgram.header().ttl <= 1) { return; - } - else { - dgram.header().ttl --; + } else { + dgram.header().ttl--; } 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); diff --git a/libsponge/router.hh b/libsponge/router.hh index 0899889..d3b4f77 100644 --- a/libsponge/router.hh +++ b/libsponge/router.hh @@ -48,7 +48,7 @@ class Router { std::vector _interfaces{}; //! Internal routing table. Tuple(prefix, prefix_length, next_hop, interface, mask) - std::vector, size_t, uint32_t>> _route_table {}; + std::vector, size_t, uint32_t>> _route_table{}; //! 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 diff --git a/writeups/ComputerNetworkDoneRight.png b/writeups/ComputerNetworkDoneRight.png new file mode 100644 index 0000000..bb71fea Binary files /dev/null and b/writeups/ComputerNetworkDoneRight.png differ diff --git a/writeups/Lab7_done_right.png b/writeups/Lab7_done_right.png new file mode 100644 index 0000000..591abac Binary files /dev/null and b/writeups/Lab7_done_right.png differ diff --git a/writeups/Lab7_done_right2.1.png b/writeups/Lab7_done_right2.1.png new file mode 100644 index 0000000..1fcd124 Binary files /dev/null and b/writeups/Lab7_done_right2.1.png differ diff --git a/writeups/Lab7_done_right2.png b/writeups/Lab7_done_right2.png new file mode 100644 index 0000000..bd3c13c Binary files /dev/null and b/writeups/Lab7_done_right2.png differ diff --git a/writeups/lab7.md b/writeups/lab7.md index c215f53..74ff0b6 100644 --- a/writeups/lab7.md +++ b/writeups/lab7.md @@ -1,23 +1,149 @@ 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] - -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. +This lab took me about `1` hours to do. 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) ✗ /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: -[] + +没有人和我一起玩(哇哇大哭~) Creative portion (optional): [] @@ -31,4 +157,6 @@ Other remarks: - Optional: I was surprised by: [describe] -- Optional: I'm not sure about: [describe] +- Optional: I'm not sure about: [发的多少有点慢的离谱,不知道是哪里的问题] + +完结撒花。虽然不知道以后这个实验的服务器会不会继续开着,因为有些实验,还不得不用它的服务器,如果没了就做不了了捏。 \ No newline at end of file