]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
fwp: Added test for checking list of stations
authorTuka Martin <tukamart@fel.cvut.cz>
Tue, 12 Apr 2011 21:41:49 +0000 (23:41 +0200)
committerTuka Martin <tukamart@fel.cvut.cz>
Tue, 12 Apr 2011 21:41:49 +0000 (23:41 +0200)
Adjusted mac address 'to number' converter.
Added test for checking right of handling with list of
stations.
Added function for printing list of stations.

src/fwp/fwp/mngr/Makefile.omk
src/fwp/fwp/mngr/fwp_mngr.c
src/fwp/fwp/mngr/test/Makefile.omk
src/fwp/fwp/mngr/test/list_of_stations_test.c [new file with mode: 0644]
src/fwp/fwp/mngr/test/list_of_stations_test.sh [new file with mode: 0755]
src/fwp/fwp/mngr/wifi_agent.c
src/fwp/fwp/mngr/wifi_agent.h
src/fwp/fwp/wifi_agent/wifi_agent.c

index 49d16f53208ebe5bd3630d758862b1e942936f0b..dd82eb3b0c0252b6b7d73865c1eabe9f049b14fb 100644 (file)
@@ -1,10 +1,15 @@
+shared_LIBRARIES += wifi_agent_functions
+wifi_agent_functions_SOURCES = wifi_agent.c
+wifi_agent_functions_SERVER_IDL = wifi_agent_idl.idl
+include_HEADERS = wifi_agent.h
+include_GEN_HEADERS = wifi_agent_idl.h
+
 bin_PROGRAMS = frm_fwp
 frm_fwp_SOURCES = fwp_mngr.c fwp_admctrl.c wifi_agent.c
-frm_fwp_LIBS = frm forb contract fosa rt ulut fcb_client
+frm_fwp_LIBS = frm forb contract fosa rt ulut wifi_agent_functions
 
 include_HEADERS = wifi_agent.h
 CFLAGS += -D_FWP_INTERNALS_
 lib_LOADLIBES+= frsh forb fosa pthread rt ulut
 
-frm_fwp_SERVER_IDL = wifi_agent_idl.idl
-include_GEN_HEADERS = wifi_agent_idl.h
+SUBDIRS = test
index 35e18d9a100d6300a857e54ab7622fae5d3479c8..f4fea8e76d97877ff99ef161b4d651796a1f9518 100644 (file)
@@ -141,7 +141,6 @@ int main(int argc, char *argv[])
 
        wifi_agent_idl wai;     //wifi agent interface
        struct fwp_sta intern_data;
-       
 
        if (getenv("FWP_BYPASS"))
                priv.bypass = true;
@@ -204,7 +203,7 @@ int main(int argc, char *argv[])
                        ret = -1;
                        goto destroy_and_error;
                }
-               
+
                forb_daemon_ready();
        
        ret = forb_executor_run(&executor);
index 4cd3b299eb1e32dfbcc53f497eab80913979868e..b7d1bf955ac609237c99120c73a42c81e21fef15 100644 (file)
@@ -1,3 +1,9 @@
 CFLAGS += -DWVTEST_CONFIGURED
 
-wvtest_SCRIPTS += adm-test.sh
+#wvtest_SCRIPTS += adm-test.sh
+
+wvtest_SCRIPTS += list_of_stations_test.sh
+test_PROGRAMS += list_of_stations_test
+list_of_stations_test_SOURCES = list_of_stations_test.c
+list_of_stations_test_LIBS += wvtest forb ulut wifi_agent_functions
+
diff --git a/src/fwp/fwp/mngr/test/list_of_stations_test.c b/src/fwp/fwp/mngr/test/list_of_stations_test.c
new file mode 100644 (file)
index 0000000..b7e7cea
--- /dev/null
@@ -0,0 +1,97 @@
+#include <forb.h>
+#include <error.h>
+#include <errno.h>
+#include <getopt.h>
+#include <fres_sa_scenario.h>
+#include <stdbool.h>
+#include <ul_list.h>
+#include <ul_log.h>
+#include <ul_logreg.h>
+#include <fwp_res.h>
+#include <stdio.h>
+#include <string.h>
+#include "wifi_agent_idl.h"
+#include "wifi_agent.h"
+#include "wvtest.h"
+
+typedef struct fwp_sta {
+       long long client_mac_addr;
+       int rate;       //mbps
+       bool erp_ofdm;
+       bool short_preamble;
+       bool bypass;
+       ul_list_node_t sta_node;        
+} fwp_sta_t;
+
+typedef struct fwp_sta_list {
+       ul_list_head_t requests;
+} fwp_sta_list_t;
+
+struct frm_fwp_priv {
+       int rate_mbps;
+       bool erp_ofdm;
+       bool short_preamble;
+       bool bypass;
+       fwp_sta_list_t sta_list;
+};
+
+UL_LIST_CUST_DEC(sta_list, // cust_prefix
+                fwp_sta_list_t, // cust_head_t
+                fwp_sta_t, // cust_item_t
+                requests, // cust_head_field
+                sta_node); // cust_node_field
+
+struct forb_wifi_agent_idl_impl wifi_agent_impl;
+
+struct frm_fwp_priv priv = {
+       .rate_mbps = 1,
+       .erp_ofdm = false,
+       .short_preamble = false,
+//     .list_head = NULL,//head of linked list initialized in main function
+};
+
+//WVTEST_MAIN("list-of-stations-test")
+int main(void)
+{
+       forb_orb orb;
+       int ret;
+       bool opt_daemon = false;
+       char *opt_pidfile = NULL;
+
+       forb_executor_t executor;
+
+       wifi_agent_idl wai;     //wifi agent interface
+       struct fwp_sta intern_data;
+       CORBA_Environment env;
+
+       if (getenv("FWP_BYPASS"))
+               priv.bypass = true;
+
+       if (opt_daemon)
+               forb_daemon_prepare(opt_pidfile);
+
+       orb = forb_init(NULL, NULL, NULL);
+       if (!orb) return 1;
+       
+        wai = forb_wifi_agent_idl_new(orb, &wifi_agent_impl, &intern_data);
+        
+        forb_register_reference(wai, "net.sourceforge.frsh-forb.wai");
+
+       sta_list_init_head(&priv.sta_list);
+       
+       ret = forb_executor_init(&executor);
+       if (ret) return 1;
+       
+       ret = forb_executor_register_object(&executor, wai);
+       if (ret) return 1;
+
+       wifi_agent_idl_add(wai, 10, 120976291, &env);
+       wifi_agent_idl_add(wai, 12, 120976291, &env);
+       wifi_agent_idl_add(wai, 20, 80976291, &env);
+       //wifi_agent_idl_add(wai, 64, 80955472, &env);
+       //wifi_agent_idl_add(wai, 1, 80976291, &env);
+       //wifi_agent_idl_add(wai, 10, 120976291, &env);         
+       
+       return 0;
+}
+
diff --git a/src/fwp/fwp/mngr/test/list_of_stations_test.sh b/src/fwp/fwp/mngr/test/list_of_stations_test.sh
new file mode 100755 (executable)
index 0000000..1f55f15
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+. $(dirname $0)/wvtest.sh
+
+wvtest_cleanup() {
+    WVPASS kill `cat fcb.pid`
+    WVPASS rm fcb.pid
+}
+
+WVPASS fcb -dfcb.pid
+
+cat > expected << EOF
+Added new station
+Actual list of all stations
+[mac address (dec) - rate]
+120976291 - 10
+------------
+
+Changed rate in a station 120976291
+Actual list of all stations
+[mac address (dec) - rate]
+120976291 - 12
+------------
+
+Added new station
+Actual list of all stations
+[mac address (dec) - rate]
+120976291 - 12
+80976291 - 20
+------------
+
+EOF
+
+WVPASS sh -c "list_of_stations_test > actual"&
+R1=$!
+
+WVPASS diff -u expected actual
+
+kill $R1
+
index 71339c221983c18964a3d3f26e02e763cef537bd..69c9ed17b27f1eacaa11824b3afbc064023135dc 100644 (file)
@@ -1,6 +1,4 @@
 
-#include "wifi_agent_idl.h"
-//#include "wifi_agent_idl.h"
 #include <frm_generic.h>
 #include <forb.h>
 #include <error.h>
@@ -21,6 +19,18 @@ struct forb_wifi_agent_idl_impl wifi_agent_impl = {
        .add = wifi_agent_idl_add, 
 };
 
+void print_list_of_stations(void)
+{
+       fwp_sta_t *sta2;
+
+       ul_list_for_each(sta_list, &priv.sta_list, sta2){
+               printf("%llu -", sta2->client_mac_addr);        
+               printf(" %d\n", sta2->rate);
+       }
+       printf("------------\n\n");
+       
+}
+
 /**
  *     Add information about AP (mac_address & bit rate)
  */
@@ -31,17 +41,24 @@ CORBA_long wifi_agent_idl_add(wifi_agent_idl _obj, const CORBA_long rate, const
        fwp_sta_t *new_to_add;
 
        new_to_add = (fwp_sta_t*)malloc(sizeof(fwp_sta_t));
-       
+
        //client transmission bitrate (wifi_agent -> fwp_manager)
        ed->rate = rate;
        ed->client_mac_addr = client_mac_addr;
+
        //fill the linked list here
        //for each list         
        ul_list_for_each(sta_list, &priv.sta_list, sta){
                //client was sending info before
+               
                if(sta->client_mac_addr == ed->client_mac_addr) {
                        //mac address is the same change only rate
                        sta->rate = ed->rate;
+       
+                       printf("Changed rate in a station %d\n", sta->client_mac_addr);
+                       printf("Actual list of all stations\n[mac address (dec) - rate]\n");
+                       print_list_of_stations();
+
                        return 0;
                }
        }
@@ -50,6 +67,11 @@ CORBA_long wifi_agent_idl_add(wifi_agent_idl _obj, const CORBA_long rate, const
        new_to_add->client_mac_addr = ed->client_mac_addr;
        
        sta_list_ins_tail(&priv.sta_list, new_to_add);
-       
+
+       printf("Added new station\n");
+       printf("Actual list of all stations\n[mac address (dec) - rate]\n");
+       print_list_of_stations();
+
        return 0;
 }
+
index 44ccb9149802e2ea09f31989ffc5df4c377db709..4d9b20ca7c54e5614b1409c32bf7b57b1103b707 100644 (file)
@@ -6,7 +6,7 @@
 #define WAI_SERVER_ID (forb_server_id){ .uuid = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 } }
 #define WAI_TCP_PORT 24943
 
-extern struct forb_wifi_agent_idl_impl wifi_agent_impl ;
+extern struct forb_wifi_agent_idl_impl wifi_agent_impl;
 
 #endif
 
index 6c3ea8a00f79e0a39a5b4c11edb036579a5af78d..6813723f84b6e169adb7aefc92eed116f7d162f0 100644 (file)
@@ -151,22 +151,33 @@ long long mac_addr_string_to_number(char * mac)
        long long help;
        int ix;
        int ix2;
+       char mac_num[12];
+
+       mac_num[0] = mac[0];
+       mac_num[1] = mac[1];
+       mac_num[2] = mac[3];
+       mac_num[3] = mac[4];
+       mac_num[4] = mac[6];
+       mac_num[5] = mac[7];
+       mac_num[6] = mac[9];
+       mac_num[7] = mac[10];
+       mac_num[8] = mac[12];
+       mac_num[9] = mac[13];
+       mac_num[10] = mac[15];
+       mac_num[11] = mac[16];
 
        number = 0;
 
-       for(ix = 0; ix <= 17 ; ix++)
+       for(ix = 0; ix <= 12 ; ix++)
        {       
-               if(mac[ix] == ':')
-                       continue;
-               else
-               {
-                       help = 1;
-                       for(ix2 = 1; ix2 < 12 - ix; ix2++)
-                               help *= 16;  
-                       number += atoint(mac[ix]) * help;
-               }
-       }
+               help = 1;
+               for(ix2 = 1; ix2 < 12 - ix; ix2++)
+                       help *= 16;  
+               number += atoint(mac_num[ix]) * help;
 
+       }
+       
+       printf("%llu \n", number);
        return number;
 }
 
@@ -330,7 +341,7 @@ int main(int argc, char **argv)
        fwp_orb = forb_init(&argc, &argv, NULL); /* FORB initialization */
 
        /* Find our implementation */
-        wai = forb_resolve_reference(fwp_orb, "wai");
+        wai = forb_resolve_reference(fwp_orb, "net.sourceforge.frsh-forb.wai");
        if(wai == NULL)
                fprintf(stderr, "failed to create connection\n");       
 
@@ -347,8 +358,9 @@ int main(int argc, char **argv)
        
                /* Call server functions and send wifi info */
                if(wai != NULL)
-                       wifi_agent_idl_add(wai, rate_glob, mac_addr_string_to_number(mac_addr_glob), &env);
-
+               {       printf("%d \n", rate_glob);
+                       wifi_agent_idl_add(wai, rate_glob / 10, mac_addr_string_to_number(mac_addr_glob), &env);
+               }
                //TODO: Optimalize sending interval
                delay(10000);
        }