122 #if defined(WIN32) || defined(WIN64) 123 #define snprintf(dst, ...) _snprintf_s((dst), _countof(dst), __VA_ARGS__) 174 printf(
"Descriptor type is PCAP.\n");
178 printf(
"Descriptor type is NT.\n");
182 printf(
"Descriptor type is NT extended.\n");
186 printf(
"Descriptor type is Dynamic\n");
191 printf(
"Unknown descriptor type.\n");
211 streamId = (uint32_t) port;
212 printf(
"Created PacketReaderThread, port=%lu, stream=%u\n", rxPort, streamId);
225 printf(
"NT_NetRxOpen() failed: %s\n", errorBuffer);
230 printf(
"Receiving packets on stream %u\n", streamId);
236 printf(
"-------------------------------------------------\n");
237 printf(
"Packet received:\n");
243 printf(
"Error: RX descriptor expected to be NT_PACKET_DESCRIPTOR_TYPE_NT\n");
244 printf(
" Shutting down...\n");
250 if (captureLength < (16 + 80 + 2 + 8))
252 printf(
"Packet is too small. Can't extract time stamp\n");
257 uint64_t txTime = *((uint64_t*)(data + 80 + 2));
261 printf(
"No TX time stamp in packet.\n");
266 printf(
"txTime=%lu, rxTime=%lu, latency=%lu\n", txTime, rxTime, rxTime - txTime);
270 uint64_t
wireLength = NT_NET_GET_PKT_WIRE_LENGTH(hNetBuf);
273 if ((g % 16) == 0) printf(
"\n");
274 printf(
"%02X ", *(data + g));
279 else if ((status != NT_STATUS_TIMEOUT) && (status != NT_STATUS_TRYAGAIN))
282 printf(
"NT_NetRxGet() failed: %s\n", errorBuffer);
307 0x94, 0xC6, 0x91, 0x1C, 0x68, 0x1D, 0x94, 0xC6, 0x91, 0x1C, 0x68, 0xC3, 0x08, 0x00, 0x45, 0x00,
308 0x00, 0x78, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06, 0xB5, 0xCF, 0xC0, 0xA8, 0x00, 0x02, 0x01, 0x02,
309 0x03, 0x04, 0x00, 0x14, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
310 0x20, 0x00, 0x42, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
331 uint64_t transmittedPackets {0};
347 printf(
"Created PacketTransmitterThread port=%u\n", txPort);
364 uint32_t sleep_time = 1000000;
375 fprintf(stderr,
"NT_NetTxGet() failed: %s\n", errorBuffer);
387 packet_ptr->offset1 = 34;
388 overlay_ptr->frame_type = 0x4;
389 overlay_ptr->checksum_cmd = 0;
391 overlay_ptr->tsiCmd = tsi & 1;
392 overlay_ptr->fcsCmd = fcs & 3;
399 fprintf(stderr,
"NT_NetTxRelease() failed: %s\n", errorBuffer);
403 ++transmittedPackets;
416 printf(
"============================================\n");
417 printf(
"Transmitter configuration\n");
418 printf(
"============================================\n");
419 printf(
"TX port : %u\n", txPort);
420 printf(
"============================================\n");
433 if (status != NT_SUCCESS)
436 fprintf(stderr,
"NT_NetTxOpenAttrSetDescriptorPosFrameType failed: %s\n", errorBuffer);
441 if (status != NT_SUCCESS)
444 fprintf(stderr,
"NT_NetTxOpenAttrSetDescriptorPosChecksumCmd failed: %s\n", errorBuffer);
449 if (status != NT_SUCCESS)
452 fprintf(stderr,
"NT_NetTxOpenAttrSetTxtDescriptorPosTimestampInjectCmd failed: %s\n", errorBuffer);
457 if (status != NT_SUCCESS)
460 fprintf(stderr,
"NT_NetTxOpenAttrSetTxtDescriptorPosFcs failed: %s\n", errorBuffer);
466 if (status != NT_SUCCESS) {
468 fprintf(stderr,
"NT_NetTxOpen() failed: %s\n", errorBuffer);
475 if (txLoops > 0) --txLoops;
478 txPacket(hNetTx, NO_TS_INJECT, FCS_UNCHANGED);
479 txPacket(hNetTx, NO_TS_INJECT, FCS_GOOD);
480 txPacket(hNetTx, NO_TS_INJECT, FCS_BAD);
481 txPacket(hNetTx, TS_INJECT, FCS_UNCHANGED);
482 txPacket(hNetTx, TS_INJECT, FCS_GOOD);
483 txPacket(hNetTx, TS_INJECT, FCS_BAD);
486 printf(
"Packets transmitted %lu\n ", transmittedPackets);
487 printf(
"Shutting down TX\n");
492 fprintf(stderr,
"NT_NetTxClose() failed: %s\n", errorBuffer);
503 #if defined(WIN32) || defined (WIN64) 524 NT_ExplainError(status, errorBuffer, (uint32_t)(
sizeof(errorBuffer)-1));
527 fprintf(stderr, formatstr, errorBuffer);
537 snprintf(ntplStr, 400,
"assign[streamid=%lu] = Port==%lu", rxPort, rxPort);
540 if ((status =
NT_ConfigOpen(&hCfgStream,
"flowtest")) != NT_SUCCESS) {
541 printError(status,
"NT_ConfigOpen() failed: %s\n");
545 printf(
"\nDoing NTPL:\n");
547 printf(
"%s\n\n", ntplStr);
564 if ((status =
NT_InfoOpen(&hInfo,
"tsi")) != NT_SUCCESS) {
566 fprintf(stderr,
"NT_InfoOpen() failed: %s\n", errorBuffer);
573 if ((status =
NT_InfoRead(hInfo, &infoRead)) != NT_SUCCESS) {
575 fprintf(stderr,
"NT_InfoRead() failed: %s\n", errorBuffer);
596 static void usage(
const char *argv0)
598 fprintf(stderr,
"\n");
599 fprintf(stderr,
"Usage: %s [options]\n", argv0);
600 fprintf(stderr,
"\n");
601 fprintf(stderr,
"This program is an example of how to control TX time stamp inject\n");
602 fprintf(stderr,
"and FCS generation per packet using dynamic descriptor 3.\n");
603 fprintf(stderr,
"\n");
604 fprintf(stderr,
" Options:\n" 605 " -r <rx port> : RX port.\n" 606 " -t <tx port> : TX port.\n" 607 " -n <tx loops> : Number of TX loops\n" 608 " -h : Print help message\n");
609 fprintf(stderr,
"\n");
612 int main(
int argc,
char **argv)
615 int64_t txLoops = -1;
618 uint64_t txActive =
false;
619 uint64_t rxActive =
false;
625 while ((opt = getopt(argc, argv,
"n:t:r:")) != -1) {
628 rxPort = strtoul(optarg, &endptr, 10);
630 if (*optarg ==
'\0' || *endptr !=
'\0') {
631 fprintf(stderr,
"Could not parse RX port, i.e. -r option\n");
636 txPort = strtoul(optarg, &endptr, 10);
638 if (*optarg ==
'\0' || *endptr !=
'\0') {
639 fprintf(stderr,
"Could not parse TX port, i.e. -t option\n");
644 txLoops = strtol(optarg, &endptr, 10);
645 if (*optarg ==
'\0' || *endptr !=
'\0') {
646 fprintf(stderr,
"Could not parse number of TX loops, , i.e. -n option\n");
661 #if defined(WIN32) || defined (WIN64) 664 struct sigaction newaction;
665 memset(&newaction, 0,
sizeof(newaction));
667 if (sigaction(SIGINT, &newaction, NULL) < 0) {
668 fprintf(stderr,
"Failed to register SIGINT sigaction.\n");
677 printf(
"\nRequired Test&Measurement features not supported on port %lu\n", txPort);
691 if (rxThread ==
nullptr && txThread ==
nullptr)
693 printf(
"\nUse at least one of the options -t, -r\n");
697 if (rxThread !=
nullptr)
704 if (txThread !=
nullptr)
709 printf(
"Threads started. Press CTRL-C to terminate program.\n");
715 if (txThread !=
nullptr)
722 printf(
"TX thread stopped. Use CTRL-C to terminate RX thread\n");
726 if (rxThread !=
nullptr)