Libunet is one example for how to use U-Net. It provides a set of functions that initialize endpoints, send and receive packets. However, libunet is not the most efficient way to use U-Net, especially the send and receive functions.
To send a packet, a U-Net application needs to do the following:
Initialize
- Open a U-Net device
- Create a U-Net endpoint
- Activate a channel (dest, port)
Send
- Push the pointer to the send buffer onto the tx queue
- Call UNET_TRAP()
Send more ...
Cleanup
- Deactivate the channel
- Destroy the endpoint
- Close the device
For initialization and clean up, libunet's functions are the most convenient:
For using the tx queue, a good place to look is test\loopback\loopback.c. UNET_TRAP() is basically a trigger for sending. One can push a few entries into the tx queue and then trigger the device for efficiency.
To receive a packet, an application needs to perform a similar initialization and cleanup afterwards as the send operation. Except it needs to poll the receive queue for incoming packets.
Initialize
- Open a U-Net device
- Create a U-Net endpoint
- Activate a channel (dest, port)
Receive
- Poll the rx queue, process data
Receive more ...
Cleanup
- Deactivate the channel
- Destroy the endpoint
- Close the device
Again, please read loopback.c for exactly how to receive. Currently, the only way to determine if receive queue has data is by polling the queue. Completion notification is not yet supported and it will be supported in the next release.
In this release, test\loopback\loopback.c can be used as an example of U-Net application. It basically has the following structure:
// initialization A. Open a U-Net device. B. Create a U-Net endpoint. C. Activate a channel. loop { // Send D. push pointer to send buffer to the tx queue. E. Call UNET_TRAP() F. Poll. } ..... more sends // cleanup G. Deactivate the channel. H. Destroy the endpoint. I. Close the device.
I realize that this is a very rough draft on how to write U-Net applications. Best of Luck...
X. Huang, xwh@cs.cornell.edu