Vdeplug library

From Virtualsquare
Revision as of 19:33, 27 December 2012 by Renzo (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

VDE provides a library for any virtual machine developer that wants to connect its VM to VDE networks. The interface is composed by just six functions:

  • vde open opens the connection to a switch. It requires three arguments:the pathname of the switch, a decription (that will be sent to the switch torecognize the virtual machine), and an optional structure for further options. It is a macro that calls the hidden vde open real hidden function. This solution gives compatibility with future versions of the interface: the macro automatically insert the interface version number in the call. It returns a handle to the VDE connection;
  • vde read receives a packet;
  • vde write sends a packet;
  • vde close closes the connection;
  • vde datafd returns a descriptor that can be used in a select() system call or in a poll() system call to test the availability of new packets to be read;
  • vde ctlfd returns a descriptor that can be used in a select() system call or in a poll() system call to test whether the switch has closed the port.
#ifndef _VDELIB_H
#define _VDELIB_H
#include <sys/types.h>
#define LIBVDEPLUG_INTERFACE_VERSION 1
struct vdeconn;
typedef struct vdeconn VDECONN;
/* Open a VDE connection.
 * vde_open_options:
 *   port: connect to a specific port of the switch (0=any)
 *   group: change the ownership of the communication port to a specific group
 *        (NULL=no change)
 *   mode: set communication port mode (if 0 standard socket mode applies)
 */
struct vde_open_args {
    int port;
    char *group;
    mode_t mode;
};
/* vde_open args:
 *   vde_switch: switch id (path)
 *   descr: description (it will appear in the port description on the switch)
 */
#define vde_open(vde_switch,descr,open_args) \
    vde_open_real((vde_switch),(descr),LIBVDEPLUG_INTERFACE_VERSION,(open_args))
VDECONN *vde_open_real(char *vde_switch,char *descr,int interface_version,
    struct vde_open_args *open_args);
ssize_t vde_recv(VDECONN *conn,char *buf,size_t len,int flags);
ssize_t vde_send(VDECONN *conn,const char *buf,size_t len,int flags);
/* for select/poll when this fd receive data, there are packets to recv
 * (call vde_recv) */
int vde_datafd(VDECONN *conn);
/* for select/poll. the ctl socket is silent after the initial handshake.
 * when EOF the switch has closed the connection */
int vde_ctlfd(VDECONN *conn);
int vde_close(VDECONN *conn);
#endif
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox