NPR Tutorial >> Summary Information | TOC |
This page summarizes some functions that might be useful to the plugin developer. The header files plugin_api.h, plugin_dl.h and plugin_helpers.h can be found in the directory ~onl/npr/pluginFramework/ on the ONL user host. The source code for the typedefs and macros listed in the section Types and Macros are in the plugin_api.h and plugin_dl.h files. The C-library functions are provided in the Intel C libraries for which no source code is available. A few low-level details (e.g., ring formats) can also be found in source files found in the subdirectories of the directory onl_router/.
Global Variables | Part of the state of a plugin's control structure (e.g., dlNextBlock). Manually included at the beginning of each plugin source code. |
Constants | Defined in plugin_dl.h and used in API and user functions. |
plugin_api.h
plugin_dl.h |
The core ONL NPR API functions (e.g., onl_api_udp_cksum()), and the ONL NPR API functions related to the IXP's dispatch loop that have been tailored for plugins (e.g., onl_api_int2str()). |
plugin_helpers.h | Functions that are candidates for inclusion in the plugin_api.h and plugin_dl.h files. |
C Library Functions | General-purpose functions (e.g., memcpy, strcpy) that can be used by including the header files stdlib.h, memory.h and string.h. |
The variable declarations listed below are included at the beginning of every plugin source file. They are included her for completeness.
Synopsis | Description |
---|---|
__declspec(gp_reg) int dlNextBlock; | Where to send meta-packet next |
__declspec(gp_reg) int dlFromBlock; | Where to get meta-packet from |
__declspec(gp_reg) int msgNextBlock; | Where to send control messages |
__declspec(gp_reg) int msgFromBlock; | Where to get control messages from |
volatile __declspec(gp_reg) plc_plugin_data ring_in; | Input ring data from PLC |
volatile __declspec(gp_reg) plugin_out_data ring_out; | Output ring data for the next block |
#define QM 0 // communication rings #define MUX 1 #define XSCALE 2 #define XSCALE_LD 3 #define XSCALE_EXC 4 #define XSCALE_ERR 5 #define PACKET_IN_RING_0 6 #define PACKET_IN_RING_1 7 #define PACKET_IN_RING_2 8 #define PACKET_IN_RING_3 9 #define PACKET_IN_RING_4 10 #define MESSAGE_OUT_RING_0 11 #define MESSAGE_OUT_RING_1 12 #define MESSAGE_OUT_RING_2 13 #define MESSAGE_OUT_RING_3 14 #define MESSAGE_OUT_RING_4 15 #define MESSAGE_IN_RING_0 16 #define MESSAGE_IN_RING_1 17 #define MESSAGE_IN_RING_2 18 #define MESSAGE_IN_RING_3 19 #define MESSAGE_IN_RING_4 20 #define DROP 21 #define DO_NOTHING 22
#define CM_CONTROLMSG 0 #define CM_CONTROLMSGRSP 1 #define CM_DEBUGMSG 2
The plugins cited as examples in the table below can be found in the subdirectories of ~onl/npr/plugins/ on the onlusr host.
Synopsis | Description | Example(s) |
---|---|---|
void dl_sink_init( ) |
Fix the value of the incoming ring-ready signal so RX can indicate when all rings are created. Start the signalling rotation for dl_sink. | All plugins |
void dl_source_init() |
Wait for the RX to signal creation of the rings, and then enter the signalling rotation for dl_source | All plugins |
void dl_sink_packet( unsigned int sink ) |
Enqueue a packet from the current processing block to the next processing block, depending on which microengine is running this. | All plugins |
void dl_source_packet( unsigned int source ) |
Dequeue a packet from previous processing block, depending on which microengine is running this. | All plugins |
void dl_source_message( unsigned int source, |
Dequeue a control message from the XScale | All plugins |
void onl_api_set_out_to_MUX( ) | Set dlNextBlock to forward to MUX | |
void onl_api_set_out_to_QM( ) | Set dlNextBlock to forward to QM | ipHdr |
void onl_api_set_out_to_XSCALE_LD( ) | Set dlNextBlock to forward to XSCALE local delivery queue | |
void onl_api_set_out_to_XSCALE_EXC( ) | Set dlNextBlock to forward to XSCALE exception queue | |
void onl_api_set_out_to_XSCALE_ERR( ) | Set dlNextBlock to forward to XSCALE error queue | |
void onl_api_set_out_to_PLUGIN(
unsigned int pluginNum ) |
Set dlNextBlock to forward to PLUGIN | ipHdr |
void onl_api_drop( ) |
Set dlNextBlock to forward to FM
(Drop packet) |
plugin_helpers.h
delay, erd++ |
__forceinline void onl_api_allocate_buffer( __declspec(sram_read_reg) buf_handle_t *buf_handle ) |
Allocate a DRAM packet buffer and return the buffer handle | ipHdr, nstats, demo++ |
__forceinline void onl_api_get_buf_handle( __declspec(gp_reg) buf_handle_t *buf_handle ) |
Return current packet's buffer handle in buf_handle by reading it from the meta-packet. | ipHdr, nstats, shaper++, stringSub, TOStag |
__forceinline unsigned int onl_api_getBufferDescriptorPtr( dl_buf_handle_t buf_handle ) |
Compute the address of the packet buffer descriptor in SRAM given the buffer handle. | ipHdr, nstats, shaper++, stringSub, TOStag |
__forceinline unsigned int onl_api_readBufferDescriptor( unsigned int bufDescPtr, |
Read the packet buffer descriptor into bufDescr given the address of the buffer descriptor (bufDescPtr). | ipHdr, nstats, shaper++, stringSub, TOStag |
unsigned int onl_api_writeBufferDescriptor( unsigned int bufDescPtr, |
Write the packet buffer descriptor to SRAM. | ipHdr |
__forceinline unsigned int onl_api_getBufferPtr( dl_buf_handle_t buf_handle ) |
Compute the address of the packet buffer in DRAM given the buffer handle. | ipHdr, nstats, shaper++, stringSub, TOStag |
__forceinline unsigned int onl_api_getIpv4HdrPtr( unsigned int dramBufferPtr, |
Compute the address of the IPv4 header in DRAM given the address of the DRAM buffer and the offset field in the buffer descriptor. For ONL, the offset is always 0x18E (398 decimal). | ipHdr, nstats, shaper++, stringSub, TOStag |
__forceinline unsigned int onl_api_readIpv4Hdr( unsigned int ipHdrPtr, | Read the IPv4 header from DRAM to *ipv4_hdr_ptr given a pointer to the header (ipHdrPtr). | ipHdr, nstats, shaper++, stringSub, TOStag |
__forceinline unsigned int onl_api_readIpv4HdrOptions( unsigned int ipHdrPtr, | Read the IP header options given a pointer to the options area (ipv4_hdr_options_ptr) | |
unsigned int onl_api_getTcpHdrPtr( unsigned int ipHdrPtr, | Return the address of the TCP header given the address of the IP header (ipHdrPtr) and the length of the IP header (iphl). | ipHdr |
__forceinline unsigned int onl_api_readTcpHdr( unsigned int tcpHdrPtr, | Read the TCP header into the location starting at the address given by tcp_hdr_ptr. Return 1 if successful. | ipHdr |
unsigned int onl_api_getUdpHdrPtr( unsigned int ipHdrPtr, | Return the address of the UDP header given the address of the IP header (ipHdrPtr) and the length of the IP header (iphl). | ipHdr, stringSub |
__forceinline unsigned int onl_api_readUdpHdr( unsigned int udpHdrPtr, | Read the UDP header into the location starting at the address given by udp_hdr_ptr. Return 1 if successful. | stringSub |
__forceinline void onl_api_ua_write_8B_dram( unsigned int from_addr, | The same as onl_api_ua_write_20B_dram() below except for eight bytes. | |
__forceinline void onl_api_ua_write_20B_dram( unsigned int from_addr, | Do a 20-byte DRAM write starting from the address from_addr to the address to_addr. The addresses can be unaligned. | |
__forceinline void onl_api_ua_write_8W_dram( unsigned int from_addr, | The same as onl_api_ua_write_20B_dram() except for eight words. | stringSub |
__forceinline void onl_api_ua_write_4W_dram( unsigned int from_addr, | The same as onl_api_ua_write_20B_dram() except for four words. | ipHdr |
__forceinline void onl_api_ua_write_2W_dram( unsigned int addr, | The same as onl_api_ua_write_20B_dram() except for two words. | |
__forceinline void onl_api_ua_write_1W_dram( unsigned int addr, | The same as onl_api_ua_write_20B_dram() except for one word. | |
__forceinline void onl_api_ua_read_1W_dram( unsigned int from_addr, | Do a one-word DRAM read starting from the address from_addr to the address to_addr. The addresses can be unaligned. | |
__forceinline unsigned int onl_api_writeIpv4Hdr( unsigned int from_ipHdrPtr, | Copy the IPv4 header which is at address from_ipHdrPtr to the memory location starting at to_ipv4_hdr_ptr. | stringSub |
__forceinline unsigned int onl_api_writeTcpHdr( unsigned int from_tcpHdrPtr, | Copy the TCP header which is at address from_tcpHdrPtr to the memory location starting at to_tcp_hdr_ptr. | stringSub |
__forceinline unsigned int onl_api_writeUdpHdr( unsigned int from_udpHdrPtr, | Copy the UDP header which is at address from_tcpHdrPtr to the memory location starting at to_tcp_hdr_ptr. | stringSub |
__forceinline void onl_api_ua_read_2W_dram( unsigned int from_addr, | Same as onl_api_ua_read_1W_word() except for two words instead of one word. | |
__forceinline void onl_api_ua_read_4W_dram( unsigned int from_addr, | Same as onl_api_ua_read_1W_word() except for four words instead of one word. | ipHdr |
__forceinline void onl_api_ua_read_8W_dram( unsigned int addr, | Same as onl_api_ua_read_1W_word() except for eight words instead of one word. | stringSub |
__forceinline unsigned int onl_api_getTcpPacketPayloadPtr( unsigned int tcpHdrPtr, | Return the address of the TCP payload given the address of the TCP header (tcpHdrPtr) and the number of 32-bit words in the TCP header (th_words). | |
__forceinline unsigned int onl_api_getUdpPacketPayloadPtr( unsigned int udpHdrPtr) | Return the address of the UDP payload given the address of the UDP header (udpHdrPtr). | stringSub |
__forceinline void onl_api_getQueueParams( unsigned int raw_qid, | Copy the queue parameters into the structure at address qparams given the internal QID raw_qid. Note: If p is the external output port number and q is the external QID, the internal QID is (1+p)*8192+q. | erd++, priq |
__forceinline unsigned int onl_api_ipv4Hdr_cksum16( __declspec(gp_reg) onl_api_ip_hdr *ipv4_hdr_ptr) | Return the 16-bit IPv4 header checksum given the address of the IPv4 header (ipv4_hdr_ptr). | demo++, stringSub |
__forceinline unsigned int onl_api_cksum16_1W( unsigned int cksum, | Return the new 16-bit checksum given the current checksum (cksum) and the address of the next word to be checksummed (word). The returned value can be larger than 16-bits, but the actual 16-bit checksum can be obtained by applying the function onl_api_cksum16_final() to the return value. | |
__forceinline unsigned int onl_api_cksum16_2W( unsigned int cksum, | Same as onl_api_cksum16_1W() except words points to two words that need to be included in the checksum. | |
__forceinline unsigned int onl_api_cksum16_4W( unsigned int cksum, | Same as onl_api_cksum16_1W() except words points to four words that need to be included in the checksum. | |
__forceinline unsigned int onl_api_cksum16_8W( unsigned int cksum, | Same as onl_api_cksum16_1W() except words points to eight words that need to be included in the checksum. | |
__forceinline unsigned int onl_api_cksum16_16W( unsigned int cksum, | Same as onl_api_cksum16_1W() except words points to 16 words that need to be included in the checksum. | |
__forceinline unsigned int onl_api_cksum16_final( unsigned int cksum) | Return the true 16-bit checksum given the value in cksum which was computed by one of the onl_api_cksum_16_xW() functions. | |
__forceinline unsigned int onl_api_udp_cksum( __declspec(gp_reg) onl_api_ip_hdr *ipv4_hdr, | Return the 16-bit UDP checksum given the address of the IPv4 header (ipv4_hdr), the address of the UDP header (udp_hdr), and the address of the actual UDP header (udpHdrPtr). Typically, we read the IP and UDP headers into local memory and use addresses to those copies for ipv4_hdr and udp_hdr. | demo++, stringSub |
__forceinline unsigned int onl_api_tcp_cksum( __declspec(gp_reg) onl_api_ip_hdr *ipv4_hdr, | Same as onl_api_udp_cksum() except for a TCP header instead of a UDP header. | ipHdr |
__forceinline void onl_api_update_ring_out_to_freelist( unsigned int buf_handle) | Update the plugin's output ring assuming that the meta-packet will be sent to the Freelist Manager. | plugin_helpers.h
priq |
__forceinline void onl_api_update_ring_out_to_qm( unsigned int buf_handle, | Update the plugin's output ring assuming that the
meta-packet will be sent to the Queue Manager.
Note: qm_qid = (1 + output port#)*8192 + qid; e.g., if qid = 64 and outport = 4, then qm_qid = 5*8192+64 = 41024. |
plugin_helpers.h |
__forceinline void onl_api_update_ring_out_to_mux( unsigned int buf_handle, | Update the plugin's output ring assuming that the meta-packet will be sent to the MUX block. | plugin_helpers.h |
__forceinline void onl_api_update_ring_out_to_xscale( unsigned int buf_handle, | Update the plugin's output ring assuming that the meta-packet will be sent to the Xscale. | |
__forceinline void onl_api_update_ring_out_to_plugin( unsigned int buf_handle, | Update the plugin's output ring assuming that the meta-packet will be sent to another plugin. | plugin_helpers.h
priq |
__forceinline void onl_api_int2str( __declspec(gp_reg) unsigned int val, |
Convert the integer val to its hexadecimal string representation and store it in the local memory array hex_str[9]. The helper function helper_ul2hex_sram() is an alternative function that uses SRAM instead of local memory. | debug, mycount, setDst |
__forceinline int onl_api_str2intarr( __declspec(local_mem) char *msg, |
Normally used in one of the final steps of handle_msg() to place the outbound control message into a form that can be transmitted to the Xscale control processor. | All plugins |
__forceinline void onl_api_intarr2str( __declspec(gp_reg) unsigned int intarr[7], |
Normally used in one of the first steps of handle_msg() to place the inbound control message into a form that can be processed by the plugin. | All plugins |
int onl_api_debug_message( unsigned int sink, |
Log the debug message in msg. | plugin_helpers.h
Most plugins |
void onl_api_plugin_cntr_inc( unsigned int plugin_id, |
Increment the plugin counter counter_id for plugin plugin_id. | mycount, priq |
void onl_api_plugin_cntr_add( unsigned int plugin_id, |
Add val to the plugin counter counter_id for plugin plugin_id. | |
Synopsis | Description | Example(s) |
---|---|---|
static __forceinline unsigned long diff_msec( __declspec(local_mem) long long t2, |
Return difference of 2 timestamps in msec | delay |
static __forceinline long long diff_usec( __declspec(local_mem) long long t2, |
Return difference of 2 timestamps in usec | |
static __forceinline long long diff_nsec( __declspec(local_mem) long long t2, |
Return difference of 2 timestamps in nsec | shaper++ |
void dl_source_nopacket( void ) | Same as dl_source_packet() but no packet will be dequeued from the previous processing block | SHOULD BE DELETED? |
void dl_sink_nopacket( void ) | Same as dl_sink_packet() but no packet will be
enqueued to the next processing block / Obsoleted by helper_set_out_to_DO_NOTHING() |
delay |
static __forceinline unsigned long msec2cycles ( __declspec(gp_reg) unsigned long msec ) |
Convert msec to #ME cycles assuming 1.4 GHz ME
CAVEAT: msec <= 49000 msec |
delay |
static __forceinline long long usec2cycles ( __declspec(gp_reg) long long usec ) |
Convert usec to #ME cycles assuming 1.4 GHz ME | |
static __forceinline long long nsec2cycles ( __declspec(gp_reg) long long nsec ) |
Convert nsec to #ME cycles assuming 1.4 GHz ME | |
static __forceinline __declspec(sram) char * nxt_token( __declspec(sram) char *p, |
Return address of next word following the current word where a word is any char sequence terminated by the space character. Limit the search to n characters. Return 0 if no word found. | delay |
static __forceinline void wait_packet_signal( SIGNAL *s ) |
Wait for the packet signal | Used by dl_sink_nopacket() / SHOULD BE DELETED |
static __forceinline void send_packet_signal( SIGNAL *s ) |
Send the packet signal | Used by dl_sink_nopacket() / SHOULD BE DELETED |
static __forceinline unsigned long helper_atou_sram( __declspec(sram) char *p ) |
Convert ASCII string to unsigned long | delay |
unsigned int helper_count_words( char *p ) |
Return the number of words starting at p where a word is any char sequence terminated by the space character or NUL byte. | delay++, erd++, shaper++ |
static __forceinline void helper_dbg_message( __declspec(local_mem) char *dbgmsg, |
Transfer debug msg from SRAM to local memory. | |
static __forceinline void helper_inc_meta_mux_tag( void ) |
Increment the plugin tag field that is in the outgoing meta-packet (ring_out) assuming dlNextBlock = MUX; i.e., the meta-packet will go to the MUX block. | TOStag |
static __forceinline void helper_plugin_cntr_zero( int counter_id ) |
Zero plugin counter | Most plugins |
static __forceinline int helper_set_meta_default( __declspec(gp_reg) int nextBlk ) |
Set ring_out data to default values given that the meta-packet will go to the block specified by nextBlk (e.g., QM). Return 0 if OK; -1 otherwise | delay++, erd++, priq, setNxtBlk, shaper++, TOStag |
static __forceinline void helper_set_meta_mux_tag( __declspec(gp_reg) int tag ) |
Set the plugin tag field assuming dlNextBlock = MUX; i.e., the meta-packet will go to the MUX block. | TOStag |
static __forceinline void helper_set_out_to_DO_NOTHING( void ) |
Set dlNextBlock = DO_NOTHING so that dl_sink_packet() will not send out the meta-packet. | delay++, priq, shaper++ |
static __forceinline void helper_set_out_to_DROP( void ) |
Set dlNextBlock = DROP so that dl_sink_packet() will send the meta-packet to the Freelist Manager. | delay++, priq, shaper++ |
static __forceinline void helper_sram_dbgmsg_1ul( unsigned long x0 ) |
Send debug message consisting of the the decimal string representation of the unsigned long value of x0. | |
static __forceinline void helper_sram_dbgmsg_2ul( unsigned long x0, |
Send debug message consisting of the catenation of the decimal string representations of the two unsigned long values of x0 and x1. | |
static __forceinline void helper_sram_dbgmsg_3ul( unsigned long x0, | Send debug message consisting of the catenation of the decimal string representations of the three unsigned long values of x0, x1 and x2. | delay++, erd++, setNxtBlk, shaper++ |
static __forceinline void helper_sram_dbgmsg_str_1ul( char *cstr, |
Send debug message consisting of the string cstr concatenated to the decimal string representation of the unsigned long value of xval. | erd++, priq, setNxtBlk |
void helper_sram_outmsg_1ul( unsigned long x0, |
Create a C-string message with one unsigned long using an SRAM workarea. | delay++, erd++, priq, setNxtBlk, shaper++ |
void helper_sram_outmsg_2ul( unsigned long x0, |
Create a C-string message with two unsigned longs using an SRAM workarea. | shaper++ |
void helper_sram_outmsg_3ul( unsigned long x0, |
Create a C-string message with three unsigned longs using an SRAM workarea. | delay++, erd++, priq, setNxtBlk, shaper++ |
void helper_sram_outmsg_5ul( unsigned long x0, |
Create a C-string message with five unsigned longs using an SRAM workarea. | delay++, erd++, priq, shaper++ |
char * helper_tokenize( char *current_word ) |
Return the address of the next word following the one at current_word where a word is any char sequence terminated by the space character and terminate the word with the NUL byte. If current_word is pointing at a space character, the current word is considered to be the empty string. Return 0 if no word found. | delay++, erd++, shaper++ |
static __forceinline __declspec(gp_reg) int helper_ultoa_sram( __declspec(sram) unsigned long x, |
Convert the unsigned long into an ASCII string area that starts at the SRAM address in p which is n bytes long. The resulting string is left-justified. | delay, delay++, erd++, priq, shaper++ |
static __forceinline void helper_ul2hex_sram( unsigned long x, |
Convert unsigned long to a hexadecimal ASCII C-string in SRAM. | |
The C-library functions that are made available through the header files <stdlib.h>, <memory.h>, <string.h> are listed below. In most cases, they have virtually the same semantics as found in the standard C libraries in conventional hosts. We summarize the major differences at the end of this section.
The functions included in <memory.h> and <string.h> also have memory-aware forms as well (e.g., strncmp_sram() assumes that its pointer arguments point into SRAM).
Revised: Thu, Apr 2, 2009
NPR Tutorial >> Summary Information | TOC |