@@ -362,9 +362,20 @@ def insert_dynamic_values(dot1x_expected_events):
362
362
msg = 'expected event: {} not in events_that_happened {}' .format (
363
363
expected_event , events_that_happened ))
364
364
365
+ def _eapol_filter (self , fields ):
366
+ return '(' + ' and ' .join (('ether proto 0x888e' ,) + fields ) + ')'
367
+
368
+ def _success_eapol_filter (self , expect_success ):
369
+ eap_code = '0x04'
370
+ if expect_success :
371
+ eap_code = '0x03'
372
+ return self ._eapol_filter (('ether[14:4] == 0x01000004' , 'ether[18] == %s' % eap_code ))
373
+
374
+ def _logoff_eapol_filter (self ):
375
+ return self ._eapol_filter (('ether[14:4] == 0x01020000' ,))
376
+
365
377
def try_8021x (self , host , port_num , conf , and_logoff = False , terminate_wpasupplicant = False ,
366
- wpasup_timeout = 180 , tcpdump_timeout = 15 , tcpdump_packets = 10 ,
367
- expect_success = True ):
378
+ wpasup_timeout = 180 , tcpdump_timeout = 30 , expect_success = True ):
368
379
if expect_success :
369
380
self .wait_8021x_flows (port_num )
370
381
port_labels = self .port_labels (port_num )
@@ -380,7 +391,11 @@ def try_8021x(self, host, port_num, conf, and_logoff=False, terminate_wpasupplic
380
391
'dp_dot1x_failure_total' , default = 0 )
381
392
dp_logoff_total = self .scrape_prometheus_var (
382
393
'dp_dot1x_logoff_total' , default = 0 )
383
- tcpdump_filter = 'ether proto 0x888e'
394
+ tcpdump_filters = [self ._success_eapol_filter (expect_success )]
395
+ if and_logoff :
396
+ tcpdump_filters .append (self ._logoff_eapol_filter ())
397
+ tcpdump_packets = len (tcpdump_filters )
398
+ tcpdump_filter = ' or ' .join (tcpdump_filters )
384
399
tcpdump_txt = self .tcpdump_helper (
385
400
host , tcpdump_filter , [
386
401
lambda : self .wpa_supplicant_callback (
@@ -393,6 +408,8 @@ def try_8021x(self, host, port_num, conf, and_logoff=False, terminate_wpasupplic
393
408
if not and_logoff :
394
409
self .wait_8021x_success_flows (host , port_num )
395
410
success = 'Success' in tcpdump_txt
411
+ if expect_success != success :
412
+ return False
396
413
new_success_total = self .scrape_prometheus_var (
397
414
'port_dot1x_success_total' , labels = port_labels , default = 0 )
398
415
new_failure_total = self .scrape_prometheus_var (
@@ -405,8 +422,6 @@ def try_8021x(self, host, port_num, conf, and_logoff=False, terminate_wpasupplic
405
422
'dp_dot1x_failure_total' , default = 0 )
406
423
new_dp_logoff_total = self .scrape_prometheus_var (
407
424
'dp_dot1x_logoff_total' , default = 0 )
408
- if expect_success != success :
409
- return False
410
425
if expect_success and success :
411
426
self .assertGreater (new_success_total , success_total )
412
427
self .assertGreater (new_dp_success_total , dp_success_total )
@@ -735,11 +750,10 @@ class Faucet8021XIdentityOnPortUpTest(Faucet8021XBaseTest):
735
750
def test_untagged (self ):
736
751
port_no1 = self .port_map ['port_1' ]
737
752
738
- # start wpa sup, logon, then send id request. should then be 2 success.
753
+ # start wpa sup, logon, then send id request.
739
754
self .set_port_up (port_no1 )
740
755
self .assertTrue (self .try_8021x (
741
- self .eapol1_host , port_no1 , self .wpasupplicant_conf_1 , and_logoff = False ,
742
- tcpdump_timeout = 180 , tcpdump_packets = 6 ))
756
+ self .eapol1_host , port_no1 , self .wpasupplicant_conf_1 , and_logoff = False ))
743
757
self .set_port_down (port_no1 )
744
758
self .one_ipv4_ping (
745
759
self .eapol1_host , self .ping_host .IP (),
@@ -749,15 +763,18 @@ def port_up(port):
749
763
self .set_port_up (port )
750
764
self .wait_8021x_flows (port )
751
765
752
- tcpdump_filter = 'ether proto 0x888e'
766
+ username = 'user'
767
+ username_bytes = '' .join (('%2x' % ord (c ) for c in username ))
768
+ tcpdump_filter = ' or ' .join ((
769
+ self ._success_eapol_filter (True ),
770
+ self ._eapol_filter (('ether[23:4] == 0x%s' % username_bytes ,))))
753
771
tcpdump_txt = self .tcpdump_helper (
754
772
self .eapol1_host , tcpdump_filter , [
755
773
lambda : port_up (port_no1 )],
756
- timeout = 80 , vflags = '-vvv' , packets = 10 )
774
+ timeout = 30 , vflags = '-vvv' , packets = 2 )
757
775
for req_str in (
758
- 'len 5, Request (1)' , # assume that this is the identity request
759
- 'Identity: user' , # supplicant replies with username
760
- 'Success' , # supplicant success
776
+ 'Identity: %s' % username , # supplicant replies with username
777
+ 'Success' , # supplicant success
761
778
):
762
779
self .assertTrue (req_str in tcpdump_txt , msg = '%s not in %s' % (req_str , tcpdump_txt ))
763
780
0 commit comments