Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void s_proc_do_tx (void)
- {
- uint_fast64_t l_cycles, i, l_expired_tsc, l_cur_tsc, l_lcore_id, l_rc, l_que_idx,
- l_drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US,
- l_diff_tsc, l_prev_tsc;
- struct rte_mbuf *l_mbuf;
- TTR2$IF_RECORD *l_if_rec;
- TTR2$TEST_HDR l_testh = {0}, *l_testhp;
- struct rte_net_hdr_lens l_hdr_lens;
- l_lcore_id = rte_lcore_id();
- $LOG(STS$K_INFO, "Start worker for <%s> on LCore #%d", __PRETTY_FUNCTION__, l_lcore_id);
- /* Ethernet II header ... */
- rte_ether_addr_copy(&s_eth_ip_multicast, &l_testh.eth.dst_addr ); /* Ethernet multicast for IP */
- l_testh.eth.src_addr; /* Source HA will be filled on sending */
- l_testh.eth.ether_type = rte_cpu_to_be_16( RTE_ETHER_TYPE_IPV4); /* Protocol is IPv4 ... */
- /* IPv4 header ... */
- l_testh.iph.version_ihl = RTE_IPV4_VHL_DEF;
- l_testh.iph.type_of_service = 0;
- l_testh.iph.total_length = sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr) + sizeof(TTR2$TEST_PDU) + g_payload;
- l_testh.iph.total_length = rte_cpu_to_be_16(l_testh.iph.total_length);
- l_testh.iph.packet_id = 0;
- l_testh.iph.fragment_offset = 0;
- l_testh.iph.time_to_live = 63;
- l_testh.iph.next_proto_id = IPPROTO_UDP;
- l_testh.iph.hdr_checksum = 0;
- l_testh.iph.src_addr = g_lip;
- l_testh.iph.dst_addr = g_rip;
- /* UDP header*/
- l_testh.udph.src_port = g_lpn;
- l_testh.udph.dst_port = g_rpn;
- l_testh.udph.dgram_len = rte_cpu_to_be_16(sizeof(TTR2$TEST_PDU) + g_payload);
- l_testh.udph.dgram_cksum = 0;
- /* Test */
- l_testh.data.magic64 = *s_starlet_sig64;
- l_testh.data.len = rte_cpu_to_be_16 (g_payload);
- l_testh.data.req = rte_cpu_to_be_16 (TTR2$K_OPCODE_REQ);
- $LOG(STS$K_INFO, "Paket is %d octets [header/payload: %d/%d octets]",
- sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr) + sizeof(TTR2$TEST_PDU) + g_payload,
- sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr) + sizeof(TTR2$TEST_PDU),
- g_payload );
- for ( l_cycles = l_expired_tsc = 0; !g_exit_flag; )
- {
- l_cur_tsc = rte_get_tsc_cycles(); /* Get current "time" ... */
- if ( g_bw ) /* Is there BW limit ? */
- {
- if ( unlikely(l_cur_tsc < l_expired_tsc) ) /* Do we reach expiration time ? */
- continue;
- l_expired_tsc = l_cur_tsc + g_xmit_delta; /* A time o next sending */
- }
- /* Send a packet to all WAN interfaces */
- l_cycles++;
- for ( i = 0; i < s_if_tbl_wan_nr; i++ )
- {
- l_if_rec = s_if_tbl_wan[i]; /* Get a pointer to Port's context */
- if ( !(l_if_rec->if_flags & TTR2_IF$M_UP) ) /* Skip port w/o active cable link */
- continue;
- l_diff_tsc = l_cur_tsc - l_prev_tsc; /* Do we need to flush TX buffers? */
- if (unlikely( (l_diff_tsc > l_drain_tsc) && l_if_rec->tx_buffer->length) )
- {
- l_rc = rte_eth_tx_buffer_flush(l_if_rec->port_id, l_que_idx, l_if_rec->tx_buffer);
- l_prev_tsc = l_cur_tsc;
- }
- if ( !(l_mbuf = rte_pktmbuf_alloc (g_pktmbuf_pool)) ) /* Get buffer from poll for new packet */
- {
- $LOG(STS$K_ERROR, "rte_pktmbuf_alloc() failed, errno=%d", rte_errno);
- break;
- }
- l_testhp = rte_pktmbuf_mtod(l_mbuf, TTR2$TEST_HDR *);
- l_mbuf->pkt_len = l_mbuf->data_len = sizeof(TTR2$TEST_HDR) + g_payload;
- *l_testhp = l_testh; /* Initialize static part of packet */
- /* Fill variable part of headers and test data ... */
- rte_ether_addr_copy(&l_if_rec->if_hwaddr, &l_testhp->eth.src_addr);
- l_testhp->iph.packet_id = rte_cpu_to_be_16 (0xffff & l_cycles);
- l_testhp->data.seq = rte_cpu_to_be_64(l_cycles);
- l_testhp->data.ts = rte_cpu_to_be_64(rte_get_tsc_cycles());
- memset(l_testhp->data.data, 'A' + (0x0F & l_cycles), g_payload);
- l_testhp->data.crc = rte_hash_crc(l_testhp->data.data, g_payload, 0xEDB88320);
- l_testhp->data.crc = rte_cpu_to_be_32(l_testhp->data.crc);
- l_mbuf->packet_type = RTE_PTYPE_L2_ETHER;
- l_mbuf->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_UDP_CKSUM;
- l_mbuf->l2_len = RTE_ETHER_HDR_LEN;
- l_mbuf->l3_len = rte_ipv4_hdr_len (&l_testhp->iph);
- /* Put new <mbuf> with the IP packet into the output buffer of the Ethernet port */
- l_que_idx = l_cycles % g_nqueue;
- l_rc = rte_eth_tx_buffer(l_if_rec->port_id, l_que_idx, l_if_rec->tx_buffer, l_mbuf);
- if ( l_if_rec->tx_buffer->length == l_if_rec->tx_buffer->size )
- l_rc += rte_eth_tx_buffer_flush(l_if_rec->port_id, l_que_idx, l_if_rec->tx_buffer);
- atomic_fetch_add(&s_xmit_cnt, 1);
- }
- }
- $LOG(STS$K_INFO, "Terminate worker for <%s> on LCore #%d", __PRETTY_FUNCTION__, l_lcore_id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement