cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
AxisUdp.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 
71 #ifndef _AXIS_UDP_H_
72 #define _AXIS_UDP_H_
73 
74 #include "AxisRaw.hpp"
75 
76 
81 #define UDP_HEADER_LEN 8 // In bytes
82 
83 
86 typedef ap_uint<16> LE_UdpSrcPort; // UDP Source Port
87 typedef ap_uint<16> LE_UdpDstPort; // UDP Destination Port
88 typedef ap_uint<16> LE_UdpPort; // UDP source or destination Port
89 typedef ap_uint<16> LE_UdpLen; // UDP header and data Length
90 typedef ap_uint<16> LE_UdpCsum; // UDP header and data Checksum
91 typedef LE_tData LE_UdpData; // UDP Data unit of transfer
92 
93 
97 typedef ap_uint<16> UdpSrcPort; // UDP Source Port
98 typedef ap_uint<16> UdpDstPort; // UDP Destination Port
99 typedef ap_uint<16> UdpPort; // UDP source or destination Port
100 typedef ap_uint<16> UdpLen; // UDP header and data Length
101 typedef ap_uint<16> UdpCsum; // UDP header and data Checksum
102 typedef tData UdpData; // UDP Data unit of transfer
103 typedef tDataHalf UdpDataHi; // UDP High part of a data unit of transfer
104 typedef tDataHalf UdpDataLo; // UDP Low part of a data unit of transfer
105 
106 typedef ap_uint<16> UdpDgmLen; // UDP Datagram Length in octets (same as UdpLen=Hdr+Data)
107 typedef ap_uint<16> UdpDatLen; // UDP Data Length in octets (same as UdpDgmLen minus UdpHdrLen)
108 
109 
113 class AxisUdp: public AxisRaw {
114 
115  public:
116  AxisUdp() {}
117  AxisUdp(AxisRaw axisRaw) :
118  AxisRaw(axisRaw.getLE_TData(), axisRaw.getLE_TKeep(), axisRaw.getLE_TLast()) {}
120  AxisRaw(tdata, tkeep, tlast) {}
121  AxisUdp(const AxisUdp &axisUdp) :
122  AxisRaw(axisUdp.tdata, axisUdp.tkeep, axisUdp.tlast) {}
123 
124 
128  // Set-Get the UDP Source Port
129  void setUdpSrcPort(UdpPort port) { tdata.range(15, 0) = swapWord(port); }
130  UdpPort getUdpSrcPort() { return swapWord (tdata.range(15, 0)); }
131  LE_UdpPort getLE_UdpSrcPort() { return tdata.range(15, 0) ; }
132 
133  // Set-Get the UDP Destination Port
134  void setUdpDstPort(UdpPort port) { tdata.range(31, 16) = swapWord(port); }
135  UdpPort getUdpDstPort() { return swapWord (tdata.range(31, 16)); }
136  LE_UdpPort getLE_UdpDstPort() { return tdata.range(31, 16); }
137 
138  // Set-Get the UDP length field
139  void setUdpLen(UdpLen length) { tdata.range(47, 32) = swapWord(length);}
140  UdpLen getUdpLen() { return swapWord (tdata.range(47, 32)); }
141  LE_UdpLen getLE_UdpLen() { return tdata.range(47, 32); }
142 
143  // Set-Get the UDP Checksum field
144  void setUdpCsum(UdpCsum csum) { tdata.range(63, 48) = swapWord(csum); }
145  UdpCsum getUdpCsum() { return swapWord (tdata.range(63, 48)); }
146 
147  private:
148  // Reverse the bits within a nibble.
149  ap_uint<4> swapNibble(ap_uint<4> nibble) {
150  return (nibble.range(0,3));
151  }
152  // Reverse the bits within a byte.
153  ap_uint<8> swapByte(ap_uint<8> byte) {
154  return (byte.range(0,7));
155  }
156  // Swap the two bytes of a word (.i.e, 16 bits)
157  ap_uint<16> swapWord(ap_uint<16> word) {
158  return (word.range(7,0), word.range(15, 8));
159  }
160  // Swap the four bytes of a double-word (.i.e, 32 bits)
161  ap_uint<32> swapDWord(ap_uint<32> dword) {
162  return (dword.range( 7, 0), dword.range(15, 8),
163  dword.range(23,16), dword.range(31, 24));
164  }
165 
166 }; // End of: AxisUdp
167 
168 #endif
169 
: 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
AxisUdp(AxisRaw axisRaw)
Definition: AxisUdp.hpp:117
AxisUdp()
Definition: AxisUdp.hpp:116
void setUdpSrcPort(UdpPort port)
Definition: AxisUdp.hpp:129
LE_UdpPort getLE_UdpSrcPort()
Definition: AxisUdp.hpp:131
UdpPort getUdpDstPort()
Definition: AxisUdp.hpp:135
LE_UdpLen getLE_UdpLen()
Definition: AxisUdp.hpp:141
UdpPort getUdpSrcPort()
Definition: AxisUdp.hpp:130
void setUdpDstPort(UdpPort port)
Definition: AxisUdp.hpp:134
LE_UdpPort getLE_UdpDstPort()
Definition: AxisUdp.hpp:136
AxisUdp(LE_tData tdata, LE_tKeep tkeep, LE_tLast tlast)
Definition: AxisUdp.hpp:119
UdpCsum getUdpCsum()
Definition: AxisUdp.hpp:145
void setUdpCsum(UdpCsum csum)
Definition: AxisUdp.hpp:144
void setUdpLen(UdpLen length)
Definition: AxisUdp.hpp:139
AxisUdp(const AxisUdp &axisUdp)
Definition: AxisUdp.hpp:121
UdpLen getUdpLen()
Definition: AxisUdp.hpp:140
ap_uint< 16 > UdpLen
Definition: nal.hpp:250
ap_uint< 16 > UdpPort
Definition: nal.hpp:249
ap_uint< 16 > LE_UdpSrcPort
Definition: AxisUdp.hpp:86
LE_tData LE_UdpData
Definition: AxisUdp.hpp:91
ap_uint< 16 > UdpDatLen
Definition: AxisUdp.hpp:107
tDataHalf UdpDataLo
Definition: AxisUdp.hpp:104
ap_uint< 16 > LE_UdpLen
Definition: AxisUdp.hpp:89
ap_uint< 64 > tData
Definition: AxisRaw.hpp:126
ap_uint< 64 > LE_tData
Definition: AxisRaw.hpp:122
ap_uint< 16 > UdpDstPort
Definition: AxisUdp.hpp:98
ap_uint< 16 > UdpDgmLen
Definition: AxisUdp.hpp:106
ap_uint< 16 > LE_UdpCsum
Definition: AxisUdp.hpp:90
ap_uint< 64/8 > LE_tKeep
Definition: AxisRaw.hpp:124
ap_uint< 16 > UdpLen
Definition: AxisUdp.hpp:100
tData UdpData
Definition: AxisUdp.hpp:102
ap_uint< 1 > LE_tLast
Definition: AxisRaw.hpp:125
ap_uint< 16 > LE_UdpPort
Definition: AxisUdp.hpp:88
ap_uint< 16 > UdpSrcPort
Definition: AxisUdp.hpp:97
ap_uint< 16 > LE_UdpDstPort
Definition: AxisUdp.hpp:87
ap_uint< 16 > UdpCsum
Definition: AxisUdp.hpp:101
ap_uint< 16 > UdpPort
Definition: AxisUdp.hpp:99
ap_uint< 64/2 > tDataHalf
Definition: AxisRaw.hpp:127
tDataHalf UdpDataHi
Definition: AxisUdp.hpp:103