#include "fwp_conf.h"
#include "fwp_msgb.h"
-/* FIXME: only typedefs should end by _t */
/** WMM defines 4 queues */
-enum ac_id_t {
+enum ac_id {
FWP_AC_VO = 0,
FWP_AC_VI = 1,
FWP_AC_BE = 2,
#ifndef _FWP_CONTRACT_H
#define _FWP_CONTRACT_H
-enum contract_status_t {
+#include "fwp_msgb.h"
+
+typedef enum {
FWP_CNT_INVALID = 0,
FWP_CNT_REQUESTED = 1,
FWP_CNT_REJECTED = 2,
FWP_CNT_NEGOTIATED = 3,
FWP_CNT_ACCEPTED = 4
-};
+}contract_status_t;
-//#warning Document which fileds should be filled by app and which are for internal use
-struct fwp_contract {
-//#warning What does global mean?
- unsigned int id; /**< global vres_id */
- /* FIXME: use enum ac_id */
- unsigned int ac_id; /**< AC id ~ priority of vres */
-//#warning id and ac_id should not be part of contract. It should be in vres. Probably, even the status field should be in vres. Vres is runtime representation of a contract.
+/**
+ * FWP contract info
+ * It is internal representation of the contract used inside
+ * protocol.
+ *
+ */
+struct fwp_contract_info { /* BETTER name ??*/
int budget; /**< bytes per period */
int period_usec; /**< all time units are in microseconds */
+
+ /**< global(assigned by manager) contract identifier*/
+ unsigned int id;
+ /* FIXME: use enum ac_id */
+ unsigned int ac_id; /**< AC id ~ priority of vres */
int status;
-};
+ /**< in distributed systems every contract must contain the address
+ * where it is applied.
+ */
+ struct fwp_socket cnt_addr;
+ unsigned int hid; /**< handshake ID, used in request-respone
+ message exchange to associate response with
+ request */
+};
#endif /*_FWP_CONTRACT_H */
#include <sys/socket.h>
#include <sys/un.h>
+/* DEPRECATED - to be changed */
enum ctable_entry_status_t {
FWP_CTENTRY_EMPTY = 0,
FWP_CTENTRY_FULL = 1
struct fwp_ctable_entry {
unsigned int hid;
- struct fwp_contract contract;
+ struct fwp_contract_info contract;
struct fwp_socket *claimer;
int status;
};
+
struct fwp_ctable {
struct fwp_ctable_entry entry[FWP_CONTRACT_MAX];
unsigned int nr_contract;
uint8_t status;
}__attribute__((packed));
-void fwp_msg_header_insert(unsigned char *data, unsigned int code, unsigned int hid);
void fwp_msg_header_parse(unsigned char *data, unsigned int *code, unsigned int *hid);
-void fwp_msg_contract_insert(unsigned char *data, struct fwp_contract *cnt);
-void fwp_msg_contract_parse(unsigned char *data, struct fwp_contract *cnt);
+void fwp_msg_contract_insert(unsigned char *data, struct fwp_contract_info *cnt);
+void fwp_msg_contract_parse(unsigned char *data, struct fwp_contract_info *cnt);
#endif /* _FWP_MSG_H */
#define FWP_AGENT_UNIXPATH "fag"
#define FWP_CLIENT_UNIXPATH "fcl" /*temporarily*/
-#include <fwp_contract.h>
+enum fwp_negt_status {
+ FWP_NEGT_ACCEPT = 0,
+ FWP_NEGT_DECLINE = 1,
+ FWP_NEGT_RUNNING = 3, /**< for asynchronous negotiations*/
+};
+
+/**
+ * FWP contract.
+ * It is an external representation of contract intented for application
+ * programmer.
+ *
+ */
+struct fwp_contract {
+ int budget; /**< bytes per period */
+ int period_usec; /**< all time units are in microseconds */
+};
int fwp_init();
void fwp_vres_table_init();
-int fwp_vres_open(struct fwp_contract *cnt);
+int fwp_vres_open(struct fwp_contract_info *cnt);
int fwp_vres_close(unsigned int id);
inline int fwp_vres_send(unsigned int id, struct fwp_msgb* msgb);
*hid = ntohs(header->hid);
}
-void fwp_msg_contract_insert(unsigned char *data, struct fwp_contract *cnt)
+void fwp_msg_contract_insert(unsigned char *data, struct fwp_contract_info *cnt)
{
struct fwp_msg_contract* msgcnt;
msgcnt->period_usec = htonl(cnt->period_usec);
}
-void fwp_msg_contract_parse(unsigned char *data, struct fwp_contract* cnt)
+void fwp_msg_contract_parse(unsigned char *data, struct fwp_contract_info *cnt)
{
struct fwp_msg_contract* msgcnt;
return 0;
}
-
+#if 0
/**
* Negotiates contract for application. Negotiation request is sent to
* fwp agent and then waits for response.
*
* \param[in] contract Contract to negotiate
- * \param[out] vres_id Id of vres if the contract was negotiated
+ * \param[out] vres_id Id of vres after the contract was accepted
+ *
+ * \return It returns FWP_NEGT_ACCEPT when the contract was accepted and
+ * identifier of created vres is return in vres_id parameter.
+ * It returns FWP_NEGT_DECLINE when the contract was declined.
*
- * \return Zero when the contract negotiation process was
- * successful with the result stored in contract->status,
- * negative number on error.
- *
+ * If an error occured it returns negative error code.
*/
-//#warning Which parameters are input and which output
-//#warning I propose to use returned vres_id to determine whether the contract was accepted.
int fwp_contract_negotiate(struct fwp_contract *contract, int *vres_id)
{
struct fwp_msgb *msgb;
{
return fwp_vres_close(vres_id);
}
+
+#endif
*
*/
struct fwp_vres{
- struct fwp_contract contract;
+ struct fwp_contract_info contract;
/* consideration: move tx_queue to endpoint */
- struct fwp_msgq tx_queue; /**< queue for messages to send */
- struct fwp_endpoint *epoint; /**< endpoint bounded to this vres */
- pthread_t tx_thread;
- pthread_attr_t tx_thread_attr;
- fwp_vres_status_t status;
+ /**< queue for messages to send */
+ struct fwp_msgq tx_queue;
+ /**< endpoint bounded to this vres */
+ struct fwp_endpoint *epoint;
+ pthread_t tx_thread;
+ pthread_attr_t tx_thread_attr;
+ fwp_vres_status_t status;
};
static struct fwp_vres fwp_vres_table[FWP_VRES_MAX];
fwp_vres_table[id].status = FWP_VRES_CLOSED;
}
-int fwp_vres_open(struct fwp_contract *cnt)
-/* queueing policy should be the next parameter*/
+int fwp_vres_open(struct fwp_contract_info *cnt)
{
int id,rc;
struct fwp_vres *vres;
vres->status = FWP_VRES_OPENED;
/* release fwp_vres_table mutex */
pthread_mutex_unlock(&vres_table_lock);
-
- memcpy(&vres->contract, cnt, sizeof(struct fwp_contract));
+ memcpy(&vres->contract, cnt, sizeof(struct fwp_contract_info));
fwp_msgq_init(&vres->tx_queue);
if ((rc = fwp_ac_open(vres->contract.ac_id)) < 0) {
period.tv_nsec = USEC_TO_NSEC*(vres->contract.period_usec);
period.tv_sec = 0;
- fwp_set_rt_prio(90 - vres->contract.ac_id);
+ fwp_set_rt_prio(90 - ac_id);
- FWP_DEBUG("vres tx thread with budget:%d period_usec = %d started.\n",
- vres->contract.budget, vres->contract.period_usec);
+ FWP_DEBUG("vres tx thread with budget:%d period_usec = %d started.\n",
+ vres->contract.budget, vres->contract.period_usec);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_cleanup_push(fwp_vres_cleanup, (void*)vres);
{
struct fwp_msgq msgq;
struct fwp_msgb *msgb;
- struct fwp_contract cnt_a, cnt_b, cnt_c, cnt_d;
+ struct fwp_contract_info cnt_a, cnt_b, cnt_c, cnt_d;
fwp_msgq_init(&msgq);
printf("in=%d out=%d pending=%d \n",msgq.in,msgq.out,msgq.nr_pending);
ssize_t len;
int vres_id1, vres_id2;
int i;
- struct fwp_contract cnt1;
- struct fwp_contract cnt2;
+ struct fwp_contract_info cnt1;
+ struct fwp_contract_info cnt2;
char msg1[] = "Hello1";
char msg2[] = "Hello2";
char buffer[30];