Writing U-Net/NT Applications

Libunet

Libunet is one example for how to interact with U-Net. It provides a set of functions that can help you initialize and close devices, as well as functions to demonstrate how to send and receive packets. It's not the most efficient way to use U-Net, especially if you use the send and receive functions.

Send

2. To send a packet, a U-Net application needs to do the following:

	// initialization
	A. Open a U-Net device.
	B. Create a U-Net endpoint.
	C. Activate a channel (dest, port).

	// Send
	D. push pointer to send buffer to the tx queue.
	E. Call UNET_TRAP() and then pray.

	..... more sends

	// cleanup
	F. Deactivate the channel.
	G. Destroy the endpoint.
	H. Close the device.

For initialization and clean up, we advise strongly to use libunet's provided functions:

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.

Receive

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.


	// initialization
	A. Open a U-Net device.
	B. Create a U-Net endpoint.
	C. Activate a channel (src, port).

	// Receive

	poll the rx queue, process data
	..... more sends

	// cleanup
	F. Deactivate the channel.
	G. Destroy the endpoint.
	H. 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 or two.

Structure of Loopback

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. I hope you would have a feeling of how to do so after reading this file. If you have any more questions, please direct your questions to Matt Welsh, mdw@cs.cornell.edu, Xun Wilson Huang, xwh@cs.cornell.edu or Thorsten Von Eicken tve@cs.cornell.edu.

Best of Luck.


X. Huang, xwh@cs.cornell.edu