def test_beacon_report(self): mac = '\x42\x62\x89\x67\x4d\xb4' # Test 1: Measurement on APID = 0xFF, channel = 100, essId = 0, # RCPI = -10 msg = '\x03' + mac + '\xFF\x64\x00\xF6' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION2, False, msg) self.assertEquals( wlanif.BeaconReport._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), -10)), payload) # Test 2: Similar but in big endian format (which makes no difference) msg = '\x03' + mac + '\xFF\x64\x00\xF6' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION2, True, msg) self.assertEquals( wlanif.BeaconReport._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), -10)), payload) # Test 3: Not supported in version 1 msg = '\x03' + mac + '\xFF\x64\x00\xF6' self.assertRaises(MessageMalformedError, wlanif.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) self.assertRaises(MessageMalformedError, wlanif.unpack_payload_from_bytes, common.Version.VERSION1, True, msg)
def test_sta_pollution_changed_msg(self): """Verify the parsing of the STA pollution changed message.""" # Test 1: Pollution changed on a BSS on channel 149 test_cases = itertools.product([False, True], [ STAPollutionChangeReason.POLLUTION_CHANGE_DETECTION, STAPollutionChangeReason.POLLUTION_CHANGE_AGING, STAPollutionChangeReason.POLLUTION_CHANGE_REMOTE, STAPollutionChangeReason.POLLUTION_CHANGE_INVALID ]) for big_endian in (False, True): mac = '\x42\x62\x89\x67\x4d\xb4' for test_case in test_cases: msg = '\x03' + mac + '\xff\x95\x01' + \ chr(test_case[0]) + chr(test_case[1].value) payload = estimator.unpack_payload_from_bytes( common.Version.VERSION2, big_endian, msg) self.assertEquals( estimator.STAPollutionChanged._make( (common.ether_ntoa(mac), common.BSSInfo(255, 149, 1), test_case[0], test_case[1])), payload) # Test 2: Invalid pollution change reason for big_endian in (False, True): mac = '\x42\x62\x89\x67\x4d\xb4' for changed in (False, True): msg = '\x03' + mac + '\xff\x95\x01' + chr(changed) + \ chr(STAPollutionChangeReason.POLLUTION_CHANGE_INVALID.value + 1) self.assertRaises(MessageMalformedError, estimator.unpack_payload_from_bytes, common.Version.VERSION2, big_endian, msg)
def test_interference_stats_msg(self): """Verify the parsing of the interference stats message""" # Test 1: Stats on a BSS on channel 36 mac = '\x42\x62\x89\x67\x4d\xb4' msg = '\x04' + mac + '\xff\x24\x00\x20\x01\x02' + \ '\x01\x02\x03\x04\x05\x06\x07\x08' + \ '\x0a\x0b\x0c\x0d' payload = estimator.unpack_payload_from_bytes(common.Version.VERSION2, False, msg) self.assertEquals( estimator.InterferenceStats._make( (common.ether_ntoa(mac), common.BSSInfo(255, 36, 0), 32, 513, 578437695752307201, 218893066)), payload) # Test 2: Similar but in big endian format (Tx rate changes) payload = estimator.unpack_payload_from_bytes(common.Version.VERSION2, True, msg) self.assertEquals( estimator.InterferenceStats._make( (common.ether_ntoa(mac), common.BSSInfo(255, 36, 0), 32, 258, 72623859790382856, 168496141)), payload)
def test_non_serving_data_metrics_msg(self): """Verify the parsing of the non-serving data metrics message.""" # Test 1: Measurement on a BSS on channel 6 mac = '\x42\x62\x89\x67\x4d\xb4' msg = '\x01' + mac + '\xff\x06\x01' + \ '\x50\x00\x00\x00\x42' payload = estimator.unpack_payload_from_bytes(common.Version.VERSION2, False, msg) self.assertEquals( estimator.NonServingDataMetrics._make( (common.ether_ntoa(mac), common.BSSInfo(255, 6, 1), 80, 66)), payload) # Test 2: Similar but in big endian format msg = '\x01' + mac + '\x02\x24\x00' + \ '\x00\x00\x00\x50\x42' payload = estimator.unpack_payload_from_bytes(common.Version.VERSION2, True, msg) self.assertEquals( estimator.NonServingDataMetrics._make( (common.ether_ntoa(mac), common.BSSInfo(2, 36, 0), 80, 66)), payload)
def test_sta_interference_detected_msg(self): """Verify the parsing of the STA interference detected message.""" # Test 1: Interference detected or not on a BSS on channel 11 for big_endian in (False, True): for detected in (False, True): mac = '\x42\x62\x89\x67\x4d\xb4' msg = '\x02' + mac + '\xff\x0b\x01' + chr(detected) payload = estimator.unpack_payload_from_bytes( common.Version.VERSION2, big_endian, msg) self.assertEquals( estimator.STAInterferenceDetected._make( (common.ether_ntoa(mac), common.BSSInfo(255, 11, 1), detected)), payload)
def test_unpack_msg(self): """Validate the top-level unpacking of messsages.""" # Test 1: A wlanif message msg = '\x10\x18\x29\xc6\x09\x00\xd6\x73\x06\x00\x01\x00\x00\x16' header, payload = parser.unpack_msg(msg) self.assertEquals( common.Header._make((common.Version.VERSION1, False, 24, 0x9c629, 0x673d6, common.ModuleID.WLANIF)), header) self.assertEquals( wlanif.RawChannelUtilization._make( (common.BAND_TYPE.BAND_24G, 22)), payload) # Test 2: A bandmon message msg = '\x11\xa2\x51\x77\x52\x0e\x00\x05\x03\xd9\x02\x01\x00\x37' header, payload = parser.unpack_msg(msg) self.assertEquals( common.Header._make( (common.Version.VERSION1, True, 162, 0x5177520e, 0x503d9, common.ModuleID.BANDMON)), header) self.assertEquals( bandmon.Utilization_v1._make((common.BAND_TYPE.BAND_24G, 55)), payload) # Test 3: A stadb message mac = '\xb2\xdd\x69\xa1\xb3\xe3' msg = '\x10\xa2\x0e\x52\x77\x51\xd9\x03\x05\x00\x05\x00' + mac + \ '\x00\x01\x01' header, payload = parser.unpack_msg(msg) self.assertEquals( common.Header._make((common.Version.VERSION1, False, 162, 0x5177520e, 0x503d9, common.ModuleID.STADB)), header) self.assertEquals( stadb.AssociationUpdate._make( (common.ether_ntoa(mac), common.BAND_TYPE.BAND_24G, True, True)), payload) # Test 4: A steerexec message mac = '\x6e\xee\xb2\x94\x33\x6f' msg = '\x11\x18\x00\x09\xc6\x29\x00\x06\x73\xd6\x06\x02' + mac + '\x01' header, payload = parser.unpack_msg(msg) self.assertEquals( common.Header._make((common.Version.VERSION1, True, 24, 0x9c629, 0x673d6, common.ModuleID.STEEREXEC)), header) self.assertEquals( steerexec.SteeringUnfriendly._make((common.ether_ntoa(mac), True)), payload) # Test 5: A diaglog message msg = '\x11\xa2\x51\x77\x52\x0e\x00\x05\x03\xd9\x08\x00abc' header, payload = parser.unpack_msg(msg) self.assertEquals( common.Header._make( (common.Version.VERSION1, True, 162, 0x5177520e, 0x503d9, common.ModuleID.DIAGLOG)), header) self.assertEquals(diaglog.StringMessage._make(('abc', )), payload) # Test 6: An estmiator message mac = '\x42\x62\x89\x67\x4d\xb4' msg = '\x20\x12\x60\x24\x87\x75\x15\x37\x00\x00\x09' + \ '\x00' + mac + '\xff\x06\x01\x2d\x00\x00\x00\x08\x00\x00\x00' + \ '\x50\x00\x00\x00\x42' header, payload = parser.unpack_msg(msg) self.assertEquals( common.Header._make( (common.Version.VERSION2, False, 18, 0x75872460, 0x3715, common.ModuleID.ESTIMATOR)), header) self.assertEquals( estimator.ServingDataMetrics._make( (common.ether_ntoa(mac), common.BSSInfo(255, 6, 1), 45, 8, 80, 66)), payload) # Test 7: An unhandled module msg = '\x11\xa2\x51\x77\x52\x0e\x00\x05\x03\xd9\x70\x12\x11\x22' self.assertRaises(ValueError, parser.unpack_msg, msg)
def test_post_assoc_steer(self): """Verify the parsing of the post-association steer message.""" test_cases = itertools.product([ SteerType.STEER_TYPE_NONE, SteerType.STEER_TYPE_LEGACY, SteerType.STEER_TYPE_BTM_AND_BLACKLIST, SteerType.STEER_TYPE_BTM, SteerType.STEER_TYPE_BTM_AND_BLACKLIST_ACTIVE, SteerType.STEER_TYPE_BTM_ACTIVE, SteerType.STEER_TYPE_PREASSOCIATION, SteerType.STEER_TYPE_BTM_BE, SteerType.STEER_TYPE_BTM_BE_ACTIVE, SteerType.STEER_TYPE_BTM_BLACKLIST_BE, SteerType.STEER_TYPE_BTM_BLACKLIST_BE_ACTIVE, SteerType.STEER_TYPE_LEGACY_BE ], [ SteerReasonType.REASON_USER, SteerReasonType.REASON_ACTIVE_UPGRADE, SteerReasonType.REASON_ACTIVE_DOWNGRADE_RATE, SteerReasonType.REASON_ACTIVE_DOWNGRADE_RSSI, SteerReasonType.REASON_IDLE_UPGRADE, SteerReasonType.REASON_IDLE_DOWNGRADE, SteerReasonType.REASON_ACTIVE_OFFLOAD, SteerReasonType.REASON_IDLE_OFFLOAD, SteerReasonType.REASON_AP_REQUEST, SteerReasonType.REASON_INTERFERENCE_AVOIDANCE, SteerReasonType.REASON_INVALID ]) for test_case in test_cases: # Type of steering. mac = '\x94\x45\x8d\x13\xb7\x86' transaction = '\x10' assoc_ap = '\xff' assoc_channel = '\x0b' assoc_ess = '\x00' ap1 = '\xff' channel1 = '\x0a' ess1 = '\x00' msg = '\x05' + mac + transaction + chr(test_case[0].value) + \ chr(test_case[1].value) + \ assoc_ap + assoc_channel + assoc_ess + '\x01' + ap1 + channel1 + ess1 payload = steerexec.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals( steerexec.PostAssocSteer._make( (common.ether_ntoa(mac), 0x10, test_case[0], test_case[1], common.BSSInfo(0xFF, 0x0B, 0), 1, [common.BSSInfo(0xFF, 0x0A, 0)])), payload) # Same as above but in big-endian (which makes no difference) payload = steerexec.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals( steerexec.PostAssocSteer._make( (common.ether_ntoa(mac), 0x10, test_case[0], test_case[1], common.BSSInfo(0xFF, 0x0B, 0), 1, [common.BSSInfo(0xFF, 0x0A, 0)])), payload) # Test 2: Invalid steer type (Version 2) mac = '\x49\xcd\x30\xda\x0c\x4c' msg = '\x05' + mac + transaction + '\x0d' + '\x01' + \ assoc_ap + assoc_channel + assoc_ess + '\x01' + ap1 + channel1 + ess1 self.assertRaises(MessageMalformedError, steerexec.unpack_payload_from_bytes, common.Version.VERSION2, False, msg) # Test 3: Invalid steer reason (Version 2) mac = '\x49\xcd\x30\xda\x0c\x4c' msg = '\x05' + mac + transaction + '\x01' + '\x0d' + \ assoc_ap + assoc_channel + assoc_ess + '\x01' + ap1 + channel1 + ess1 self.assertRaises(MessageMalformedError, steerexec.unpack_payload_from_bytes, common.Version.VERSION2, False, msg) # Test 4: Two candidate BSSes ap2 = '\xff' channel2 = '\x0c' ess2 = '\x00' msg = '\x05' + mac + transaction + chr(test_case[0].value) + \ chr(test_case[1].value) + \ assoc_ap + assoc_channel + assoc_ess + '\x02' + ap1 + channel1 + ess1 + \ ap2 + channel2 + ess2 payload = steerexec.unpack_payload_from_bytes(common.Version.VERSION2, False, msg) self.assertEquals( steerexec.PostAssocSteer._make( (common.ether_ntoa(mac), 0x10, test_case[0], test_case[1], common.BSSInfo(0xFF, 0x0B, 0), 2, [ common.BSSInfo(0xFF, 0x0A, 0), common.BSSInfo(0xFF, 0x0C, 0) ])), payload) # Test 5: Can't be parsed with version 1 self.assertRaises(MessageMalformedError, steerexec.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Test 6: Incorrect candidate count raises an error msg = '\x05' + mac + transaction + '\x01' + '\x01' + \ assoc_ap + assoc_channel + assoc_ess + '\x00' + ap1 + channel1 + ess1 + \ ap2 + channel2 + ess2 self.assertRaises(MessageMalformedError, steerexec.unpack_payload_from_bytes, common.Version.VERSION2, False, msg) msg = '\x05' + mac + transaction + '\x01' + '\x01' + \ assoc_ap + assoc_channel + assoc_ess + '\x03' + ap1 + channel1 + ess1 + \ ap2 + channel2 + ess2 self.assertRaises(MessageMalformedError, steerexec.unpack_payload_from_bytes, common.Version.VERSION2, False, msg)
def test_association_update(self): """Verify the parsing of the association update message.""" # Test 1: Associated on 2.4 GHz mac = '\xb2\xdd\x69\xa1\xb3\xe3' msg = '\x00' + mac + '\x00\x01\x00' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, False, msg) self.assertEquals(stadb.AssociationUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_24G, True, False)), payload) # Same as above but in big-endian (which makes no difference) payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, True, msg) self.assertEquals(stadb.AssociationUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_24G, True, False)), payload) # Test 2: Associated on 5 GHz mac = '\x67\xae\x3b\x86\xc3\x8e' msg = '\x00' + mac + '\x01\x01\x01' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, False, msg) self.assertEquals(stadb.AssociationUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_5G, True, True)), payload) # Same as above but in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, True, msg) self.assertEquals(stadb.AssociationUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_5G, True, True)), payload) # Test 3: Disassociated mac = '\x29\xed\x66\x8b\x16\x77' msg = '\x00' + mac + '\x02\x00\x00' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, False, msg) self.assertEquals(stadb.AssociationUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_INVALID, False, False)), payload) # Same as above but in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, True, msg) self.assertEquals(stadb.AssociationUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_INVALID, False, False)), payload) # Test 3.1: A valid version 1 payload with a version 2 header is malformed self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION2, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION2, True, msg) # Test 4: Association update on a bogus band is malformed mac = '\xfc\x91\x14\xc5\x3c\x7f' msg = '\x00' + mac + '\x03\x00\x01' self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, True, msg) # Repeat above test with a version 2 message # Test 5: Associated on 2.4 GHz mac = '\xb2\xdd\x69\xa1\xb3\xe3' msg = '\x00' + mac + '\xFF\x0b\x00\x01\x01\x00\x01\x00' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals(stadb.AssociationUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 11, 0), True, True, False, True, False)), payload) # Same as above but in big-endian (which makes no difference) payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals(stadb.AssociationUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 11, 0), True, True, False, True, False)), payload) # Test 6: Associated on 5 GHz mac = '\x67\xae\x3b\x86\xc3\x8e' msg = '\x00' + mac + '\xFF\x64\x00\x01\x01\x01\x00\x01' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals(stadb.AssociationUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), True, True, True, False, True)), payload) # Same as above but in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals(stadb.AssociationUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), True, True, True, False, True)), payload) # Test 7: Disassociated mac = '\x29\xed\x66\x8b\x16\x77' msg = '\x00' + mac + '\xFF\x64\x00\x00\x00\x00\x00\x00' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals(stadb.AssociationUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), False, False, False, False, False)), payload) # Same as above but in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals(stadb.AssociationUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), False, False, False, False, False)), payload)
def test_activity_update(self): """Verify the parsing of the activity update message v1.""" test_cases = itertools.product([BAND_TYPE.BAND_24G, BAND_TYPE.BAND_5G], [True, False]) for test_case in test_cases: # Test with all combinations of band and activity change mac = '\xcd\x92\x1f\xe3\x84\x11' msg = '\x02' + mac + chr(test_case[0].value) + chr(test_case[1]) payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, False, msg) self.assertEquals(stadb.ActivityUpdate._make( (common.ether_ntoa(mac), test_case[0], test_case[1])), payload) # Same as above but in big-endian (which makes no difference) payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, True, msg) self.assertEquals(stadb.ActivityUpdate._make( (common.ether_ntoa(mac), test_case[0], test_case[1])), payload) # Test 2: Activity update on a invalid band is malformed mac = '\x00\x66\x9a\x85\x7b\xd9' msg = '\x02' + mac + '\x02\x00' self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Test 3: Activity update on a bogus band is malformed mac = '\xbb\xb9\x21\xd4\xab\xd4' msg = '\x02' + mac + '\x03\x00' self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) """Verify the parsing of the activity update message v2.""" for activity in [True, False]: # Test with all combinations of activity change mac = '\xcd\x92\x1f\xe3\x84\x11' msg = '\x02' + mac + '\xFF\x64\x00' + chr(activity) payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals(stadb.ActivityUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), activity)), payload) # Same as above but in big-endian (which makes no difference) payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals(stadb.ActivityUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), activity)), payload)
def test_rssi_update(self): """Verify the parsing of the RSSI update message v1.""" # Test 1: RSSI update on 2.4 GHz mac = '\x8a\x25\xf2\x83\x93\x85' msg = '\x01' + mac + '\x00\x17' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, False, msg) self.assertEquals(stadb.RSSIUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_24G, 23)), payload) # Same in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, True, msg) self.assertEquals(stadb.RSSIUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_24G, 23)), payload) # Test 2: RSSI update on 5 GHz mac = '\x32\x10\xbb\xf6\xa5\x35' msg = '\x01' + mac + '\x01\x12' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, False, msg) self.assertEquals(stadb.RSSIUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_5G, 18)), payload) # Same in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION1, True, msg) self.assertEquals(stadb.RSSIUpdate._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_5G, 18)), payload) # Test 3: RSSI update on invalid band is malformed mac = '\xff\x7e\x74\x17\x52\xa9' msg = '\x01' + mac + '\x02\x06' self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, True, msg) # Test 4: RSSI update on invalid band is malformed mac = '\xab\xd6\xd1\xd0\xfd\x25' msg = '\x01' + mac + '\x03\x06' self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION1, True, msg) """Verify the parsing of the RSSI update message v2.""" # Test 1: RSSI update on channel 1 mac = '\x8a\x25\xf2\x83\x93\x85' msg = '\x02' + mac + '\xff\x01\x00\x17' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals(stadb.RSSIUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 1, 0), 23)), payload) # Same in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals(stadb.RSSIUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 1, 0), 23)), payload) # Test 2: RSSI update on channel 100 mac = '\x32\x10\xbb\xf6\xa5\x35' msg = '\x02' + mac + '\x00\x24\x01\x12' payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, False, msg) self.assertEquals(stadb.RSSIUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0, 36, 1), 18)), payload) # Same in big endian payload = stadb.unpack_payload_from_bytes( common.Version.VERSION2, True, msg) self.assertEquals(stadb.RSSIUpdate_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0, 36, 1), 18)), payload) # Test 3: RSSI update with V2 header and V1 payload is malformed mac = '\x32\x10\xbb\xf6\xa5\x35' msg = '\x02' + mac + '\x01\x12' self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION2, False, msg) # Same in big endian self.assertRaises( MessageMalformedError, stadb.unpack_payload_from_bytes, common.Version.VERSION2, True, msg)
def test_raw_rssi(self): """Verify the parsing of the RSSI message v1.""" # Test 1: Measurement on 2.4 GHz mac = '\x42\x62\x89\x67\x4d\xb4' msg = '\x01' + mac + '\x00\x16' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION1, False, msg) self.assertEquals( wlanif.RawRSSI._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_24G, 22)), payload) # Test 2: Similar but in big endian format (which makes no difference) msg = '\x01' + mac + '\x00\x25' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION1, True, msg) self.assertEquals( wlanif.RawRSSI._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_24G, 37)), payload) # Test 3: RSSI measurement on 5 GHz now mac = '\xec\x40\xe4\xe7\xf5\xa5' msg = '\x01' + mac + '\x01\x50' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION1, False, msg) self.assertEquals( wlanif.RawRSSI._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_5G, 80)), payload) # Test 4: Same in big endian msg = '\x01' + mac + '\x01\x47' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION1, True, msg) self.assertEquals( wlanif.RawRSSI._make( (common.ether_ntoa(mac), BAND_TYPE.BAND_5G, 71)), payload) # Test 5: The invalid enumerated band is rejected msg = '\x01' + mac + '\x02\x37' self.assertRaises(MessageMalformedError, wlanif.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) self.assertRaises(MessageMalformedError, wlanif.unpack_payload_from_bytes, common.Version.VERSION1, True, msg) # Test 6: Band that is not even contained within the enum msg = '\x01' + mac + '\x03\x37' self.assertRaises(MessageMalformedError, wlanif.unpack_payload_from_bytes, common.Version.VERSION1, False, msg) self.assertRaises(MessageMalformedError, wlanif.unpack_payload_from_bytes, common.Version.VERSION1, True, msg) """Verify the parsing of the RSSI message v2.""" # Test 1: Measurement on APID = 0xFF, channel = 100, essId = 0 msg = '\x01' + mac + '\xFF\x64\x00\x16' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION2, False, msg) self.assertEquals( wlanif.RawRSSI_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), 22)), payload) # Test 2: Similar but in big endian format (which makes no difference) msg = '\x01' + mac + '\xFF\x64\x00\x16' payload = wlanif.unpack_payload_from_bytes(common.Version.VERSION2, True, msg) self.assertEquals( wlanif.RawRSSI_v2._make( (common.ether_ntoa(mac), common.BSSInfo(0xFF, 100, 0), 22)), payload)