388 | | The GIET_VM allows a user application to get and use a private NIC channel, using the CMA component (chained buffers DMA) to transfer packets to or from an user buffer. |
389 | | The NIC channel and the CMA channel are registered in the threads contexts. |
390 | | |
391 | | === 1) void '''giet_nic_tx_alloc'''( unsigned int xmax, unsigned int ymax) === |
392 | | This function must be called by one single thread (typically the main() ). It allocates a private NIC_TX channel (coming with the associated kernel NIC_TX chbuf), and a private CMA_TX channel to an application. It registers these NIC_TX and CMA_TX channels in the contexts of all threads that are in the same vspace as the calling thread. These NIC and CMA channels are therefore shared by all thread of a multi-threads application. |
393 | | The packets are transfered by the hardware to the NIC from a distributed kernel chbuf (one 4 Kbytes container per cluster), where the number of involved clusters is defined by the <xmax> & <ymax> arguments. The (xmax / ymax) arguments cannot be larger than (X_SIZE / Y_SIZE) defining the max number of clusters in the platform, but they can be smaller. |
394 | | The calling thread exit if no available NIC_TX channel, if no available CMA channel, if (xmax / ymax) are too large, or if there is not enough memory for the distributed kernel containers in one selected cluster. |
395 | | |
396 | | === 2) void '''giet_nic_rx_alloc'''( unsigned int xmax, unsigned int ymax ) === |
397 | | This function must be called by one single thread (typically the main() ). It allocates a private NIC_RX channel (coming with the associated kernel NIC_RX chbuf), and a private CMA channel to an application. It registers these NIC_RX and CMA_RX channels in the contexts of all threads that are in the same space as the calling thread. These NIC and CMA channels are therefore shared by all threads of a multi-threads application. |
398 | | The packets are transfered by the hardware from the NIC to a distributed kernel chbuf (one 4 Kbytes container per cluster), where the number of involved clusters is defined by the <xmax> & <ymax> argumentss. The (xmax / ymax) arguments cannot be larger than (X_SIZE / Y_SIZE) defining the max number of clusters in the platform, but they can be smaller. |
399 | | The calling thread exit if no available NIC_TX channel, if no available CMA channel, if (xmax / ymax) are too large, or if there is not enough memory for the distributed kernel containers in one selected cluster. |
400 | | |
401 | | === 3) void '''giet_nic_tx_start'''( ) === |
402 | | This function must be called by one single thread (typically the main() ). It activates both the NIC_TX channel, and the CMA_TX channel allocated to an application, to start the transfer of packets from the distributed kernel chbuf to the NIC. |
403 | | The calling thread exit if no allocated NIC_TX channel or no allocated CMA_TX channel. |
404 | | |
405 | | === 4) void '''giet_nic_rx_start'''( ) === |
406 | | This function must be called by one single thread (typically the main() ). It activates both the NIC_RX channel, and the CMA_RX channel allocated to an application, to start the transfer of packets from the NIC to the distributed kernel chbuf. |
407 | | The calling thread exit if no allocated NIC_RX channel or no allocated CMA_RX channel. |
| 388 | The GIET_VM allows a user application to dynamically create and access sockets in non-connected mode. Only the AF_INET family, SOCK_DGRAM type, and UDP protocol are supported. To define a socket address the giet_VM |
| 389 | uses the following structure, defined in the stdio.h file. |
| 390 | {{{ |
| 391 | typedef struct sockaddr_s |
| 392 | { |
| 393 | unsigned int sin_addr; // IPV4 address |
| 394 | unsigned short sin_port; // port number |
| 395 | short sin_family; // should be AF_INET |
| 396 | |
| 397 | } |
| 398 | sockaddr_t; |
| 399 | }}} |
| 400 | |
| 401 | |
| 402 | === 1) int '''giet_nic_socket'''( int family , int type , int protocol ) === |
| 403 | This function must creates a socket. It returns a socket identifier that can be used by the calling thread to send or receive packets form the internet network. It cannot be accessed by another thread. This function creates also the RX packets & Tx packets queues associated to the socket, as well as the kernel threads that are in charge of moving packets between these queues and the hardware NIC controller. |
| 404 | As only non connected sockets communicating with remote hosts are supported, the three arguments have imposed values: |
| 405 | * '''family''' : should be AF_INET. |
| 406 | * '''type''' : must be SOCK_DGRAM. |
| 407 | * '''protocol''' : must be 0 (actually UDP). |
| 408 | * return socket identifier if success / returns -1 if error. |
| 409 | |
| 410 | === 2) void '''giet_nic_close'''( int socket ) === |
| 411 | This function releases all memory allocated for a socket: the socket descriptor itself, and the RX packets / Tx packets queues associated to the socket. The kernel threads associated to these queues are desactivated. |
| 412 | * '''socket''' : socket identifier. |
| 413 | * return 0 if success / returns -1 if error. |
| 414 | |
| 415 | === 3) void '''giet_nic_bind'''( int socket , sockaddr_t * addr , int addr_len ) === |
| 416 | This function makes the binding between a socket identified by the <socket> argument, and a local socket addres, that is a couple (IPV4 address / port number). The default value |
| 417 | INADDR_ANY value can be used fot thr IPV4 address, toask the kernel to define the value. |
| 418 | * '''socket''' : socket identifier. |
| 419 | * '''addr''' : pointer on the local socket address. |
| 420 | * '''addr_len''' : address structure length (in bytes). |
| 421 | * return 0 if success / returns -1 if error. |
| 422 | |
| 423 | === 4) void '''giet_nic_connect'''( int socket , sockaddr_t * addr , int addr_len ) === |
| 424 | This function is generally used by a client to connect a local client socket to a remote |
| 425 | server socket. It forces the local socket in connected mode, and register the remote socket address in the local socket descriptor. It allows the client to use the read() / write() sytem call without specifying the explicitely the remote server address. |
| 426 | * '''socket''' : socket identifier. |
| 427 | * '''addr''' : pointer on the remote socket address. |
| 428 | * '''addr_len''' : address structure length (in bytes). |
| 429 | * return 0 if success / returns -1 if error. |