cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
AxisTcp.hpp
Go to the documentation of this file.
1 
18 
70 #ifndef _AXIS_TCP_H_
71 #define _AXIS_TCP_H_
72 
73 #include "AxisRaw.hpp"
74 
75 
79 // A TCP segment has a default header len of 20 bytes. This length may vary in
80 // the presence of option(s) and is indicated by the field "DataOffset" > 5.
81 #define TCP_HEADER_LEN 20 // In bytes
82 
83 
86 typedef ap_uint<16> LE_TcpSrcPort; // TCP Source Port from the MAC
87 typedef ap_uint<16> LE_TcpDstPort; // TCP Destination Port from the MAC
88 typedef ap_uint<16> LE_TcpPort; // TCP Source or Destination Port from the MAC
89 typedef ap_uint<32> LE_TcpSeqNum; // TCP Sequence Number from the MAC
90 typedef ap_uint<32> LE_TcpAckNum; // TCP Acknowledgment Number from the MAC
91 typedef ap_uint<3> LE_TcpResBits; // TCP Reserved Bits from the MAC
92 typedef ap_uint<4> LE_TcpDataOff; // TCP Data Offset from the MAC
93 typedef ap_uint<6> LE_TcpCtrlBits; // TCP Control Bits from the MAC
94 typedef ap_uint<16> LE_TcpWindow; // TCP Window from the MAC
95 typedef ap_uint<16> LE_TcpChecksum; // TCP Checksum
96 typedef ap_uint<16> LE_TcpUrgPtr; // TCP Urgent Pointer from the MAC
97 typedef ap_uint<64> LE_TcpData; // TCP Data stream from the MAC
98 
99 
103 typedef ap_uint<16> TcpSrcPort; // TCP Source Port
104 typedef ap_uint<16> TcpDstPort; // TCP Destination Port
105 typedef ap_uint<16> TcpPort; // TCP Source or Destination Port Number
106 typedef ap_uint<32> TcpSeqNum; // TCP Sequence Number
107 typedef ap_uint<32> TcpAckNum; // TCP Acknowledge Number
108 typedef ap_uint<3> TcpResBits; // TCP Reserved Bits
109 typedef ap_uint<4> TcpDataOff; // TCP Data Offset
110 typedef ap_uint<6> TcpCtrlBits; // TCP Control Bits
111 typedef ap_uint<1> TcpCtrlBit; // TCP Control Bit
112 typedef ap_uint<16> TcpWindow; // TCP Window
113 typedef ap_uint<16> TcpChecksum; // TCP Checksum
114 typedef ap_uint<16> TcpCsum; // TCP Checksum (alias for TcpChecksum)
115 typedef ap_uint<16> TcpUrgPtr; // TCP Urgent Pointer
116 
117 typedef ap_uint< 8> TcpOptKind; // TCP Option Kind
118 typedef ap_uint< 8> TcpOptLen ; // TCP Option Length
119 typedef ap_uint<16> TcpOptMss; // TCP Option Maximum Segment Size
120 
121 typedef ap_uint<16> TcpSegLen; // TCP Segment Length in octets (Header+Data)
122 typedef ap_uint< 8> TcpHdrLen; // TCP Header Length in octets
123 typedef ap_uint<16> TcpDatLen; // TCP Data Length in octets (same as TcpSegLen minus TcpHdrLen)
124 
125 // TCP supports a variable set of options to be appended in the header.
126 // Each option is identified by an 'option-kind' byte.
127 #define TCP_OPT_KIND_EOL 0 // End Of List
128 #define TCP_OPT_KIND_NOP 1 // No Operation
129 #define TCP_OPT_KIND_MSS 2 // Maximum Segment Size
130 #define TCP_OPT_KIND_WSS 3 // Window Size Shift
131 #define TCP_OPT_KIND_SACK 4 // Selective ACKnowledgment permitted
132 
133 
137 class AxisTcp: public AxisRaw {
138 
139  public:
140  AxisTcp() {}
141  AxisTcp(AxisRaw axisRaw) :
142  AxisRaw(axisRaw.getLE_TData(), axisRaw.getLE_TKeep(), axisRaw.getLE_TLast()) {}
144  AxisRaw(tdata, tkeep, tlast) {}
145  AxisTcp(const AxisTcp &axisTcp) :
146  AxisRaw(axisTcp.tdata, axisTcp.tkeep, axisTcp.tlast) {}
147 
148 
152  // Set the TCP Source Port
153  void setTcpSrcPort(TcpPort port) { tdata.range(15, 0) = swapWord(port); }
154  // Get the TCP Source Port
155  TcpPort getTcpSrcPort() { return swapWord (tdata.range(15, 0)); }
156  LE_TcpPort getLE_TcpSrcPort() { return tdata.range(15, 0) ; }
157 
158  // Set the TCP Destination Port
159  void setTcpDstPort(TcpPort port) { tdata.range(31, 16) = swapWord(port); }
160  // Get the TCP Destination Port
161  TcpPort getTcpDstPort() { return swapWord (tdata.range(31, 16)); }
162  LE_TcpPort getLE_TcpDstPort() { return tdata.range(31, 16); }
163 
164  // Set the TCP Sequence Number
165  void setTcpSeqNum(TcpSeqNum num) { tdata.range(63, 32) = swapDWord(num); }
166  // Get the TCP Sequence Number
167  TcpSeqNum getTcpSeqNum() { return swapDWord(tdata.range(63, 32)); }
168 
169  // Set the TCP Acknowledgment Number
170  void setTcpAckNum(TcpAckNum num) { tdata.range(31, 0) = swapDWord(num); }
171  // Get the TCP Acknowledgment Number
172  TcpAckNum getTcpAckNum() { return swapDWord(tdata.range(31, 0)); }
173 
174  // Set the TCP Data Offset
175  void setTcpDataOff(TcpDataOff offset) { tdata.range(39, 36) = offset; }
176  // Get the TCP Data Offset
177  TcpDataOff getTcpDataOff() { return tdata.range(39, 36); }
178 
179  // Set-Get the TCP Control Bits
180  void setTcpCtrlFin(TcpCtrlBit bit) { tdata.bit(40) = bit; }
181  TcpCtrlBit getTcpCtrlFin() { return tdata.bit(40); }
182  void setTcpCtrlSyn(TcpCtrlBit bit) { tdata.bit(41) = bit; }
183  TcpCtrlBit getTcpCtrlSyn() { return tdata.bit(41); }
184  void setTcpCtrlRst(TcpCtrlBit bit) { tdata.bit(42) = bit; }
185  TcpCtrlBit getTcpCtrlRst() { return tdata.bit(42); }
186  void setTcpCtrlPsh(TcpCtrlBit bit) { tdata.bit(43) = bit; }
187  TcpCtrlBit getTcpCtrlPsh() { return tdata.bit(43); }
188  void setTcpCtrlAck(TcpCtrlBit bit) { tdata.bit(44) = bit; }
189  TcpCtrlBit getTcpCtrlAck() { return tdata.bit(44); }
190  void setTcpCtrlUrg(TcpCtrlBit bit) { tdata.bit(45) = bit; }
191  TcpCtrlBit getTcpCtrlUrg() { return tdata.bit(45); }
192 
193  // Set the TCP Window
194  void setTcpWindow(TcpWindow win) { tdata.range(63, 48) = swapWord(win); }
195  // Get the TCP Window
196  TcpWindow getTcpWindow() { return swapWord (tdata.range(63, 48)); }
197 
198  // Set the TCP Checksum
199  void setTcpChecksum(TcpChecksum csum){ tdata.range(15, 0) = swapWord(csum); }
200  // Get the TCP Checksum
201  TcpChecksum getTcpChecksum() { return swapWord (tdata.range(15, 0)); }
202 
203  // Set the TCP Urgent Pointer
204  void setTcpUrgPtr(TcpUrgPtr ptr) { tdata.range(31, 16) = swapWord(ptr); }
205  // Get the TCP Urgent Pointer
206  TcpUrgPtr getTcpUrgPtr() { return swapWord (tdata.range(31, 16)); }
207 
208  // Set the TCP Option Kind
209  void setTcpOptKind(TcpOptKind val) { tdata.range(39, 32); }
210  // Get the TCP Option Kind
211  TcpOptKind getTcpOptKind() { return tdata.range(39, 32); }
212  // Set the TCP Maximum Segment Size Option
213  void setTcpOptMss(TcpOptMss val) { tdata.range(63, 48); }
214  // Get the TCP Maximum Segment Size Option
215  TcpOptMss getTcpOptMss() { return swapWord (tdata.range(63, 48)); }
216 
217  private:
218  // Swap the two bytes of a word (.i.e, 16 bits)
219  ap_uint<16> swapWord(ap_uint<16> inpWord) {
220  return (inpWord.range(7,0), inpWord.range(15, 8));
221  }
222  // Swap the four bytes of a double-word (.i.e, 32 bits)
223  ap_uint<32> swapDWord(ap_uint<32> inpDWord) {
224  return (inpDWord.range( 7, 0), inpDWord.range(15, 8),
225  inpDWord.range(23,16), inpDWord.range(31, 24));
226  }
227 
228 }; // End of: AxisTcp
229 
230 #endif
231 
: A generic class used by the Network-Transport-Stack (NTS) to to transfer a chunk of data over an AX...
LE_tKeep getLE_TKeep(int leHi=64/8-1, int leLo=0) const
Definition: AxisRaw.hpp:264
LE_tData tdata
Definition: AxisRaw.hpp:173
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
Definition: AxisRaw.hpp:260
LE_tKeep tkeep
Definition: AxisRaw.hpp:174
LE_tLast getLE_TLast() const
Definition: AxisRaw.hpp:268
LE_tLast tlast
Definition: AxisRaw.hpp:175
LE_TcpPort getLE_TcpDstPort()
Definition: AxisTcp.hpp:162
AxisTcp(LE_tData tdata, LE_tKeep tkeep, LE_tLast tlast)
Definition: AxisTcp.hpp:143
void setTcpOptMss(TcpOptMss val)
Definition: AxisTcp.hpp:213
TcpSeqNum getTcpSeqNum()
Definition: AxisTcp.hpp:167
void setTcpCtrlFin(TcpCtrlBit bit)
Definition: AxisTcp.hpp:180
AxisTcp(const AxisTcp &axisTcp)
Definition: AxisTcp.hpp:145
TcpUrgPtr getTcpUrgPtr()
Definition: AxisTcp.hpp:206
TcpPort getTcpDstPort()
Definition: AxisTcp.hpp:161
void setTcpUrgPtr(TcpUrgPtr ptr)
Definition: AxisTcp.hpp:204
void setTcpCtrlPsh(TcpCtrlBit bit)
Definition: AxisTcp.hpp:186
void setTcpCtrlUrg(TcpCtrlBit bit)
Definition: AxisTcp.hpp:190
TcpCtrlBit getTcpCtrlFin()
Definition: AxisTcp.hpp:181
TcpChecksum getTcpChecksum()
Definition: AxisTcp.hpp:201
void setTcpSrcPort(TcpPort port)
Definition: AxisTcp.hpp:153
TcpOptMss getTcpOptMss()
Definition: AxisTcp.hpp:215
void setTcpDataOff(TcpDataOff offset)
Definition: AxisTcp.hpp:175
LE_TcpPort getLE_TcpSrcPort()
Definition: AxisTcp.hpp:156
void setTcpSeqNum(TcpSeqNum num)
Definition: AxisTcp.hpp:165
void setTcpDstPort(TcpPort port)
Definition: AxisTcp.hpp:159
AxisTcp(AxisRaw axisRaw)
Definition: AxisTcp.hpp:141
void setTcpOptKind(TcpOptKind val)
Definition: AxisTcp.hpp:209
TcpCtrlBit getTcpCtrlUrg()
Definition: AxisTcp.hpp:191
TcpCtrlBit getTcpCtrlRst()
Definition: AxisTcp.hpp:185
TcpCtrlBit getTcpCtrlPsh()
Definition: AxisTcp.hpp:187
void setTcpChecksum(TcpChecksum csum)
Definition: AxisTcp.hpp:199
TcpAckNum getTcpAckNum()
Definition: AxisTcp.hpp:172
TcpWindow getTcpWindow()
Definition: AxisTcp.hpp:196
TcpCtrlBit getTcpCtrlAck()
Definition: AxisTcp.hpp:189
void setTcpCtrlSyn(TcpCtrlBit bit)
Definition: AxisTcp.hpp:182
TcpPort getTcpSrcPort()
Definition: AxisTcp.hpp:155
void setTcpCtrlRst(TcpCtrlBit bit)
Definition: AxisTcp.hpp:184
TcpOptKind getTcpOptKind()
Definition: AxisTcp.hpp:211
TcpDataOff getTcpDataOff()
Definition: AxisTcp.hpp:177
AxisTcp()
Definition: AxisTcp.hpp:140
TcpCtrlBit getTcpCtrlSyn()
Definition: AxisTcp.hpp:183
void setTcpAckNum(TcpAckNum num)
Definition: AxisTcp.hpp:170
void setTcpWindow(TcpWindow win)
Definition: AxisTcp.hpp:194
void setTcpCtrlAck(TcpCtrlBit bit)
Definition: AxisTcp.hpp:188
ap_uint< 16 > LE_TcpPort
Definition: AxisTcp.hpp:88
ap_uint< 16 > TcpSegLen
Definition: AxisTcp.hpp:121
ap_uint< 3 > TcpResBits
Definition: AxisTcp.hpp:108
ap_uint< 32 > TcpSeqNum
Definition: AxisTcp.hpp:106
ap_uint< 16 > TcpSrcPort
Definition: AxisTcp.hpp:103
ap_uint< 4 > LE_TcpDataOff
Definition: AxisTcp.hpp:92
ap_uint< 8 > TcpOptKind
Definition: AxisTcp.hpp:117
ap_uint< 16 > LE_TcpDstPort
Definition: AxisTcp.hpp:87
ap_uint< 32 > LE_TcpAckNum
Definition: AxisTcp.hpp:90
ap_uint< 8 > TcpHdrLen
Definition: AxisTcp.hpp:122
ap_uint< 64 > LE_tData
Definition: AxisRaw.hpp:122
ap_uint< 16 > TcpUrgPtr
Definition: AxisTcp.hpp:115
ap_uint< 6 > LE_TcpCtrlBits
Definition: AxisTcp.hpp:93
ap_uint< 16 > TcpCsum
Definition: AxisTcp.hpp:114
ap_uint< 1 > TcpCtrlBit
Definition: AxisTcp.hpp:111
ap_uint< 64/8 > LE_tKeep
Definition: AxisRaw.hpp:124
ap_uint< 8 > TcpOptLen
Definition: AxisTcp.hpp:118
ap_uint< 16 > TcpDstPort
Definition: AxisTcp.hpp:104
ap_uint< 16 > LE_TcpUrgPtr
Definition: AxisTcp.hpp:96
ap_uint< 1 > LE_tLast
Definition: AxisRaw.hpp:125
ap_uint< 64 > LE_TcpData
Definition: AxisTcp.hpp:97
ap_uint< 16 > LE_TcpSrcPort
Definition: AxisTcp.hpp:86
ap_uint< 16 > TcpPort
Definition: AxisTcp.hpp:105
ap_uint< 16 > TcpDatLen
Definition: AxisTcp.hpp:123
ap_uint< 32 > LE_TcpSeqNum
Definition: AxisTcp.hpp:89
ap_uint< 3 > LE_TcpResBits
Definition: AxisTcp.hpp:91
ap_uint< 16 > LE_TcpChecksum
Definition: AxisTcp.hpp:95
ap_uint< 16 > TcpWindow
Definition: AxisTcp.hpp:112
ap_uint< 4 > TcpDataOff
Definition: AxisTcp.hpp:109
ap_uint< 16 > TcpOptMss
Definition: AxisTcp.hpp:119
ap_uint< 32 > TcpAckNum
Definition: AxisTcp.hpp:107
ap_uint< 16 > LE_TcpWindow
Definition: AxisTcp.hpp:94
ap_uint< 16 > TcpChecksum
Definition: AxisTcp.hpp:113
ap_uint< 6 > TcpCtrlBits
Definition: AxisTcp.hpp:110