summaryrefslogtreecommitdiff
path: root/cesar/test_general/station
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-11-10 17:38:05 +0100
committerNélio Laranjeiro2011-11-28 17:12:41 +0100
commit685e9dfed36d71d30bb8c4bce3217612845b01bf (patch)
tree0c91d05c9931361a13434f2197b24da9099789bc /cesar/test_general/station
parent6869b43fe082008d43e7a7b95cfa61857d4f0517 (diff)
cesar: update and move cco0/s2 brige test to scenario
Diffstat (limited to 'cesar/test_general/station')
-rw-r--r--cesar/test_general/station/cco0/s2/py/sc01_bridge.py231
-rw-r--r--cesar/test_general/station/scenario/Makefile3
-rw-r--r--cesar/test_general/station/scenario/py/sc07_bridge.py109
3 files changed, 111 insertions, 232 deletions
diff --git a/cesar/test_general/station/cco0/s2/py/sc01_bridge.py b/cesar/test_general/station/cco0/s2/py/sc01_bridge.py
deleted file mode 100644
index 0eb9165a83..0000000000
--- a/cesar/test_general/station/cco0/s2/py/sc01_bridge.py
+++ /dev/null
@@ -1,231 +0,0 @@
-#!/usr/bin/env python
-
-##############################################################################
-# Bridge MMEs #
-# ---------------------------------------------------------------------- #
-# Objective: Two or more stations authenticated on the same #
-# AVLN are exchanging data with bridged entities MMEs. #
-##############################################################################
-
-# Add Maximus and CSI to PATH module lookup.
-import sys
-sys.path.append(sys.path[0] + '/../../../../../maximus/python/tools/csi/')
-sys.path.append(sys.path[0] + '/../../../../../maximus/python/obj/')
-sys.path.append(sys.path[0] + '/../../../../../maximus/python/')
-sys.path.append(sys.path[0] + '/../../../../../maximus/python/lib/cesar')
-# Import some classes from the CSI module.
-from csicore import csiCore, csiPacket, csiSta, csiPacket
-from sta_mgr import Sta_mgr
-# Random.
-import random
-
-### Handy functions.
-def send_bridged_packet(sta_src, sta_dst, bridged_mac_src):
- """
- Send a packet coming from a STA out of the AVLN with bridged_mac_src
- through sta_src to sta_dst.
- """
- # Add MAC address to the internal bridged list of CSI module.
- sta_src.bridge_mac_addr_add(bridged_mac_src)
- # Create a list of one packet to send.
- bridged_packet = list()
- bridged_packet.append(csiPacket(150, avln, sta_src, bridged_mac_src,
- sta_dst))
- # Send bridged packet.
- csi.process_data_send_traffic(bridged_packet)
-
-def is_mac_into_bridge_table(range, mac, has = True):
- """
- Check a range of STAs of the AVLN has or has not the MAC entry presents
- into its bridge table.
- """
- # Create a sta manager.
- sta_data = Sta_mgr()
- # Get maximus.
- maximus = csi.get_maximus()
- # For each STA of the AVLN in range.
- if has:
- for i in range:
- if not sta_data.is_bridged_mac(maximus,
- avln.get_sta(i).get_sta_cesar(), mac):
- # Error!
- return False
- else:
- for i in range:
- if sta_data.is_bridged_mac(maximus,
- avln.get_sta(i).get_sta_cesar(), mac):
- # Error!
- return False
- # No error.
- return True
-
-def is_mac_into_mactotei_table(range, mac, has = True):
- """
- Check a range of STAs of the AVLN has or has not the MAC entry presents
- into the MAC to TEI table.
- """
- # Create a sta manager.
- sta_data = Sta_mgr()
- # Get maximus.
- maximus = csi.get_maximus()
- # For each STA of the AVLN in range.
- if has:
- for i in range:
- if sta_data.get_tei_from_mac(maximus,
- avln.get_sta(i).get_sta_cesar(), mac) == 0:
- # Error!
- return False
- else:
- for i in range:
- if sta_data.get_tei_from_mac(maximus,
- avln.get_sta(i).get_sta_cesar(), mac) != 0:
- # Error!
- return False
- # No error.
- return True
-
-### Some "defines".
-# Count of STA in the AVLN (need to be between 2 and 10).
-avln_sta_count = 2
-# List of bridged addresses.
-bridged_address = list()
-bridged_address.append (("42:42:42:42:42:42", (66, 66, 66, 66, 66, 66)))
-bridged_address.append (("24:24:24:24:24:24", (36, 36, 36, 36, 36, 36)))
-bridged_address.append (("66:66:66:66:66:66", (102, 102, 102, 102, 102, 102)))
-
-# Initialize CSI.
-csi = csiCore(4242);
-
-# Create an AVLN.
-avln = csi.avln_add("HomePlug_AVLN", "AVLN")
-
-# Add some STA to the AVLN.
-for i in range(avln_sta_count):
- # Generate MAC address
- mac = ''
- for j in range(6):
- mac += str(i)
- mac += str(j)
- if j != 5:
- mac += ':'
- # Add STA to the AVLN.
- avln.sta_add(mac, False, False, 'Homeplug_Station' + str(i),
- 'spidcom_spc300_sta' + str(i), 'station' + str(i),
- 1, False, 0)
-
-# Start the simulation.
-csi.process_init(sys.argv + ['-e', sys.path[0] + '/../obj/cco0s2.elf'])
-# Start the AVLN and STA.
-csi.process_avlns_launch()
-# Wait for association and authentication.
-csi.process_wait_association()
-csi.process_wait_authentication()
-
-# Send a bridged packet from the first STA to another one.
-send_bridged_packet(avln.get_sta(0), avln.get_sta(1), bridged_address[0][0])
-
-# Let's wait a little bit for the update of the bridge table to be triggered
-# by the garbage CP function.
-csi.process_wait_sec(1)
-
-# Check first STA bridges the MAC address (i.e., have the MAC address in the
-# bridge table).
-if not (is_mac_into_bridge_table((0,), bridged_address[0][1]), True):
- raise Exception("STA 0 should contain one bridged entry")
-# Check first STA has not the bridge MAC address into its MAC to TEI table.
-if not (is_mac_into_mactotei_table((0,), bridged_address[0][1]), False):
- raise Exception("STA 0 should not contain the MAC address into the "
- "MAC to TEI table")
-# Check other STA has not the MAC address in the bridge table.
-if not (is_mac_into_bridge_table(range(1, avln_sta_count),
- bridged_address[0][1]), False):
- raise Exception("STA should not contain bridged entry")
-# Check other STAs have the MAC address into the MAC to TEI.
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[0][1]), True):
- raise Exception("STA should have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-
-
-# We now send a second bridge packet with a MAC address different. The STA
-# should add it to its bridge table but not "publish" it to other STA.
-send_bridged_packet(avln.get_sta(0), avln.get_sta(1), bridged_address[1][0])
-# Wait a little.
-csi.process_wait_sec(1)
-# Check first STA bridges the MAC address.
-if not (is_mac_into_bridge_table((0,), bridged_address[1][1]), True):
- raise Exception("STA 0 should have bridged the MAC address.")
-# Check first STA has not the bridge MAC address into its MAC to TEI table.
-if not (is_mac_into_mactotei_table((0,), bridged_address[1][1]), False):
- raise Exception("STA 0 should not contain the MAC address into the "
- "MAC to TEI table")
-# Check other STA has not the MAC address in the bridge table.
-if not (is_mac_into_bridge_table(range(1, avln_sta_count),
- bridged_address[1][1]), False):
- raise Exception("STA should not contain bridged entry")
-# Check other STAs have not yet the MAC address into the MAC to TEI.
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[1][1]), False):
- raise Exception("STA should not have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-
-# Let's now wait some time for the bridge MAC address to be published.
-csi.process_wait_sec(4)
-# The MAC address should still not be present in the bridge table of other
-# STA.
-if not (is_mac_into_bridge_table(range(1, avln_sta_count),
- bridged_address[1][1]), False):
- raise Exception("STA should not contain bridged entry")
-# Check other STAs have now the MAC address into the MAC to TEI.
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[1][1]), True):
- raise Exception("STA should have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-
-# We now send a third bridge packet with a MAC address different.
-send_bridged_packet(avln.get_sta(0), avln.get_sta(1), bridged_address[2][0])
-# The MAC address will be published in 5 seconds, and them the bridge table
-# will be published again in 90 seconds. But the first bridged MAC address
-# should have expire in the bridge table and should not published again.
-csi.process_wait_sec(95)
-# Check first STA does not bridge the MAC address anymore.
-if not (is_mac_into_bridge_table((0,), bridged_address[0][1]), False):
- raise Exception("STA 0 should not bridge the MAC address anymore.")
-# Other STA should have remove the entry from their MAC to TEI table.
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[0][1]), False):
- raise Exception("STA should not have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-
-# We now send again a packet with the third bridge MAC address and wait until
-# it the next publication of the bridge table (in 90 seconds). It should be
-# the only remaining entry.
-send_bridged_packet(avln.get_sta(0), avln.get_sta(1), bridged_address[2][0])
-csi.process_wait_sec(91)
-# Check first STA only contains the third MAC address into the bridge table.
-if not (is_mac_into_bridge_table((0,), bridged_address[0][1]), False):
- raise Exception("STA 0 should not bridge the MAC address anymore.")
-if not (is_mac_into_bridge_table((0,), bridged_address[1][1]), False):
- raise Exception("STA 0 should not bridge the MAC address anymore.")
-if not (is_mac_into_bridge_table((0,), bridged_address[2][1]), True):
- raise Exception("STA 0 should bridge the MAC address anymore.")
-# Other STA should have remove the entries from their MAC to TEI table and
-# only keep one.
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[0][1]), False):
- raise Exception("STA should not have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[1][1]), False):
- raise Exception("STA should not have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-if not (is_mac_into_mactotei_table(range(1, avln_sta_count),
- bridged_address[2][1]), True):
- raise Exception("STA should have an entry for the "
- "bridged MAC address into the MAC to TEI table.")
-
-# Check every packets sent have been received.
-csi.process_verify_transmission()
-# Report errors for nightly build.
-result = csi.process_end_get_result()
-sys.exit((1, 0)[result])
diff --git a/cesar/test_general/station/scenario/Makefile b/cesar/test_general/station/scenario/Makefile
index ee672e158f..3ae696b53d 100644
--- a/cesar/test_general/station/scenario/Makefile
+++ b/cesar/test_general/station/scenario/Makefile
@@ -13,7 +13,8 @@ include $(BASE)/common/make/top.mk
testbook: py/sc01_assoc_auth.py py/sc02_stas_communication.py \
py/sc03_two_avln_coexisting.py py/sc04_cc_whoru.py \
- py/sc05_cc_leave.py py/sc06_discover_procedure.py
+ py/sc05_cc_leave.py py/sc06_discover_procedure.py \
+ py/sc07_bridge.py
python testbook.py $^ > $@.rst
CLEAN_FILES += testbook.rst
diff --git a/cesar/test_general/station/scenario/py/sc07_bridge.py b/cesar/test_general/station/scenario/py/sc07_bridge.py
new file mode 100644
index 0000000000..95ae3c6085
--- /dev/null
+++ b/cesar/test_general/station/scenario/py/sc07_bridge.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (C) 2011 Spidcom
+##############################################################################
+
+import sys
+sys.path.append ('py')
+from scenario_init import *
+
+class TestBridge (unittest.TestCase):
+ """Two or more stations authenticated on the same AVLN are exchanging data
+ with bridged entities MMEs.
+ """
+
+ def setUp (self):
+ self.csi = csiCore (1234)
+ self.csi.process_init (args)
+ self.csi.init_test_bed ([2])
+ self.computer_mac = "10:10:10:10:10:10"
+
+ def tearDown (self):
+ self.csi.uninit_test_bed ()
+ self.csi.process_uninit ()
+ del self.csi
+
+
+ def mac2tei_verification (self, avln, sta, sta_remote):
+ """Verify that the sta_remote station is present in the mac2tei table
+ of sta."""
+ mac2tei = Ether (dst = sta_remote.get_mac_addr (), src = MAC_DEFAULT)\
+ / scammer.MME () / scammer.VS_GET_MACTOTEI_REQ ()
+ rsp = sendnrecv_mme (self.csi.get_maximus (), sta, mac2tei)
+ self.failUnless (rsp)
+ # Dissect the confirmation.
+ mac2teicnf = Ether (rsp[0].get ())
+ # Mac a simple table of all mac address present in the sta remote.
+ sta_remote_macs = []
+ for i in range (sta_remote.bridge_mac_addr_nb ()):
+ sta_remote_macs.append (sta_remote.bridge_mac_addr_get (i))
+ sta_remote_macs.append (sta_remote.get_mac_addr ())
+ # Check it.
+ for i in mac2teicnf.entries:
+ self.failUnless (i.mac in sta_remote_macs)
+
+ def testBridge (self):
+ """Create an AVLN with two stations. Exchange Bridge ethernet packets
+ from one station to another one.
+
+ Excepted result: The CM_BRIDGE_INFO.IND is sent and the bridged MAC
+ addresses are present in the mac2tei table.
+ """
+ # Get the AVLN.
+ avln = self.csi.avln_get (0)
+ sta1 = avln.get_sta (0)
+ sta2 = avln.get_sta (1)
+ # List of bridged addresses.
+ sta1_macs = [sta1.get_mac_addr ()]
+ sta2_macs = [sta2.get_mac_addr ()]
+ packets = []
+ for i in range (2):
+ sta1b = '00:10:00:00:00:%02x' % (i + 1)
+ sta2b = '00:20:00:00:00:%02x' % (i + 1)
+ sta1_macs.append (sta1b)
+ sta2_macs.append (sta2b)
+ sta1.bridge_mac_addr_add (sta1b)
+ sta2.bridge_mac_addr_add (sta2b)
+ packets.append (csiPacket (payload_size = 1400, avln = avln,
+ sta_src = sta1, mac_addr_src = sta1b, sta_dest = sta2))
+ packets.append (csiPacket (payload_size = 1400, avln = avln,
+ sta_src = sta2, mac_addr_src = sta2b, sta_dest = sta1))
+ while (len (packets)):
+ # Activate the sniffer on one station to catch the MME exchange.
+ ss = sniffer (self.csi.get_maximus (), sta1, mme_tx = True,
+ mme_rx = True)
+ self.failUnless (ss)
+ # Prepare packets to be sent by each station in the AVLN using the
+ # first MAC address bridge of each one.
+ p = packets[:2]
+ packets = packets[2:]
+ self.csi.process_data_send_traffic (p)
+ # Sniff the MME exchanges
+ rsp = self.csi.sniff_packets (2, 10);
+ for i in rsp:
+ m = scammer.get_sniffed_mme (Ether (i.get ()))
+ self.failUnless (m.mmtype == \
+ scammer.HPAV_MMTYPES['CM_BRG_INFO_CNF'])
+ # MME should only have a bridged Mac address to provide.
+ self.failUnless (m.nbda)
+ # Verify it is the right mac address provided.
+ for j in m.bdas:
+ if m.src == sta1.get_mac_addr ():
+ self.failUnless (j.mac in sta1_macs)
+ elif m.src == sta2.get_mac_addr ():
+ self.failUnless (j.mac in sta2_macs)
+ # Check the traffic.
+ sniffer (self.csi.get_maximus (), sta1)
+ self.csi.process_verify_transmission ()
+ result = self.csi.process_end_get_result ()
+ self.csi.transmission_result_reset ()
+ self.failUnless (result)
+ # Now we can verify the mac2tei table of each station.
+ self.mac2tei_verification (avln, sta1, sta2)
+ self.mac2tei_verification (avln, sta2, sta1)
+
+if __name__ == '__main__':
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestBridge)
+ testResult = unittest.TextTestRunner(verbosity=2).run(suite)
+ sys.exit ((1, 0)[testResult.wasSuccessful ()])