return 0;
}
+/**
+ * Allocates endpoint
+ *
+ * \return On success returns endpoint structure.
+ * On error, NULL is returned.
+ *
+ */
static fwp_endpoint_t* fwp_endpoint_alloc()
{
int i, max_endpoints;
return (&fwp_endpoint_table.entry[i]);
}
+/**
+ * Destroy endpoint
+ *
+ * \param[in] epointd Endpoint descriptor
+ * \return On success 0 is returned.
+ * On error, negative error value is returned.
+ */
int fwp_endpoint_destroy(fwp_endpoint_d_t epointd)
{
fwp_endpoint_t *epoint = epointd;
return 0;
}
+/**
+ * Get endpoint parameters
+ *
+ * \param[in] epointd Endpoint descriptor
+ * \param[out] node Node identifier
+ * \param[out] port Port
+ * \param[out] attr Endpoint`s attributes
+ * \return On success 0 is returned.
+ * On error, negative error value is returned.
+ */
int fwp_endpoint_get_params(fwp_endpoint_d_t epointd, unsigned int *node,
unsigned int *port, fwp_endpoint_attr_t *attr)
{
*
* \return On success returns descriptor of endpoint.
* On error, negative error code is returned.
- *
*/
int fwp_receive_endpoint_create(/*unsigned int node,*/ unsigned int port,
fwp_endpoint_attr_t *attr,
/**
* Unbinds send endpoint from vres
*
- * \param[in] id send endpoint identifier
+ * \param[in] epointd Send endpoint descriptor
* \return On success returns 0. On error, negative error code is returned
*
*/
/**
* Receives message
*
- * \param[in] epointd descriptor of endpoint
- * \param[in] buffer buffer to store message
- * \param[in] buffer_size size of buffer
+ * \param[in] epointd Descriptor of endpoint
+ * \param[in] buffer Buffer to store message
+ * \param[in] buffer_size Size of buffer
*
* \return
* On success, it returns number of received bytes.
peer->addr, &peer->addrlen);
return len;
}
-next_recv:
+
+ while (1) {
/* FIXME: What about using a loop here and continue instead of goto???? */
/* FWP_EPOINT_RELIABLE */
fdset = epoint->fdset;
if (FD_ISSET(epoint->sockd, &fdset)) { /* is it listen socket? */
if (epoint->nr_connections == epoint->attr.max_connections)
- goto next_recv;
+ continue;
csockd = accept(epoint->sockd, (struct sockaddr*)peer->addr,
&peer->addrlen);
epoint->nr_connections++;
FD_SET(csockd, &epoint->fdset);
-
- goto next_recv;
+ continue;
}
/* Check client TCP sockets */
memcpy(epoint->c_sockd+i, epoint->c_sockd+i+1,
sizeof(int)*(epoint->nr_connections -i-1));
epoint->nr_connections--;
- goto next_recv;
+ continue;
}
}
-
- return -EPERM;
+
+ }
}
/**
* Sends message through vres
*
- * \param[in] epointd identificator of endpoint
- * \param[in] msg message to sent
- * \param[in] size message size
+ * \param[in] epointd Endpoint descriptor
+ * \param[in] msg Message to sent
+ * \param[in] size Message size
*
* \return
* On success, it returns zero.
} fwp_endpoint_reliability_t;
struct fwp_endpoint;
-/* fwp endpoint descriptor type */
+/** fwp endpoint descriptor type */
typedef struct fwp_endpoint* fwp_endpoint_d_t;
+/**
+ * Endpoint attributes
+ */
typedef
struct fwp_endpoint_attr {
unsigned int reliability;
+/**
+ * \file fwp_msgb.c
+ *
+ * Routines for manipulation with fwp message buffer (msgb)
+ *
+ */
+
#include "fwp_msgb.h"
#include "fwp_util.h"
#include <stdlib.h>
/*unsigned char* fwp_msgb_dealloc(size_t buf_size) */
/*unsigned char* fwp_msgb_pool_init(size_t buf_size) */
+/**
+ * Allocates msgb.
+ *
+ * \param buf_size Size of msgb
+ * \return Allocated msgb
+ *
+ */
struct fwp_msgb* fwp_msgb_alloc(size_t buf_size)
{
struct fwp_msgb* msgb;
return msgb;
}
+/**
+ * Deallocates msgb.
+ *
+ * \param msgb Pointer to msgb
+ *
+ */
void fwp_msgb_free(struct fwp_msgb *msgb)
{
free((void*) msgb);
msgb = NULL;
}
+/**
+ * Routine is usually called after putting data of length len to msgb
+ * to adjust internal tail pointer and len fields of msgb
+ *
+ * \param msgb Pointer to msgb
+ * \param len The lenght data put to msgb
+ * \return Previous tail pointer
+ *
+ */
inline unsigned char* fwp_msgb_put(struct fwp_msgb *msgb, unsigned int len)
{
unsigned char *tmp= msgb->tail;
return tmp;
}
-/* to parse received message */
+/**
+ * Routine is usually called after reading data of lenght len from msgb to
+ * adjust internal data pointer and len of msgb
+ *
+ * \param msgb Pointer to msgb
+ * \param len The lenght data
+ * \return Previous tail pointer
+ *
+ */
inline unsigned char* fwp_msgb_pull(struct fwp_msgb *msgb, unsigned int len)
{
if (len > msgb->len)
return msgb->data += len;
}
+/**
+ * Routine is usually called after fwp_msgb_reserve after reserved area is filled
+ * adjust pointers
+ *
+ * \param msgb Pointer to msgb
+ * \param len The lenght data
+ * \return Current data pointer
+ *
+ */
inline unsigned char* fwp_msgb_push(struct fwp_msgb* msgb, unsigned int len)
{
msgb->data-=len;
return msgb->data += len;
}
+/**
+ * Sets data pointer to the start of buffer
+ *
+ * \param msgb Pointer to msgb
+ *
+ */
inline void fwp_msgb_reset_data_pointer(struct fwp_msgb *msgb)
{
msgb->data = (unsigned char*) msgb + sizeof(struct fwp_msgb);
}
+/**
+ * Sets data pointer to the start of buffer and the length of used data to zero
+ *
+ * \param msgb Pointer to msgb
+ */
inline void fwp_msgb_reset_data(struct fwp_msgb* msgb)
{
msgb->len = 0;
msgb->tail = msgb->data;
}
-
-/* reserve is called first then push */
+/**
+ * Reserve place of length len in msgb
+ *
+ * \param msgb Pointer to msgb
+ * \param len The lenght data
+ */
inline void fwp_msgb_reserve(fwp_msgb_t *msgb, unsigned int len)
{
msgb->data+=len;
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
-/*#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>*/
#define ADDRLEN_MAX 30
socklen_t addrlen;
} fwp_sockaddr_t;
+/**
+ * Message buffer structure
+ */
typedef
struct fwp_msgb {
size_t buffer_size;
#include <pthread.h>
#include <semaphore.h>
+/**
+ * Message queue structure
+ *
+ */
struct fwp_msgq {
unsigned int nr_pending; /**< number of messages in the queue */
struct fwp_msgb* queue[FWP_MSGQ_SIZE];
/**< IP tos for AC_VI, AC_VO, AC_BE, AC_BK */
static const unsigned int ac_to_tos[4] = {224,160,96,64};
+/**
+ * Set access category (AC) to socket
+ *
+ * \param[in] sockd Socket descriptor
+ * \param[in] ac_id AC identifier
+ *
+ * \return On success returns zero.
+ * On error, negative error code is returned.
+ *
+ */
static inline int fwp_vres_set_ac(int sockd, fwp_ac_t ac_id)
{
unsigned int tos;
return (vres - fwp_vres_table.entry);
}
+/**
+ * Allocate vres
+ *
+ * \return On success returns vres descriptor.
+ */
fwp_vres_d_t fwp_vres_alloc()
{
int i;
return (&fwp_vres_table.entry[i]);
}
+/**
+ * Set vres params
+ *
+ * \param[in] vresdp Vres descriptor
+ * \param[in] params Vres parameters
+ *
+ * \return On success returns zero.
+ * On error, negative error code is returned.
+ *
+ */
int fwp_vres_set_params(fwp_vres_d_t vresd, fwp_vres_params_t *params)
{
fwp_vres_t *vres = vresd;
fwp_vres_free(vres);
}
+/**
+ * Thread that does budgeting
+ *
+ */
static void* fwp_vres_tx_thread(void *_vres)
{/* TODO: make changes that count with changing of params */
struct fwp_vres *vres = (struct fwp_vres*)_vres;
/**
* FWP vres parameters
*
- * It is like an internal representation of the contract used inside
- * protocol and contains negotiated parameters from contract.
- *
*/
typedef
struct fwp_vres_params {
+/**
+ * \file fwp_contract.c
+ *
+ * Routines for manipulation with contract
+ *
+ */
#include "fwp_msg.h"
#include "fwp_contract.h"
#include "fwp_contract_table.h"
#include "fwp_mngt.h"
+#include <pthread.h>
static int fwp_contract_is_reserved(fwp_contract_d_t contract)
{
* Negotiates contract for application. Negotiation request is sent to
* fwp agent and then waits for response.
*
- * \param[in] contractd descriptor of the contract to negotiate
- * \param[out] vresd Id of vres after the contract was accepted
+ * \param[in] contractd Descriptor of the contract to negotiate
+ * \param[out] vresd Vres descriptor after the contract was accepted
*
* \return
* If successful, the function returns zero and vres descriptor is
return 0;
}
+/**
+ * Creates contract
+ *
+ * \param[in] contract User-level contract
+ *
+ * \return On success, returns contract descriptor
+ *
+ */
/*fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract, resource_d_t resource)*/
fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract)
{
return contdata;
}
+/**
+ * Destroys contract
+ *
+ * \param[in] contractd Contract descriptor
+ *
+ * \return On success, returns zero.
+ * On error, returns negative error code.
+ *
+ */
int fwp_contract_destroy(fwp_contract_d_t contractd)
{
fwp_contract_data_t *contdata = contractd;
return 0;
}
+/**
+ * Reserves contract
+ *
+ * \param[in] contractd Contract descriptor
+ *
+ * \return On success, returns zero.
+ * On error, returns negative error code.
+ *
+ */
int fwp_contract_reserve(fwp_contract_d_t contractd)
{
fwp_contract_data_t *contdata = contractd;
return 0;
}
+/**
+ * Commits contract
+ *
+ * \param[in] contractd Contract descriptor
+ * \param[out] vresd Descriptor of vres
+ *
+ * \return On success, returns zero.
+ * On error, returns negative error code.
+ *
+ */
int fwp_contract_commit(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp)
{
fwp_contract_data_t *contdata = contractd;
return 0;
}
+/**
+ * Cancels contract
+ *
+ * \param[in] contractd Contract descriptor
+ *
+ * \return On success, returns zero.
+ * On error, returns negative error code.
+ *
+ */
int fwp_contract_cancel(fwp_contract_d_t contractd)
{
fwp_contract_data_t *contdata = contractd;
* Global mngt variables
*/
-/**< Pointer to participant of this application*/
+/**< Pointer to participant of this application */
fwp_participant_t *fwp_participant_this;
-/**< Pointer to manager participant record*/
+/**< Pointer to manager participant */
fwp_participant_t *fwp_participant_mngr;
static fwp_contract_t fwp_service_contract = {
fwp_participant_mngr->vresd);
return 0;
}
-
+/**
+ * Disconnect from manager
+ *
+ */
int fwp_mngt_disconnect()
{
fwp_msgb_t *msgb;
return 0;
}
-
+/**
+ * FWP Management initialization
+ * - creates and initializes fwp_participant_this
+ * - creates and initializes fwp_participant_mngr
+ * - calls fwp_mngt
+ */
int fwp_mngt_init()
{
fwp_participant_info_t my_info, mngr_info;
#include "fwp_msg.h"
/**
+ * \file fwp_msg.c
+ *
* Routines for serializing and deserializing FWP messages.
*
* (It should be in separate library.)
* Participant of FWP
*
*/
-
typedef
struct fwp_participant {
fwp_participant_id_t id;
+/**
+ * \file fwp_resource.h
+ *
+ * NOT USED!!
+ *
+ *
+ */
#ifndef _FWP_RESOURCE_H
#define _FWP_RESOURCE_H
-/**< NOT USED!! */
-
typedef unsigned int fwp_resource_id_t;
typedef unsigned int fwp_resource_d_t;
#define FWP_MTU 2346
#define BUFFSIZE FWP_MTU
-/* buffer and socket for incomming message */
-static unsigned char buffer[FWP_MTU];
-/* FIXME: This could be moved to local static variable in
- * fwp_mngt_input() */
-
/* Admission control test */
fwp_admctrl_test_t fwp_admctrl_test = &fwp_admctrl_stupid;
*/
int fwp_mngr_input(struct fwp_msgb **pmsgb)
{
+ /* buffer and socket for incomming message */
+ static unsigned char buffer[FWP_MTU];
struct fwp_msgb *msgb;
ssize_t size;
pthread_mutex_unlock(&fwp_participant_table.lock);
}
-fwp_participant_t* fwp_participant_table_find(fwp_participant_id_t *participant_id)
+fwp_participant_t*
+fwp_participant_table_find(fwp_participant_id_t *participant_id)
{
- return _fwp_participant_table_find(&fwp_participant_table, participant_id);
+ return _fwp_participant_table_find(&fwp_participant_table,
+ participant_id);
}
int fwp_participant_table_delete(fwp_participant_t *participant)
+/**
+ * \file fwp_mngrtest.c
+ *
+ * This is a test application that:
+ * - connects to manager
+ * - negotiates contract
+ * - creates send endpoint and binds it to vres
+ * - sends and receives two messages Hello1 and Hello2
+ * - cancels contract
+ * - disconnects from manager
+ */
+
#define CONFIGURE_MNGR_ADDR 127.0.0.1
#include "fwp_confdefs.h"
#include "fwp.h"
+/**
+ * \file fwp_msgtest.c
+ *
+ * This is a test application for msg handling that
+ * - allocates two msgb
+ * - serializes two contracts into msgb
+ * - put both msgb to message queue
+ * - revert previous steps
+ * - compare contracts
+ */
#include "fwp_msgq.h"
#include "fwp_msgb.h"
#include "fwp_msg.h"
+/**
+ * \file fwp_sendrecv_test1.c
+ *
+ * This a test application that:
+ * - creates two vres without negotiation
+ * - creates send and receive endpoint
+ * - binds that endpoint to vres
+ * - sends two messages
+ * - receives messages
+ * - destroys vres
+ *
+ */
#define CONFIGURE_FWP_MNGT 0
#include "fwp_confdefs.h"
#include "fwp.h"
+/**
+ * \file fwp_sendrecv_test1.c
+ *
+ * This a test application that:
+ * - creates vres without negotiation
+ * - creates reliable send endpoint
+ * - cretaes receiver thread and receive endpoint within it
+ * - binds that endpoint to vres
+ * - sends two messages
+ * - receives messages
+ *
+ */
#define CONFIGURE_FWP_MNGT 0
#include "fwp_confdefs.h"
#include "fwp.h"
+/**
+ * \file fwp_vrestest1.c
+ *
+ * This a test application that:
+ * - creates vres without negotiation
+ * - creates send and receive endpoint
+ * - binds that endpoint to vres
+ * - in cycle (NUM loops) sends messages and prints send time
+ * - receives messages
+ * - destroys vres
+ *
+ */
#define CONFIGURE_FWP_MNGT 0
#include "fwp_confdefs.h"
#include "fwp.h"
+/**
+ * \file fwp_vrestest2.c
+ *
+ * This a test application that:
+ * - creates vres without negotiation
+ * - creates send and receive endpoint
+ * - binds that endpoint to vres
+ * - in cycle (NUM loops) sends messages in separate thread and
+ * prints send time
+ * - receives messages in separate receiver thread
+ * - destroys vres
+ *
+ */
#define CONFIGURE_FWP_MNGT 0
#include "fwp_confdefs.h"
#include "fwp.h"