CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: LIBPCAP linked by target "tcp_parser" in directory /home/kangyu/sponge/testslinked by target "tcp_parser" in directory /home/ryao/Projects/cppProjects/CS144Labs/tests
WrappingInt32 wrap(uint64_t n, WrappingInt32 isn){ // uint64_t m = (1ll << 32); // uint32_t num = (n + isn.raw_value()) % m; // return WrappingInt32{num}; return WrappingInt32{isn.raw_value() + static_cast<uint32_t>(n)}; }
//! Transform a WrappingInt32 into an "absolute" 64-bit sequence number (zero-indexed) //! \param n The relative sequence number //! \param isn The initial sequence number //! \param checkpoint A recent absolute 64-bit sequence number //! \returns the 64-bit sequence number that wraps to `n` and is closest to `checkpoint` //! //! \note Each of the two streams of the TCP connection has its own ISN. One stream //! runs from the local TCPSender to the remote TCPReceiver and has one ISN, //! and the other stream runs from the remote TCPSender to the local TCPReceiver and //! has a different ISN. uint64_tunwrap(WrappingInt32 n, WrappingInt32 isn, uint64_t checkpoint){ uint32_t offset = n.raw_value() - isn.raw_value(); uint64_t t = (checkpoint & 0xFFFFFFFF00000000) + offset; uint64_t ret = t; if (abs(int64_t(t + (1ul << 32) - checkpoint)) < abs(int64_t(t - checkpoint))) { ret = t + (1ul << 32); } if (t >= (1ul << 32) && abs(int64_t(t - (1ul << 32) - checkpoint)) < abs(int64_t(ret - checkpoint))) { ret = t - (1ul << 32); } return ret; }
用 ctest -R wrap 进行测试
tcp_receiver
实现tcp的接收端。
要求为:
In the rest of this lab, you’ll be implementing the TCPReceiver. It will (1) receive segments from its peer, (2) reassemble the ByteStream using your StreamReassembler, and calculate the (3) acknowledgment number (ackno) and (4) the window size.
classTCPReceiver { //! Our data structure for re-assembling bytes. StreamReassembler _reassembler; uint64_t _abs_seqno; WrappingInt32 _isn; bool _syn_flag;
//! The maximum number of bytes we'll store. size_t _capacity;
public: //! \brief Construct a TCP receiver //! //! \param capacity the maximum number of bytes that the receiver will //! store in its buffers at any give time. TCPReceiver(constsize_t capacity) : _reassembler(capacity) , _abs_seqno(0) , _isn(0) , _syn_flag(false) , _capacity(capacity) {}