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

Class IPv4 Packet for simulation. More...

#include <SimIp4Packet.hpp>

Public Member Functions

 SimIp4Packet ()
 
 SimIp4Packet (int pktLen, int hdrLen=20)
 
void pushChunk (AxisIp4 ip4Chunk)
 
AxisIp4 pullChunk ()
 
int length ()
 
int size ()
 
void clear ()
 
void clone (SimIp4Packet &ipPkt)
 Clone an IP packet. More...
 
void cloneHeader (SimIp4Packet &ipPkt)
 Clone the header of an IP packet. More...
 
void setIpVersion (int version)
 
int getIpVersion ()
 
void setIpInternetHeaderLength (int ihl)
 
int getIpInternetHeaderLength ()
 
void setIpTypeOfService (int tos)
 
int getIpTypeOfService ()
 
void setIpTotalLength (int totLen)
 
int getIpTotalLength ()
 
void setIpIdentification (int id)
 
int getIpIdentification ()
 
void setIpFragmentOffset (int offset)
 
int getIpFragmentOffset ()
 
void setIpFlags (int flags)
 
void setIpTimeToLive (Ip4TtL ttl)
 
int getIpTimeToLive ()
 
void setIpProtocol (int prot)
 
int getIpProtocol ()
 
void setIpHeaderChecksum (int csum)
 
Ip4HdrCsum getIpHeaderChecksum ()
 
void setIpSourceAddress (int addr)
 
Ip4Addr getIpSourceAddress ()
 
LE_Ip4Addr getLE_IpSourceAddress ()
 
void setIpDestinationAddress (int addr)
 
Ip4Addr getIpDestinationAddress ()
 
LE_Ip4Addr getLE_IpDestinationAddress ()
 
void setTcpSourcePort (int port)
 
int getTcpSourcePort ()
 
LE_TcpPort getLE_TcpSourcePort ()
 
void setTcpDestinationPort (int port)
 
int getTcpDestinationPort ()
 
LE_TcpPort getLE_TcpDestinationPort ()
 
void setTcpSequenceNumber (TcpSeqNum num)
 
TcpSeqNum getTcpSequenceNumber ()
 
void setTcpAcknowledgeNumber (TcpAckNum num)
 
TcpAckNum getTcpAcknowledgeNumber ()
 
void setTcpDataOffset (int offset)
 
int getTcpDataOffset ()
 
void setTcpControlFin (int bit)
 
TcpCtrlBit getTcpControlFin ()
 
void setTcpControlSyn (int bit)
 
TcpCtrlBit getTcpControlSyn ()
 
void setTcpControlRst (int bit)
 
TcpCtrlBit getTcpControlRst ()
 
void setTcpControlPsh (int bit)
 
TcpCtrlBit getTcpControlPsh ()
 
void setTcpControlAck (int bit)
 
TcpCtrlBit getTcpControlAck ()
 
void setTcpControlUrg (int bit)
 
TcpCtrlBit getTcpControlUrg ()
 
void setTcpWindow (int win)
 
int getTcpWindow ()
 
void setTcpChecksum (int csum)
 
int getTcpChecksum ()
 
void setTcpUrgentPointer (int ptr)
 
int getTcpUrgentPointer ()
 
void setTcpOptionKind (int val)
 
int getTcpOptionKind ()
 
void setTcpOptionMss (int val)
 
int getTcpOptionMss ()
 
void setUdpSourcePort (UdpPort port)
 
UdpPort getUdpSourcePort ()
 
void setUdpDestinationPort (UdpPort port)
 
UdpPort getUdpDestinationPort ()
 
void setUdpLength (UdpLen len)
 
UdpLen getUdpLength ()
 
void setUdpChecksum (UdpCsum csum)
 
UdpCsum getUdpChecksum ()
 
string getIpHeader ()
 
string getIpPayload ()
 
SimIcmpPacket getIcmpPacket ()
 
SimUdpDatagram getUdpDatagram ()
 
SimTcpSegment getTcpSegment ()
 
Ip4DatLen getTcpSegmentLength ()
 
bool addIpPayload (SimUdpDatagram &udpDgm, int len=-1)
 Append some data to this packet from a UDP datagram. More...
 
bool addIpPayload (SimIcmpPacket icmpPkt)
 Append the data payload of this packet as an ICMP packet. More...
 
bool setIpPayload (SimIcmpPacket icmpPkt)
 Set the data payload of this packet as an ICMP packet. More...
 
string getTcpData ()
 Get TCP data from the current IPv4 packet. More...
 
bool isFIN ()
 Returns true if packet is a FIN. More...
 
bool isSYN ()
 Returns true if packet is a SYN. More...
 
bool isACK ()
 Returns true if packet is an ACK. More...
 
bool isWellFormed (const char *callerName, bool checkIp4TotLen=true, bool checkIp4HdrCsum=true, bool checkUdpLen=true, bool checkLy4Csum=true)
 Checks if the IP header and embedded protocol fields are properly set. More...
 
void printHdr (const char *callerName)
 Print the header details of an IP packet. More...
 
void printRaw (const char *callerName)
 Raw print of an IP packet (.i.e, as AxisRaw chunks). More...
 
Ip4HdrCsum reCalculateIpHeaderChecksum ()
 Recalculate the IPv4 header checksum of a packet. More...
 
int tcpRecalculateChecksum ()
 Recalculate the checksum of a TCP segment after it was modified. More...
 
int sizeOfTcpData ()
 Return the size of the TCP data payload in octets. More...
 
bool verifyIpHeaderChecksum ()
 Recalculate the IPv4 header checksum and compare it with the one embedded into the packet. More...
 
UdpCsum udpRecalculateChecksum ()
 Recalculate checksum of an UDP datagram after it was modified. More...
 
bool tcpVerifyChecksum ()
 Recalculate the TCP checksum and compare it with the one embedded into the segment. More...
 
bool udpVerifyChecksum ()
 Recalculate the UDP checksum and compare it with the one embedded into the datagram. More...
 
bool writeToDatFile (ofstream &outFileStream)
 Dump this IP packet as AxisIp4 chunks into a file. More...
 
void writeTcpDataToDatFile (ofstream &outFile)
 Dump the TCP payload of this IP packet into a file. Data is written as a string. More...
 

Detailed Description

Class IPv4 Packet for simulation.

This class defines an IPv4 packet as a set of 'AxisIp4' data chunks. Such an IPv4 packet consists of a double-ended queue that is used to accumulate all these data chunks. For the 10GbE MAC, the IPv4 chunks are 64 bits wide. IPv4 packets are processed by cores IPRX, IPTX, TOE, UDP and ICMP.

Definition at line 55 of file SimIp4Packet.hpp.

Constructor & Destructor Documentation

◆ SimIp4Packet() [1/2]

SimIp4Packet::SimIp4Packet ( )
inline

Definition at line 206 of file SimIp4Packet.hpp.

206  {
207  this->myName = "SimIp4Packet";
208  this->len = 0;
209  }

◆ SimIp4Packet() [2/2]

SimIp4Packet::SimIp4Packet ( int  pktLen,
int  hdrLen = 20 
)
inline

Definition at line 211 of file SimIp4Packet.hpp.

211  {
212  this->myName = "SimIp4Packet";
213  setLen(0);
214  if (pktLen >= hdrLen && pktLen <= MTU) {
215  int noBytes = pktLen;
216  while(noBytes > 8) {
217  pushChunk(AxisIp4(0x0000000000000000, 0xFF, 0));
218  noBytes -= 8;
219  }
220  pushChunk(AxisIp4(0x0000000000000000, lenToLE_tKeep(noBytes), TLAST));
221  // Set all the default IP packet fields.
222  setIpInternetHeaderLength(hdrLen/4);
223  setIpVersion(4);
225  setIpTotalLength(this->length());
228  setIpFlags(0);
229  setIpTimeToLive(255);
230  setIpProtocol(0);
232  // Set all the default TCP segment fields
233  setTcpDataOffset(5);
234  }
235  else {
236  // [TODO-ThrowException]
237  }
238  }
void setIpTotalLength(int totLen)
void setIpFragmentOffset(int offset)
void setTcpDataOffset(int offset)
void setIpInternetHeaderLength(int ihl)
void setIpFlags(int flags)
void setIpTypeOfService(int tos)
void setIpVersion(int version)
void setIpHeaderChecksum(int csum)
void setIpTimeToLive(Ip4TtL ttl)
void pushChunk(AxisIp4 ip4Chunk)
void setIpProtocol(int prot)
void setIpIdentification(int id)
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:

Member Function Documentation

◆ addIpPayload() [1/2]

bool SimIp4Packet::addIpPayload ( SimIcmpPacket  icmpPkt)
inline

Append the data payload of this packet as an ICMP packet.

Parameters
[in]icmpPktThe ICMP packet to use as IPv4 payload.
Returns
true upon success, otherwise false.
Warning
The IP4 packet object must be of length 20 bytes (.i.e a default IP4 packet w/o options) @info This method updates the 'Total Length' and the 'Protocol' fields.

Definition at line 859 of file SimIp4Packet.hpp.

859  {
860  bool alternate = true;
861  bool endOfPkt = false;
862  AxisIcmp axisIcmp(0, 0, 0);
863  int axisIcmpCnt = 0;
864  int axisIp4Cnt = 2; // Start with the 2nd word which contains IP_DA
865  if (this->getLen() != IP4_HEADER_LEN) {
866  printFatal(this->myName, "Packet is expected to be of length %d bytes (was found to be %d bytes).\n",
867  IP4_HEADER_LEN, this->getLen());
868  }
869  // Read and pop the very first chunk from the packet
870  axisIcmp = icmpPkt.pullChunk();
871  while (!endOfPkt) {
872  if (alternate) {
873  LE_tData tmpTData = this->pktQ[axisIp4Cnt].getLE_TData();
874  LE_tKeep tmpTKeep = this->pktQ[axisIp4Cnt].getLE_TKeep();
875  LE_tLast tmpTLast = this->pktQ[axisIp4Cnt].getLE_TLast();
876  if (axisIcmp.getLE_TKeep() & 0x01) {
877  tmpTData.range(39,32) = axisIcmp.getLE_TData().range( 7, 0);
878  tmpTKeep = tmpTKeep | 0x10;
879  this->setLen(this->getLen() + 1);
880  }
881  if (axisIcmp.getLE_TKeep() & 0x02) {
882  tmpTData.range(47,40) = axisIcmp.getLE_TData().range(15, 8);
883  tmpTKeep = tmpTKeep | 0x20;
884  this->setLen(this->getLen() + 1);
885  }
886  if (axisIcmp.getLE_TKeep() & 0x04) {
887  tmpTData.range(55,48) = axisIcmp.getLE_TData().range(23,16);
888  tmpTKeep = tmpTKeep | 0x40;
889  this->setLen(this->getLen() + 1);
890  }
891  if (axisIcmp.getLE_TKeep() & 0x08) {
892  tmpTData.range(63,56) = axisIcmp.getLE_TData().range(31,24);
893  tmpTKeep = tmpTKeep | 0x80;
894  this->setLen(this->getLen() + 1);
895  }
896  if ((axisIcmp.getLE_TLast()) && (axisIcmp.getLE_TKeep() <= 0x0F)) {
897  tmpTLast = TLAST;
898  endOfPkt = true;
899  }
900  else {
901  tmpTLast = 0;
902  }
903  this->pktQ[axisIp4Cnt].setLE_TData(tmpTData);
904  this->pktQ[axisIp4Cnt].setLE_TKeep(tmpTKeep);
905  this->pktQ[axisIp4Cnt].setLE_TLast(tmpTLast);
906  alternate = !alternate;
907  }
908  else {
909  // Build a new chunck and add it to the queue
910  LE_tData newTData = 0;
911  LE_tKeep newTKeep = 0;
912  LE_tLast newTLast = 0;
913  if (axisIcmp.getLE_TKeep() & 0x10) {
914  newTData.range( 7, 0) = axisIcmp.getLE_TData().range(39, 32);
915  newTKeep = newTKeep | (0x01);
916  }
917  if (axisIcmp.getLE_TKeep() & 0x20) {
918  newTData.range(15, 8) = axisIcmp.getLE_TData().range(47, 40);
919  newTKeep = newTKeep | (0x02);
920  }
921  if (axisIcmp.getLE_TKeep() & 0x40) {
922  newTData.range(23,16) = axisIcmp.getLE_TData().range(55, 48);
923  newTKeep = newTKeep | (0x04);
924  }
925  if (axisIcmp.getLE_TKeep() & 0x80) {
926  newTData.range(31,24) = axisIcmp.getLE_TData().range(63, 56);
927  newTKeep = newTKeep | (0x08);
928  }
929  // Done with the incoming ICMP word
930  axisIcmpCnt++;
931 
932  if (axisIcmp.getLE_TLast()) {
933  newTLast = TLAST;
934  this->pushChunk(AxisIp4(newTData, newTKeep, newTLast));
935  endOfPkt = true;
936  }
937  else {
938  newTLast = 0;
939  this->pushChunk(AxisIp4(newTData, newTKeep, newTLast));
940  axisIp4Cnt++;
941  // Read and pop a new chunk from the ICMP packet
942  axisIcmp = icmpPkt.pullChunk();
943  }
944  alternate = !alternate;
945  }
946  } // End-of while(!endOfPkt)
948  return true;
949  } // End-of: addIpPayload
AxisIcmp pullChunk()
#define IP4_PROT_ICMP
Definition: nts_types.hpp:183
ap_uint< 64 > LE_tData
Definition: AxisRaw.hpp:122
ap_uint< 64/8 > LE_tKeep
Definition: AxisRaw.hpp:124
ap_uint< 1 > LE_tLast
Definition: AxisRaw.hpp:125
#define IP4_HEADER_LEN
Definition: AxisIp4.hpp:133
#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:

◆ addIpPayload() [2/2]

bool SimIp4Packet::addIpPayload ( SimUdpDatagram udpDgm,
int  len = -1 
)
inline

Append some data to this packet from a UDP datagram.

Parameters
[in]udpDgrmA ref. to the UDP datagram to use as data source.
[in]lenThe number of bytes to append (must be a multiple of 8 bytes). If it is not specified, the entire datagram is appended.
Returns
true upon success, otherwise false.
Warning
The IP4 packet object must be of length 20 bytes or more. (.i.e a default IP4 packet w/o options) @info This method updates the 'Total Length' and the 'Protocol' fields.

Definition at line 763 of file SimIp4Packet.hpp.

763  {
764  bool alternate = true;
765  bool done = false;
766  AxisIp4 axisIp4(0, 0, 0);
767  AxisUdp axisUdp(0, 0, 0);
768  int bits = (this->length() * 8);
769  int axisIp4Cnt = bits/ARW;
770  int axisUdpCnt = 0;
771  bool ipIsQwordAligned = (bits % ARW) ? false : true;
772  int byteCnt = 0;
773 
774  if (this->getLen() < IP4_HEADER_LEN) {
775  printFatal(this->myName, "Minimum packet is expected to be of length %d bytes (was found to be %d bytes).\n",
776  IP4_HEADER_LEN, this->getLen());
777  }
778  if (len == -1) {
779  len = udpDgm.length();
780  }
781  else if (len > udpDgm.length()) {
782  printFatal(this->myName, "Requesting to append more bytes (%d) than present in the UDP datagram (%d).\n",
783  len, udpDgm.length());
784  }
785 
786  // Read and pop the very first chunk from the datagram
787  axisUdp = udpDgm.pullChunk();
788  while (!done) {
789  if (ipIsQwordAligned) {
790  for (int i=0; i<8; i++) {
791  if (axisUdp.getLE_TKeep() & (0x01 << i)) {
792  axisIp4.setLE_TData(axisIp4.getLE_TData() |
793  ((axisUdp.getLE_TData().range((i*8)+7, (i*8)+0)) << (i*8)));
794  axisIp4.setLE_TKeep(axisIp4.getLE_TKeep() | (0x01 << i));
795  byteCnt++;
796  }
797  }
798  axisIp4.setLE_TLast(axisUdp.getLE_TLast());
799  axisUdpCnt++;
800  axisIp4Cnt++;
801  this->pushChunk(axisIp4);
802  if ((axisUdp.getLE_TLast()) or (byteCnt >= len) ) {
803  done = true;
804  }
805  }
806  else {
807  if (alternate) {
808  this->pktQ[axisIp4Cnt].setTDataLo(axisUdp.getTDataHi());
809  this->pktQ[axisIp4Cnt].setTKeepLo(axisUdp.getTKeepHi());
810  if (axisUdp.getTLast() and (axisUdp.getLen() <= 4)) {
811  this->pktQ[axisIp4Cnt].setTLast(TLAST);
812  done = true;
813  }
814  else {
815  this->pktQ[axisIp4Cnt].setTLast(0);
816  }
817  this->setLen(this->getLen() + axisUdp.getLenHi());
818  byteCnt += axisUdp.getLenHi();
819  alternate = !alternate;
820  }
821  else {
822  // Build a new chunk, init its higher-half part with the
823  // lower-half-part of the UDP chunk and push the new chunk
824  // onto the packet queue
825  AxisIp4 newChunk(0, 0, 0);
826  newChunk.setTDataHi(axisUdp.getTDataLo());
827  newChunk.setTKeepHi(axisUdp.getTKeepLo());
828  byteCnt += axisUdp.getLenLo();
829  if ((axisUdp.getTLast()) or (byteCnt >= len) ) {
830  newChunk.setTLast(TLAST);
831  done = true;
832  }
833  else {
834  newChunk.setTLast(0);
835  axisIp4Cnt++;
836  // Read and pop a new chunk from the UDP datagram
837  axisUdp = udpDgm.pullChunk();
838  }
839  this->pushChunk(newChunk);
840  axisUdpCnt++;
841  alternate = !alternate;
842  }
843  }
844  } // End-of while(!endOfDgm)
846  return true;
847  } // End-of: addIpPayload(UdpDatagram udpDgm)
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
Definition: AxisRaw.hpp:272
int byteCnt
Definition: tb_nal.cpp:829
#define IP4_PROT_UDP
Definition: nts_types.hpp:185
#define ARW
Definition: AxisRaw.hpp:114
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void SimIp4Packet::clear ( )
inline

Definition at line 269 of file SimIp4Packet.hpp.

269  {
270  this->pktQ.clear();
271  this->len = 0;
272  }
Here is the caller graph for this function:

◆ clone()

void SimIp4Packet::clone ( SimIp4Packet ipPkt)
inline

Clone an IP packet.

Parameters
[in]ipPktA reference to the packet to clone.

Definition at line 278 of file SimIp4Packet.hpp.

278  {
279  AxisIp4 newAxisIp4;
280  for (int i=0; i<ipPkt.pktQ.size(); i++) {
281  newAxisIp4 = ipPkt.pktQ[i];
282  this->pktQ.push_back(newAxisIp4);
283  }
284  this->setLen(ipPkt.getLen());
285  }
Here is the caller graph for this function:

◆ cloneHeader()

void SimIp4Packet::cloneHeader ( SimIp4Packet ipPkt)
inline

Clone the header of an IP packet.

Parameters
[in]ipPktA reference to the packet to clone.

Definition at line 291 of file SimIp4Packet.hpp.

291  {
292  int hdrLen = ipPkt.getIpInternetHeaderLength() * 4; // in bytes
293  if (hdrLen > 0 && hdrLen <= MTU) {
294  int cloneBytes = hdrLen;
295  int inpWordCnt = 0;
296  while(cloneBytes > 0) {
297  if (cloneBytes > 8) {
298  this->pushChunk(ipPkt.pktQ[inpWordCnt]);
299  }
300  else {
301  AxisIp4 lastHdrWord(ipPkt.pktQ[inpWordCnt].getLE_TData(),
302  lenToLE_tKeep(cloneBytes), TLAST);
303  this->pushChunk(lastHdrWord);
304  }
305  cloneBytes -= 8;
306  inpWordCnt++;
307  }
308  }
309  }
int getIpInternetHeaderLength()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIcmpPacket()

SimIcmpPacket SimIp4Packet::getIcmpPacket ( )
inline

Definition at line 518 of file SimIp4Packet.hpp.

518  {
519  SimIcmpPacket icmpPacket;
520  LE_tData newTData = 0;
521  LE_tKeep newTKeep = 0;
522  LE_tLast newTLast = 0;
523  int wordOutCnt = 0;
524  int wordInpCnt = 2; // Skip the 1st two IP4 words
525  bool alternate = true;
526  bool endOfPkt = false;
527  int ip4PktSize = this->size();
528  if (this->getIpInternetHeaderLength() != 5) {
529  printFatal(this->myName, "IPv4 options are not supported yet (sorry)");
530  }
531  while (wordInpCnt < ip4PktSize) {
532  if (endOfPkt) {
533  break;
534  }
535  else if (alternate) {
536  newTData = 0;
537  newTKeep = 0;
538  newTLast = 0;
539  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x10) {
540  newTData.range( 7, 0) = this->pktQ[wordInpCnt].getLE_TData().range(39, 32);
541  newTKeep = newTKeep | (0x01);
542  }
543  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x20) {
544  newTData.range(15, 8) = this->pktQ[wordInpCnt].getLE_TData().range(47, 40);
545  newTKeep = newTKeep | (0x02);
546  }
547  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x40) {
548  newTData.range(23, 16) = this->pktQ[wordInpCnt].getLE_TData().range(55, 48);
549  newTKeep = newTKeep | (0x04);
550  }
551  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x80) {
552  newTData.range(31, 24) = this->pktQ[wordInpCnt].getLE_TData().range(63, 56);
553  newTKeep = newTKeep | (0x08);
554  }
555  if (this->pktQ[wordInpCnt].getLE_TLast()) {
556  newTLast = TLAST;
557  endOfPkt = true;
558  icmpPacket.pushChunk(AxisIcmp(newTData, newTKeep, newTLast));
559  }
560  alternate = !alternate;
561  wordInpCnt++;
562  }
563  else {
564  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x01) {
565  newTData.range(39, 32) = this->pktQ[wordInpCnt].getLE_TData().range( 7, 0);
566  newTKeep = newTKeep | (0x10);
567  }
568  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x02) {
569  newTData.range(47, 40) = this->pktQ[wordInpCnt].getLE_TData().range(15, 8);
570  newTKeep = newTKeep | (0x20);
571  }
572  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x04) {
573  newTData.range(55, 48) = this->pktQ[wordInpCnt].getLE_TData().range(23, 16);
574  newTKeep = newTKeep | (0x40);
575  }
576  if (this->pktQ[wordInpCnt].getLE_TKeep() & 0x08) {
577  newTData.range(63, 56) = this->pktQ[wordInpCnt].getLE_TData().range(31, 24);
578  newTKeep = newTKeep | (0x80);
579  }
580  if (this->pktQ[wordInpCnt].getLE_TLast() && (not (this->pktQ[wordInpCnt].getLE_TKeep() & 0xC0))) {
581  newTLast = TLAST;
582  endOfPkt = true;
583  }
584  alternate = !alternate;
585  wordOutCnt++;
586  icmpPacket.pushChunk(AxisIcmp(newTData, newTKeep, newTLast));
587  }
588  }
589  return icmpPacket;
590  } // End-of: getIcmpPacket()
Class ICMP Packet for simulation.
void pushChunk(AxisIcmp icmpChunk)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIpDestinationAddress()

Ip4Addr SimIp4Packet::getIpDestinationAddress ( )
inline

Definition at line 360 of file SimIp4Packet.hpp.

360 { return pktQ[2].getIp4DstAddr(); }
Here is the caller graph for this function:

◆ getIpFragmentOffset()

int SimIp4Packet::getIpFragmentOffset ( )
inline

Definition at line 337 of file SimIp4Packet.hpp.

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

◆ getIpHeader()

string SimIp4Packet::getIpHeader ( )
inline

Definition at line 472 of file SimIp4Packet.hpp.

472  {
473  int q = 0;
474  string headerStr;
475  int hl = this->getIpInternetHeaderLength() * 4; // in bytes
476  while (hl != 0) {
477  for (int b=0; b<8; b++) {
478  unsigned char valByte = ((pktQ[q].getLE_TKeep().to_uchar() >> (1*b)) & 0x01);
479  unsigned char datByte = ((pktQ[q].getLE_TData().to_ulong() >> (8*b)) & 0xFF);
480  if (valByte) {
481  headerStr += datByte;
482  }
483  if (hl == 0) {
484  break;
485  }
486  hl--;
487  }
488  q += 1;
489  }
490  return headerStr;
491  }
Here is the call graph for this function:

◆ getIpHeaderChecksum()

Ip4HdrCsum SimIp4Packet::getIpHeaderChecksum ( )
inline

Definition at line 351 of file SimIp4Packet.hpp.

351 { return pktQ[1].getIp4HdrCsum(); }
Here is the caller graph for this function:

◆ getIpIdentification()

int SimIp4Packet::getIpIdentification ( )
inline

Definition at line 333 of file SimIp4Packet.hpp.

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

◆ getIpInternetHeaderLength()

int SimIp4Packet::getIpInternetHeaderLength ( )
inline

Definition at line 321 of file SimIp4Packet.hpp.

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

◆ getIpPayload()

string SimIp4Packet::getIpPayload ( )
inline

Definition at line 494 of file SimIp4Packet.hpp.

494  {
495  string payloadStr;
496  int hdrLen = this->getIpInternetHeaderLength() * 4; // in bytes
497  int totLen = this->getIpTotalLength();
498  int pldLen = totLen - hdrLen;
499  int q = (hdrLen / 8);
500  int b = (hdrLen % 8);
501  while (pldLen != 0) {
502  while (b <= 7) {
503  unsigned char valByte = ((pktQ[q].getLE_TKeep().to_uchar() >> (1*b)) & 0x01);
504  unsigned char datByte = ((pktQ[q].getLE_TData().to_ulong() >> (8*b)) & 0xFF);
505  if (valByte) {
506  payloadStr += datByte;
507  pldLen--;
508  }
509  b++;
510  }
511  b = 0;
512  q += 1;
513  }
514  return payloadStr;
515  }
int getIpTotalLength()
Here is the call graph for this function:

◆ getIpProtocol()

int SimIp4Packet::getIpProtocol ( )
inline

Definition at line 347 of file SimIp4Packet.hpp.

347 { return pktQ[1].getIp4Prot(); }
Here is the caller graph for this function:

◆ getIpSourceAddress()

Ip4Addr SimIp4Packet::getIpSourceAddress ( )
inline

Definition at line 355 of file SimIp4Packet.hpp.

355 { return pktQ[1].getIp4SrcAddr(); }
Here is the caller graph for this function:

◆ getIpTimeToLive()

int SimIp4Packet::getIpTimeToLive ( )
inline

Definition at line 343 of file SimIp4Packet.hpp.

343 { return pktQ[1].getIp4TtL(); }
Here is the caller graph for this function:

◆ getIpTotalLength()

int SimIp4Packet::getIpTotalLength ( )
inline

Definition at line 329 of file SimIp4Packet.hpp.

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

◆ getIpTypeOfService()

int SimIp4Packet::getIpTypeOfService ( )
inline

Definition at line 325 of file SimIp4Packet.hpp.

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

◆ getIpVersion()

int SimIp4Packet::getIpVersion ( )
inline

Definition at line 317 of file SimIp4Packet.hpp.

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

◆ getLE_IpDestinationAddress()

LE_Ip4Addr SimIp4Packet::getLE_IpDestinationAddress ( )
inline

Definition at line 361 of file SimIp4Packet.hpp.

361 { return pktQ[2].getLE_Ip4DstAddr(); }

◆ getLE_IpSourceAddress()

LE_Ip4Addr SimIp4Packet::getLE_IpSourceAddress ( )
inline

Definition at line 356 of file SimIp4Packet.hpp.

356 { return pktQ[1].getLE_Ip4SrcAddr(); }

◆ getLE_TcpDestinationPort()

LE_TcpPort SimIp4Packet::getLE_TcpDestinationPort ( )
inline

Definition at line 373 of file SimIp4Packet.hpp.

373 { return pktQ[2].getLE_TcpDstPort(); }

◆ getLE_TcpSourcePort()

LE_TcpPort SimIp4Packet::getLE_TcpSourcePort ( )
inline

Definition at line 369 of file SimIp4Packet.hpp.

369 { return pktQ[2].getLE_TcpSrcPort(); }

◆ getTcpAcknowledgeNumber()

TcpAckNum SimIp4Packet::getTcpAcknowledgeNumber ( )
inline

Definition at line 379 of file SimIp4Packet.hpp.

379 { return pktQ[3].getTcpAckNum(); }
Here is the caller graph for this function:

◆ getTcpChecksum()

int SimIp4Packet::getTcpChecksum ( )
inline

Definition at line 401 of file SimIp4Packet.hpp.

401 { return pktQ[4].getTcpChecksum(); }
Here is the caller graph for this function:

◆ getTcpControlAck()

TcpCtrlBit SimIp4Packet::getTcpControlAck ( )
inline

Definition at line 393 of file SimIp4Packet.hpp.

393 { return pktQ[4].getTcpCtrlAck(); }
Here is the caller graph for this function:

◆ getTcpControlFin()

TcpCtrlBit SimIp4Packet::getTcpControlFin ( )
inline

Definition at line 385 of file SimIp4Packet.hpp.

385 { return pktQ[4].getTcpCtrlFin(); }
Here is the caller graph for this function:

◆ getTcpControlPsh()

TcpCtrlBit SimIp4Packet::getTcpControlPsh ( )
inline

Definition at line 391 of file SimIp4Packet.hpp.

391 { return pktQ[4].getTcpCtrlPsh(); }
Here is the caller graph for this function:

◆ getTcpControlRst()

TcpCtrlBit SimIp4Packet::getTcpControlRst ( )
inline

Definition at line 389 of file SimIp4Packet.hpp.

389 { return pktQ[4].getTcpCtrlRst(); }
Here is the caller graph for this function:

◆ getTcpControlSyn()

TcpCtrlBit SimIp4Packet::getTcpControlSyn ( )
inline

Definition at line 387 of file SimIp4Packet.hpp.

387 { return pktQ[4].getTcpCtrlSyn(); }
Here is the caller graph for this function:

◆ getTcpControlUrg()

TcpCtrlBit SimIp4Packet::getTcpControlUrg ( )
inline

Definition at line 395 of file SimIp4Packet.hpp.

395 { return pktQ[4].getTcpCtrlUrg(); }
Here is the caller graph for this function:

◆ getTcpData()

string SimIp4Packet::getTcpData ( )
inline

Get TCP data from the current IPv4 packet.

Returns
a string.

Definition at line 1059 of file SimIp4Packet.hpp.

1059  {
1060  string tcpDataStr = "";
1061  int tcpDataSize = this->sizeOfTcpData();
1062 
1063  if(tcpDataSize > 0) {
1064  int ip4DataOffset = (4 * this->getIpInternetHeaderLength());
1065  int tcpDataOffset = ip4DataOffset + (4 * this->getTcpDataOffset());
1066  int bytCnt = 0;
1067 
1068  for (int chunkNum=0; chunkNum<this->pktQ.size(); chunkNum++) {
1069  for (int bytNum=0; bytNum<8; bytNum++) {
1070  if ((bytCnt >= tcpDataOffset) & (bytCnt < (tcpDataOffset + tcpDataSize))) {
1071  if (this->pktQ[chunkNum].getLE_TKeep().bit(bytNum)) {
1072  int hi = ((bytNum*8) + 7);
1073  int lo = ((bytNum*8) + 0);
1074  ap_uint<8> octet = this->pktQ[chunkNum].getLE_TData().range(hi, lo);
1075  tcpDataStr += myUint8ToStrHex(octet);
1076  }
1077  }
1078  bytCnt++;
1079  }
1080  }
1081  }
1082  return tcpDataStr;
1083  }
int sizeOfTcpData()
Return the size of the TCP data payload in octets.
int getTcpDataOffset()
string myUint8ToStrHex(ap_uint< 8 > inputNumber)
Converts an UINT8 into a string of 2 HEX characters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTcpDataOffset()

int SimIp4Packet::getTcpDataOffset ( )
inline

Definition at line 382 of file SimIp4Packet.hpp.

382 { return pktQ[4].getTcpDataOff(); }
Here is the caller graph for this function:

◆ getTcpDestinationPort()

int SimIp4Packet::getTcpDestinationPort ( )
inline

Definition at line 372 of file SimIp4Packet.hpp.

372 { return pktQ[2].getTcpDstPort(); }
Here is the caller graph for this function:

◆ getTcpOptionKind()

int SimIp4Packet::getTcpOptionKind ( )
inline

Definition at line 407 of file SimIp4Packet.hpp.

407 { return pktQ[5].getTcpOptKind(); }
Here is the caller graph for this function:

◆ getTcpOptionMss()

int SimIp4Packet::getTcpOptionMss ( )
inline

Definition at line 409 of file SimIp4Packet.hpp.

409 { return pktQ[5].getTcpOptMss(); }
Here is the caller graph for this function:

◆ getTcpSegment()

SimTcpSegment SimIp4Packet::getTcpSegment ( )
inline

Definition at line 667 of file SimIp4Packet.hpp.

667  {
668  SimTcpSegment tcpSegment;
669  LE_tData newTData = 0;
670  LE_tKeep newTKeep = 0;
671  LE_tLast newTLast = 0;
672  int wordOutCnt = 0;
673  bool alternate = true;
674  bool endOfPkt = false;
675  int ip4PktSize = this->size();
676  int ihl = this->getIpInternetHeaderLength();
677  int wordInpCnt = ihl/2; // Skip the IP header words
678  bool qwordAligned = (ihl % 2) ? false : true;
679  while (wordInpCnt < ip4PktSize) {
680  if (endOfPkt)
681  break;
682  if (qwordAligned) {
683  newTData = 0;
684  newTKeep = 0;
685  newTLast = 0;
686  for (int i=0; i<8; i++) {
687  if (this->pktQ[wordInpCnt].getLE_TKeep() & (0x01 << i)) {
688  newTData.range((i*8)+7, (i*8)+0) =
689  this->pktQ[wordInpCnt].getLE_TData().range((i*8)+7, (i*8)+0);
690  newTKeep = newTKeep | (0x01 << i);
691  }
692  }
693  newTLast = this->pktQ[wordInpCnt].getLE_TLast();
694  wordInpCnt++;
695  wordOutCnt++;
696  tcpSegment.pushChunk(AxisTcp(newTData, newTKeep, newTLast));
697  }
698  else if (alternate) {
699  //-- Populate the upper-half of a new chunk (.i.e, LE(31, 0))
700  newTData = 0;
701  newTKeep = 0;
702  newTLast = 0;
703  for (int i=0, hi=7, lo=0; i<4; i++) {
704  if (this->pktQ[wordInpCnt].getLE_TKeep() & (0x10<<i)) {
705  newTData.range(hi+8*i, lo+8*i) = this->pktQ[wordInpCnt].getLE_TData().range(32+hi+8*i, 32+lo+8*i);
706  newTKeep = newTKeep | (0x01<<i);
707  }
708  }
709  if (this->pktQ[wordInpCnt].getLE_TLast()) {
710  newTLast = TLAST;
711  endOfPkt = true;
712  tcpSegment.pushChunk(AxisTcp(newTData, newTKeep, newTLast));
713  }
714  alternate = !alternate;
715  wordInpCnt++;
716  }
717  else {
718  //-- Populate the lower-half of a new chunk (.i.e, LE(63,32))
719  for (int i=0, hi=7, lo=0; i<4; i++) {
720  if (this->pktQ[wordInpCnt].getLE_TKeep() & (0x01<<i)) {
721  newTData.range(32+hi+8*i, 32+lo+8*i) = this->pktQ[wordInpCnt].getLE_TData().range(hi+8*i, lo+8*i);
722  newTKeep = newTKeep | (0x10<<i);
723  }
724  }
725  if (this->pktQ[wordInpCnt].getLE_TLast()) {
726  LE_tKeep leTKeep = this->pktQ[wordInpCnt].getLE_TKeep();
727  if (not (leTKeep & 0xF0)) {
728  newTLast = TLAST;
729  endOfPkt = true;
730  }
731  }
732  alternate = !alternate;
733  wordOutCnt++;
734  tcpSegment.pushChunk(AxisTcp(newTData, newTKeep, newTLast));
735  }
736  }
737  return tcpSegment;
738  } // End-of: getTcpSegment
Class TCP Segment.
void pushChunk(AxisTcp tcpChunk)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTcpSegmentLength()

Ip4DatLen SimIp4Packet::getTcpSegmentLength ( )
inline

Definition at line 741 of file SimIp4Packet.hpp.

741  {
742  if (this->getIpProtocol() != IP4_PROT_TCP) {
743  printFatal(this->myName, "Cannot compute TCP segment length. The current IPv4 packet does not contain any TCP segment (prot=0x%2.2x).\n",
744  this->getIpProtocol());
745  }
746  return (this->getIpTotalLength() - (this->getIpInternetHeaderLength() * 4));
747  }
#define IP4_PROT_TCP
Definition: nts_types.hpp:184
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTcpSequenceNumber()

TcpSeqNum SimIp4Packet::getTcpSequenceNumber ( )
inline

Definition at line 376 of file SimIp4Packet.hpp.

376 { return pktQ[3].getTcpSeqNum(); }
Here is the caller graph for this function:

◆ getTcpSourcePort()

int SimIp4Packet::getTcpSourcePort ( )
inline

Definition at line 368 of file SimIp4Packet.hpp.

368 { return pktQ[2].getTcpSrcPort(); }
Here is the caller graph for this function:

◆ getTcpUrgentPointer()

int SimIp4Packet::getTcpUrgentPointer ( )
inline

Definition at line 404 of file SimIp4Packet.hpp.

404 { return pktQ[4].getTcpUrgPtr(); }
Here is the caller graph for this function:

◆ getTcpWindow()

int SimIp4Packet::getTcpWindow ( )
inline

Definition at line 398 of file SimIp4Packet.hpp.

398 { return pktQ[4].getTcpWindow(); }
Here is the caller graph for this function:

◆ getUdpChecksum()

UdpCsum SimIp4Packet::getUdpChecksum ( )
inline

Definition at line 464 of file SimIp4Packet.hpp.

464  {
465  int ihl = this->getIpInternetHeaderLength();
466  int bit = (ihl*4*8) + 48; // Field starts at bit #48
467  int raw = bit/ARW;
468  return pktQ[raw].getUdpCsum(bit % ARW);
469  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUdpDatagram()

SimUdpDatagram SimIp4Packet::getUdpDatagram ( )
inline

Definition at line 593 of file SimIp4Packet.hpp.

593  {
594  SimUdpDatagram udpDatagram;
595  LE_tData newTData = 0;
596  LE_tKeep newTKeep = 0;
597  LE_tLast newTLast = 0;
598  int wordOutCnt = 0;
599  bool alternate = true;
600  bool endOfPkt = false;
601  int ip4PktSize = this->size();
602  int ihl = this->getIpInternetHeaderLength();
603  int wordInpCnt = ihl/2; // Skip the IP header words
604  bool qwordAligned = (ihl % 2) ? false : true;
605  while (wordInpCnt < ip4PktSize) {
606  if (endOfPkt)
607  break;
608  if (qwordAligned) {
609  newTData = 0;
610  newTKeep = 0;
611  newTLast = 0;
612  for (int i=0; i<8; i++) {
613  if (this->pktQ[wordInpCnt].getLE_TKeep() & (0x01 << i)) {
614  newTData.range((i*8)+7, (i*8)+0) =
615  this->pktQ[wordInpCnt].getLE_TData().range((i*8)+7, (i*8)+0);
616  newTKeep = newTKeep | (0x01 << i);
617  }
618  }
619  newTLast = this->pktQ[wordInpCnt].getLE_TLast();
620  wordInpCnt++;
621  wordOutCnt++;
622  udpDatagram.pushChunk(AxisUdp(newTData, newTKeep, newTLast));
623  }
624  else if (alternate) {
625  //-- Populate the upper-half of a new chunk (.i.e, LE(31, 0))
626  newTData = 0;
627  newTKeep = 0;
628  newTLast = 0;
629  for (int i=0, hi=7, lo=0; i<4; i++) {
630  if (this->pktQ[wordInpCnt].getLE_TKeep() & (0x10<<i)) {
631  newTData.range(hi+8*i, lo+8*i) = this->pktQ[wordInpCnt].getLE_TData().range(32+hi+8*i, 32+lo+8*i);
632  newTKeep = newTKeep | (0x01<<i);
633  }
634  }
635  if (this->pktQ[wordInpCnt].getLE_TLast()) {
636  newTLast = TLAST;
637  endOfPkt = true;
638  udpDatagram.pushChunk(AxisUdp(newTData, newTKeep, newTLast));
639  }
640  alternate = !alternate;
641  wordInpCnt++;
642  }
643  else {
644  //-- Populate the lower-half of a new chunk (.i.e, LE(63,32))
645  for (int i=0, hi=7, lo=0; i<4; i++) {
646  if (this->pktQ[wordInpCnt].getLE_TKeep() & (0x01<<i)) {
647  newTData.range(32+hi+8*i, 32+lo+8*i) = this->pktQ[wordInpCnt].getLE_TData().range(hi+8*i, lo+8*i);
648  newTKeep = newTKeep | (0x10<<i);
649  }
650  }
651  if (this->pktQ[wordInpCnt].getLE_TLast()) {
652  LE_tKeep leTKeep = this->pktQ[wordInpCnt].getLE_TKeep();
653  if (not (leTKeep & 0xF0)) {
654  newTLast = TLAST;
655  endOfPkt = true;
656  }
657  }
658  alternate = !alternate;
659  wordOutCnt++;
660  udpDatagram.pushChunk(AxisUdp(newTData, newTKeep, newTLast));
661  }
662  }
663  return udpDatagram;
664  } // End-of: getUdpDatagram
Class UDP Datagram.
void pushChunk(AxisUdp udpChunk)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUdpDestinationPort()

UdpPort SimIp4Packet::getUdpDestinationPort ( )
inline

Definition at line 437 of file SimIp4Packet.hpp.

437  {
438  int ihl = this->getIpInternetHeaderLength();
439  int bit = (ihl*4*8) + 16; // Field starts at bit #16
440  int raw = bit/ARW;
441  return pktQ[raw].getUdpDstPort(bit % ARW);
442  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUdpLength()

UdpLen SimIp4Packet::getUdpLength ( )
inline

Definition at line 450 of file SimIp4Packet.hpp.

450  {
451  int ihl = this->getIpInternetHeaderLength();
452  int bit = (ihl*4*8) + 32; // Field starts at bit #32
453  int raw = bit/ARW;
454  return pktQ[raw].getUdpLen(bit % ARW);
455  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUdpSourcePort()

UdpPort SimIp4Packet::getUdpSourcePort ( )
inline

Definition at line 423 of file SimIp4Packet.hpp.

423  {
424  int ihl = this->getIpInternetHeaderLength();
425  int bit = (ihl*4*8) + 0; // Field starts at bit #00
426  int raw = bit/ARW;
427  return pktQ[raw].getUdpSrcPort(bit % ARW);
428  }
Here is the call graph for this function:

◆ isACK()

bool SimIp4Packet::isACK ( )
inline

Returns true if packet is an ACK.

Definition at line 1108 of file SimIp4Packet.hpp.

1108  {
1109  if (this->getTcpControlAck())
1110  return true;
1111  else
1112  return false;
1113  }
TcpCtrlBit getTcpControlAck()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isFIN()

bool SimIp4Packet::isFIN ( )
inline

Returns true if packet is a FIN.

Definition at line 1088 of file SimIp4Packet.hpp.

1088  {
1089  if (this->getTcpControlFin())
1090  return true;
1091  else
1092  return false;
1093  }
TcpCtrlBit getTcpControlFin()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSYN()

bool SimIp4Packet::isSYN ( )
inline

Returns true if packet is a SYN.

Definition at line 1098 of file SimIp4Packet.hpp.

1098  {
1099  if (this->getTcpControlSyn())
1100  return true;
1101  else
1102  return false;
1103  }
TcpCtrlBit getTcpControlSyn()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isWellFormed()

bool SimIp4Packet::isWellFormed ( const char *  callerName,
bool  checkIp4TotLen = true,
bool  checkIp4HdrCsum = true,
bool  checkUdpLen = true,
bool  checkLy4Csum = true 
)
inline

Checks if the IP header and embedded protocol fields are properly set.

Parameters
[in]callerNameThe name of the calling function or process.
[in]checkIp4TotLenA default argument to disable this test.
[in]checkIp4HdrCsumA default argument to disable this test.
[in]checkUdpLenA default argument to disable this test.
[in]checkLy4CsumA default argument to disable this test.
Returns
true if the packet is well-formed.

Definition at line 1129 of file SimIp4Packet.hpp.

1131  {
1132  bool rc = true;
1133  if (checkIp4TotLen) {
1134  if (this->getIpTotalLength() != this->getLen()) {
1135  printError(callerName, "Malformed IPv4 packet: 'Total Length' field does not match the length of the packet.\n");
1136  printError(callerName, "\tFound Total Length field=0x%4.4X, Was expecting 0x%4.4X)\n",
1137  this->getIpTotalLength(), this->getLen());
1138  rc = false;
1139  }
1140  }
1141  if (checkIp4HdrCsum) {
1142  if (this->getIpHeaderChecksum() != this->calculateIpHeaderChecksum()) {
1143  if (this->getIpHeaderChecksum() == 0) {
1144  printWarn(callerName, "Malformed IPv4 packet: 'Header Checksum' field does not match the computed header checksum.\n");
1145  printWarn(callerName, "\tFound Header Checksum field=0x%4.4X, Was expecting 0x%4.4X)\n",
1146  this->getIpHeaderChecksum().to_ushort(), this->calculateIpHeaderChecksum().to_ushort());
1147  printWarn(callerName, "\t[1] You should disable this checking if the IP packet is generated by the TOE because the header checksum will be computed and inserted later by IPTX.\n");
1148  printWarn(callerName, "\t[2] Otherwise, you can also disable this checking if you want to skip computing and providing the IP header checksum in your test vectors files.\n");
1149  }
1150  else {
1151  printError(callerName, "Malformed IPv4 packet: 'Header Checksum' field does not match the computed header checksum.\n");
1152  printError(callerName, "\tFound Header Checksum field=0x%4.4X, Was expecting 0x%4.4X)\n",
1153  this->getIpHeaderChecksum().to_ushort(), this->calculateIpHeaderChecksum().to_ushort());
1154  rc = false;
1155  }
1156  }
1157  }
1158  if (this->getIpProtocol() == IP4_PROT_UDP) {
1159  // Asses UDP datagram
1160  SimUdpDatagram udpDatagram = this->getUdpDatagram();
1161  if (checkUdpLen) {
1162  UdpLen udpHLen = this->getUdpLength();
1163  int calcLen = udpDatagram.length();
1164  if (udpHLen != calcLen) {
1165  printError(callerName, "Malformed IPv4 packet: UDP 'Length' field does not match the length of the datagram.\n");
1166  printError(callerName, "\tFound IPV4/UDP/Length field=0x%4.4X, Was expecting 0x%4.4X)\n",
1167  udpHLen.to_uint(), calcLen);
1168  rc = false;
1169  }
1170  }
1171  if (checkLy4Csum) {
1172  UdpCsum udpHCsum = this->getUdpChecksum();
1173  UdpCsum calcCsum = udpDatagram.reCalculateUdpChecksum( \
1174  this->getIpSourceAddress(),
1175  this->getIpDestinationAddress());
1176  if ((udpHCsum != 0) and (udpHCsum != calcCsum)) {
1177  // UDP datagram comes with an invalid checksum
1178  printError(callerName, "Malformed IPv4 packet: UDP 'Checksum' field does not match the checksum of the pseudo-packet.\n");
1179  printError(callerName, "\tFound IPv4/UDP/Checksum field=0x%4.4X, Was expecting 0x%4.4X)\n",
1180  udpHCsum.to_uint(), calcCsum.to_ushort());
1181  if (udpHCsum == 0xDEAD) {
1182  printWarn(callerName, "This will not be considered an error but an intentional corrupted checksum inserted by the user for testing purpose.\n");
1183  }
1184  else {
1185  rc = false;
1186  }
1187  }
1188  }
1189  }
1190  else if (this->getIpProtocol() == IP4_PROT_TCP) {
1191  // Asses TCP segment
1192  SimTcpSegment tcpSegment = this->getTcpSegment();
1193  if (0) { tcpSegment.dump(); }
1194  if (checkLy4Csum) {
1195  // Assess IPv4/TCP/Checksum field vs segment checksum
1196  TcpCsum tcpHCsum = this->getTcpChecksum();
1197  TcpCsum calcCsum = tcpSegment.reCalculateTcpChecksum(this->getIpSourceAddress(),
1198  this->getIpDestinationAddress(),
1199  this->getTcpSegmentLength());
1200  if (tcpHCsum != calcCsum) {
1201  // TCP segment comes with an invalid checksum
1202  printError(callerName, "Malformed IPv4 packet: TCP 'Checksum' field does not match the checksum of the pseudo-packet.\n");
1203  printError(callerName, "\tFound IPv4/TCP/Checksum field=0x%4.4X, Was expecting 0x%4.4X)\n",
1204  tcpHCsum.to_uint(), calcCsum.to_ushort());
1205  if (tcpHCsum == 0xDEAD) {
1206  printWarn(callerName, "This will not be considered an error but an intentional corrupted checksum inserted by the user for testing purpose.\n");
1207  }
1208  else {
1209  rc = false;
1210  }
1211  }
1212  }
1213  }
1214  else if (this->getIpProtocol() == IP4_PROT_ICMP) {
1215  // Asses ICMP packet
1216  printWarn(myName, "[TODO-Must check if message is well-formed !!!\n");
1217  }
1218  return rc;
1219  }
SimTcpSegment getTcpSegment()
Ip4Addr getIpSourceAddress()
UdpCsum getUdpChecksum()
int getTcpChecksum()
Ip4HdrCsum getIpHeaderChecksum()
SimUdpDatagram getUdpDatagram()
UdpLen getUdpLength()
Ip4Addr getIpDestinationAddress()
Ip4DatLen getTcpSegmentLength()
void dump()
Dump this TCP segment as HEX and ASCII characters to screen.
TcpCsum reCalculateTcpChecksum(Ip4Addr ipSa, Ip4Addr ipDa, Ip4DatLen segLen)
Recalculate the TCP checksum of this segment.
UdpCsum reCalculateUdpChecksum(Ip4Addr ipSa, Ip4Addr ipDa)
Recalculate the UDP checksum of a datagram.
ap_uint< 16 > UdpLen
Definition: nal.hpp:250
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
ap_uint< 16 > TcpCsum
Definition: AxisTcp.hpp:114
#define printWarn(callerName, format,...)
A macro to print a warning message.
Definition: nts_utils.hpp:182
ap_uint< 16 > UdpCsum
Definition: AxisUdp.hpp:101
Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

int SimIp4Packet::length ( )
inline

Definition at line 259 of file SimIp4Packet.hpp.

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

◆ printHdr()

void SimIp4Packet::printHdr ( const char *  callerName)
inline

Print the header details of an IP packet.

Parameters
[in]callerName,thename of the calling function or process.

Definition at line 1225 of file SimIp4Packet.hpp.

1225  {
1226  LE_Ip4TotalLen leIp4TotalLen = byteSwap16(this->getIpTotalLength());
1227  LE_Ip4SrcAddr leIp4SrcAddr = byteSwap32(this->getIpSourceAddress());
1228  LE_Ip4DstAddr leIp4DstAddr = byteSwap32(this->getIpDestinationAddress());
1229 
1230  LE_TcpSrcPort leTcpSrcPort = byteSwap16(this->getTcpSourcePort());
1231  LE_TcpDstPort leTcpDstPort = byteSwap16(this->getTcpDestinationPort());
1232  LE_TcpSeqNum leTcpSeqNum = byteSwap32(this->getTcpSequenceNumber());
1233  LE_TcpAckNum leTcpAckNum = byteSwap32(this->getTcpAcknowledgeNumber());
1234 
1235  LE_TcpWindow leTcpWindow = byteSwap16(this->getTcpWindow());
1236  LE_TcpChecksum leTcpCSum = byteSwap16(this->getTcpChecksum());
1237  LE_TcpUrgPtr leTcpUrgPtr = byteSwap16(this->getTcpUrgentPointer());
1238 
1239  printInfo(callerName, "IP PACKET HEADER (HEX numbers are in LITTLE-ENDIAN order): \n");
1240  printInfo(callerName, "IP4 IHL = %15u \n",
1241  this->getIpInternetHeaderLength());
1242  printInfo(callerName, "IP4 Version = %15u \n",
1243  this->getIpVersion());
1244  printInfo(callerName, "IP4 Type Of Service = %15u \n",
1245  this->getIpTypeOfService());
1246  printInfo(callerName, "IP4 Total Length = %15u (0x%4.4X) \n",
1247  this->getIpTotalLength(), leIp4TotalLen.to_uint());
1248  printInfo(callerName, "IP4 Identification = %15u \n",
1249  this->getIpIdentification());
1250  printInfo(callerName, "IP4 Fragment Offset = %15u \n",
1251  this->getIpFragmentOffset());
1252  printInfo(callerName, "IP4 Type To Live = %15u \n",
1253  this->getIpTimeToLive());
1254  printInfo(callerName, "IP4 Protocol = %15u \n",
1255  this->getIpProtocol());
1256  printInfo(callerName, "IP4 Header Checksum = %15u \n",
1257  this->getIpHeaderChecksum().to_ushort());
1258  printInfo(callerName, "IP4 Source Address = %3.3d.%3.3d.%3.3d.%3.3d (0x%8.8X) \n",
1259  (this->getIpSourceAddress().to_uint() & 0xFF000000) >> 24,
1260  (this->getIpSourceAddress().to_uint() & 0x00FF0000) >> 16,
1261  (this->getIpSourceAddress().to_uint() & 0x0000FF00) >> 8,
1262  (this->getIpSourceAddress().to_uint() & 0x000000FF) >> 0,
1263  leIp4SrcAddr.to_uint());
1264  printInfo(callerName, "IP4 Destination Address = %3.3d.%3.3d.%3.3d.%3.3d (0x%8.8X) \n",
1265  (this->getIpDestinationAddress().to_uint() & 0xFF000000) >> 24,
1266  (this->getIpDestinationAddress().to_uint() & 0x00FF0000) >> 16,
1267  (this->getIpDestinationAddress().to_uint() & 0x0000FF00) >> 8,
1268  (this->getIpDestinationAddress().to_uint() & 0x000000FF) >> 0,
1269  leIp4DstAddr.to_uint());
1270  printInfo(callerName, "TCP Source Port = %15u (0x%4.4X) \n",
1271  this->getTcpSourcePort(), leTcpSrcPort.to_uint());
1272  printInfo(callerName, "TCP Destination Port = %15u (0x%4.4X) \n",
1273  this->getTcpDestinationPort(), leTcpDstPort.to_uint());
1274  printInfo(callerName, "TCP Sequence Number = %15u (0x%8.8X) \n",
1275  this->getTcpSequenceNumber().to_uint(), leTcpSeqNum.to_uint());
1276  printInfo(callerName, "TCP Acknowledge Number = %15u (0x%8.8X) \n",
1277  this->getTcpAcknowledgeNumber().to_uint(), leTcpAckNum.to_uint());
1278  printInfo(callerName, "TCP Data Offset = %15d (0x%1.1X) \n",
1279  this->getTcpDataOffset(), this->getTcpDataOffset());
1280  printInfo(callerName, "TCP Control Bits = %s%s%s%s%s%s\n",
1281  this->getTcpControlFin() ? "FIN |" : "",
1282  this->getTcpControlSyn() ? "SYN |" : "",
1283  this->getTcpControlRst() ? "RST |" : "",
1284  this->getTcpControlPsh() ? "PSH |" : "",
1285  this->getTcpControlAck() ? "ACK |" : "",
1286  this->getTcpControlUrg() ? "URG |" : "");
1287  printInfo(callerName, "TCP Window = %15u (0x%4.4X) \n",
1288  this->getTcpWindow(), leTcpWindow.to_uint());
1289  printInfo(callerName, "TCP Checksum = %15u (0x%4.4X) \n",
1290  this->getTcpChecksum(), leTcpCSum.to_uint());
1291  printInfo(callerName, "TCP Urgent Pointer = %15u (0x%4.4X) \n",
1292  this->getTcpUrgentPointer(), leTcpUrgPtr.to_uint());
1293  if (this->getTcpDataOffset() == 6) {
1294  printInfo(callerName, "TCP Option:\n");
1295  switch (this->getTcpOptionKind()) {
1296  case 0x02:
1297  printInfo(callerName, " Maximum Segment Size = %15u \n",
1298  this->getTcpOptionMss());
1299  }
1300  }
1301  printInfo(callerName, "TCP Data Length = %15u \n",
1302  this->sizeOfTcpData());
1303  }
TcpSeqNum getTcpSequenceNumber()
int getIpTypeOfService()
int getIpTimeToLive()
int getTcpOptionMss()
TcpAckNum getTcpAcknowledgeNumber()
int getIpIdentification()
TcpCtrlBit getTcpControlUrg()
int getTcpDestinationPort()
int getTcpUrgentPointer()
TcpCtrlBit getTcpControlRst()
int getTcpOptionKind()
int getIpFragmentOffset()
TcpCtrlBit getTcpControlPsh()
int getTcpSourcePort()
ap_uint< 32 > LE_Ip4DstAddr
Definition: AxisIp4.hpp:147
ap_uint< 32 > LE_Ip4SrcAddr
Definition: AxisIp4.hpp:146
ap_uint< 16 > LE_TcpDstPort
Definition: AxisTcp.hpp:87
ap_uint< 32 > LE_TcpAckNum
Definition: AxisTcp.hpp:90
ap_uint< 16 > LE_TcpUrgPtr
Definition: AxisTcp.hpp:96
ap_uint< 16 > LE_TcpSrcPort
Definition: AxisTcp.hpp:86
ap_uint< 32 > LE_TcpSeqNum
Definition: AxisTcp.hpp:89
ap_uint< 16 > LE_TcpChecksum
Definition: AxisTcp.hpp:95
#define printInfo(callerName, format,...)
A macro to print an information message.
Definition: nts_utils.hpp:169
ap_uint< 16 > LE_Ip4TotalLen
Definition: AxisIp4.hpp:142
ap_uint< 16 > LE_TcpWindow
Definition: AxisTcp.hpp:94
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
Definition: udp.cpp:78
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:

◆ printRaw()

void SimIp4Packet::printRaw ( const char *  callerName)
inline

Raw print of an IP packet (.i.e, as AxisRaw chunks).

Parameters
[in]callerNameThe name of the calling function or process.

Definition at line 1309 of file SimIp4Packet.hpp.

1309  {
1310  printInfo(callerName, "Current packet is : \n");
1311  for (int c=0; c<this->pktQ.size(); c++) {
1312  printf("\t\t%16.16lX %2.2X %d \n",
1313  this->pktQ[c].getLE_TData().to_ulong(),
1314  this->pktQ[c].getLE_TKeep().to_ushort(),
1315  this->pktQ[c].getLE_TLast().to_uchar());
1316  }
1317  }
Here is the caller graph for this function:

◆ pullChunk()

AxisIp4 SimIp4Packet::pullChunk ( )
inline

Definition at line 251 of file SimIp4Packet.hpp.

251  {
252  AxisIp4 headingChunk = this->front();
253  this->pop_front();
254  setLen(getLen() - headingChunk.getLen());
255  return headingChunk;
256  }
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 SimIp4Packet::pushChunk ( AxisIp4  ip4Chunk)
inline

Definition at line 241 of file SimIp4Packet.hpp.

241  {
242  if (this->size() > 0) {
243  // Always clear 'TLAST' bit of previous chunck
244  this->pktQ[this->size()-1].setTLast(0);
245  }
246  this->push_back(ip4Chunk);
247  setLen(getLen() + ip4Chunk.getLen());
248  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reCalculateIpHeaderChecksum()

Ip4HdrCsum SimIp4Packet::reCalculateIpHeaderChecksum ( )
inline

Recalculate the IPv4 header checksum of a packet.

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

Definition at line 1326 of file SimIp4Packet.hpp.

1326  {
1327  Ip4HdrCsum newIp4HdrCsum = calculateIpHeaderChecksum();
1328  // Overwrite the former IP header checksum
1329  this->setIpHeaderChecksum(newIp4HdrCsum);
1330  return (newIp4HdrCsum);
1331  }
ap_uint< 16 > Ip4HdrCsum
Definition: AxisIp4.hpp:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIpDestinationAddress()

void SimIp4Packet::setIpDestinationAddress ( int  addr)
inline

Definition at line 358 of file SimIp4Packet.hpp.

358 { pktQ[2].setIp4DstAddr(addr); }
Here is the caller graph for this function:

◆ setIpFlags()

void SimIp4Packet::setIpFlags ( int  flags)
inline

Definition at line 339 of file SimIp4Packet.hpp.

339 { pktQ[0].setIp4Flags(flags); }
Here is the caller graph for this function:

◆ setIpFragmentOffset()

void SimIp4Packet::setIpFragmentOffset ( int  offset)
inline

Definition at line 335 of file SimIp4Packet.hpp.

335 { pktQ[0].setIp4FragOff(offset); }
Here is the caller graph for this function:

◆ setIpHeaderChecksum()

void SimIp4Packet::setIpHeaderChecksum ( int  csum)
inline

Definition at line 349 of file SimIp4Packet.hpp.

349 { pktQ[1].setIp4HdrCsum(csum); }
Here is the caller graph for this function:

◆ setIpIdentification()

void SimIp4Packet::setIpIdentification ( int  id)
inline

Definition at line 331 of file SimIp4Packet.hpp.

331 { pktQ[0].setIp4Ident(id); }
Here is the caller graph for this function:

◆ setIpInternetHeaderLength()

void SimIp4Packet::setIpInternetHeaderLength ( int  ihl)
inline

Definition at line 319 of file SimIp4Packet.hpp.

319 { pktQ[0].setIp4HdrLen(ihl); }
Here is the caller graph for this function:

◆ setIpPayload()

bool SimIp4Packet::setIpPayload ( SimIcmpPacket  icmpPkt)
inline

Set the data payload of this packet as an ICMP packet.

Parameters
[in]icmpPktThe ICMP packet to use as IPv4 payload.
Returns
true upon success, otherwise false.
Warning
The IP4 packet object must be large enough to hold this this payload.

Definition at line 959 of file SimIp4Packet.hpp.

959  {
960  bool alternate = true;
961  bool endOfPkt = false;
962  AxisIcmp axisIcmp(0, 0, 0);
963  int axisIcmpCnt = 0;
964  int axisIp4Cnt = 2; // Start with the 2nd word which contains IP_DA
965 
966  if ((this->getLen() - IP4_HEADER_LEN) < icmpPkt.length()) {
967  printFatal(this->myName, "Packet length is expected to be larger than %d bytes (was found to be %d bytes).\n",
968  (IP4_HEADER_LEN+icmpPkt.length()), this->getLen());
969  }
970  // Read and pop the very first chunk from the ICMP packet
971  axisIcmp = icmpPkt.pullChunk();
972 
973  while (!endOfPkt) {
974  if (alternate) {
975  LE_tData tmpTData = this->pktQ[axisIp4Cnt].getLE_TData();
976  LE_tKeep tmpTKeep = this->pktQ[axisIp4Cnt].getLE_TKeep();
977  LE_tLast tmpTLast = this->pktQ[axisIp4Cnt].getLE_TLast();
978  if (axisIcmp.getLE_TKeep() & 0x01) {
979  tmpTData.range(39,32) = axisIcmp.getLE_TData().range( 7, 0);
980  tmpTKeep = tmpTKeep | (0x10);
981  this->setLen(this->getLen() + 1);
982  }
983  if (axisIcmp.getLE_TKeep() & 0x02) {
984  tmpTData.range(47,40) = axisIcmp.getLE_TData().range(15, 8);
985  tmpTKeep = tmpTKeep | (0x20);
986  this->setLen(this->getLen() + 1);
987  }
988  if (axisIcmp.getLE_TKeep() & 0x04) {
989  tmpTData.range(55,48) = axisIcmp.getLE_TData().range(23,16);
990  tmpTKeep = tmpTKeep | (0x40);
991  this->setLen(this->getLen() + 1);
992  }
993  if (axisIcmp.getLE_TKeep() & 0x08) {
994  tmpTData.range(63,56) = axisIcmp.getLE_TData().range(31,24);
995  tmpTKeep = tmpTKeep | (0x80);
996  this->setLen(this->getLen() + 1);
997  }
998  if ((axisIcmp.getLE_TLast()) && (axisIcmp.getLE_TKeep() <= 0x0F)) {
999  tmpTLast = TLAST;
1000  endOfPkt = true;
1001  }
1002  else {
1003  tmpTLast = 0;
1004  }
1005  this->pktQ[axisIp4Cnt].setLE_TData(tmpTData);
1006  this->pktQ[axisIp4Cnt].setLE_TKeep(tmpTKeep);
1007  this->pktQ[axisIp4Cnt].setLE_TLast(tmpTLast);
1008  alternate = !alternate;
1009  axisIp4Cnt++;
1010  }
1011  else {
1012  LE_tData tmpTData = this->pktQ[axisIp4Cnt].getLE_TData();
1013  LE_tKeep tmpTKeep = this->pktQ[axisIp4Cnt].getLE_TKeep();
1014  LE_tLast tmpTLast = this->pktQ[axisIp4Cnt].getLE_TLast();
1015  if (axisIcmp.getLE_TKeep() & 0x10) {
1016  tmpTData.range( 7, 0) = axisIcmp.getLE_TData().range(39, 32);
1017  tmpTKeep = tmpTKeep | (0x01);
1018  }
1019  if (axisIcmp.getLE_TKeep() & 0x20) {
1020  tmpTData.range(15, 8) = axisIcmp.getLE_TData().range(47, 40);
1021  tmpTKeep = tmpTKeep | (0x02);
1022  }
1023  if (axisIcmp.getLE_TKeep() & 0x40) {
1024  tmpTData.range(23,16) = axisIcmp.getLE_TData().range(55, 48);
1025  tmpTKeep = tmpTKeep | (0x04);
1026  }
1027  if (axisIcmp.getLE_TKeep() & 0x80) {
1028  tmpTData.range(31,24) = axisIcmp.getLE_TData().range(63, 56);
1029  tmpTKeep = tmpTKeep | (0x08);
1030  }
1031  // Done with the incoming ICMP word
1032  axisIcmpCnt++;
1033 
1034  if (axisIcmp.getLE_TLast()) {
1035  tmpTLast = TLAST;
1036  endOfPkt = true;
1037  }
1038  else {
1039  tmpTLast = 0;
1040  // Read and pop a new chunk from the ICMP packet
1041  axisIcmp = icmpPkt.pullChunk();
1042  }
1043  this->pktQ[axisIp4Cnt].setLE_TData(tmpTData);
1044  this->pktQ[axisIp4Cnt].setLE_TKeep(tmpTKeep);
1045  this->pktQ[axisIp4Cnt].setLE_TLast(tmpTLast);
1046  alternate = !alternate;
1047  }
1048  } // End-of while(!endOfPkt)
1049  return true;
1050  } // End-of: setIpPayload
Here is the call graph for this function:

◆ setIpProtocol()

void SimIp4Packet::setIpProtocol ( int  prot)
inline

Definition at line 345 of file SimIp4Packet.hpp.

345 { pktQ[1].setIp4Prot(prot); }
Here is the caller graph for this function:

◆ setIpSourceAddress()

void SimIp4Packet::setIpSourceAddress ( int  addr)
inline

Definition at line 353 of file SimIp4Packet.hpp.

353 { pktQ[1].setIp4SrcAddr(addr); }
Here is the caller graph for this function:

◆ setIpTimeToLive()

void SimIp4Packet::setIpTimeToLive ( Ip4TtL  ttl)
inline

Definition at line 341 of file SimIp4Packet.hpp.

341 { pktQ[1].setIp4TtL(ttl); }
Here is the caller graph for this function:

◆ setIpTotalLength()

void SimIp4Packet::setIpTotalLength ( int  totLen)
inline

Definition at line 327 of file SimIp4Packet.hpp.

327 { pktQ[0].setIp4TotalLen(totLen);}
Here is the caller graph for this function:

◆ setIpTypeOfService()

void SimIp4Packet::setIpTypeOfService ( int  tos)
inline

Definition at line 323 of file SimIp4Packet.hpp.

323 { pktQ[0].setIp4ToS(tos); }
Here is the caller graph for this function:

◆ setIpVersion()

void SimIp4Packet::setIpVersion ( int  version)
inline

Definition at line 315 of file SimIp4Packet.hpp.

315 { pktQ[0].setIp4Version(version);}
Here is the caller graph for this function:

◆ setTcpAcknowledgeNumber()

void SimIp4Packet::setTcpAcknowledgeNumber ( TcpAckNum  num)
inline

Definition at line 378 of file SimIp4Packet.hpp.

378 { pktQ[3].setTcpAckNum(num); }
Here is the caller graph for this function:

◆ setTcpChecksum()

void SimIp4Packet::setTcpChecksum ( int  csum)
inline

Definition at line 400 of file SimIp4Packet.hpp.

400 { pktQ[4].setTcpChecksum(csum); }
Here is the caller graph for this function:

◆ setTcpControlAck()

void SimIp4Packet::setTcpControlAck ( int  bit)
inline

Definition at line 392 of file SimIp4Packet.hpp.

392 { pktQ[4].setTcpCtrlAck(bit); }
Here is the caller graph for this function:

◆ setTcpControlFin()

void SimIp4Packet::setTcpControlFin ( int  bit)
inline

Definition at line 384 of file SimIp4Packet.hpp.

384 { pktQ[4].setTcpCtrlFin(bit); }
Here is the caller graph for this function:

◆ setTcpControlPsh()

void SimIp4Packet::setTcpControlPsh ( int  bit)
inline

Definition at line 390 of file SimIp4Packet.hpp.

390 { pktQ[4].setTcpCtrlPsh(bit); }

◆ setTcpControlRst()

void SimIp4Packet::setTcpControlRst ( int  bit)
inline

Definition at line 388 of file SimIp4Packet.hpp.

388 { pktQ[4].setTcpCtrlRst(bit); }

◆ setTcpControlSyn()

void SimIp4Packet::setTcpControlSyn ( int  bit)
inline

Definition at line 386 of file SimIp4Packet.hpp.

386 { pktQ[4].setTcpCtrlSyn(bit); }

◆ setTcpControlUrg()

void SimIp4Packet::setTcpControlUrg ( int  bit)
inline

Definition at line 394 of file SimIp4Packet.hpp.

394 { pktQ[4].setTcpCtrlUrg(bit); }

◆ setTcpDataOffset()

void SimIp4Packet::setTcpDataOffset ( int  offset)
inline

Definition at line 381 of file SimIp4Packet.hpp.

381 { pktQ[4].setTcpDataOff(offset); }
Here is the caller graph for this function:

◆ setTcpDestinationPort()

void SimIp4Packet::setTcpDestinationPort ( int  port)
inline

Definition at line 371 of file SimIp4Packet.hpp.

371 { pktQ[2].setTcpDstPort(port); }
Here is the caller graph for this function:

◆ setTcpOptionKind()

void SimIp4Packet::setTcpOptionKind ( int  val)
inline

Definition at line 406 of file SimIp4Packet.hpp.

406 { pktQ[5].setTcpOptKind(val); }

◆ setTcpOptionMss()

void SimIp4Packet::setTcpOptionMss ( int  val)
inline

Definition at line 408 of file SimIp4Packet.hpp.

408 { pktQ[5].setTcpOptMss(val); }

◆ setTcpSequenceNumber()

void SimIp4Packet::setTcpSequenceNumber ( TcpSeqNum  num)
inline

Definition at line 375 of file SimIp4Packet.hpp.

375 { pktQ[3].setTcpSeqNum(num); }
Here is the caller graph for this function:

◆ setTcpSourcePort()

void SimIp4Packet::setTcpSourcePort ( int  port)
inline

Definition at line 367 of file SimIp4Packet.hpp.

367 { pktQ[2].setTcpSrcPort(port); }
Here is the caller graph for this function:

◆ setTcpUrgentPointer()

void SimIp4Packet::setTcpUrgentPointer ( int  ptr)
inline

Definition at line 403 of file SimIp4Packet.hpp.

403 { pktQ[4].setTcpUrgPtr(ptr); }

◆ setTcpWindow()

void SimIp4Packet::setTcpWindow ( int  win)
inline

Definition at line 397 of file SimIp4Packet.hpp.

397 { pktQ[4].setTcpWindow(win); }
Here is the caller graph for this function:

◆ setUdpChecksum()

void SimIp4Packet::setUdpChecksum ( UdpCsum  csum)
inline

Definition at line 457 of file SimIp4Packet.hpp.

457  {
458  int ihl = this->getIpInternetHeaderLength();
459  int bit = (ihl*4*8) + 48; // Field starts at bit #48
460  int raw = bit/ARW;
461  pktQ[raw].setUdpCsum(csum, (bit % ARW));
462  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUdpDestinationPort()

void SimIp4Packet::setUdpDestinationPort ( UdpPort  port)
inline

Definition at line 430 of file SimIp4Packet.hpp.

430  {
431  int ihl = this->getIpInternetHeaderLength();
432  int bit = (ihl*4*8) + 16; // Field starts at bit #16
433  int raw = bit/ARW;
434  pktQ[raw].setUdpDstPort(port, (bit % ARW));
435  }
Here is the call graph for this function:

◆ setUdpLength()

void SimIp4Packet::setUdpLength ( UdpLen  len)
inline

Definition at line 444 of file SimIp4Packet.hpp.

444  {
445  int ihl = this->getIpInternetHeaderLength();
446  int bit = (ihl*4*8) + 32; // Field starts at bit #32
447  int raw = bit/ARW;
448  }
Here is the call graph for this function:

◆ setUdpSourcePort()

void SimIp4Packet::setUdpSourcePort ( UdpPort  port)
inline

Definition at line 416 of file SimIp4Packet.hpp.

416  {
417  int ihl = this->getIpInternetHeaderLength();
418  int bit = (ihl*4*8) + 0; // Field starts at bit #00
419  int raw = bit/ARW;
420  pktQ[raw].setUdpSrcPort(port, (bit % ARW));
421  }
Here is the call graph for this function:

◆ size()

int SimIp4Packet::size ( )
inline

Definition at line 264 of file SimIp4Packet.hpp.

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

◆ sizeOfTcpData()

int SimIp4Packet::sizeOfTcpData ( )
inline

Return the size of the TCP data payload in octets.

Definition at line 1355 of file SimIp4Packet.hpp.

1355  {
1356  int ipDataLen = this->getIpTotalLength() - (4 * this->getIpInternetHeaderLength());
1357  int tcpDatalen = ipDataLen - (4 * this->getTcpDataOffset());
1358  return tcpDatalen;
1359  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpRecalculateChecksum()

int SimIp4Packet::tcpRecalculateChecksum ( )
inline

Recalculate the checksum of a TCP segment after it was modified.

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

Definition at line 1340 of file SimIp4Packet.hpp.

1340  {
1341  int newChecksum = 0;
1342  deque<AxisPsd4> tcpBuffer;
1343  // Assemble a TCP buffer with a pseudo-header and TCP data
1344  tcpAssemblePseudoHeaderAndData(tcpBuffer);
1345  // Compute the TCP checksum
1346  int tcpCsum = checksumCalculation(tcpBuffer);
1347  // Overwrite the former checksum
1348  this->setTcpChecksum(tcpCsum);
1349  return tcpCsum;
1350  }
void setTcpChecksum(int csum)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpVerifyChecksum()

bool SimIp4Packet::tcpVerifyChecksum ( )
inline

Recalculate the TCP checksum and compare it with the one embedded into the segment.

Returns
true/false.

Definition at line 1399 of file SimIp4Packet.hpp.

1399  {
1400  TcpChecksum tcpChecksum = this->getTcpChecksum();
1401  TcpChecksum computedCsum = this->tcpRecalculateChecksum();
1402  if (computedCsum == tcpChecksum) {
1403  return true;
1404  }
1405  else {
1406  printWarn(this->myName, " Embedded TCP checksum = 0x%8.8X \n", tcpChecksum.to_uint());
1407  printWarn(this->myName, " Computed TCP checksum = 0x%8.8X \n", computedCsum.to_uint());
1408  return false;
1409  }
1410  }
int tcpRecalculateChecksum()
Recalculate the checksum of a TCP segment after it was modified.
ap_uint< 16 > TcpChecksum
Definition: AxisTcp.hpp:113
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udpRecalculateChecksum()

UdpCsum SimIp4Packet::udpRecalculateChecksum ( )
inline

Recalculate checksum of an UDP datagram after it was modified.

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

Definition at line 1384 of file SimIp4Packet.hpp.

1384  {
1385  SimUdpDatagram udpDatagram = this->getUdpDatagram();
1386  UdpCsum computedCsum = udpDatagram.reCalculateUdpChecksum( \
1387  this->getIpSourceAddress(),
1388  this->getIpDestinationAddress());
1389  // Overwrite the former checksum
1390  this->setUdpChecksum(computedCsum);
1391  return computedCsum;
1392  }
void setUdpChecksum(UdpCsum csum)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udpVerifyChecksum()

bool SimIp4Packet::udpVerifyChecksum ( )
inline

Recalculate the UDP checksum and compare it with the one embedded into the datagram.

Returns
true/false.

Definition at line 1417 of file SimIp4Packet.hpp.

1417  {
1418  UdpCsum udpChecksum = this->getUdpChecksum();
1419  SimUdpDatagram udpDatagram = this->getUdpDatagram();
1420  UdpCsum computedCsum = udpDatagram.reCalculateUdpChecksum( \
1421  this->getIpSourceAddress(),
1422  this->getIpDestinationAddress());
1423  if (computedCsum == udpChecksum) {
1424  return true;
1425  }
1426  else {
1427  printWarn(this->myName, " Embedded UDP checksum = 0x%8.8X \n", udpChecksum.to_uint());
1428  printWarn(this->myName, " Computed UDP checksum = 0x%8.8X \n", computedCsum.to_uint());
1429  return false;
1430  }
1431  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verifyIpHeaderChecksum()

bool SimIp4Packet::verifyIpHeaderChecksum ( )
inline

Recalculate the IPv4 header checksum and compare it with the one embedded into the packet.

Returns
true/false.

Definition at line 1366 of file SimIp4Packet.hpp.

1366  {
1367  Ip4HdrCsum computedCsum = this->calculateIpHeaderChecksum();
1368  Ip4HdrCsum packetCsum = this->getIpHeaderChecksum();
1369  if (computedCsum == packetCsum) {
1370  return true;
1371  }
1372  else {
1373  return false;
1374  }
1375  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeTcpDataToDatFile()

void SimIp4Packet::writeTcpDataToDatFile ( ofstream &  outFile)
inline

Dump the TCP payload of this IP packet into a file. Data is written as a string.

Parameters
[in]outFileA ref to the gold file to write.

Definition at line 1453 of file SimIp4Packet.hpp.

1453  {
1454  if(this->sizeOfTcpData() > 0) {
1455  string tcpData = this->getTcpData();
1456  if (tcpData.size() > 0) {
1457  outFile << tcpData << endl;
1458  }
1459  }
1460  }
string getTcpData()
Get TCP data from the current IPv4 packet.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeToDatFile()

bool SimIp4Packet::writeToDatFile ( ofstream &  outFileStream)
inline

Dump this IP packet as AxisIp4 chunks into a file.

Parameters
[in]outFileStreamA reference to the file stream to write.
Returns
true upon success, otherwise false.

Definition at line 1438 of file SimIp4Packet.hpp.

1438  {
1439  for (int i=0; i < this->size(); i++) {
1440  AxisIp4 axisIp4 = this->pktQ[i];
1441  if (not writeAxisRawToFile(axisIp4, outFileStream)) {
1442  return false;
1443  }
1444  }
1445  return true;
1446  }
bool writeAxisRawToFile(AxisRaw &axisRaw, ofstream &outFileStream)
Dump an Axis raw data chunk to a file.
Here is the call graph for this function:
Here is the caller graph for this function:

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