1 /// Different kinds of options that can be present in the options part of a tcp header.
2 #[derive(Clone, Debug, Eq, PartialEq)]
3 pub enum TcpOptionElement {
4     /// "No-Operation" option.
5     ///
6     /// Description from RFC 793:
7     ///
8     /// This option code may be used between options, for example, to
9     /// align the beginning of a subsequent option on a word boundary.
10     /// There is no guarantee that senders will use this option, so
11     /// receivers must be prepared to process options even if they do
12     /// not begin on a word boundary.
13     Noop,
14     /// "Maximum Segment Size" option.
15     ///
16     /// Description from RFC 793:
17     ///
18     /// If this option is present, then it communicates the maximum
19     /// receive segment size at the TCP which sends this segment.
20     /// This field must only be sent in the initial connection request
21     /// (i.e., in segments with the SYN control bit set).  If this
22     //// option is not used, any segment size is allowed.
23     MaximumSegmentSize(u16),
24     WindowScale(u8),
25     SelectiveAcknowledgementPermitted,
26     SelectiveAcknowledgement((u32, u32), [Option<(u32, u32)>; 3]),
27     ///Timestamp & echo (first number is the sender timestamp, the second the echo timestamp)
28     Timestamp(u32, u32),
29 }
30 
31 #[cfg(test)]
32 mod test {
33     use crate::*;
34     use alloc::format;
35 
36     #[test]
clone_eq()37     fn clone_eq() {
38         use TcpOptionElement::*;
39         let values = [
40             Noop,
41             MaximumSegmentSize(123),
42             WindowScale(123),
43             SelectiveAcknowledgementPermitted,
44             SelectiveAcknowledgement((1, 2), [Some((3, 4)), Some((5, 6)), None]),
45             Timestamp(123, 456),
46         ];
47         for value in values {
48             assert_eq!(value.clone(), value);
49         }
50     }
51 
52     #[test]
debug()53     fn debug() {
54         use TcpOptionElement::*;
55         assert_eq!("Noop", format!("{:?}", Noop));
56         assert_eq!(
57             "MaximumSegmentSize(123)",
58             format!("{:?}", MaximumSegmentSize(123))
59         );
60         assert_eq!("WindowScale(123)", format!("{:?}", WindowScale(123)));
61         assert_eq!(
62             "SelectiveAcknowledgementPermitted",
63             format!("{:?}", SelectiveAcknowledgementPermitted)
64         );
65         assert_eq!(
66             "SelectiveAcknowledgement((1, 2), [Some((3, 4)), Some((5, 6)), None])",
67             format!(
68                 "{:?}",
69                 SelectiveAcknowledgement((1, 2), [Some((3, 4)), Some((5, 6)), None])
70             )
71         );
72         assert_eq!("Timestamp(123, 456)", format!("{:?}", Timestamp(123, 456)));
73     }
74 }
75