cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
SimIcmpPacket Class Reference

Class ICMP Packet for simulation. More...

#include <SimIcmpPacket.hpp>

Public Member Functions

 SimIcmpPacket (int pktLen)
 
 SimIcmpPacket ()
 
void pushChunk (AxisIcmp icmpChunk)
 
AxisIcmp pullChunk ()
 
int length ()
 
int size ()
 
void setIcmpType (IcmpType type)
 
IcmpType getIcmpType ()
 
void setIcmpCode (IcmpCode code)
 
IcmpCode getCode ()
 
void setIcmpChecksum (IcmpCsum csum)
 
IcmpCsum getIcmpChecksum ()
 
void setIcmpIdent (IcmpIdent id)
 
IcmpIdent getIcmpIdent ()
 
void setIcmpSeqNum (IcmpSeqNum num)
 
IcmpSeqNum getIcmpSeqNum ()
 
void addIcmpPayload (string pldStr)
 
IcmpCsum calculateIcmpChecksum ()
 
IcmpCsum reCalculateIcmpChecksum ()
 Recalculate the ICMP checksum of a packet. More...
 

Detailed Description

Class ICMP Packet for simulation.

This class defines an ICMP packet as a stream of 'AxisIcmp' data chunks. Such an ICMP packet consists of a double-ended queue that is used to accumulate all these data chunks. For the 10GbE MAC, the ICMP chunks are 64 bits wide. ICMP chunks are extracted from the Ethernet frame by the IPRX core and are transmitted by the ICMP core.

Definition at line 49 of file SimIcmpPacket.hpp.

Constructor & Destructor Documentation

◆ SimIcmpPacket() [1/2]

SimIcmpPacket::SimIcmpPacket ( int  pktLen)
inline

Definition at line 86 of file SimIcmpPacket.hpp.

86  {
87  this->myName = "SimIcmpPacket";
88  setLen(0);
89  if (pktLen > 0 && pktLen <= MTU) {
90  int noBytes = pktLen;
91  while(noBytes > 8) {
92  pushChunk(AxisIcmp(0x0000000000000000, 0xFF, 0));
93  noBytes -= 8;
94  }
95  pushChunk(AxisIcmp(0x0000000000000000, lenToLE_tKeep(noBytes), TLAST));
96  }
97  }
void pushChunk(AxisIcmp icmpChunk)
LE_tKeep lenToLE_tKeep(ap_uint< 4 > noValidBytes)
A function to set a number of '1' in an 8-bit field. It is used here to set the number of valid bytes...
Definition: nts_utils.cpp:307
#define TLAST
Definition: AxisRaw.hpp:116
#define MTU
Definition: udp.hpp:71
Here is the call graph for this function:

◆ SimIcmpPacket() [2/2]

SimIcmpPacket::SimIcmpPacket ( )
inline

Definition at line 98 of file SimIcmpPacket.hpp.

98  {
99  this->myName = "SimIcmpPacket";
100  this->len = 0;
101  }

Member Function Documentation

◆ addIcmpPayload()

void SimIcmpPacket::addIcmpPayload ( string  pldStr)
inline

Definition at line 148 of file SimIcmpPacket.hpp.

148  {
149  if (this->getLen() != ICMP_HEADER_LEN) {
150  printFatal("IcmpPacket", "Empty packet is expected to be of length %d bytes (was found to be %d bytes).\n",
151  ICMP_HEADER_LEN, this->getLen());
152  }
153  int hdrLen = this->getLen(); // in bytes
154  int pldLen = pldStr.size();
155  int q = (hdrLen / 8);
156  int b = (hdrLen % 8);
157  int i = 0;
158  // At this point we are aligned on an 8-byte data chunk since all
159  // ICMP packets have an 8-byte header.
160  while (i < pldLen) {
161  unsigned long leQword = 0x0000000000000000; // in LE order
162  unsigned char leKeep = 0x00;
163  bool leLast = false;
164  while (b < 8) {
165  unsigned char datByte = pldStr[i];
166  leQword = leQword | (datByte << b*8);
167  leKeep = leKeep | (1 << b);
168  i++;
169  b++;
170  if (i == pldLen) {
171  leLast = true;
172  break;
173  }
174  }
175  b = 0;
176  pushChunk(AxisIcmp(leQword, leKeep, leLast));
177  }
178  } // End-of: addIcmpPayload
#define ICMP_HEADER_LEN
Definition: AxisIcmp.hpp:78
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
Definition: nts_utils.hpp:208
Here is the call graph for this function:

◆ calculateIcmpChecksum()

IcmpCsum SimIcmpPacket::calculateIcmpChecksum ( )
inline

Definition at line 181 of file SimIcmpPacket.hpp.

181  {
182  ap_uint<32> csum = 0;
183  for (uint8_t i=0;i<this->size();++i) {
184  ap_uint<64> tempInput = 0x0000000000000000;
185  if (pktQ[i].getLE_TKeep() & 0x01)
186  tempInput.range( 7, 0) = (pktQ[i].getLE_TData().range( 7, 0));
187  if (pktQ[i].getLE_TKeep() & 0x02)
188  tempInput.range(15, 8) = (pktQ[i].getLE_TData().range(15, 8));
189  if (pktQ[i].getLE_TKeep() & 0x04)
190  tempInput.range(23,16) = (pktQ[i].getLE_TData().range(23,16));
191  if (pktQ[i].getLE_TKeep() & 0x08)
192  tempInput.range(31,24) = (pktQ[i].getLE_TData().range(31,24));
193  if (pktQ[i].getLE_TKeep() & 0x10)
194  tempInput.range(39,32) = (pktQ[i].getLE_TData().range(39,32));
195  if (pktQ[i].getLE_TKeep() & 0x20)
196  tempInput.range(47,40) = (pktQ[i].getLE_TData().range(47,40));
197  if (pktQ[i].getLE_TKeep() & 0x40)
198  tempInput.range(55,48) = (pktQ[i].getLE_TData().range(55,48));
199  if (pktQ[i].getLE_TKeep() & 0x80)
200  tempInput.range(63,56) = (pktQ[i].getLE_TData().range(63,56));
201  csum = ((((csum +
202  tempInput.range(63, 48)) + tempInput.range(47, 32)) +
203  tempInput.range(31, 16)) + tempInput.range(15, 0));
204  csum = (csum & 0xFFFF) + (csum >> 16);
205  }
206  // Reverse the bits of the result
207  IcmpCsum icmpCsum = csum;
208  icmpCsum = ~icmpCsum;
209  return byteSwap16(icmpCsum);
210  }
ap_uint< 16 > IcmpCsum
Definition: AxisIcmp.hpp:93
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)
Definition: udp.cpp:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCode()

IcmpCode SimIcmpPacket::getCode ( )
inline

Definition at line 133 of file SimIcmpPacket.hpp.

133 { return pktQ[0].getIcmpCode(); }
Here is the caller graph for this function:

◆ getIcmpChecksum()

IcmpCsum SimIcmpPacket::getIcmpChecksum ( )
inline

Definition at line 137 of file SimIcmpPacket.hpp.

137 { return pktQ[0].getIcmpCsum(); }
Here is the caller graph for this function:

◆ getIcmpIdent()

IcmpIdent SimIcmpPacket::getIcmpIdent ( )
inline

Definition at line 141 of file SimIcmpPacket.hpp.

141 { return pktQ[0].getIcmpIdent(); }

◆ getIcmpSeqNum()

IcmpSeqNum SimIcmpPacket::getIcmpSeqNum ( )
inline

Definition at line 145 of file SimIcmpPacket.hpp.

145 { return pktQ[0].getIcmpSeqNum(); }

◆ getIcmpType()

IcmpType SimIcmpPacket::getIcmpType ( )
inline

Definition at line 129 of file SimIcmpPacket.hpp.

129 { return pktQ[0].getIcmpType(); }
Here is the caller graph for this function:

◆ length()

int SimIcmpPacket::length ( )
inline

Definition at line 122 of file SimIcmpPacket.hpp.

122 { return this->len; }
Here is the caller graph for this function:

◆ pullChunk()

AxisIcmp SimIcmpPacket::pullChunk ( )
inline

Definition at line 114 of file SimIcmpPacket.hpp.

114  {
115  AxisIcmp headingChunk = this->front();
116  this->pop_front();
117  setLen(getLen() - headingChunk.getLen());
118  return headingChunk;
119  }
int getLen() const
Definition: AxisRaw.hpp:411
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushChunk()

void SimIcmpPacket::pushChunk ( AxisIcmp  icmpChunk)
inline

Definition at line 104 of file SimIcmpPacket.hpp.

104  {
105  if (this->size() > 0) {
106  // Always clear 'TLAST' bit of previous chunck
107  this->pktQ[this->size()-1].setLE_TLast(0);
108  }
109  this->pktQ.push_back(icmpChunk);
110  setLen(this->getLen() + icmpChunk.getLen());
111  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reCalculateIcmpChecksum()

IcmpCsum SimIcmpPacket::reCalculateIcmpChecksum ( )
inline

Recalculate the ICMP checksum of a packet.

  • This will also overwrite the former ICMP checksum.
  • You typically use this method if the packet was modified or when the checksum has not yet been calculated.
Returns
the computed checksum.

Definition at line 220 of file SimIcmpPacket.hpp.

220  {
221  this->setIcmpChecksum(0x0000);
222  IcmpCsum newIcmpCsum = calculateIcmpChecksum();
223  // Overwrite the former ICMP checksum
224  this->setIcmpChecksum(newIcmpCsum);
225  return (newIcmpCsum);
226  }
IcmpCsum calculateIcmpChecksum()
void setIcmpChecksum(IcmpCsum csum)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIcmpChecksum()

void SimIcmpPacket::setIcmpChecksum ( IcmpCsum  csum)
inline

Definition at line 136 of file SimIcmpPacket.hpp.

136 { pktQ[0].setIcmpCsum(csum); }
Here is the caller graph for this function:

◆ setIcmpCode()

void SimIcmpPacket::setIcmpCode ( IcmpCode  code)
inline

Definition at line 132 of file SimIcmpPacket.hpp.

132 { pktQ[0].setIcmpCode(code); }
Here is the caller graph for this function:

◆ setIcmpIdent()

void SimIcmpPacket::setIcmpIdent ( IcmpIdent  id)
inline

Definition at line 140 of file SimIcmpPacket.hpp.

140 { pktQ[0].setIcmpIdent(id); }

◆ setIcmpSeqNum()

void SimIcmpPacket::setIcmpSeqNum ( IcmpSeqNum  num)
inline

Definition at line 144 of file SimIcmpPacket.hpp.

144 { pktQ[0].setIcmpSeqNum(num); }

◆ setIcmpType()

void SimIcmpPacket::setIcmpType ( IcmpType  type)
inline

Definition at line 128 of file SimIcmpPacket.hpp.

128 { pktQ[0].setIcmpType(type); }
Here is the caller graph for this function:

◆ size()

int SimIcmpPacket::size ( )
inline

Definition at line 125 of file SimIcmpPacket.hpp.

125 { return this->pktQ.size(); }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: