summaryrefslogtreecommitdiff
path: root/maximus
diff options
context:
space:
mode:
authorburet2008-02-29 08:56:45 +0000
committerburet2008-02-29 08:56:45 +0000
commit30acb80faa92a0e67d15fb64962050d8920f7c46 (patch)
treea1b6798560e0bf472cee8235025cf6028aa70fd3 /maximus
parentec943b37ce30efba9fb8a1bf27fb91e0024b947a (diff)
Maximus V2: Implement the timeout reception feature in Maximus Python.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1510 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'maximus')
-rw-r--r--maximus/python/maximus/macframe/mpdu.py6
-rw-r--r--maximus/python/maximus/macframe/msdu.py6
-rw-r--r--maximus/python/maximus/simu/rx.py22
-rw-r--r--maximus/python/maximus/simu/tx.py2
-rw-r--r--maximus/python/test/test_ethernet.py3
-rw-r--r--maximus/python/test/test_macframe.py14
-rw-r--r--maximus/python/test/test_mme.py11
-rw-r--r--maximus/python/test/test_simu.py4
8 files changed, 48 insertions, 20 deletions
diff --git a/maximus/python/maximus/macframe/mpdu.py b/maximus/python/maximus/macframe/mpdu.py
index 0377364ccb..8f91fe44d9 100644
--- a/maximus/python/maximus/macframe/mpdu.py
+++ b/maximus/python/maximus/macframe/mpdu.py
@@ -132,15 +132,13 @@ class MPDU:
def sendnrecv(self, maximus, fc_mode=4, short_ppdu=0, mod=4, file=None, timeout=None, filter=None, count=1):
"""This function sends the MPDU synchronously.
"""
- from maximus.simu.rx import Rx
+ from maximus.simu.rx import recv
# Set MPDU attributes for Maximus
self.fill_mpdu_attr(fc_mode, short_ppdu, mod)
- # Create an RX object for MAC Frame(s) reception
- rx = Rx(maximus, filter_fc=filter, counter=count)
# Request to Maximus to send the MPDU synchronously
maximus.send_mpdu(self)
# Return the received MAC Frame(s)
- return rx.recv()
+ return recv(maximus, timeout=timeout, filter=filter, count=count)
def send(self, maximus, fc_mode=4, short_ppdu=0, mod=4, file=None):
"""This function sends the MPDU asynchronously.
diff --git a/maximus/python/maximus/macframe/msdu.py b/maximus/python/maximus/macframe/msdu.py
index cb14dfcb40..9bf4504d45 100644
--- a/maximus/python/maximus/macframe/msdu.py
+++ b/maximus/python/maximus/macframe/msdu.py
@@ -26,15 +26,13 @@ class MSDU:
def sendnrecv(self, maximus, station, file=None, timeout=None, filter=None, count=1):
"""This function sends the MSDU synchronously.
"""
- from maximus.simu.rx import Rx
- # Create an RX object for Ethernet Frame(s) reception
- rx = Rx(maximus, filter_fc=filter, counter=count)
+ from maximus.simu.rx import recv
# Request to Maximus to send the MSDU synchronously
while not station.is_idle():
maximus.process()
maximus.send_msdu(self, station.get_station_id())
# Return the received Ethernet Frame(s)
- return rx.recv()
+ return recv(maximus, timeout=timeout, filter=filter, count=count)
def send(self, maximus, station, file=None):
"""This function sends the MSDU asynchronously.
diff --git a/maximus/python/maximus/simu/rx.py b/maximus/python/maximus/simu/rx.py
index 6f7f934642..d4257bf12a 100644
--- a/maximus/python/maximus/simu/rx.py
+++ b/maximus/python/maximus/simu/rx.py
@@ -48,13 +48,23 @@ class Rx:
self.__maximus.set_mpdu_rx(self.__cb, create_pb)
self.__maximus.set_msdu_rx(self.__cb, create_eth, create_mme, create_buffer, create_sniffer)
- def recv(self):
+ def recv(self, timeout=None):
"""This function only returns when the response defined by user is received,
- i.e. when the messages counter equals 0.
- The returned value is the received frame(s) list.
+ i.e. when the messages counter equals 0,
+ or when the timeout expires.
+ The returned value is the received frame(s) list,
+ or None if timeout has expired before receiving any frame.
"""
- while self.get_counter() != 0:
- self.__maximus.process()
+ if timeout is None:
+ while self.get_counter() != 0:
+ self.__maximus.process()
+ elif type(timeout) is int or long and timeout >= 0:
+ # Calculate timeout tick value
+ timeout_tick_value = self.__maximus.get_date() + timeout
+ while self.get_counter() != 0 and self.__maximus.get_date() < timeout_tick_value:
+ self.__maximus.process()
+ else:
+ raise OutOfRangeError("Timeout")
return self.get_frame_list()
def set_filter_fc(self, filter_fc):
@@ -123,4 +133,4 @@ def recv(maximus, timeout=None, filter=None, count=1):
# Create an RX object for frame(s) reception
rx = Rx(maximus, filter_fc=filter, counter=count)
# Return the received frame(s)
- return rx.recv()
+ return rx.recv(timeout)
diff --git a/maximus/python/maximus/simu/tx.py b/maximus/python/maximus/simu/tx.py
index 0204780e43..0e3f679531 100644
--- a/maximus/python/maximus/simu/tx.py
+++ b/maximus/python/maximus/simu/tx.py
@@ -2,7 +2,7 @@
#print __name__
-def sendnrecv(file, filter=None, timeout=None, count=1):
+def sendnrecv(file, timeout=None, filter=None, count=1):
pass
def send(file, count=1):
diff --git a/maximus/python/test/test_ethernet.py b/maximus/python/test/test_ethernet.py
index 204b226d89..dba7a75529 100644
--- a/maximus/python/test/test_ethernet.py
+++ b/maximus/python/test/test_ethernet.py
@@ -274,7 +274,8 @@ class TestBufferFunctions(unittest.TestCase):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
data_buffer = Buffer('ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=2)
- rsp = data_buffer.sendnrecv(self.m, sta, count=0) # count = 0 because no answer is expected
+ rsp = data_buffer.sendnrecv(self.m, sta)[0]
+ self.assertEqual(rsp.get_type(), 'ETHERNET_TYPE_SNIFFER')
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
diff --git a/maximus/python/test/test_macframe.py b/maximus/python/test/test_macframe.py
index 42d504ee7c..6f85f7628c 100644
--- a/maximus/python/test/test_macframe.py
+++ b/maximus/python/test/test_macframe.py
@@ -291,7 +291,12 @@ class TestMACFrameFunctions(unittest.TestCase):
def test_sendnrecv(self):
# Tested in 'py/test_tx_rx.py' because another station is needed for this test
- pass
+ # Here, just test the timeout
+ t = self.m.get_date()
+ d = 250000
+ rsp = self.macframe.sendnrecv(self.m, timeout=d)
+ self.assertEqual(rsp, None)
+ self.assertEqual(self.m.get_date(), t + d)
def test_send(self):
prepare_rx(self.sta)
@@ -386,7 +391,12 @@ class TestMACFrameQueueFunctions(unittest.TestCase):
def test_sendnrecv(self):
# Tested in 'py/test_tx_rx.py' because another station is needed for this test
- pass
+ # Here, just test the timeout
+ t = self.m.get_date()
+ d = 250000
+ rsp = self.macframequeue.sendnrecv(self.m, timeout=d)
+ self.assertEqual(rsp, None)
+ self.assertEqual(self.m.get_date(), t + d)
def test_send(self):
prepare_rx(self.sta, pb_nb=3)
diff --git a/maximus/python/test/test_mme.py b/maximus/python/test/test_mme.py
index e1936e55e9..e6a7be1621 100644
--- a/maximus/python/test/test_mme.py
+++ b/maximus/python/test/test_mme.py
@@ -32,7 +32,7 @@ mme1.send(m, staRx)
mme2 = MME()
# Send the MME asynchronously
-#rsp = mme2.sendnrecv(m)
+rsp = mme2.sendnrecv(m, staRx, timeout=250000)
# Remove the destination station
staRx.remove()
@@ -204,7 +204,14 @@ class TestMMEFunctions(unittest.TestCase):
def test_sendnrecv(self):
# Tested in 'py/test_ether.py' because another station is needed for this test
- pass
+ # Here, just test the timeout
+ sta = self.m.create_sta()
+ t = self.m.get_date()
+ d = 250000
+ rsp = self.mme.sendnrecv(self.m, sta, timeout=d)
+ self.assertEqual(rsp, None)
+ self.assertEqual(self.m.get_date(), t + d)
+ sta.remove()
def test_send(self):
sta = self.m.create_sta()
diff --git a/maximus/python/test/test_simu.py b/maximus/python/test/test_simu.py
index 28465b54d9..6a3f2b9952 100644
--- a/maximus/python/test/test_simu.py
+++ b/maximus/python/test/test_simu.py
@@ -103,6 +103,10 @@ class TestRxFunctions(unittest.TestCase):
def test_recv(self):
self.assertEqual(recv(maximus=m, timeout=None, filter=None, count=0), None)
+ t = m.get_date()
+ d = 750001
+ recv(maximus=m, timeout=d)
+ self.assertEqual(m.get_date(), t + 1000000)
suite = unittest.TestLoader().loadTestsFromTestCase(TestRxFunctions)