How do I interface an application layer to UDP?

Categories:
Solution Number:
S20730
Last Modified:
2013-08-20
Issue

How do I interface an application layer to UDP?

Solution

The RIP process model (rip_v3.pr.m.) provides the best example for how to interface to UDP. The guidelines below were adapted from it.----------------------------------------------------------------------Step 1: Create a 'local port' that the server will listen on and that all the senders will send to. The following sample code (with additional comments) is taken from the rip_create_udp_rcv_port() function in the function block of the rip_v3 process model. Note you should include udp_api.h to get the UDP symbolic constants./* Issue the CREATE_PORT command. */command_ici_ptr = op_ici_create (udp_command_v3);/* * Note: port_num is just a number you can hardcode, like '1001'. * This is the port that senders will send to. */op_ici_attr_set (command_ici_ptr, local_port, port_num); op_ici_install (command_ici_ptr);op_intrpt_force_remote (UDPC_COMMAND_CREATE_PORT, udp_objid);/* * Get the status indication from the ici. The value of _indshould be * UDPC_IND_SUCCESS if the operation succeeded */op_ici_attr_get (command_ici_ptr, status, &ind); -----------------------------------------------------------------------Step 2: After you open the port, you can wait for data to arrive as a stream interrupt on the stream from UDP to your server. The following is from rip_receive() in the rip_v3 process model:data_pkptr = op_pk_get (RIP_INSTRM);iciptr = op_intrpt_ici ();if (iciptr == OPC_NIL) { *src_port_ptr = UDPC_PORT_UNSPEC; *src_addr_ptr = IpI_Default_Addr; }else { /* Get the local port of the sender of the UDP message */ op_ici_attr_get (iciptr, rem_port, src_port_ptr); /* Get the IP address of the sender of the UDP message */ op_ici_attr_get (iciptr, rem_addr, src_addr_ptr); } /* data_pkptr is the received data packet */pk_size = (double) op_pk_total_size_get (data_pkptr); --------------------------------------------------------------------Step 3: On the sender's end, send data out. This is from the rip_send() function in the rip_v3 process model:op_ici_attr_set (command_ici_ptr, local_port, loc_port);/* rem_port is the port number, like '1001', that the sinks open as their receive ports */op_ici_attr_set (command_ici_ptr, rem_port, rem_port); /* rem_addr is the remote IP address for the node you are sending to */op_ici_attr_set (command_ici_ptr, rem_addr, rem_addr); /* * Set the connection class to 1. This only really matters if you are * sitting on top of protocols like ATM which have a concept of * high-priority vs. low priority traffic. You can leave this unset. */op_ici_attr_set (command_ici_ptr, connection_class, CONNECTION_CLASS_1); op_ici_install (command_ici_ptr);op_pk_send_forced (data_pkptr, RIP_OUTSTRM); /* Get the status indication from the ici */op_ici_attr_get (command_ici_ptr, status, &ind); -------------------------------------------------------The only remaining question is how to specify the destination IP addresses in the rem_addr field of the send. This is an IpT_Address, which is really an unsigned integer, so use the 32-bit integer representing the destination IP address. You can use the function ip_address_create() to create an IpT_Address from a string. Look in ip_addr_v4.ex.c for examples.In addition, note that you could also use the TPAL layer to interface with UDP or any protocol. TPAL is aimed: * To provide a unified interface for all transport protocols (UDP, TCP, X25, etc.) * To make interfacing between application layer and transport protocol layer simpler by removing all the specific features of a transport protocol.You can look at these files if you wish to use TPAL instead of interfacing directly with UDP: * /std/applications/tpal_app_support.ex.c (API to interface with TPAL) * /std/applications/gna_email_cli.pr.m (example of how to use API)

Environment

Protocols->Other

Attachments
NOTICE: Riverbed® product names have changed. Please refer to the Product List for a complete list of product names.
Can't find an answer? Create a case