GNU Radio 3.4.2 C++ API
usrp2::eth_buffer Class Reference

high-performance interface to send and receive raw ethernet frames with out-of-order retirement of received frames. More...

#include <eth_buffer.h>

List of all members.

Public Types

enum  result { EB_OK, EB_ERROR, EB_WOULD_BLOCK, EB_TIMED_OUT }

Public Member Functions

 eth_buffer (size_t rx_bufsize=0)
 ~eth_buffer ()
bool open (const std::string &ifname, int protocol)
 open the specified interface
bool close ()
 close the interface
bool attach_pktfilter (pktfilter *pf)
 attach packet filter to socket to restrict which packets read sees.
const uint8_tmac () const
 return 6 byte string containing our MAC address
result rx_frames (data_handler *f, int timeout=-1)
 Call f for each frame in the receive buffer.
void release_frame (void *p)
result tx_frame (const void *base, size_t len, int flags=0)
result tx_framev (const eth_iovec *iov, int iovcnt, int flags=0)
unsigned int max_frames () const

Static Public Attributes

static const unsigned int MAX_PKTLEN = 1512
static const unsigned int MIN_PKTLEN = 64

Detailed Description

high-performance interface to send and receive raw ethernet frames with out-of-order retirement of received frames.

On many systems it should be possible to implement this on top of libpcap


Member Enumeration Documentation

Enumerator:
EB_OK 
EB_ERROR 
EB_WOULD_BLOCK 
EB_TIMED_OUT 

Constructor & Destructor Documentation

usrp2::eth_buffer::eth_buffer ( size_t  rx_bufsize = 0)
Parameters:
rx_bufsizeis a hint as to the number of bytes of memory to allocate for received ethernet frames (0 -> reasonable default)
usrp2::eth_buffer::~eth_buffer ( )

Member Function Documentation

bool usrp2::eth_buffer::attach_pktfilter ( pktfilter pf)

attach packet filter to socket to restrict which packets read sees.

Parameters:
pfthe packet filter
bool usrp2::eth_buffer::close ( )

close the interface

const uint8_t* usrp2::eth_buffer::mac ( ) const [inline]

return 6 byte string containing our MAC address

unsigned int usrp2::eth_buffer::max_frames ( ) const [inline]
bool usrp2::eth_buffer::open ( const std::string &  ifname,
int  protocol 
)

open the specified interface

Parameters:
ifnameethernet interface name, e.g., "eth0"
protocolis the ethertype protocol number in network order. Use 0 to receive all protocols.
void usrp2::eth_buffer::release_frame ( void *  p)
result usrp2::eth_buffer::rx_frames ( data_handler f,
int  timeout = -1 
)

Call f for each frame in the receive buffer.

Parameters:
fis the frame data handler
timeout(in ms) controls behavior when there are no frames to read

If timeout is 0, rx_frames will not wait for frames if none are available, and f will not be invoked. If timeout is -1 (the default), rx_frames will block indefinitely until frames are available. If timeout is positive, it indicates the number of milliseconds to wait for a frame to become available. Once the timeout has expired, rx_frames will return, f never having been invoked.

f will be called on each ethernet frame that is available. f returns a bit mask with one of the following set or cleared:

data_handler::KEEP - hold onto the frame and present it again during the next call to rx_frames, otherwise discard it

data_handler::DONE - return from rx_frames now even though more frames might be available; otherwise continue if more frames are ready.

The idea of holding onto a frame for the next iteration allows the caller to scan the received packet stream for particular classes of frames (such as command replies) leaving the rest intact. On the next call all kept frames, followed by any new frames received, will be presented in order to f. See usrp2.cc for an example of the pattern.

Returns:
EB_OK if at least one frame was received
EB_WOULD_BLOCK if timeout is 0 and the call would have blocked
EB_TIMED_OUT if timeout occurred
EB_ERROR if there was an unrecoverable error.
result usrp2::eth_buffer::tx_frame ( const void *  base,
size_t  len,
int  flags = 0 
)
result usrp2::eth_buffer::tx_framev ( const eth_iovec *  iov,
int  iovcnt,
int  flags = 0 
)

Member Data Documentation

const unsigned int usrp2::eth_buffer::MAX_PKTLEN = 1512 [static]
const unsigned int usrp2::eth_buffer::MIN_PKTLEN = 64 [static]

The documentation for this class was generated from the following file: