/** * Print odp packets * * @param thr worker id * @param pkt_tbl packets to be print * @param len packet number */ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) { odp_packet_t pkt; char *buf; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; struct timeval tvrecv; struct timeval tvsend; double rtt; unsigned i; size_t offset; char msg[1024]; int rlen; for (i = 0; i < len; ++i) { pkt = pkt_tbl[i]; rlen = 0; /* only ip pkts */ if (!odp_packet_has_ipv4(pkt)) continue; odp_atomic_inc_u64(&counters.ip); buf = odp_packet_data(pkt); ip = (odph_ipv4hdr_t *)(buf + odp_packet_l3_offset(pkt)); offset = odp_packet_l4_offset(pkt); /* udp */ if (ip->proto == ODPH_IPPROTO_UDP) { odp_atomic_inc_u64(&counters.udp); } /* icmp */ if (ip->proto == ODPH_IPPROTO_ICMP) { icmp = (odph_icmphdr_t *)(buf + offset); /* echo reply */ if (icmp->type == ICMP_ECHOREPLY) { odp_atomic_inc_u64(&counters.icmp); memcpy(&tvsend, buf + offset + ODPH_ICMPHDR_LEN, sizeof(struct timeval)); /* TODO This should be changed to use an * ODP timer API once one exists. */ gettimeofday(&tvrecv, NULL); tv_sub(&tvrecv, &tvsend); rtt = tvrecv.tv_sec*1000 + tvrecv.tv_usec/1000; rlen += sprintf(msg + rlen, "ICMP Echo Reply seq %d time %.1f ", odp_be_to_cpu_16(icmp->un.echo.sequence) , rtt); } else if (icmp->type == ICMP_ECHO) { rlen += sprintf(msg + rlen, "Icmp Echo Request"); } msg[rlen] = '\0'; printf(" [%02i] %s\n", thr, msg); } } }
void test_atomic_inc_64(void) { int i; for (i = 0; i < CNT; i++) odp_atomic_inc_u64(&a64u); }