3
3
4
4
// //////////////////////////////////////////////////////////////////////////////
5
5
// Company:
6
- // Engineer: Chris Shucksmith
7
- // Description:
8
- // Pull out TCP payload bytes from packet-orientated TCP/IP frames.
9
- // Follows a single TCP session/stream
6
+ // Engineer: Chris Shucksmith
7
+ // Description: Read-only TCP/IP decoder stack, 4x socket streams.
8
+ //
9
+ // Identify and classify TCP payload bytes from packet-orientated TCP/IP frames.
10
+ // Follow up to four extenally configured TCP session/streams for sequence correctness
11
+ //
12
+ // Four sockets can be independantly followed, ABCD, documented here genericaly as N.
13
+ //
14
+ // If TCP packet with SYN flag set is seen matching the src/dest ip/port an initial sequence
15
+ // number is loaded. TCP Payload bytes in-sequence from this are emitted guarded by
16
+ // outDataMatchN flag. Out of sequence packets are emitted with the lower guard tcp_matchN
17
+ // set, which indicates payload for the right TCP socket, but not in sequenece. A yet-lower
18
+ // priority flag, outDataPayload indicates payload bytes belong *some* unclassified TCP session.
19
+ //
20
+ // Eg. For in-sequence payload bytes of TCPA, outDataMatchA and outDataPayload
21
+ // are all asserted for every byte in the payload, while tcp_matchA is asserted from the
22
+ // bytes that identidy the stream until the next stream is selected. Guard it by outDataPayload
23
+ // if that is required.
24
+ //
25
+ // If the tcpN_{src/dest}_{port/ip} registers are modified to follow an established session
26
+ // it is likely a SYN will not be seen. If the next packet should be used to seed the sequence
27
+ // number, assert tcpN_resync for one cycle. This will be latched internally until such a
28
+ // matching packet arrives. If the context of the packet should be used to determine if the
29
+ // join is appropriate, based on the context within some higher level protocol, drive
30
+ // tcp_rejoin within the payload to indicate the rejoin is permitted. Otherwise drive rejoin
31
+ // with 1 to join at any packet boundary, or zero to join only at SYN packets.
32
+ //
33
+ // TCP sequence number is a modulo 32-bit counter increasing from the 'initial sequence number'
34
+ // seeded from a random value. For a packet of payload length L and sequence number S, the next
35
+ // packet will contain sequence number S+L.
36
+ //
37
+ // As mentioned previously, for packets in-sequence, outDataMatchN is asserted.
38
+ // if the sequence number is below that expected, 'tcp_retran' is asserted, and the
39
+ // stream sequence number unchanged. If the sequence number is above that expected,
40
+ // 'tcp_gap' is asserted.
41
+ //
42
+ // TCP retransmission can be benign: packets with 'tcp_retran' can be ignored in the
43
+ // hope that the retransmission will conclude with the expected packet. Such a scenario can
44
+ // be caused by a lost-ACK on the reutrn path. A gap however requires active handling. If the
45
+ // active host also experiances the gap and causes retransmission in the usual way (ack'ing a prev
46
+ // sequence number) it is possible the sequence will be resumed autonoumously by that host's actions.
47
+ // In an imperfect local network however it should be considered that the packet could be lost before
48
+ // this decoder yet reached the active host. In this case, the gap will never be filled, ie. outDataMatchN
49
+ // never resserted.
50
+ //
51
+ // Knowledge of the upper-level payload protocol is required to rejoin the stream at a
52
+ // safe point, or to trigger the active host to reconnect, causing a SYN and reset of the sequence
53
+ // number. By setting tcp_rejoin at a safe-point the logic is asserting to the stack that payload was
54
+ // rejoined and that packets after that should be considered in sequence.
55
+ //
56
+ // There is a third classification for packets arriveing more than 1M bytes behind or 1M ahead of the
57
+ // expected stream position, 'tcp_sequnknown' which is often found when looping a packet capture and
58
+ // may require careful handling. It is not clear when this is asserted, if a retransmission or gap has
59
+ // occured. Most likely ignoring the packet is the correct action to take, reusming from the next
60
+ // safe-point.
61
+ //
62
+ //
63
+ //
10
64
//
11
65
// //////////////////////////////////////////////////////////////////////////////
12
66
@@ -21,6 +75,8 @@ module Tcp
21
75
input dataValid,
22
76
input [7 :0 ] data,
23
77
78
+ input rejoin, // assert during a payload, whilst tcp_matchN is asserted but not outDataMatchN to rejoin stream
79
+
24
80
// per session
25
81
input [15 :0 ] tcpA_src_port, tcpB_src_port, tcpC_src_port, tcpD_src_port,
26
82
input [31 :0 ] tcpA_src_ip, tcpB_src_ip, tcpC_src_ip, tcpD_src_ip,
0 commit comments