summaryrefslogtreecommitdiff
path: root/maximus
diff options
context:
space:
mode:
authorburet2008-03-12 18:07:08 +0000
committerburet2008-03-12 18:07:08 +0000
commitf0b33b90efa6e8be3b4a905b52dfa172e6fe44ed (patch)
tree0843a4ce95dc22721c974f16d9e0243b203003f7 /maximus
parent4135487d8996da51edf67b349dc47d75bfcf858c (diff)
Maximus V2: - HAL HLE => modify the INTERFACE message format of the IPMBox. - Maximus Python => add a function to automatically reallocate released buffers.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1593 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'maximus')
-rw-r--r--maximus/common/interfaces/Maximus.h8
-rw-r--r--maximus/common/types/ethernet_types.h29
-rw-r--r--maximus/coreengine/inc/MaximusTest.h2
-rw-r--r--maximus/coreengine/src/Maximus.cpp15
-rw-r--r--maximus/coreengine/src/MaximusTest.cpp21
-rw-r--r--maximus/ethernet/src/EtherSciMsg.cpp5
-rw-r--r--maximus/python/lib/cesar/sta_cesar.py8
-rw-r--r--maximus/python/maximus/ethernet/__init__.py2
-rw-r--r--maximus/python/maximus/ethernet/buffer.py103
-rw-r--r--maximus/python/maximus/ethernet/sniffer.py2
-rw-r--r--maximus/python/maximus/macframe/msdu.py1
-rw-r--r--maximus/python/maximus/station/sta.py70
-rw-r--r--maximus/python/py/test_ether.py48
-rw-r--r--maximus/python/src/interface_module.cpp30
-rw-r--r--maximus/python/test/test_ethernet.py85
-rw-r--r--maximus/python/test/test_interface.py6
-rw-r--r--maximus/stationtest/src/test_ether.c41
-rw-r--r--maximus/stationtest/src/test_station.c4
18 files changed, 384 insertions, 96 deletions
diff --git a/maximus/common/interfaces/Maximus.h b/maximus/common/interfaces/Maximus.h
index eb643f87b6..f87358d976 100644
--- a/maximus/common/interfaces/Maximus.h
+++ b/maximus/common/interfaces/Maximus.h
@@ -36,6 +36,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/interfa
#include "networkclock_types.h" // for 'tick_t'
#include "channel_types.h" // for 'MAXIMUS_CHANNEL_INTERVAL_MAX_NB'
+#include "sci_types.h" // for 'Sci_Msg_Station_Id'
#include <fstream> // for 'std::ofstream'
#include <string> // for 'std::string'
@@ -225,6 +226,13 @@ public:
*/
void deactivate_false_alarm ( );
+ /**
+ * Indicate if the station is IDLE or not.
+ * @param station_id the ID of the station
+ * @return 'true' if the station is IDLE, 'false' otherwise
+ */
+ const bool is_station_idle ( Sci_Msg_Station_Id station_id );
+
private:
// private attributes
diff --git a/maximus/common/types/ethernet_types.h b/maximus/common/types/ethernet_types.h
index d1f3c2ac86..752f6c185f 100644
--- a/maximus/common/types/ethernet_types.h
+++ b/maximus/common/types/ethernet_types.h
@@ -37,7 +37,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/types/e
// Ethernet_Header.flags
//
-typedef uint8_t Ethernet_Flags;
+typedef uint8_t Ethernet_Flags; // used in case of ETHERNET_TYPE_SNIFFER only
#define ETHERNET_FLAG_NONE 0x00
#define ETHERNET_FLAG_WAY 0x01 // Rx if set, Tx if none
#define ETHERNET_FLAG_ENCRYPTED 0x02 // If set, Ether SCI msg is encrypted
@@ -58,14 +58,25 @@ struct Ethernet_Header
enum Ethernet_Type
{
ETHERNET_TYPE_NONE = 0x00,
- ETHERNET_TYPE_DATA = 0x01, // Ether SCI msg data contain the MSDU (Ethernet Frame)
- ETHERNET_TYPE_MME = 0x02, // Ether SCI msg data contain the MSDU (MME)
- ETHERNET_TYPE_DATA_BUFFER_ADD = 0x03, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
- // and IDs of each buffer to allocate (uint32_t)
- ETHERNET_TYPE_MME_BUFFER_ADD = 0x04, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
- // and IDs of each buffer to allocate (uint32_t)
- ETHERNET_TYPE_BUFFER_RELEASED = 0x05, // Ether SCI msg data contain the ID of released buffer (uint32_t)
- ETHERNET_TYPE_SNIFFER = 0x06, // Ether SCI msg data contain a sniffed packet
+
+ /* HLE_MSG_TYPE_DATA > Data or MME message type. */
+ ETHERNET_TYPE_DATA = 0x01, // Ether SCI msg data contain the MSDU (Ethernet Frame)
+ ETHERNET_TYPE_MME = 0x02, // Ether SCI msg data contain the MSDU (MME)
+
+ /* HLE_MSG_TYPE_BUFFER_ADD > Buffer alloc message type. */
+ ETHERNET_TYPE_DATA_BUFFER_ADD = 0x03, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ // and IDs of each buffer to allocate (uint32_t)
+ ETHERNET_TYPE_MME_BUFFER_ADD = 0x04, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ // and IDs of each buffer to allocate (uint32_t)
+ ETHERNET_TYPE_INTERFACE_BUFFER_ADD = 0x05, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ // and IDs of each buffer to allocate (uint32_t)
+
+ /* HLE_MSG_TYPE_SEND_DONE > Buffer dealloc message type. */
+ ETHERNET_TYPE_BUFFER_RELEASED = 0x06, // Ether SCI msg data contain the ID of released buffer (uint32_t)
+
+ /* HLE_MSG_TYPE_INTERFACE > Interface message type. */
+ ETHERNET_TYPE_SNIFFER = 0x07, // Ether SCI msg data contain a sniffed packet
+
ETHERNET_TYPE_NB
};
diff --git a/maximus/coreengine/inc/MaximusTest.h b/maximus/coreengine/inc/MaximusTest.h
index a791534933..726cbc24d8 100644
--- a/maximus/coreengine/inc/MaximusTest.h
+++ b/maximus/coreengine/inc/MaximusTest.h
@@ -29,6 +29,7 @@ class MaximusTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (set_freq_test);
CPPUNIT_TEST (activate_false_alarm_test);
CPPUNIT_TEST (deactivate_false_alarm_test);
+ CPPUNIT_TEST (is_station_idle_test);
CPPUNIT_TEST_SUITE_END ();
public:
@@ -55,6 +56,7 @@ protected:
void set_freq_test (void);
void activate_false_alarm_test (void);
void deactivate_false_alarm_test (void);
+ void is_station_idle_test (void);
private:
diff --git a/maximus/coreengine/src/Maximus.cpp b/maximus/coreengine/src/Maximus.cpp
index b9ac579ff9..dfa37a30c3 100644
--- a/maximus/coreengine/src/Maximus.cpp
+++ b/maximus/coreengine/src/Maximus.cpp
@@ -908,6 +908,21 @@ void Maximus::deactivate_false_alarm ( )
}
+const bool Maximus::is_station_idle ( Sci_Msg_Station_Id station_id )
+{
+ logFunction();
+ bool isIdle = false;
+
+ try
+ {
+ isIdle = getSystemManager()->isStationIdle(station_id);
+ }
+ catchFunction(this);
+
+ return isIdle;
+}
+
+
// private methods
//
diff --git a/maximus/coreengine/src/MaximusTest.cpp b/maximus/coreengine/src/MaximusTest.cpp
index 055108f140..e9532c9b2c 100644
--- a/maximus/coreengine/src/MaximusTest.cpp
+++ b/maximus/coreengine/src/MaximusTest.cpp
@@ -421,3 +421,24 @@ void MaximusTest::deactivate_false_alarm_test (void)
}
}
+
+void MaximusTest::is_station_idle_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", !mpMaximus->is_station_idle(sta.getStationId()) );
+ mpMaximus->wait(1);
+ CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", mpMaximus->is_station_idle(sta.getStationId()) );
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
diff --git a/maximus/ethernet/src/EtherSciMsg.cpp b/maximus/ethernet/src/EtherSciMsg.cpp
index bb05317557..7869fb9cd3 100644
--- a/maximus/ethernet/src/EtherSciMsg.cpp
+++ b/maximus/ethernet/src/EtherSciMsg.cpp
@@ -229,9 +229,12 @@ void EtherSciMsg::displaySpecializedSciMsgType ( int log_level ) const
clog << logger(log_level) << "\ttype = ETHERNET_TYPE_MME_BUFFER_ADD" << endl;
break;
case 5:
- clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_RELEASED" << endl;
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_INTERFACE_BUFFER_ADD" << endl;
break;
case 6:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_RELEASED" << endl;
+ break;
+ case 7:
clog << logger(log_level) << "\ttype = ETHERNET_TYPE_SNIFFER" << endl;
break;
default:
diff --git a/maximus/python/lib/cesar/sta_cesar.py b/maximus/python/lib/cesar/sta_cesar.py
index 90f3675d85..bf02b23e4e 100644
--- a/maximus/python/lib/cesar/sta_cesar.py
+++ b/maximus/python/lib/cesar/sta_cesar.py
@@ -24,7 +24,9 @@ def STACesar(maximus,\
executable = None,\
debug = False,\
name = None,\
- mme_buffer_nb = 1,\
+ data_buffer_nb=0,\
+ mme_buffer_nb=1,\
+ interface_buffer_nb=0,\
config_mode = 'MME',\
config = Config()):
"""This function creates a STA object with the given arguments,
@@ -35,6 +37,8 @@ def STACesar(maximus,\
executable = executable,\
debug = debug,\
name = name,\
- mme_buffer_nb = mme_buffer_nb + INTERFACE_BUFFER_LIST_NUM_SLOTS,\
+ data_buffer_nb=data_buffer_nb,\
+ mme_buffer_nb=mme_buffer_nb,\
+ interface_buffer_nb=INTERFACE_BUFFER_LIST_NUM_SLOTS,\
config_mode = config_mode,\
config = config)
diff --git a/maximus/python/maximus/ethernet/__init__.py b/maximus/python/maximus/ethernet/__init__.py
index f4b1d9ba75..fa21730e37 100644
--- a/maximus/python/maximus/ethernet/__init__.py
+++ b/maximus/python/maximus/ethernet/__init__.py
@@ -4,7 +4,7 @@
#__all__ = ["buffer", "create", "eth", "scapy"]
-from buffer import alloc_data_buffer, alloc_mme_buffer, get_buffer_dict
+from buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer, realloc_buffer, get_buffer_dict
from eth import Eth
from scapy import *
from maximus.macframe.msdu import MSDU_TYPES
diff --git a/maximus/python/maximus/ethernet/buffer.py b/maximus/python/maximus/ethernet/buffer.py
index b4831abedd..1b2f2b13af 100644
--- a/maximus/python/maximus/ethernet/buffer.py
+++ b/maximus/python/maximus/ethernet/buffer.py
@@ -11,22 +11,37 @@ MAX_VALUE_OF_BUFFER_NB = MAX_VALUE_OF_U32
SIZE_OF_BUFFER_ID = SIZE_OF_U32
class Buffer(MSDU):
- """The Buffer object is composed of the 2 following fields:
- number of buffers to allocate (u32)
- ID of each buffer to allocate (u32)
+ """The Buffer object is composed of the 6 following fields:
+ buffer_id - the current buffer ID
+ buffer_dict - the list of current allocated buffers (ID and type)
+ buffer_realloc - indicates if buffer reallocation is automatic
+ maximus - the Maximus object
+ type - type of buffer
+ buffer_nb - number of buffers to allocate
"""
# Static attributes of the class
buffer_id = 0
buffer_dict = {}
-
- def __init__(self, type, buffer_nb=1):
+ buffer_realloc = False
+ __maximus = None
+
+ def __init__(self, type, buffer_nb=1, maximus=None):
+ """Initialize the Buffer with following attributes:
+ type - a Python string
+ buffer_nb - a Python integer
+ maximus - the Maximus object
+ """
self.set_type(type)
self.set_buffer_nb(buffer_nb)
+ self.__set_maximus(maximus)
def set_type(self, type):
"""This function sets the Buffer object type.
- The Buffer type can be a Python integer (uint8_t)
- or a Python string equals to 'ETHERNET_TYPE_DATA_BUFFER_ADD', 'ETHERNET_TYPE_MME_BUFFER_ADD' or 'ETHERNET_TYPE_BUFFER_RELEASED'.
+ The Buffer type can be a Python integer (u8)
+ or a Python string equals to 'ETHERNET_TYPE_DATA_BUFFER_ADD',
+ 'ETHERNET_TYPE_MME_BUFFER_ADD',
+ 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',
+ or 'ETHERNET_TYPE_BUFFER_RELEASED'.
"""
self.__type = 0
for i, j in enumerate(MSDU_TYPES):
@@ -45,6 +60,21 @@ class Buffer(MSDU):
else:
self.__buffer_nb = buffer_nb
+ def set_buffer_realloc(self, auto):
+ """This function enables or disables the automatic buffer allocation.
+ Auto must be a Python boolean.
+ """
+ if type(auto) is not bool:
+ raise TypeError("Auto")
+ else:
+ self.__class__.buffer_realloc = auto
+
+ def __set_maximus(self, maximus):
+ """This function sets the Maximus object.
+ """
+ if maximus is not None and self.__class__.__maximus is None:
+ self.__class__.__maximus = maximus
+
def __inc_buffer_id(self):
"""This function increments the buffer ID (static attribute of the class).
"""
@@ -60,15 +90,32 @@ class Buffer(MSDU):
"""
del self.__class__.buffer_dict[id]
+ def realloc(self, station_id, payload):
+ """If requested by user, this function allocates a new buffer to replace released buffer.
+ """
+ from maximus.simu.rx import recv
+ if self.get_buffer_realloc():
+ if len(payload) != SIZE_OF_BUFFER_ID:
+ raise Error('Buffer ID length')
+ else:
+ buffer = Buffer(type=self.__class__.buffer_dict[hptoh32(payload)], maximus=self.__get_maximus())
+ # Request to Maximus to send the MSDU asynchronously
+ while not self.__get_maximus().is_station_idle(station_id):
+ self.__get_maximus().process()
+ self.__get_maximus().send_msdu(buffer, station_id)
+
def set_msdu_attr(self, payload):
"""This function sets the MSDU attributes from the received Ethernet Frame.
"""
if len(payload) != SIZE_OF_BUFFER_ID:
raise Error('Buffer ID length')
- self.__remove_buffer(hptoh32(payload))
+ else:
+ self.__remove_buffer(hptoh32(payload))
def get(self):
- """This function returns the Buffer object into a string.
+ """This function returns the Buffer object into a string composed of the 2 following fields:
+ number of buffers to allocate (u32)
+ ID of each buffer to allocate (u32)
"""
buffer = htohp32(self.get_buffer_nb())
for n in range(0, self.get_buffer_nb()):
@@ -80,14 +127,17 @@ class Buffer(MSDU):
return buffer
def get_ether_type(self):
- """This function returns the Buffer object type into a Python integer (uint8_t).
+ """This function returns the Buffer object type into a Python integer (u8).
"""
- return self.__type # 3, 4 or 5
+ return self.__type # 3, 4, 5 or 6
def get_type(self):
"""This function returns the Buffer object type into a Python string.
"""
- return MSDU_TYPES[self.get_ether_type()] # 'ETHERNET_TYPE_DATA_BUFFER_ADD', 'ETHERNET_TYPE_MME_BUFFER_ADD' or 'ETHERNET_TYPE_BUFFER_RELEASED'
+ return MSDU_TYPES[self.get_ether_type()] # 'ETHERNET_TYPE_DATA_BUFFER_ADD',
+ # 'ETHERNET_TYPE_MME_BUFFER_ADD',
+ # 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',
+ # or 'ETHERNET_TYPE_BUFFER_RELEASED'
def get_buffer_nb(self):
"""This function gets the number of buffers to allocate.
@@ -105,13 +155,34 @@ class Buffer(MSDU):
"""
return self.__class__.buffer_dict
+ def get_buffer_realloc(self):
+ """This function gets if the current buffer reallocation is enabled or disabled.
+ """
+ return self.__class__.buffer_realloc
+
+ def __get_maximus(self):
+ """This function gets the Maximus object.
+ """
+ if self.__class__.__maximus is None:
+ raise Error("Maximus object not set")
+ return self.__class__.__maximus
+
+
def alloc_data_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=buffer_nb)
- buffer.send(maximus, station)
+ buffer = Buffer(type='ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+ buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
def alloc_mme_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=buffer_nb)
- buffer.send(maximus, station)
+ buffer = Buffer(type='ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+ buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
+
+def alloc_interface_buffer(maximus, station, buffer_nb=1):
+ buffer = Buffer(type='ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+ buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
+
+def realloc_buffer(auto):
+ buffer = Buffer('ETHERNET_TYPE_NONE')
+ buffer.set_buffer_realloc(auto)
def get_buffer_dict():
buffer = Buffer('ETHERNET_TYPE_NONE')
diff --git a/maximus/python/maximus/ethernet/sniffer.py b/maximus/python/maximus/ethernet/sniffer.py
index def45d9199..65abfa2d35 100644
--- a/maximus/python/maximus/ethernet/sniffer.py
+++ b/maximus/python/maximus/ethernet/sniffer.py
@@ -83,7 +83,7 @@ class Sniffer(MSDU):
for i in range (0,len(MSDU_TYPES)):
if MSDU_TYPES[i] == self.get_type():
ether_type = i
- return ether_type # 6
+ return ether_type # 7
def get_type(self):
"""This function returns the Sniffer object type into a Python string.
diff --git a/maximus/python/maximus/macframe/msdu.py b/maximus/python/maximus/macframe/msdu.py
index 9bf4504d45..26d8997c5d 100644
--- a/maximus/python/maximus/macframe/msdu.py
+++ b/maximus/python/maximus/macframe/msdu.py
@@ -14,6 +14,7 @@ MSDU_TYPES = ['ETHERNET_TYPE_NONE',\
'ETHERNET_TYPE_MME',\
'ETHERNET_TYPE_DATA_BUFFER_ADD',\
'ETHERNET_TYPE_MME_BUFFER_ADD',\
+ 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',\
'ETHERNET_TYPE_BUFFER_RELEASED',\
'ETHERNET_TYPE_SNIFFER']
diff --git a/maximus/python/maximus/station/sta.py b/maximus/python/maximus/station/sta.py
index 0e1e56f0c6..95d3942ecd 100644
--- a/maximus/python/maximus/station/sta.py
+++ b/maximus/python/maximus/station/sta.py
@@ -3,7 +3,7 @@
#print __name__
from maximus.station.config import *
-from maximus.ethernet.buffer import alloc_mme_buffer
+from maximus.ethernet.buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer
from maximus.macframe.msdu import MSDU_TYPES
from maximus.mme import *
from maximus.mme.mmheader import SIZE_OF_MMHEADER, SIZE_OF_MMTYPE, SIZE_OF_FMI
@@ -40,7 +40,7 @@ ERROR_CODES = {0x00:'Bad parameter', 0x01:'Unknown ID', 0x02:'Invalid value'}
def mme_filter(rsp):
if rsp.get_type() is MSDU_TYPES[2]: # ETHERNET_TYPE_MME
return True
- elif rsp.get_type() is MSDU_TYPES[5]: # ETHERNET_TYPE_BUFFER_RELEASED
+ elif rsp.get_type() is MSDU_TYPES[6]: # ETHERNET_TYPE_BUFFER_RELEASED
return False
else:
raise Error("Received unexpected message of type " + rsp.get_type())
@@ -51,7 +51,9 @@ class STA:
maximus - a Maximus object
station - a Sta object
name - a Python string
+ data_buffer_nb - a Python integer
mme_buffer_nb - a Python integer
+ interface_buffer_nb - a Python integer
mme_config - a Python boolean
mac_address - a Python tuple of 6 Python integers
cco_preference - a Python boolean
@@ -65,14 +67,25 @@ class STA:
tonemask - a Python tuple of Python integers
snid - a Python integer from 0 to 15
"""
- def __init__(self, maximus, executable=None, debug=False, name=None, mme_buffer_nb=1, config_mode=CONFIG_MODES[0], config=Config()):
+ def __init__(self,\
+ maximus,\
+ executable=None,\
+ debug=False,\
+ name=None,\
+ data_buffer_nb=0,\
+ mme_buffer_nb=1,\
+ interface_buffer_nb=0,\
+ config_mode=CONFIG_MODES[0],\
+ config=Config()):
"""Initialize the STA with following attributes:
maximus - a Maximus object (already initialized)
executable - a Python string
debug - a Python boolean
name - a Python string
+ data_buffer_nb - a Python integer
mme_buffer_nb - a Python integer
- mme_config - a Python boolean
+ interface_buffer_nb - a Python integer
+ config_mode - a Python string
config - a Python Config object
"""
@@ -84,7 +97,9 @@ class STA:
# Set station configuration
self.set_name(name)
+ self.set_data_buffer_nb(data_buffer_nb)
self.set_mme_buffer_nb(mme_buffer_nb)
+ self.set_interface_buffer_nb(interface_buffer_nb)
self.set_config_mode(config_mode)
self.set_config(config)
@@ -178,6 +193,22 @@ class STA:
if self.get_name() is not None:
self.get().set_name(name)
+ def set_data_buffer_nb(self, data_buffer_nb):
+ """Set the number of data buffers to allocate into the station.
+ The number of data buffers must be a Python integer.
+ """
+ if type(data_buffer_nb) is int:
+ if data_buffer_nb >= 0:
+ self.__data_buffer_nb = data_buffer_nb
+ else:
+ raise OutOfRangeError("Number of data buffers")
+ else:
+ raise TypeError
+
+ # Allocate data buffers
+ if data_buffer_nb > 0:
+ alloc_data_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=data_buffer_nb)
+
def set_mme_buffer_nb(self, mme_buffer_nb):
"""Set the number of MME buffers to allocate into the station.
The number of MME buffers must be a Python integer.
@@ -191,7 +222,24 @@ class STA:
raise TypeError
# Allocate MME buffers
- alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=mme_buffer_nb)
+ if mme_buffer_nb > 0:
+ alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=mme_buffer_nb)
+
+ def set_interface_buffer_nb(self, interface_buffer_nb):
+ """Set the number of interface buffers to allocate into the station.
+ The number of interface buffers must be a Python integer.
+ """
+ if type(interface_buffer_nb) is int:
+ if interface_buffer_nb >= 0:
+ self.__interface_buffer_nb = interface_buffer_nb
+ else:
+ raise OutOfRangeError("Number of interface buffers")
+ else:
+ raise TypeError
+
+ # Allocate interface buffers
+ if interface_buffer_nb > 0:
+ alloc_interface_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=interface_buffer_nb)
def set_config_mode(self, config_mode):
"""Set the configuration mode.
@@ -459,12 +507,24 @@ class STA:
"""
return self.__name
+ def get_data_buffer_nb(self):
+ """Get the number of data buffers allocated into the station.
+ The number of data buffers is a Python integer.
+ """
+ return self.__data_buffer_nb
+
def get_mme_buffer_nb(self):
"""Get the number of MME buffers allocated into the station.
The number of MME buffers is a Python integer.
"""
return self.__mme_buffer_nb
+ def get_interface_buffer_nb(self):
+ """Get the number of interface buffers allocated into the station.
+ The number of interface buffers is a Python integer.
+ """
+ return self.__interface_buffer_nb
+
def get_config_mode(self):
"""Get the configuration mode.
The configuration mode is a Python string of the CONFIG_MODES Python list.
diff --git a/maximus/python/py/test_ether.py b/maximus/python/py/test_ether.py
index 42a6b7a0d8..00c2ca4081 100644
--- a/maximus/python/py/test_ether.py
+++ b/maximus/python/py/test_ether.py
@@ -55,31 +55,9 @@ frame1.type = type
msdu1 = 'This is the Ethernet payload'
frame1.payload = msdu1
alloc_data_buffer(m, sta1, buffer_nb=2)
-snif = recv(m)[0]
frame1.send(m, sta1)
rsp1 = recv(m, count=4)
-# Test the sniffed received MSDU (Sniffer) object
-snif.display()
-if snif.get()[0:48] != "This is a sniffed packet coming from the station":
- print "packet =", snif.get()
- raise Error("packet")
-if snif.get_ether_type() != 6:
- print "ether type =", snif.get_ether_type()
- raise Error("ether type")
-if snif.get_type() != 'ETHERNET_TYPE_SNIFFER':
- print "type =", snif.get_type()
- raise Error("type")
-if snif.get_way() != True:
- print "way =", snif.get_way()
- raise Error("way")
-if snif.get_encryption() != True:
- print "encryption =", snif.get_encryption()
- raise Error("encryption")
-if snif.get_sniffer_type() != 1:
- print "sniffer type =", snif.get_sniffer_type()
- raise Error("sniffer type")
-
# Test the 1st received MSDU (Eth) object
i = 0
if rsp1[i].dst.lower() != dst:
@@ -119,7 +97,6 @@ frame2.type = type
msdu2 = 'This is the Ethernet payload'
frame2.payload = msdu2
alloc_data_buffer(m, sta1, buffer_nb=2)
-recv(m)
rsp2 = frame2.sendnrecv(m, sta1, count=4)
# Test the 1st received MSDU (Eth) object
@@ -154,7 +131,6 @@ m.wait(100000)
# Send an MME asynchronously
mme3 = MME(MMHeader=mmheader, MMEntry=mmentry)
alloc_data_buffer(m, sta1, buffer_nb=2)
-recv(m)
mme3.send(m, sta1)
rsp3 = recv(m, count=4)
@@ -190,7 +166,6 @@ m.wait(100000)
# Send an MME synchronously
mme4 = MME(MMHeader=mmheader, MMEntry=mmentry)
alloc_data_buffer(m, sta1, buffer_nb=2)
-recv(m)
rsp4 = mme4.sendnrecv(m, sta1, count=4)
# Test the 1st received MSDU (Eth) object
@@ -222,6 +197,29 @@ if rsp4[i].get_mmentry() != mmentry:
m.wait(100000)
+# Test the sniffed received MSDU (Sniffer) object
+alloc_interface_buffer(m, sta1)
+snif = recv(m, count=2)[0] # the second received frame is the BUFFER RELEASED message
+snif.display()
+if snif.get()[0:48] != "This is a sniffed packet coming from the station":
+ print "packet =", snif.get()
+ raise Error("packet")
+if snif.get_ether_type() != 7:
+ print "ether type =", snif.get_ether_type()
+ raise Error("ether type")
+if snif.get_type() != 'ETHERNET_TYPE_SNIFFER':
+ print "type =", snif.get_type()
+ raise Error("type")
+if snif.get_way() != True:
+ print "way =", snif.get_way()
+ raise Error("way")
+if snif.get_encryption() != True:
+ print "encryption =", snif.get_encryption()
+ raise Error("encryption")
+if snif.get_sniffer_type() != 1:
+ print "sniffer type =", snif.get_sniffer_type()
+ raise Error("sniffer type")
+
# Uninit ether
fcall2 = m.create_fcall('uninit_ether')
fcall2.send(sta1)
diff --git a/maximus/python/src/interface_module.cpp b/maximus/python/src/interface_module.cpp
index cc8234595a..cd60b16d55 100644
--- a/maximus/python/src/interface_module.cpp
+++ b/maximus/python/src/interface_module.cpp
@@ -119,9 +119,13 @@ void recv_ether_cb ( EtherSciMsg & ether )
{
logFunction();
- if (ether_rx_param.activated)
+ if ( ether_rx_param.activated
+ || (ETHERNET_TYPE_BUFFER_RELEASED == ether.getSpecializedSciMsgType()) )
{
- // Create a new MSDU Python object (Eth or MME)
+ // Get Ethernet SCI message attributes
+ string payload((char *)ether.getSpecializedSciMsgData(), ether.getSpecializedSciMsgDataLength());
+
+ // Create a new MSDU Python object (Eth, MME, Buffer or Sniffer)
object rx_msdu;
if (ETHERNET_TYPE_DATA == ether.getSpecializedSciMsgType())
{
@@ -151,14 +155,20 @@ void recv_ether_cb ( EtherSciMsg & ether )
throw Error(__PRETTY_FUNCTION__, "receive an Ether SCI message with a bad type (should be DATA, MME, BUFFER_RELEASED or SNIFFER)", errno);
}
- // Get Ethernet SCI message attributes
- // and set the MSDU object attributes
- // (payload)
- string payload((char *)ether.getSpecializedSciMsgData(), ether.getSpecializedSciMsgDataLength());
+ if (ETHERNET_TYPE_BUFFER_RELEASED == ether.getSpecializedSciMsgType())
+ {
+ // Reallocate a buffer if requested by user
+ rx_msdu.attr("realloc")(ether.getSciMsgStationId(), payload);
+ }
+
+ // Set the MSDU object attributes (payload)
rx_msdu.attr("set_msdu_attr")(payload);
- // Call the Python reception callback
- ether_rx_param.activated = !ether_rx_param.cb(rx_msdu);
+ if (ether_rx_param.activated)
+ {
+ // Call the Python reception callback
+ ether_rx_param.activated = !ether_rx_param.cb(rx_msdu);
+ }
}
}
@@ -439,7 +449,8 @@ void send_ether ( Maximus & m, object msdu, int station_id )
}
-void set_ether_rx ( Maximus & m, object user_cb,
+void set_ether_rx ( Maximus & m,
+ object user_cb,
object create_eth_function,
object create_mme_function,
object create_buffer_function,
@@ -631,6 +642,7 @@ BOOST_PYTHON_MODULE(interface)
.def("set_snr_from_src_to_dst", set_snr_from_src_to_dstx2)
.def("activate_false_alarm", &Maximus::activate_false_alarm)
.def("deactivate_false_alarm", &Maximus::deactivate_false_alarm)
+ .def("is_station_idle", &Maximus::is_station_idle)
;
/* class Sta */
diff --git a/maximus/python/test/test_ethernet.py b/maximus/python/test/test_ethernet.py
index 795c043942..aba2f62a2b 100644
--- a/maximus/python/test/test_ethernet.py
+++ b/maximus/python/test/test_ethernet.py
@@ -6,7 +6,7 @@ import sys, startup
from maximus.ethernet import *
from maximus.ethernet.buffer import Buffer
-from maximus.ethernet.create import create_buffer, create_eth
+from maximus.ethernet.create import create_eth, create_buffer, create_sniffer
from maximus.ethernet.eth import SIZE_OF_HEADER
from maximus.ethernet.sniffer import Sniffer
from maximus.macframe.msdu import MIN_SIZE_OF_MSDU
@@ -186,7 +186,6 @@ class TestEthFunctions(unittest.TestCase):
none_buffer = Buffer('ETHERNET_TYPE_NONE')
length = len(none_buffer.get_buffer_dict())
alloc_data_buffer(self.m, sta, buffer_nb=2)
- recv(self.m, count=1)
rsp = self.eth.sendnrecv(self.m, sta, count=4)
# 1st received frame is the Ethernet frame
@@ -195,9 +194,11 @@ class TestEthFunctions(unittest.TestCase):
self.assertEqual(rsp[0].vlantag, 0)
self.assertEqual(rsp[0].type, 0)
- # 2nd received frame is the BUFFER RELEASED message
- self.assertEqual(rsp[1].get_ether_type(), 5)
+ # 2nd and 4th received frames are BUFFER RELEASED messages
+ self.assertEqual(rsp[1].get_ether_type(), 6)
self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ self.assertEqual(rsp[3].get_ether_type(), 6)
+ self.assertEqual(rsp[3].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
self.assertEqual(len(rsp[1].get_buffer_dict()), length)
self.m.create_fcall('uninit_ether').send(sta)
@@ -242,6 +243,10 @@ class TestBufferFunctions(unittest.TestCase):
self.assertEqual(self.mme_buffer.get_ether_type(), 4)
self.assertEqual(self.mme_buffer.get_type(), 'ETHERNET_TYPE_MME_BUFFER_ADD')
self.assertEqual(self.mme_buffer.get_buffer_nb(), 2)
+ self.interface_buffer = Buffer('ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=3)
+ self.assertEqual(self.interface_buffer.get_ether_type(), 5)
+ self.assertEqual(self.interface_buffer.get_type(), 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD')
+ self.assertEqual(self.interface_buffer.get_buffer_nb(), 3)
self.m = m
def tearDown(self):
@@ -249,7 +254,7 @@ class TestBufferFunctions(unittest.TestCase):
def test_set_type(self):
self.data_buffer.set_type('ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(self.data_buffer.get_ether_type(), 5)
+ self.assertEqual(self.data_buffer.get_ether_type(), 6)
self.assertEqual(self.data_buffer.get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
try:
self.mme_buffer.set_type('ETHERNET_TYPE_MME')
@@ -265,17 +270,45 @@ class TestBufferFunctions(unittest.TestCase):
except OutOfRangeError:
self.assertEqual(self.mme_buffer.get_buffer_nb(), 0)
+ def test_set_buffer_realloc(self):
+ self.assertEqual(self.data_buffer.get_buffer_realloc(), False)
+ self.data_buffer.set_buffer_realloc(True)
+ self.assertEqual(self.data_buffer.get_buffer_realloc(), True)
+ self.data_buffer.set_buffer_realloc(False)
+
+ def test_realloc(self):
+ sta = self.m.create_sta()
+ self.m.create_fcall('init_ether').send(sta)
+ realloc_buffer(True)
+ buffer_id = 123
+ self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_DATA_BUFFER_ADD'
+ self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
+ buffer_id = 456
+ self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_MME_BUFFER_ADD'
+ self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
+ buffer_id = 789
+ self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD'
+ self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
+ rsp = recv(self.m, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ realloc_buffer(False)
+ self.m.create_fcall('uninit_ether').send(sta)
+ sta.remove()
+
def test_set_msdu_attr(self):
- self.assert_(self.data_buffer.get_buffer_dict().has_key(10))
- self.data_buffer.set_msdu_attr(pack('I', 10))
- self.assert_(not self.data_buffer.get_buffer_dict().has_key(10))
+ id = len(self.data_buffer.get_buffer_dict())
+ self.assert_(self.data_buffer.get_buffer_dict().has_key(id))
+ self.data_buffer.set_msdu_attr(pack('I', id))
+ self.assert_(not self.data_buffer.get_buffer_dict().has_key(id))
def test_sendnrecv(self):
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)[0]
- self.assertEqual(rsp.get_type(), 'ETHERNET_TYPE_SNIFFER')
+ interface_buffer = Buffer('ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=2)
+ rsp = interface_buffer.sendnrecv(self.m, sta, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
@@ -312,6 +345,28 @@ class TestBufferFunctions(unittest.TestCase):
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
+ def test_alloc_interface_buffer(self):
+ sta = self.m.create_sta()
+ self.m.create_fcall('init_ether').send(sta)
+ realloc_buffer(True)
+ alloc_interface_buffer(self.m, sta)
+ rsp = recv(self.m, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ realloc_buffer(False)
+ alloc_interface_buffer(self.m, sta)
+ rsp = recv(self.m, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ self.m.create_fcall('uninit_ether').send(sta)
+ sta.remove()
+
+ def test_realloc_buffer(self):
+ self.assertEqual(self.interface_buffer.get_buffer_realloc(), False)
+ realloc_buffer(True)
+ self.assertEqual(self.interface_buffer.get_buffer_realloc(), True)
+ realloc_buffer(False)
+
def test_get_buffer_dict(self):
get_buffer_dict()
@@ -322,7 +377,7 @@ class TestSnifferFunctions(unittest.TestCase):
def setUp(self):
self.sniffer = Sniffer(way=False, encryption=False, sniffer_type=0)
self.assertEqual(self.sniffer.get(), None)
- self.assertEqual(self.sniffer.get_ether_type(), 6)
+ self.assertEqual(self.sniffer.get_ether_type(), 7)
self.assertEqual(self.sniffer.get_type(), 'ETHERNET_TYPE_SNIFFER')
self.assertEqual(self.sniffer.get_way(), False)
self.assertEqual(self.sniffer.get_encryption(), False)
@@ -360,6 +415,12 @@ class TestSnifferFunctions(unittest.TestCase):
self.sniffer.set_msdu_attr("ABCD")
self.sniffer.display()
+ def test_create_sniffer(self):
+ way = True
+ encryption = True
+ sniffer_type = 1
+ self.assertNotEqual(create_sniffer(way, encryption, sniffer_type), None)
+
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSnifferFunctions))
try:
diff --git a/maximus/python/test/test_interface.py b/maximus/python/test/test_interface.py
index cd0bcacfc5..fa0e18d21e 100644
--- a/maximus/python/test/test_interface.py
+++ b/maximus/python/test/test_interface.py
@@ -179,6 +179,12 @@ class TestInterfaceFunctions(unittest.TestCase):
self.m.activate_false_alarm(duration, deviation)
self.m.deactivate_false_alarm()
+ def test_is_station_idle(self):
+ self.m.wait(1) # to process the system IDLE message coming from the station
+ self.assert_(self.m.is_station_idle(self.station.get_station_id()))
+ self.station.deactivate()
+ self.assert_(not self.m.is_station_idle(self.station.get_station_id()))
+
def test_remove(self):
# Remove station
diff --git a/maximus/stationtest/src/test_ether.c b/maximus/stationtest/src/test_ether.c
index 3e2539afc2..83a8452774 100644
--- a/maximus/stationtest/src/test_ether.c
+++ b/maximus/stationtest/src/test_ether.c
@@ -21,6 +21,7 @@
#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+#include <stdlib.h> // for 'malloc()'
extern station_ctx_t my_station;
ipmbox_t * ctx;
@@ -57,21 +58,35 @@ void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
}
else if (HLE_MSG_TYPE_BUFFER_ADD == hdr->type)
{
- /* When receiving an Ether SCI message of type DATA_BUFFER_ADD or MME_BUFFER_ADD from Maximus,
- * answer by sending an Ether SCI message of type SNIFFER. */
-
- uint data_length = 64;
- char data[data_length];
- memset(data, '\0', data_length);
- strcpy(data, "This is a sniffed packet coming from the station");
-
hdr->type = HLE_MSG_TYPE_SEND_DONE;
ipmbox_tx (ctx, ctx->rx.mailbox, 2); // do nothing
- hdr->type = HLE_MSG_TYPE_INTERFACE_SNIFFER;
- hdr->param = (data_length << 5) | 0x7;
- ctx->rx.mailbox[1] = (u32)data;
- ipmbox_tx (ctx, ctx->rx.mailbox, 2);
+ if (2 == hdr->param)
+ {
+ /* When receiving an Ether SCI message of type INTERFACE_BUFFER_ADD from Maximus,
+ * answer by sending an Ether SCI message of type SNIFFER,
+ * with an Ether SCI message of type BUFFER_RELEASED. */
+
+ uint data_length = 64;
+ char * p_data = malloc(data_length);
+ memset(p_data, '\0', data_length);
+ strcpy(p_data, "This is a sniffed packet coming from the station");
+
+ maximus_hle_buffer_t *p_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
+ u32 id = ctx->last_buffer->id;
+ ctx->last_buffer->next = p_buffer;
+ ctx->last_buffer = p_buffer;
+ ctx->last_buffer->next = NULL;
+ ctx->last_buffer->id = id;
+ ctx->last_buffer->data = (u32 *)p_data;
+
+ hdr->type = HLE_MSG_TYPE_INTERFACE;
+ hdr->length = 2;
+ hdr->param = (data_length << 8) & 0x7FF00;
+ ctx->rx.mailbox[1] = 0x00000007;
+ ctx->rx.mailbox[2] = (u32)p_data;
+ ipmbox_tx (ctx, ctx->rx.mailbox, 3);
+ }
}
return;
@@ -89,7 +104,7 @@ int init_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void
ctx->warning_assert = true;
// Activate ipmbox interruptions
- ipmbox_activate(ctx, true);
+ ipmbox_activate (ctx, true);
/* now make the return parameter list */
fcall_param_reset(*param);
diff --git a/maximus/stationtest/src/test_station.c b/maximus/stationtest/src/test_station.c
index 557a67c952..b31ba7c24c 100644
--- a/maximus/stationtest/src/test_station.c
+++ b/maximus/stationtest/src/test_station.c
@@ -48,7 +48,7 @@ void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
}
else if (HLE_MSG_TYPE_BUFFER_ADD == hdr->type)
{
- /* Receive an Ether SCI message of type MME_BUFFER_ADD from Maximus. */
+ /* Receive an Ether SCI message of type DATA_BUFFER_ADD, MME_BUFFER_ADD or INTERFACE_BUFFER_ADD from Maximus. */
hdr->type = HLE_MSG_TYPE_SEND_DONE;
ipmbox_tx (ctx, ctx->rx.mailbox, 2); // do nothing
@@ -83,7 +83,7 @@ int main(void)
ctx->warning_assert = true;
// Activate ipmbox interruptions
- ipmbox_activate(ctx, true);
+ ipmbox_activate (ctx, true);
fcall_register(my_station.fcall, "uninit_ether", (void*)&uninit_ether, NULL);