]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Split internal and external representation of contract
authorMartin Molnar <molnar@sum.(none)>
Tue, 12 Feb 2008 11:49:40 +0000 (12:49 +0100)
committerMartin Molnar <molnar@sum.(none)>
Tue, 12 Feb 2008 11:49:40 +0000 (12:49 +0100)
fwp/libfwp/include/fwp_ac.h
fwp/libfwp/include/fwp_contract.h
fwp/libfwp/include/fwp_ctable.h
fwp/libfwp/include/fwp_msg.h
fwp/libfwp/include/fwp_proto.h
fwp/libfwp/include/fwp_vres.h
fwp/libfwp/src/fwp_msg.c
fwp/libfwp/src/fwp_proto.c
fwp/libfwp/src/fwp_vres.c
fwp/tests/fwp_msgtest/fwp_msgtest.c
fwp/tests/fwp_prototest/fwp_sendrecv_test.c

index a751bd003a9de2889b02bdc35079fadc5bf8c874..053505ec12a42023b81a7f8891333824a9a3accc 100644 (file)
@@ -13,9 +13,8 @@
 #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,
index 9616c0c68991ecb1a7f51f529a0dc25b56142691..0f44150dba03c77293843df429306f8d3e988e30 100644 (file)
@@ -1,25 +1,39 @@
 #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 */ 
index c2157d54965736b5c651ab6d6f1744462e2500de..904a58c89e5379d5ad1fbd809539c8aebc99c76d 100644 (file)
@@ -8,6 +8,7 @@
 #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
@@ -15,11 +16,12 @@ enum ctable_entry_status_t {
 
 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;
index bb786b43f1211000f21d1b2bd73e682b1dc745a5..075a7bc8c4a60e29389189cc50c716e31b283586 100644 (file)
@@ -20,10 +20,9 @@ struct fwp_msg_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 */
index 67aa6c17bdfc26b31fb205baa8e6d5db1d7c66ae..a5557fbdc56648d685f405440d6a96768fdcf454 100644 (file)
@@ -4,7 +4,22 @@
 #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();
 
index 325e4ff93c187536db8123103d0b1eb782fd3ee6..09da6cc7dc3955970561c9faa90c5bf56d2698f9 100644 (file)
@@ -8,7 +8,7 @@
 
 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);
index 8deb99438feeb999f8720f6319f6afc53fe9c418..11faa4e01390d84aa416991483705e3cda450b74 100644 (file)
@@ -26,7 +26,7 @@ void fwp_msg_header_parse(unsigned char *data, unsigned int *code,
        *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;
 
@@ -43,7 +43,7 @@ void fwp_msg_contract_insert(unsigned char *data, struct fwp_contract *cnt)
        msgcnt->period_usec = htonl(cnt->period_usec);
 }
 
-void fwp_msg_contract_parse(unsigned char *data, struct fwp_contractcnt)
+void fwp_msg_contract_parse(unsigned char *data, struct fwp_contract_info *cnt)
 {
        struct fwp_msg_contract* msgcnt;
 
index 714906786e5c0a1224c0afe98855acb675e5c8a3..03d7d3e126edeb42970e488188a0aa01436aee9b 100644 (file)
@@ -41,21 +41,20 @@ int fwp_init()
        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;
@@ -111,3 +110,5 @@ int fwp_contract_cancel(unsigned int vres_id)
 {
        return fwp_vres_close(vres_id);
 }
+
+#endif
index 2ca883ced855184e4a60ead84ae1c8631f2da58e..c16ceab8f881d9d177200cdd8d7e1500e68d8536 100644 (file)
@@ -25,13 +25,15 @@ typedef unsigned int  fwp_vresid_t;
  * 
  */
 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];
@@ -54,8 +56,7 @@ void fwp_vres_table_init()
                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;
@@ -82,8 +83,7 @@ int fwp_vres_open(struct fwp_contract *cnt)
        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) {
@@ -162,10 +162,10 @@ static void* fwp_vres_tx_thread(void *_vres)
        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);
index 887d6c25a09df36ce6b7a19c8be8ac781462d729..599a1930ad2c69f552abb08449d2f1d3de4c78cd 100644 (file)
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
 {
        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);
index f1e8db252c2318e39fecff002fd9f2deacd8ad93..df335c464b7ccc587dfc65ac41239d0e802317f4 100644 (file)
@@ -12,8 +12,8 @@ int main()
         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];