linksys_test.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import time
00004 import unittest
00005 
00006 import roslib; roslib.load_manifest('network_control_tests')
00007 import rospy
00008 import rostest 
00009 
00010 import dynamic_reconfigure.client
00011 from ieee80211_channels.channels import IEEE80211_Channels
00012 
00013 class LinksysTest(unittest.TestCase):
00014     def __init__(self, *args):
00015         super(LinksysTest, self).__init__(*args)
00016         rospy.init_node('linksys_access_point_test')
00017 
00018         self.dyn_ap24 = dynamic_reconfigure.client.Client("linksys_2_4")
00019         self.dyn_ap5 = dynamic_reconfigure.client.Client("linksys_5")
00020 
00021     def test_linksys_24(self):
00022         start_time = time.time()
00023         config = self.dyn_ap24.update_configuration({"enabled": False})
00024         rospy.loginfo("Disabling interface (while previously disabled) executed in: %.2fs", time.time() - start_time)
00025         self.assertTrue(config['status'] == "OK",
00026                         "Operation failed: " + config['errmsg'])
00027 
00028         start_time = time.time()
00029         config = self.dyn_ap24.update_configuration({"ssid": "testnet", "mode": "g"})
00030         rospy.loginfo("Updating configuration (while disabled) executed in: %.2fs", time.time() - start_time)
00031         self.assertTrue(config['status'] == "OK",
00032                         "Operation failed: " + config['errmsg'])
00033         self.assertFalse(config['enabled'],
00034                          "Expected AP to be stopped")
00035 
00036         start_time = time.time()
00037         config = self.dyn_ap24.update_configuration({"enabled": True})
00038         rospy.loginfo("Enabling interface executed in: %.2fs", time.time() - start_time)
00039         self.assertTrue(config['status'] == "OK",
00040                         "Operation failed: " + config['errmsg'])
00041 
00042         start_time = time.time()
00043         config = self.dyn_ap24.update_configuration({"ssid": "anotherssid", "encryption_mode": "wep", "encryption_pass": "0123456789",
00044                                                      "ieee80211n": True, "wmm": True})
00045         rospy.loginfo("Updating config (while enabled) executed in: %.2fs", time.time() - start_time)
00046         self.assertTrue(config['status'] == "OK",
00047                         "Operation failed: " + config['errmsg'])
00048 
00049         start_time = time.time()
00050         config = self.dyn_ap24.update_configuration({"mode": "a", "ieee80211n": False})
00051         rospy.loginfo("Updating config (while enabled) with bad params executed in: %.2fs", time.time() - start_time)
00052         self.assertTrue(config['status'] == "FAIL",
00053                         "Expected setting mode 802.11a on 2.4GHz interface to fail")
00054 
00055         start_time = time.time()
00056         config = self.dyn_ap24.update_configuration({"enabled": True, 
00057                                                      "mode": "b", "ieee80211n": False, "txpower": -5, "bitrate": 1000000})
00058         rospy.loginfo("Updating config (while enabled) including txpower executed in: %.2fs", time.time() - start_time)
00059         self.assertTrue(config['status'] == "OK",
00060                         "Operation failed: " + config['errmsg'])
00061         self.assertTrue(config['txpower'] >= 0,
00062                         "Expected txpower to be greater than 0 instead it was: %d dBm"%(config['txpower']))
00063 
00064         start_time = time.time()
00065         config = self.dyn_ap24.update_configuration({"bitrate": 11000000})
00066         rospy.loginfo("Updating just bitrate (while enabled) executed in: %.2fs", time.time() - start_time)
00067         self.assertTrue(config['status'] == "OK",
00068                         "Operation failed: " + config['errmsg'])
00069         self.assertTrue(config['bitrate'] == 11000000,
00070                         "Expected bitrate to be 11M instead it was: %d"%(config['bitrate']))
00071 
00072         start_time = time.time()
00073         config = self.dyn_ap24.update_configuration({"enabled": False})
00074         rospy.loginfo("Disabling interface (previously enabled) exeuted in: %.2fs", time.time() - start_time)
00075         self.assertTrue(config['status'] == "OK",
00076                         "Operation failed: " + config['errmsg'])
00077         self.assertFalse(config['enabled'],
00078                          "Expected AP to be stopped")
00079 
00080     def test_linksys_5(self):
00081         config = self.dyn_ap5.update_configuration({"enabled": False, "mode": "b", "ieee80211n": False, "freq": 0,
00082                                                     "bitrate": 0})
00083         self.assertTrue(config['status'] == "OK",
00084                         "Operation failed: " + config['errmsg'])
00085 
00086         start_time = time.time()
00087         config = self.dyn_ap5.update_configuration({"enabled": True})
00088         rospy.loginfo("Failed enable executed in: %.2fs", time.time() - start_time)
00089         self.assertTrue(config['status'] == "FAIL",
00090                         "Expected enabling 5GHz interface while in default mode 'b' to fail" +
00091                         ", returned config: " + str(config))
00092         self.assertFalse(config['enabled'],
00093                          "Expected AP to be stopped")
00094 
00095         start_time = time.time()
00096         config = self.dyn_ap5.update_configuration({"enabled": True, "mode": "a", 
00097                                                     "freq": IEEE80211_Channels.get_freq(153, IEEE80211_Channels.BAND_5000_MHz)})
00098         rospy.loginfo("Enabling 5GHz executed in: %.2fs", time.time() - start_time)
00099         self.assertTrue(config['status'] == "OK",
00100                         "Operation failed: " + config['errmsg'])
00101         self.assertTrue(config['enabled'],
00102                          "Expected AP to be running")
00103 
00104         start_time = time.time()
00105         config = self.dyn_ap5.update_configuration({"freq": IEEE80211_Channels.get_freq(161, IEEE80211_Channels.BAND_5000_MHz)})
00106         rospy.loginfo("Change channel 5GHz executed in: %.2fs", time.time() - start_time)
00107         self.assertTrue(config['status'] == "OK",
00108                         "Operation failed: " + config['errmsg'])
00109 
00110         start_time = time.time()
00111         config = self.dyn_ap5.update_configuration({"ieee80211n": True, "bitrate": 0})
00112         rospy.loginfo("Enabling 802.11n executed in: %.2fs", time.time() - start_time)
00113         self.assertTrue(config['status'] == "OK",
00114                         "Operation failed: " + config['errmsg'])
00115 
00116         start_time = time.time()
00117         config = self.dyn_ap5.update_configuration({"enabled": False})
00118         rospy.loginfo("Disabling 5GHz executed in: %.2fs", time.time() - start_time)
00119         self.assertTrue(config['status'] == "OK",
00120                         "Operation failed: " + config['errmsg'])
00121         self.assertFalse(config['enabled'],
00122                          "Expected AP to be stopped")
00123 
00124     def test_linksys_both(self):
00125         config = self.dyn_ap5.update_configuration({"enabled": True, "mode": "a", "bitrate": 0, "wmm": False,
00126                                                     "freq": IEEE80211_Channels.get_freq(153, IEEE80211_Channels.BAND_5000_MHz)})
00127         self.assertTrue(config['status'] == "OK",
00128                         "Operation failed: " + config['errmsg'])
00129         config = self.dyn_ap24.update_configuration({"enabled": True, "mode": "g", "ieee80211n": True, "bitrate": 0, "wmm": False,
00130                                                       "freq": IEEE80211_Channels.get_freq(9, IEEE80211_Channels.BAND_2400_MHz)})
00131         self.assertTrue(config['status'] == "OK",
00132                         "Operation failed: " + config['errmsg'])
00133 
00134         config = self.dyn_ap24.update_configuration({"ssid": "myssid24"})
00135         self.assertTrue(config['status'] == "OK",
00136                         "Operation failed: " + config['errmsg'])
00137 
00138         config = self.dyn_ap5.update_configuration({"ssid": "myssid5"})
00139         self.assertTrue(config['status'] == "OK",
00140                         "Operation failed: " + config['errmsg'])
00141 
00142         config = self.dyn_ap24.update_configuration({"txpower": 30})
00143         self.assertTrue(config['status'] == "OK",
00144                         "Operation failed: " + config['errmsg'])
00145         rospy.loginfo("Max txpower level on 2.4GHz is: %d dbm", config['txpower'])
00146 
00147         config = self.dyn_ap5.update_configuration({"txpower": -1})
00148         self.assertTrue(config['status'] == "OK",
00149                         "Operation failed: " + config['errmsg'])
00150         rospy.loginfo("Min txpower level on 5GHz is: %d dbm", config['txpower'])
00151 
00152     def test_linksys_security(self):
00153         config = self.dyn_ap5.update_configuration({"enabled": True, "mode": "a", "ieee80211n": False, "bitrate": 0, "wmm": False,
00154                                                     "freq": IEEE80211_Channels.get_freq(153, IEEE80211_Channels.BAND_5000_MHz),
00155                                                     "encryption_mode": "open", "encryption_pass": ""})
00156         self.assertTrue(config['status'] == "OK",
00157                         "Operation failed: " + config['errmsg'])
00158         config = self.dyn_ap24.update_configuration({"enabled": True, "mode": "g", "ieee80211n": False, "bitrate": 0, "wmm": False,
00159                                                      "freq": IEEE80211_Channels.get_freq(9, IEEE80211_Channels.BAND_2400_MHz),
00160                                                      "encryption_mode": "open", "encryption_pass": ""})
00161         self.assertTrue(config['status'] == "OK",
00162                         "Operation failed: " + config['errmsg'])
00163         config = self.dyn_ap24.update_configuration({"encryption_mode": "wpa2", "encryption_pass": "mypassword24"})
00164         self.assertTrue(config['status'] == "OK",
00165                         "Operation failed: " + config['errmsg'])
00166         config = self.dyn_ap5.update_configuration({"encryption_mode": "wep", "encryption_pass": "9876543210"})
00167         self.assertTrue(config['status'] == "OK",
00168                         "Operation failed: " + config['errmsg'])
00169         config = self.dyn_ap5.update_configuration({"wmm": True})
00170         self.assertTrue(config['status'] == "OK",
00171                         "Operation failed: " + config['errmsg'])
00172         self.assertTrue(config['encryption_mode'] == "wep",
00173                         "Wrong encryption mode: " + config['encryption_mode'])
00174         config = self.dyn_ap24.update_configuration({"wmm": True})
00175         self.assertTrue(config['status'] == "OK",
00176                         "Operation failed: " + config['errmsg'])
00177         self.assertTrue(config['encryption_mode'] == "wpa2",
00178                         "Wrong encryption mode: " + config['encryption_mode'])
00179                         
00180 if __name__ == '__main__':
00181     try:
00182         rostest.run('network_control_tests', 'linksys_test', LinksysTest)
00183     except KeyboardInterrupt, e:
00184         pass


network_control_tests
Author(s): Catalin Drula
autogenerated on Thu Apr 24 2014 15:35:20