cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
AxisPsd4.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 -- 2021 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
88 #ifndef _AXIS_PSD4_H_
89 #define _AXIS_PSD4_H_
90 
91 #include "./AxisRaw.hpp"
92 #include "./AxisTcp.hpp"
93 
94 
98 #define PSD4_HEADER_LEN 12 // In bytes
99 
100 
103 typedef ap_uint< 8> Psd4Res; // Pseudo-Header Reserved Bits
104 //typedef ap_uint<16> Psd4Len; // Pseudo-Header UDP datagram or TCP segment Length
105 
106 
110 class AxisPsd4: public AxisRaw {
111 
112  public:
113  AxisPsd4() {}
114  AxisPsd4(AxisRaw &axisRaw) :
115  AxisRaw(axisRaw.getLE_TData(), axisRaw.getLE_TKeep(), axisRaw.getLE_TLast()) {}
117  AxisRaw(tdata, tkeep, tlast) {}
118  AxisPsd4(const AxisPsd4 &axisPsd4) :
119  AxisRaw(axisPsd4.tdata, axisPsd4.tkeep, axisPsd4.tlast) {}
120 
121 
125  // Set-Get the PSD4 Source Address
126  void setPsd4SrcAddr(Ip4Addr addr) { tdata.range(31, 0) = swapDWord(addr); }
127  Ip4Addr getPsd4SrcAddr() { return swapDWord(tdata.range(31, 0)); }
128  // Set-Get the PSD4 Destination Address
129  void setPsd4DstAddr(Ip4Addr addr) { tdata.range(63, 32) = swapDWord(addr); }
130  Ip4Addr getPsd4DstAddr() { return swapDWord(tdata.range(63, 32)); }
131  // Set-Get the PSD4 Reserved Bits
132  void setPsd4ResBits(Psd4Res res) { tdata.range( 7, 0) = res; }
133  Psd4Res getPsd4ResBits() { return tdata.range( 7, 0); }
134  // Set-Get the PSD4 Protocol
135  void setPsd4Prot(Ip4Prot prot) { tdata.range(15, 8) = prot; }
136  Ip4Prot getPsd4Prot() { return tdata.range(15, 8); }
137  // Set-Get the PSD4 LY4 Length
138  void setPsd4Len(Ly4Len len) { tdata.range(31, 16) = swapWord(len); }
139  Ly4Len getPsd4Len() { return swapWord (tdata.range(31, 16)); }
140 
141  //-----------------------------------------------------
142  //-- ENCAPSULATED TCP SEGMENT - Setters and Getters
143  //-----------------------------------------------------
144  // Set-Get the TCP Source Port
145  void setTcpSrcPort(TcpPort port) { tdata.range(47, 32) = swapWord(port); }
146  TcpPort getTcpSrcPort() { return swapWord (tdata.range(47, 32)); }
147  // Set-Get the TCP Destination Port
148  void setTcpDstPort(TcpPort port) { tdata.range(63, 48) = swapWord(port); }
149  TcpPort getTcpDstPort() { return swapWord (tdata.range(63, 48)); }
150  // Set-Get the TCP Sequence Number
151  void setTcpSeqNum(TcpSeqNum num) { tdata.range(31, 0) = swapDWord(num); }
152  TcpSeqNum getTcpSeqNum() { return swapDWord(tdata.range(31, 0)); }
153  // Set-Get the TCP Acknowledgment Number
154  void setTcpAckNum(TcpAckNum num) { tdata.range(63, 32) = swapDWord(num); }
155  TcpAckNum getTcpAckNum() { return swapDWord(tdata.range(63, 32)); }
156  // Set-Get the TCP ECN-Nonce bit
157  void setTcpCtrlNs(TcpCtrlBit bit) { tdata.bit( 0) = bit; }
158  TcpCtrlBit getTcpCtrlNs() { return tdata.bit( 0); }
159  // Set-Get the TCP Reserved bits
160  void setTcpResBits(TcpResBits res) { tdata.range( 3, 1) = res; }
161  TcpResBits getTcpResBits() { return tdata.range( 3, 1); }
162  // Set-Get the TCP Data Offset
163  void setTcpDataOff(TcpDataOff offset){ tdata.range( 7, 4) = offset; }
164  TcpDataOff getTcpDataOff() { return tdata.range( 7, 4); }
165  // Set-Get the TCP Control Bits
166  void setTcpCtrlFin(TcpCtrlBit bit) { tdata.bit( 8) = bit; }
167  TcpCtrlBit getTcpCtrlFin() { return tdata.bit( 8); }
168  void setTcpCtrlSyn(TcpCtrlBit bit) { tdata.bit( 9) = bit; }
169  TcpCtrlBit getTcpCtrlSyn() { return tdata.bit( 9); }
170  void setTcpCtrlRst(TcpCtrlBit bit) { tdata.bit(10) = bit; }
171  TcpCtrlBit getTcpCtrlRst() { return tdata.bit(10); }
172  void setTcpCtrlPsh(TcpCtrlBit bit) { tdata.bit(11) = bit; }
173  TcpCtrlBit getTcpCtrlPsh() { return tdata.bit(11); }
174  void setTcpCtrlAck(TcpCtrlBit bit) { tdata.bit(12) = bit; }
175  TcpCtrlBit getTcpCtrlAck() { return tdata.bit(12); }
176  void setTcpCtrlUrg(TcpCtrlBit bit) { tdata.bit(13) = bit; }
177  TcpCtrlBit getTcpCtrlUrg() { return tdata.bit(13); }
178  void setTcpCtrlEce(TcpCtrlBit bit) { tdata.bit(14) = bit; }
179  TcpCtrlBit getTcpCtrlEce() { return tdata.bit(14); }
180  void setTcpCtrlCwr(TcpCtrlBit bit) { tdata.bit(15) = bit; }
181  TcpCtrlBit getTcpCtrlCwr() { return tdata.bit(15); }
182  // Set-Get the TCP Window
183  void setTcpWindow(TcpWindow win) { tdata.range(31, 16) = swapWord(win); }
184  TcpWindow getTcpWindow() { return swapWord (tdata.range(31, 16)); }
185  // Set-Get the TCP Checksum
186  void setTcpChecksum(TcpChecksum csum){ tdata.range(47, 32) = swapWord(csum); }
187  TcpChecksum getTcpChecksum() { return swapWord (tdata.range(47, 32)); }
188  // Set-Get the TCP Urgent Pointer
189  void setTcpUrgPtr(TcpUrgPtr ptr) { tdata.range(63, 48) = swapWord(ptr); }
190  TcpUrgPtr getTcpUrgPtr() { return swapWord (tdata.range(63, 48)); }
191  // Set-Get the TCP Options
192  void setTcpOptKind(TcpOptKind val) { tdata.range( 7, 0) = val; }
193  TcpOptKind getTcpOptKind() { return tdata.range( 7, 0); }
194  // Set-Get the TCP Options
195  void setTcpOptLen(TcpOptLen len) { tdata.range(15, 8) = len; }
196  TcpOptLen getTcpOptLend() { return tdata.range(15, 8); }
197  void setTcpOptMss(TcpOptMss val) { tdata.range(31, 16) = swapWord(val); }
198  TcpOptMss getTcpOptMss() { return swapWord (tdata.range(31, 16)); }
199 
200  LE_TcpPort getLE_TcpSrcPort() { return tdata.range(47, 32) ; }
201  LE_TcpPort getLE_TcpDstPort() { return tdata.range(63, 48); }
202 
203  //-----------------------------------------------------
204  //-- ENCAPSULATED UDP DATAGRAM - Setters and Getters
205  //-----------------------------------------------------
206  // Set-Get the UDP Source Port
207  void setUdpSrcPort(UdpPort port) { tdata.range(47, 32) = swapWord(port); }
208  UdpPort getUdpSrcPort() { return swapWord (tdata.range(47, 32)); }
209  // Set-Get the UDP Destination Port
210  void setUdpDstPort(UdpPort port) { tdata.range(63, 48) = swapWord(port); }
211  UdpPort getUdpDstPort() { return swapWord (tdata.range(63, 48)); }
212  // Set-Get the UDP Length
213  void setUdpLen(UdpLen len) { tdata.range(15, 0) = swapWord(len); }
214  UdpLen getUdpLen() { return swapWord (tdata.range(15, 0)); }
215  // Set-Get the UDP Checksum
216  void setUdpCsum(UdpCsum csum) { tdata.range(31, 16) = swapWord(csum); }
217  TcpChecksum getUdpCsum() { return swapWord (tdata.range(31, 16)); }
218 
219  private:
220  // Reverse the bits within a nibble.
221  ap_uint<4> swapNibble(ap_uint<4> nibble) {
222  return (nibble.range(0,3));
223  }
224  // Swap the two bytes of a word (.i.e, 16 bits)
225  ap_uint<16> swapWord(ap_uint<16> inpWord) {
226  return (inpWord.range(7,0), inpWord.range(15, 8));
227  }
228  // Swap the four bytes of a double-word (.i.e, 32 bits)
229  ap_uint<32> swapDWord(ap_uint<32> inpDWord) {
230  return (inpDWord.range( 7, 0), inpDWord.range(15, 8),
231  inpDWord.range(23,16), inpDWord.range(31, 24));
232  }
233  // Swap the eight bytes of a quad-word (.i.e, 64 bits)
234  ap_uint<64> swapQWord(ap_uint<64> inpQWord) {
235  return (inpQWord.range( 7, 0), inpQWord.range(15, 8),
236  inpQWord.range(23,16), inpQWord.range(31, 24),
237  inpQWord.range(39,32), inpQWord.range(47, 40),
238  inpQWord.range(55,48), inpQWord.range(63, 56));
239  }
240 
241 }; // End of: AxisPsd4
242 
243 #endif
244 
ap_uint< 8 > Psd4Res
Definition: AxisPsd4.hpp:103
: A generic class used by the Network-Transport-Stack (NTS) to to transfer a chunk of data over an AX...
: A class to access TCP header fields within data chunks transmitted over an AXI4-Stream interface.
TcpPort getTcpDstPort()
Definition: AxisPsd4.hpp:149
void setTcpWindow(TcpWindow win)
Definition: AxisPsd4.hpp:183
UdpPort getUdpDstPort()
Definition: AxisPsd4.hpp:211
TcpOptLen getTcpOptLend()
Definition: AxisPsd4.hpp:196
AxisPsd4(LE_tData tdata, LE_tKeep tkeep, LE_tLast tlast)
Definition: AxisPsd4.hpp:116
TcpSeqNum getTcpSeqNum()
Definition: AxisPsd4.hpp:152
void setTcpResBits(TcpResBits res)
Definition: AxisPsd4.hpp:160
void setTcpCtrlPsh(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:172
void setTcpUrgPtr(TcpUrgPtr ptr)
Definition: AxisPsd4.hpp:189
void setTcpChecksum(TcpChecksum csum)
Definition: AxisPsd4.hpp:186
void setTcpDstPort(TcpPort port)
Definition: AxisPsd4.hpp:148
TcpCtrlBit getTcpCtrlCwr()
Definition: AxisPsd4.hpp:181
void setUdpDstPort(UdpPort port)
Definition: AxisPsd4.hpp:210
TcpCtrlBit getTcpCtrlPsh()
Definition: AxisPsd4.hpp:173
void setPsd4Len(Ly4Len len)
Definition: AxisPsd4.hpp:138
void setPsd4DstAddr(Ip4Addr addr)
Definition: AxisPsd4.hpp:129
void setTcpCtrlAck(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:174
void setTcpCtrlEce(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:178
void setTcpSrcPort(TcpPort port)
Definition: AxisPsd4.hpp:145
void setUdpLen(UdpLen len)
Definition: AxisPsd4.hpp:213
LE_TcpPort getLE_TcpDstPort()
Definition: AxisPsd4.hpp:201
Ip4Addr getPsd4SrcAddr()
Definition: AxisPsd4.hpp:127
LE_TcpPort getLE_TcpSrcPort()
Definition: AxisPsd4.hpp:200
TcpCtrlBit getTcpCtrlAck()
Definition: AxisPsd4.hpp:175
TcpCtrlBit getTcpCtrlEce()
Definition: AxisPsd4.hpp:179
TcpCtrlBit getTcpCtrlNs()
Definition: AxisPsd4.hpp:158
TcpPort getTcpSrcPort()
Definition: AxisPsd4.hpp:146
AxisPsd4(AxisRaw &axisRaw)
Definition: AxisPsd4.hpp:114
TcpCtrlBit getTcpCtrlFin()
Definition: AxisPsd4.hpp:167
void setTcpOptKind(TcpOptKind val)
Definition: AxisPsd4.hpp:192
void setTcpCtrlUrg(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:176
Psd4Res getPsd4ResBits()
Definition: AxisPsd4.hpp:133
void setTcpCtrlSyn(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:168
void setUdpCsum(UdpCsum csum)
Definition: AxisPsd4.hpp:216
Ip4Prot getPsd4Prot()
Definition: AxisPsd4.hpp:136
TcpChecksum getUdpCsum()
Definition: AxisPsd4.hpp:217
void setTcpAckNum(TcpAckNum num)
Definition: AxisPsd4.hpp:154
TcpDataOff getTcpDataOff()
Definition: AxisPsd4.hpp:164
TcpResBits getTcpResBits()
Definition: AxisPsd4.hpp:161
void setTcpOptMss(TcpOptMss val)
Definition: AxisPsd4.hpp:197
UdpLen getUdpLen()
Definition: AxisPsd4.hpp:214
void setPsd4ResBits(Psd4Res res)
Definition: AxisPsd4.hpp:132
TcpOptKind getTcpOptKind()
Definition: AxisPsd4.hpp:193
void setTcpDataOff(TcpDataOff offset)
Definition: AxisPsd4.hpp:163
void setTcpCtrlFin(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:166
void setTcpCtrlRst(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:170
TcpAckNum getTcpAckNum()
Definition: AxisPsd4.hpp:155
UdpPort getUdpSrcPort()
Definition: AxisPsd4.hpp:208
TcpWindow getTcpWindow()
Definition: AxisPsd4.hpp:184
TcpOptMss getTcpOptMss()
Definition: AxisPsd4.hpp:198
void setPsd4Prot(Ip4Prot prot)
Definition: AxisPsd4.hpp:135
TcpCtrlBit getTcpCtrlUrg()
Definition: AxisPsd4.hpp:177
TcpUrgPtr getTcpUrgPtr()
Definition: AxisPsd4.hpp:190
AxisPsd4(const AxisPsd4 &axisPsd4)
Definition: AxisPsd4.hpp:118
TcpCtrlBit getTcpCtrlRst()
Definition: AxisPsd4.hpp:171
void setTcpSeqNum(TcpSeqNum num)
Definition: AxisPsd4.hpp:151
void setTcpCtrlNs(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:157
void setTcpCtrlCwr(TcpCtrlBit bit)
Definition: AxisPsd4.hpp:180
Ly4Len getPsd4Len()
Definition: AxisPsd4.hpp:139
Ip4Addr getPsd4DstAddr()
Definition: AxisPsd4.hpp:130
TcpChecksum getTcpChecksum()
Definition: AxisPsd4.hpp:187
TcpCtrlBit getTcpCtrlSyn()
Definition: AxisPsd4.hpp:169
void setTcpOptLen(TcpOptLen len)
Definition: AxisPsd4.hpp:195
void setUdpSrcPort(UdpPort port)
Definition: AxisPsd4.hpp:207
void setPsd4SrcAddr(Ip4Addr addr)
Definition: AxisPsd4.hpp:126
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
ap_uint< 16 > UdpLen
Definition: nal.hpp:250
ap_uint< 16 > UdpPort
Definition: nal.hpp:249
ap_uint< 16 > LE_TcpPort
Definition: AxisTcp.hpp:88
ap_uint< 8 > Ip4Prot
Definition: AxisIp4.hpp:164
ap_uint< 3 > TcpResBits
Definition: AxisTcp.hpp:108
ap_uint< 32 > TcpSeqNum
Definition: AxisTcp.hpp:106
ap_uint< 8 > TcpOptKind
Definition: AxisTcp.hpp:117
ap_uint< 64 > LE_tData
Definition: AxisRaw.hpp:122
ap_uint< 16 > TcpUrgPtr
Definition: AxisTcp.hpp:115
ap_uint< 1 > TcpCtrlBit
Definition: AxisTcp.hpp:111
ap_uint< 16 > Ly4Len
Definition: nts_types.hpp:202
ap_uint< 64/8 > LE_tKeep
Definition: AxisRaw.hpp:124
ap_uint< 32 > Ip4Addr
Definition: AxisIp4.hpp:169
ap_uint< 8 > TcpOptLen
Definition: AxisTcp.hpp:118
ap_uint< 1 > LE_tLast
Definition: AxisRaw.hpp:125
ap_uint< 16 > TcpPort
Definition: AxisTcp.hpp:105
ap_uint< 16 > UdpCsum
Definition: AxisUdp.hpp:101
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 > TcpChecksum
Definition: AxisTcp.hpp:113