Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make afpacket support PACKET_TX_RING #1

Open
changtimwu opened this issue Aug 20, 2016 · 1 comment
Open

make afpacket support PACKET_TX_RING #1

changtimwu opened this issue Aug 20, 2016 · 1 comment

Comments

@changtimwu
Copy link

changtimwu commented Aug 20, 2016

WritePacketData still use traditional write(). Make packet transmission also benefit from mmap.

https://www.kernel.org/doc/Documentation/networking/packet_mmap.txt
packet(7) describes how to use PACKET_TX_RING

PACKET_TX_RING (since Linux 2.6.31)
              Create a memory-mapped ring buffer for packet transmission.
              This option is similar to PACKET_RX_RING and takes the same
              arguments.  The application writes packets into slots with
              tp_status equal to TP_STATUS_AVAILABLE and schedules them for
              transmission by changing tp_status to TP_STATUS_SEND_REQUEST.
              When packets are ready to be transmitted, the application
              calls send(2) or a variant thereof.  The buf and len fields of
              this call are ignored.  If an address is passed using
              sendto(2) or sendmsg(2), then that overrides the socket
              default.  On successful transmission, the socket resets
              tp_status to TP_STATUS_AVAILABLE.  It immediately aborts the
              transmission on error unless PACKET_LOSS is set.

it seems

retval = send(this->socket, NULL, 0, 0);
@changtimwu
Copy link
Author

a good reference on how to use TX_RING is tcpreplay
https://github.com/appneta/tcpreplay/blob/master/src/common/txring.c

  • txring_send runs in a standalone thread. It keeps sending or sleep if no data to send.
  • tx_ring_put. it puts a packet into the tx ring. some techniques are used here
    • looking for the next available slot in TX ring. If a slot is busy, it checks the next. Before hoping to the next slot, it runs usleep(0).
    • If all slots are busy, it returns NOBUFS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant