summaryrefslogtreecommitdiff
path: root/cesar/test_general
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-07-19 13:31:03 +0200
committerNélio Laranjeiro2011-07-20 17:37:07 +0200
commit8bf24c9a1b414e593f198efc0e55ef7914e575cb (patch)
treefb27a904361485ba43844a36650639b1fd3889c1 /cesar/test_general
parent839e26e4706c719ec2732032f7bb5dd9e2015001 (diff)
cesar/test_general: improve NEK exchange verification, refs #2627
The python test compare the beacon period dates at the one the NEK index is changed. The dates in station side must correspond to the CCo's side.
Diffstat (limited to 'cesar/test_general')
-rw-r--r--cesar/test_general/station/cco0/s2/py/sc14_change_nek.py124
-rw-r--r--cesar/test_general/station/common/src/station.c1
-rw-r--r--cesar/test_general/station/fcall/fcall.h11
-rw-r--r--cesar/test_general/station/fcall/src/beacon.c28
4 files changed, 129 insertions, 35 deletions
diff --git a/cesar/test_general/station/cco0/s2/py/sc14_change_nek.py b/cesar/test_general/station/cco0/s2/py/sc14_change_nek.py
index 91db383544..9df5d51540 100644
--- a/cesar/test_general/station/cco0/s2/py/sc14_change_nek.py
+++ b/cesar/test_general/station/cco0/s2/py/sc14_change_nek.py
@@ -11,6 +11,7 @@ sys.path.append ('../../../../maximus/python/')
sys.path.append ('../../../../maximus/python/lib/cesar')
from csicore import *
+from own_data import Schedules
csi = csiCore (1234)
@@ -32,6 +33,49 @@ csi.process_wait_association (15)
csi.process_wait_authentication (15)
csi.authentication_status (avln1)
+class EKS:
+ """Define an EKS class."""
+ def __init__ (self, eks, nek):
+ """Initialise the class with the EKS and the NEK.
+ - eks: encryption key select
+ - nek: network encryption key.
+ """
+ self.eks = eks
+ self.nek = nek
+
+ def is_valid (self):
+ """Verify the EKS is valid.
+ In AV specification, an EKS valid is a value between 0 and 7
+ included. 15 Is the clear value.
+ Return true if the NEK is valid.
+ """
+ return (self.eks >= 0 and self.eks <= 7)
+
+def get_nek (csi, sta):
+ """Require the NEK from a station."""
+ fcall = csi.get_maximus().create_fcall ("fc_nek_get")
+ fcall.set_sta (sta.get_sta_cesar().get())
+ fcall.send ()
+ # Get the neks.
+ e = []
+ for i in range (2):
+ eks = 0
+ nek = ""
+ eks = fcall.bind_param_n_u32 ("eks" + str(i))[0]
+ for j in range (4):
+ nek += "%08x" \
+ % (fcall.bind_param_n_u32 ("nek" + str(i) + str (j))[0])
+ e.append (EKS (eks, nek))
+ return e
+
+def compare_keys (key1, key2):
+ """Compare two keys.
+ - key1: encryption key select class.
+ - key2: encryption key select class.
+ return true is equals.
+ """
+ return key1.eks == key2.eks and key1.nek == key2.nek
+
class TestNEKChange(unittest.TestCase):
def setUp(self):
@@ -58,41 +102,51 @@ class TestNEKChange(unittest.TestCase):
fcall = csi.get_maximus().create_fcall ("fc_cco_change_nek")
fcall.set_sta (cco.get_sta_cesar().get())
fcall.send()
- # Wait 1 second.
- csi.process_wait_sec (1)
- fcall = csi.get_maximus().create_fcall ("fc_nek_get")
- fcall.set_sta (cco.get_sta_cesar().get())
- fcall.send ()
- # Get the neks.
- cco_eks = []
- cco_nek_enc = []
- for i in range (2):
- cco_eks.append (fcall.bind_param_n_u32 ("eks" + str(i))[0])
- for j in range (4):
- cco_nek_enc.append (fcall.bind_param_n_u32 ("nek" + str(i) \
- + str (j))[0])
- self.failUnless (cco_eks[0] != cco_eks[1]);
- csi.process_wait_sec (1)
- fcall = csi.get_maximus().create_fcall ("fc_nek_get")
- fcall.set_sta (sta.get_sta_cesar().get())
- fcall.send ()
- # Get the neks.
- sta_eks = []
- sta_nek_enc = []
- for i in range (2):
- sta_eks.append (fcall.bind_param_n_u32 ("eks" + str(i))[0])
- for j in range (4):
- sta_nek_enc.append (fcall.bind_param_n_u32 ("nek" + str(i) \
- + str (j))[0])
- self.failUnless (sta_eks[0] != sta_eks[1]);
- for i in range (2):
- print "CCo EKS " + str(cco_eks[i]) \
- + " STA EKS " + str(sta_eks[i])
- self.failUnless (cco_eks[i] == sta_eks[i])
- for j in range (4):
- print "CCo NEK " + str(cco_nek_enc[j]) \
- + " STA NEC " + str (sta_nek_enc[j])
- self.failUnless (cco_nek_enc[j] == sta_nek_enc[j])
+ # let time for MME to be exchange.
+ csi.process_wait_sec (0.010)
+ for i in range (0, 15):
+ print "Verify NEK on both CCo and STA"
+ cco_keys = get_nek (csi, cco)
+ sta_keys = get_nek (csi, sta)
+ if not (compare_keys (cco_keys[0], cco_keys[1]) \
+ or compare_keys (sta_keys[0], sta_keys[1])) \
+ and compare_keys (cco_keys[0], sta_keys[0]) \
+ and compare_keys (cco_keys[1], sta_keys[1]):
+ break
+ # The EKS must be valid.
+ print "CCo keys"
+ for i in cco_keys:
+ self.failUnless (i.is_valid ())
+ print "EKS %d NEK %s" % (i.eks, i.nek)
+ print "STA keys"
+ for i in sta_keys:
+ self.failUnless (i.is_valid ())
+ print "EKS %d NEK %s" % (i.eks, i.nek)
+ # Verify NEK switch.
+ while True:
+ print "Verifying NEK switch in both CCo and STA"
+ cco_schedule = Schedules ()
+ cco_schedule.get_schedules (csi.get_maximus (),
+ cco.get_sta_cesar ())
+ sta_schedule = Schedules ()
+ sta_schedule.get_schedules (csi.get_maximus (),
+ sta.get_sta_cesar ())
+ # It must check that at the same beacon period the values are
+ # equals between the CCo and the STA.
+ for i in range (len (cco_schedule.bpsd)):
+ if cco_schedule.bpsd[i] == sta_schedule.bpsd[i]:
+ print "CCo nek index %d STA nek index %d" \
+ % (cco_schedule.nek_index[i],
+ sta_schedule.nek_index[i])
+ self.failUnless (cco_schedule.coexistence_mode[i] ==
+ sta_schedule.coexistence_mode[i])
+ self.failUnless (cco_schedule.snid[i] ==
+ sta_schedule.snid[i])
+ self.failUnless (cco_schedule.nek_index[i] ==
+ sta_schedule.nek_index[i])
+ if cco_keys[1].eks == cco_schedule.nek_index[0]:
+ break
+ csi.process_wait_sec (0.040)
csi.process_avlns_remove ()
suite = unittest.TestLoader().loadTestsFromTestCase(TestNEKChange)
diff --git a/cesar/test_general/station/common/src/station.c b/cesar/test_general/station/common/src/station.c
index 56736c35a7..7a21f3d4d3 100644
--- a/cesar/test_general/station/common/src/station.c
+++ b/cesar/test_general/station/common/src/station.c
@@ -122,6 +122,7 @@ cyg_user_start (void)
fcall_register (fcall, "fc_cco_change_nek",
&fc_cco_change_nek, cesar);
fcall_register (fcall, "fc_nek_get", &fc_nek_get, cesar);
+ fcall_register (fcall, "fc_schedules_get", &fc_schedules_get, cesar);
#if CONFIG_TRACE
fcall_register (fcall, "fc_sta_trace_dump_cl",
diff --git a/cesar/test_general/station/fcall/fcall.h b/cesar/test_general/station/fcall/fcall.h
index 74aa10558e..72809ff4dc 100644
--- a/cesar/test_general/station/fcall/fcall.h
+++ b/cesar/test_general/station/fcall/fcall.h
@@ -181,6 +181,17 @@ fc_nek_get (fcall_ctx_t *fcall, fcall_param_t **param,
sci_msg_t **msg, void *data);
/**
+ * Get the schedules programmed in the CA.
+ * \param fcall the fcall context.
+ * \param param the parameter structure.
+ * \param msg the simulator communication message.
+ * \param data the cesar structure.
+ */
+int
+fc_schedules_get (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data);
+
+/**
* Check if the memory is fully released.
* \param fcall the fcall context.
* \param param the parameter structure, which must be filled with the MAC
diff --git a/cesar/test_general/station/fcall/src/beacon.c b/cesar/test_general/station/fcall/src/beacon.c
index ebd06dddd5..bbb4bd53df 100644
--- a/cesar/test_general/station/fcall/src/beacon.c
+++ b/cesar/test_general/station/fcall/src/beacon.c
@@ -15,6 +15,7 @@
#include "cp/beacon/beacon.h"
#include "station/station.h"
#include "host/fcall/fcall.h"
+#include "mac/ca/inc/context.h"
#include "cp/fsm/fsm.h"
#include <string.h>
@@ -95,3 +96,30 @@ fc_nek_get (fcall_ctx_t *fcall, fcall_param_t **param,
}
return true;
}
+
+int
+fc_schedules_get (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ char id[20];
+ uint i;
+ ca_schedule_t *schedule;
+ cesar_t *cesar = data;
+ ca_t *ca = pbproc_get_ca (cesar->pbproc);
+ dbg_assert (data);
+ fcall_param_reset (*param);
+ for (i = 0; i < BSU_BEACON_SCHEDULES_NB; i++)
+ {
+ sprintf (id, "bpsd%d", i);
+ fcall_param_add_long (*param, *msg, id,
+ &ca->beacon_periods[i].start_date);
+ schedule = &ca->schedules[ca->beacon_periods[i].schedule_index];
+ sprintf (id, "hm%d", i);
+ fcall_param_add_long (*param, *msg, id, &schedule->coexistence_mode);
+ sprintf (id, "snid%d", i);
+ fcall_param_add_long (*param, *msg, id, &schedule->snid);
+ sprintf (id, "nek_index%d", i);
+ fcall_param_add_long (*param, *msg, id, &schedule->nek_switch);
+ }
+ return true;
+}