30 #ifndef _SIM_IP4_PACKET_
31 #define _SIM_IP4_PACKET_
59 std::deque<AxisIp4> pktQ;
63 void setLen(
int pktLen) {
73 return this->pktQ.front();
77 this->pktQ.pop_front();
80 void push_back(
AxisIp4 ipChunk) {
81 this->pktQ.push_back(ipChunk);
90 unsigned int csum = 0;
92 csum += this->pktQ[0].getLE_TData().range(15, 0);
93 csum += this->pktQ[0].getLE_TData().range(31, 16);
94 csum += this->pktQ[0].getLE_TData().range(47, 32);
95 csum += this->pktQ[0].getLE_TData().range(63, 48);
97 csum += this->pktQ[1].getLE_TData().range(15, 0);
99 csum += this->pktQ[1].getLE_TData().range(47, 32);
100 csum += this->pktQ[1].getLE_TData().range(63, 48);
102 csum += this->pktQ[2].getLE_TData().range(15, 0);
103 csum += this->pktQ[2].getLE_TData().range(31, 16);
110 csum += this->pktQ[qw].getLE_TData().range(47, 32);
111 csum += this->pktQ[qw].getLE_TData().range(63, 48);
117 csum += this->pktQ[qw].getLE_TData().range(15, 0);
118 csum += this->pktQ[qw].getLE_TData().range(31, 16);
123 while (csum > 0xFFFF) {
124 csum = (csum & 0xFFFF) + (csum >> 16);
126 leIp4HdrCsum = ~csum;
136 int checksumCalculation(deque<AxisPsd4> pseudoPacket) {
137 ap_uint<32> ipChecksum = 0;
138 for (
int i=0; i<pseudoPacket.size(); ++i) {
139 ap_uint<64> tempInput = 0;
140 ap_uint<64> toto = (pseudoPacket[i].getLE_TData().range( 7, 0),
141 pseudoPacket[i].getLE_TData().range(15, 8),
142 pseudoPacket[i].getLE_TData().range(23, 16),
143 pseudoPacket[i].getLE_TData().range(31, 24),
144 pseudoPacket[i].getLE_TData().range(39, 32),
145 pseudoPacket[i].getLE_TData().range(47, 40),
146 pseudoPacket[i].getLE_TData().range(55, 48),
147 pseudoPacket[i].getLE_TData().range(63, 56));
148 for (
int b=0; b<8; b++) {
149 if (pseudoPacket[i].getLE_TKeep()[b]) {
150 tempInput(63-((b*8)+0), 63-((b*8)+7)) = pseudoPacket[i].getLE_TData().range((b*8)+7, (b*8)+0);
153 ipChecksum = ((((ipChecksum +
154 tempInput.range(63, 48)) + tempInput.range(47, 32)) +
155 tempInput.range(31, 16)) + tempInput.range(15, 0));
156 ipChecksum = (ipChecksum & 0xFFFF) + (ipChecksum >> 16);
157 ipChecksum = (ipChecksum & 0xFFFF) + (ipChecksum >> 16);
160 ipChecksum = ~ipChecksum;
161 return ipChecksum.range(15, 0).to_int();
172 void tcpAssemblePseudoHeaderAndData(deque<AxisPsd4> &tcpBuffer) {
180 tcpBuffer.push_back(firstAxisPsd4);
183 AxisPsd4 secondAxisPsd4(0, 0xFF, 0);
189 tcpBuffer.push_back(secondAxisPsd4);
195 for (
int i=2; i<pktQ.size()-1; ++i) {
196 AxisPsd4 axisPsd4(this->pktQ[i+1].getLE_TData(),
197 this->pktQ[i+1].getLE_TKeep(),
198 this->pktQ[i+1].getLE_TLast());
199 tcpBuffer.push_back(axisPsd4);
207 this->myName =
"SimIp4Packet";
212 this->myName =
"SimIp4Packet";
214 if (pktLen >= hdrLen && pktLen <=
MTU) {
215 int noBytes = pktLen;
242 if (this->
size() > 0) {
244 this->pktQ[this->
size()-1].setTLast(0);
246 this->push_back(ip4Chunk);
247 setLen(getLen() + ip4Chunk.
getLen());
252 AxisIp4 headingChunk = this->front();
254 setLen(getLen() - headingChunk.
getLen());
265 return this->pktQ.size();
280 for (
int i=0; i<ipPkt.pktQ.size(); i++) {
281 newAxisIp4 = ipPkt.pktQ[i];
282 this->pktQ.push_back(newAxisIp4);
284 this->setLen(ipPkt.getLen());
293 if (hdrLen > 0 && hdrLen <=
MTU) {
294 int cloneBytes = hdrLen;
296 while(cloneBytes > 0) {
297 if (cloneBytes > 8) {
301 AxisIp4 lastHdrWord(ipPkt.pktQ[inpWordCnt].getLE_TData(),
418 int bit = (ihl*4*8) + 0;
420 pktQ[raw].setUdpSrcPort(
port, (bit %
ARW));
425 int bit = (ihl*4*8) + 0;
427 return pktQ[raw].getUdpSrcPort(bit %
ARW);
432 int bit = (ihl*4*8) + 16;
434 pktQ[raw].setUdpDstPort(
port, (bit %
ARW));
439 int bit = (ihl*4*8) + 16;
441 return pktQ[raw].getUdpDstPort(bit %
ARW);
446 int bit = (ihl*4*8) + 32;
452 int bit = (ihl*4*8) + 32;
454 return pktQ[raw].getUdpLen(bit %
ARW);
459 int bit = (ihl*4*8) + 48;
461 pktQ[raw].setUdpCsum(csum, (bit %
ARW));
466 int bit = (ihl*4*8) + 48;
468 return pktQ[raw].getUdpCsum(bit %
ARW);
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);
481 headerStr += datByte;
498 int pldLen = totLen - hdrLen;
499 int q = (hdrLen / 8);
500 int b = (hdrLen % 8);
501 while (pldLen != 0) {
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);
506 payloadStr += datByte;
525 bool alternate =
true;
526 bool endOfPkt =
false;
527 int ip4PktSize = this->
size();
529 printFatal(this->myName,
"IPv4 options are not supported yet (sorry)");
531 while (wordInpCnt < ip4PktSize) {
535 else if (alternate) {
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);
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);
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);
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);
555 if (this->pktQ[wordInpCnt].getLE_TLast()) {
560 alternate = !alternate;
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);
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);
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);
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);
580 if (this->pktQ[wordInpCnt].getLE_TLast() && (not (this->pktQ[wordInpCnt].getLE_TKeep() & 0xC0))) {
584 alternate = !alternate;
599 bool alternate =
true;
600 bool endOfPkt =
false;
601 int ip4PktSize = this->
size();
603 int wordInpCnt = ihl/2;
604 bool qwordAligned = (ihl % 2) ?
false :
true;
605 while (wordInpCnt < ip4PktSize) {
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);
619 newTLast = this->pktQ[wordInpCnt].getLE_TLast();
624 else if (alternate) {
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);
635 if (this->pktQ[wordInpCnt].getLE_TLast()) {
640 alternate = !alternate;
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);
651 if (this->pktQ[wordInpCnt].getLE_TLast()) {
652 LE_tKeep leTKeep = this->pktQ[wordInpCnt].getLE_TKeep();
653 if (not (leTKeep & 0xF0)) {
658 alternate = !alternate;
673 bool alternate =
true;
674 bool endOfPkt =
false;
675 int ip4PktSize = this->
size();
677 int wordInpCnt = ihl/2;
678 bool qwordAligned = (ihl % 2) ?
false :
true;
679 while (wordInpCnt < ip4PktSize) {
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);
693 newTLast = this->pktQ[wordInpCnt].getLE_TLast();
698 else if (alternate) {
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);
709 if (this->pktQ[wordInpCnt].getLE_TLast()) {
714 alternate = !alternate;
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);
725 if (this->pktQ[wordInpCnt].getLE_TLast()) {
726 LE_tKeep leTKeep = this->pktQ[wordInpCnt].getLE_TKeep();
727 if (not (leTKeep & 0xF0)) {
732 alternate = !alternate;
743 printFatal(this->myName,
"Cannot compute TCP segment length. The current IPv4 packet does not contain any TCP segment (prot=0x%2.2x).\n",
764 bool alternate =
true;
768 int bits = (this->
length() * 8);
769 int axisIp4Cnt = bits/
ARW;
771 bool ipIsQwordAligned = (bits %
ARW) ?
false :
true;
775 printFatal(this->myName,
"Minimum packet is expected to be of length %d bytes (was found to be %d bytes).\n",
781 else if (len > udpDgm.
length()) {
782 printFatal(this->myName,
"Requesting to append more bytes (%d) than present in the UDP datagram (%d).\n",
789 if (ipIsQwordAligned) {
790 for (
int i=0; i<8; i++) {
793 ((axisUdp.
getLE_TData().range((i*8)+7, (i*8)+0)) << (i*8)));
808 this->pktQ[axisIp4Cnt].setTDataLo(axisUdp.
getTDataHi());
809 this->pktQ[axisIp4Cnt].setTKeepLo(axisUdp.
getTKeepHi());
811 this->pktQ[axisIp4Cnt].setTLast(
TLAST);
815 this->pktQ[axisIp4Cnt].setTLast(0);
817 this->setLen(this->getLen() + axisUdp.
getLenHi());
819 alternate = !alternate;
841 alternate = !alternate;
860 bool alternate =
true;
861 bool endOfPkt =
false;
866 printFatal(this->myName,
"Packet is expected to be of length %d bytes (was found to be %d bytes).\n",
874 LE_tKeep tmpTKeep = this->pktQ[axisIp4Cnt].getLE_TKeep();
875 LE_tLast tmpTLast = this->pktQ[axisIp4Cnt].getLE_TLast();
877 tmpTData.range(39,32) = axisIcmp.
getLE_TData().range( 7, 0);
878 tmpTKeep = tmpTKeep | 0x10;
879 this->setLen(this->getLen() + 1);
882 tmpTData.range(47,40) = axisIcmp.
getLE_TData().range(15, 8);
883 tmpTKeep = tmpTKeep | 0x20;
884 this->setLen(this->getLen() + 1);
887 tmpTData.range(55,48) = axisIcmp.
getLE_TData().range(23,16);
888 tmpTKeep = tmpTKeep | 0x40;
889 this->setLen(this->getLen() + 1);
892 tmpTData.range(63,56) = axisIcmp.
getLE_TData().range(31,24);
893 tmpTKeep = tmpTKeep | 0x80;
894 this->setLen(this->getLen() + 1);
903 this->pktQ[axisIp4Cnt].setLE_TData(tmpTData);
904 this->pktQ[axisIp4Cnt].setLE_TKeep(tmpTKeep);
905 this->pktQ[axisIp4Cnt].setLE_TLast(tmpTLast);
906 alternate = !alternate;
914 newTData.range( 7, 0) = axisIcmp.
getLE_TData().range(39, 32);
915 newTKeep = newTKeep | (0x01);
918 newTData.range(15, 8) = axisIcmp.
getLE_TData().range(47, 40);
919 newTKeep = newTKeep | (0x02);
922 newTData.range(23,16) = axisIcmp.
getLE_TData().range(55, 48);
923 newTKeep = newTKeep | (0x04);
926 newTData.range(31,24) = axisIcmp.
getLE_TData().range(63, 56);
927 newTKeep = newTKeep | (0x08);
944 alternate = !alternate;
960 bool alternate =
true;
961 bool endOfPkt =
false;
967 printFatal(this->myName,
"Packet length is expected to be larger than %d bytes (was found to be %d bytes).\n",
976 LE_tKeep tmpTKeep = this->pktQ[axisIp4Cnt].getLE_TKeep();
977 LE_tLast tmpTLast = this->pktQ[axisIp4Cnt].getLE_TLast();
979 tmpTData.range(39,32) = axisIcmp.
getLE_TData().range( 7, 0);
980 tmpTKeep = tmpTKeep | (0x10);
981 this->setLen(this->getLen() + 1);
984 tmpTData.range(47,40) = axisIcmp.
getLE_TData().range(15, 8);
985 tmpTKeep = tmpTKeep | (0x20);
986 this->setLen(this->getLen() + 1);
989 tmpTData.range(55,48) = axisIcmp.
getLE_TData().range(23,16);
990 tmpTKeep = tmpTKeep | (0x40);
991 this->setLen(this->getLen() + 1);
994 tmpTData.range(63,56) = axisIcmp.
getLE_TData().range(31,24);
995 tmpTKeep = tmpTKeep | (0x80);
996 this->setLen(this->getLen() + 1);
1005 this->pktQ[axisIp4Cnt].setLE_TData(tmpTData);
1006 this->pktQ[axisIp4Cnt].setLE_TKeep(tmpTKeep);
1007 this->pktQ[axisIp4Cnt].setLE_TLast(tmpTLast);
1008 alternate = !alternate;
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();
1016 tmpTData.range( 7, 0) = axisIcmp.
getLE_TData().range(39, 32);
1017 tmpTKeep = tmpTKeep | (0x01);
1020 tmpTData.range(15, 8) = axisIcmp.
getLE_TData().range(47, 40);
1021 tmpTKeep = tmpTKeep | (0x02);
1024 tmpTData.range(23,16) = axisIcmp.
getLE_TData().range(55, 48);
1025 tmpTKeep = tmpTKeep | (0x04);
1028 tmpTData.range(31,24) = axisIcmp.
getLE_TData().range(63, 56);
1029 tmpTKeep = tmpTKeep | (0x08);
1044 this->pktQ[axisIp4Cnt].setLE_TKeep(tmpTKeep);
1045 this->pktQ[axisIp4Cnt].setLE_TLast(tmpTLast);
1046 alternate = !alternate;
1060 string tcpDataStr =
"";
1063 if(tcpDataSize > 0) {
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);
1130 bool checkIp4TotLen=
true,
bool checkIp4HdrCsum=
true,
1131 bool checkUdpLen=
true,
bool checkLy4Csum=
true) {
1133 if (checkIp4TotLen) {
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",
1141 if (checkIp4HdrCsum) {
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",
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");
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",
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);
1176 if ((udpHCsum != 0) and (udpHCsum != calcCsum)) {
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");
1193 if (0) { tcpSegment.
dump(); }
1200 if (tcpHCsum != calcCsum) {
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");
1216 printWarn(myName,
"[TODO-Must check if message is well-formed !!!\n");
1239 printInfo(callerName,
"IP PACKET HEADER (HEX numbers are in LITTLE-ENDIAN order): \n");
1240 printInfo(callerName,
"IP4 IHL = %15u \n",
1242 printInfo(callerName,
"IP4 Version = %15u \n",
1244 printInfo(callerName,
"IP4 Type Of Service = %15u \n",
1246 printInfo(callerName,
"IP4 Total Length = %15u (0x%4.4X) \n",
1248 printInfo(callerName,
"IP4 Identification = %15u \n",
1250 printInfo(callerName,
"IP4 Fragment Offset = %15u \n",
1252 printInfo(callerName,
"IP4 Type To Live = %15u \n",
1254 printInfo(callerName,
"IP4 Protocol = %15u \n",
1256 printInfo(callerName,
"IP4 Header Checksum = %15u \n",
1258 printInfo(callerName,
"IP4 Source Address = %3.3d.%3.3d.%3.3d.%3.3d (0x%8.8X) \n",
1263 leIp4SrcAddr.to_uint());
1264 printInfo(callerName,
"IP4 Destination Address = %3.3d.%3.3d.%3.3d.%3.3d (0x%8.8X) \n",
1269 leIp4DstAddr.to_uint());
1270 printInfo(callerName,
"TCP Source Port = %15u (0x%4.4X) \n",
1272 printInfo(callerName,
"TCP Destination Port = %15u (0x%4.4X) \n",
1274 printInfo(callerName,
"TCP Sequence Number = %15u (0x%8.8X) \n",
1276 printInfo(callerName,
"TCP Acknowledge Number = %15u (0x%8.8X) \n",
1278 printInfo(callerName,
"TCP Data Offset = %15d (0x%1.1X) \n",
1280 printInfo(callerName,
"TCP Control Bits = %s%s%s%s%s%s\n",
1287 printInfo(callerName,
"TCP Window = %15u (0x%4.4X) \n",
1289 printInfo(callerName,
"TCP Checksum = %15u (0x%4.4X) \n",
1291 printInfo(callerName,
"TCP Urgent Pointer = %15u (0x%4.4X) \n",
1297 printInfo(callerName,
" Maximum Segment Size = %15u \n",
1301 printInfo(callerName,
"TCP Data Length = %15u \n",
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());
1327 Ip4HdrCsum newIp4HdrCsum = calculateIpHeaderChecksum();
1330 return (newIp4HdrCsum);
1341 int newChecksum = 0;
1342 deque<AxisPsd4> tcpBuffer;
1344 tcpAssemblePseudoHeaderAndData(tcpBuffer);
1346 int tcpCsum = checksumCalculation(tcpBuffer);
1367 Ip4HdrCsum computedCsum = this->calculateIpHeaderChecksum();
1369 if (computedCsum == packetCsum) {
1391 return computedCsum;
1402 if (computedCsum == tcpChecksum) {
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());
1423 if (computedCsum == udpChecksum) {
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());
1439 for (
int i=0; i < this->
size(); i++) {
1440 AxisIp4 axisIp4 = this->pktQ[i];
1456 if (tcpData.size() > 0) {
: A class to access an IPv4 data chunk transmitted over an AXI4-Stream interface.
: A class to access the fields of a TCP/IPv4 or UDP/IPv4 pseudo packet when transmitted over an AXI4-...
: A class to access TCP header fields within data chunks transmitted over an AXI4-Stream interface.
: A class to access UDP header fields within data chunks transmitted over an AXI4-Stream interface.
: A simulation class to build and handle ICMP packets.
: A simulation class to build TCP segments.
: A simulation class to build UDP datagrams.
void setTcpDstPort(TcpPort port)
void setPsd4Len(Ly4Len len)
void setTcpSrcPort(TcpPort port)
void setPsd4ResBits(Psd4Res res)
void setPsd4Prot(Ip4Prot prot)
void setTLast(tLast last)
void setTDataHi(tDataHalf halfData)
tDataHalf getTDataLo() const
LE_tKeep getLE_TKeep(int leHi=64/8-1, int leLo=0) const
tKeepHalf getTKeepHi() const
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
void setLE_TLast(LE_tLast last)
void setTKeepHi(tKeepHalf halfKeep)
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
tDataHalf getTDataHi() const
void setLE_TKeep(LE_tKeep keep, int leHi=64/8-1, int leLo=0)
tKeepHalf getTKeepLo() const
LE_tLast getLE_TLast() const
Class ICMP Packet for simulation.
void pushChunk(AxisIcmp icmpChunk)
Class IPv4 Packet for simulation.
void writeTcpDataToDatFile(ofstream &outFile)
Dump the TCP payload of this IP packet into a file. Data is written as a string.
int sizeOfTcpData()
Return the size of the TCP data payload in octets.
TcpSeqNum getTcpSequenceNumber()
bool tcpVerifyChecksum()
Recalculate the TCP checksum and compare it with the one embedded into the segment.
void setUdpSourcePort(UdpPort port)
void setTcpOptionMss(int val)
bool isACK()
Returns true if packet is an ACK.
void setIpTotalLength(int totLen)
void setTcpSequenceNumber(TcpSeqNum num)
LE_Ip4Addr getLE_IpDestinationAddress()
void setTcpUrgentPointer(int ptr)
LE_TcpPort getLE_TcpSourcePort()
void setTcpControlFin(int bit)
void setIpFragmentOffset(int offset)
int tcpRecalculateChecksum()
Recalculate the checksum of a TCP segment after it was modified.
SimTcpSegment getTcpSegment()
UdpCsum udpRecalculateChecksum()
Recalculate checksum of an UDP datagram after it was modified.
void setIpSourceAddress(int addr)
string getTcpData()
Get TCP data from the current IPv4 packet.
void setTcpDataOffset(int offset)
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.
TcpAckNum getTcpAcknowledgeNumber()
void setIpInternetHeaderLength(int ihl)
void setIpFlags(int flags)
void setUdpChecksum(UdpCsum csum)
Ip4Addr getIpSourceAddress()
void setIpTypeOfService(int tos)
bool verifyIpHeaderChecksum()
Recalculate the IPv4 header checksum and compare it with the one embedded into the packet.
int getIpIdentification()
void setTcpControlPsh(int bit)
void setIpVersion(int version)
void setIpHeaderChecksum(int csum)
void setIpTimeToLive(Ip4TtL ttl)
TcpCtrlBit getTcpControlUrg()
int getIpInternetHeaderLength()
int getTcpDestinationPort()
void setTcpControlRst(int bit)
int getTcpUrgentPointer()
void setTcpControlUrg(int bit)
void pushChunk(AxisIp4 ip4Chunk)
Ip4HdrCsum getIpHeaderChecksum()
SimUdpDatagram getUdpDatagram()
void clone(SimIp4Packet &ipPkt)
Clone an IP packet.
SimIp4Packet(int pktLen, int hdrLen=20)
bool isFIN()
Returns true if packet is a FIN.
TcpCtrlBit getTcpControlRst()
void setTcpAcknowledgeNumber(TcpAckNum num)
LE_Ip4Addr getLE_IpSourceAddress()
bool udpVerifyChecksum()
Recalculate the UDP checksum and compare it with the one embedded into the datagram.
void cloneHeader(SimIp4Packet &ipPkt)
Clone the header of an IP packet.
void setTcpWindow(int win)
void setTcpControlAck(int bit)
void setIpProtocol(int prot)
void setIpDestinationAddress(int addr)
void setUdpDestinationPort(UdpPort port)
void setTcpOptionKind(int val)
TcpCtrlBit getTcpControlSyn()
UdpPort getUdpDestinationPort()
UdpPort getUdpSourcePort()
Ip4HdrCsum reCalculateIpHeaderChecksum()
Recalculate the IPv4 header checksum of a packet.
TcpCtrlBit getTcpControlAck()
void setIpIdentification(int id)
Ip4Addr getIpDestinationAddress()
int getIpFragmentOffset()
bool setIpPayload(SimIcmpPacket icmpPkt)
Set the data payload of this packet as an ICMP packet.
void printHdr(const char *callerName)
Print the header details of an IP packet.
void setTcpSourcePort(int port)
void printRaw(const char *callerName)
Raw print of an IP packet (.i.e, as AxisRaw chunks).
bool addIpPayload(SimUdpDatagram &udpDgm, int len=-1)
Append some data to this packet from a UDP datagram.
Ip4DatLen getTcpSegmentLength()
void setTcpControlSyn(int bit)
TcpCtrlBit getTcpControlFin()
bool isSYN()
Returns true if packet is a SYN.
bool writeToDatFile(ofstream &outFileStream)
Dump this IP packet as AxisIp4 chunks into a file.
bool addIpPayload(SimIcmpPacket icmpPkt)
Append the data payload of this packet as an ICMP packet.
void setTcpChecksum(int csum)
TcpCtrlBit getTcpControlPsh()
void setTcpDestinationPort(int port)
LE_TcpPort getLE_TcpDestinationPort()
void setUdpLength(UdpLen len)
SimIcmpPacket getIcmpPacket()
void pushChunk(AxisTcp tcpChunk)
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.
void pushChunk(AxisUdp udpChunk)
UdpCsum reCalculateUdpChecksum(Ip4Addr ipSa, Ip4Addr ipDa)
Recalculate the UDP checksum of a datagram.
string myUint8ToStrHex(ap_uint< 8 > inputNumber)
Converts an UINT8 into a string of 2 HEX characters.
bool writeAxisRawToFile(AxisRaw &axisRaw, ofstream &outFileStream)
Dump an Axis raw data chunk to a file.
ap_uint< 32 > LE_Ip4DstAddr
ap_uint< 32 > LE_Ip4SrcAddr
#define printError(callerName, format,...)
A macro to print an error message.
ap_uint< 16 > LE_TcpDstPort
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...
ap_uint< 32 > LE_TcpAckNum
ap_uint< 16 > LE_TcpUrgPtr
ap_uint< 16 > LE_TcpSrcPort
ap_uint< 32 > LE_TcpSeqNum
ap_uint< 16 > LE_TcpChecksum
#define printInfo(callerName, format,...)
A macro to print an information message.
ap_uint< 16 > LE_Ip4HdrCsum
ap_uint< 16 > LE_Ip4TotalLen
#define printWarn(callerName, format,...)
A macro to print a warning message.
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
ap_uint< 16 > LE_TcpWindow
ap_uint< 16 > TcpChecksum
: Definition of the Network Transport Stack (NTS) component as if it was an HLS IP core.
: Utilities and helpers for the Network-Transport-Stack (NTS) components.
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)