3
3
import random
4
4
import socket
5
5
import sys
6
+ import struct
7
+ import ipaddress
8
+ import re
6
9
7
10
import ptf
8
11
import ptf .packet as scapy
13
16
from ptf .mask import Mask
14
17
from ptf .testutils import *
15
18
19
+
16
20
class PfcWdTest (BaseTest ):
17
21
def __init__ (self ):
18
22
BaseTest .__init__ (self )
@@ -24,41 +28,83 @@ def setUp(self):
24
28
self .queue_index = int (self .test_params ['queue_index' ])
25
29
self .pkt_count = int (self .test_params ['pkt_count' ])
26
30
self .port_src = int (self .test_params ['port_src' ])
27
- self .ip_src = self .test_params ['ip_src ' ]
31
+ self .port_dst = self .test_params ['port_dst ' ]
28
32
self .ip_dst = self .test_params ['ip_dst' ]
33
+ self .port_type = self .test_params ['port_type' ]
29
34
self .wd_action = self .test_params .get ('wd_action' , 'drop' )
30
35
31
36
def runTest (self ):
32
37
ecn = 1
33
38
dscp = self .queue_index
34
39
tos = dscp << 2
35
40
tos |= ecn
36
- dst_port_list = range (0 ,32 )
37
- sport = random .randint (0 , 65535 )
38
- dport = random .randint (0 , 65535 )
41
+
42
+ matches = re .findall ('\[([\d\s]+)\]' , self .port_dst )
43
+
44
+ dst_port_list = []
45
+ for match in matches :
46
+ for port in match .split ():
47
+ dst_port_list .append (int (port ))
39
48
src_mac = self .dataplane .get_mac (0 , 0 )
40
49
41
- pkt = simple_tcp_packet (
42
- eth_dst = self .router_mac ,
43
- eth_src = src_mac ,
44
- ip_src = self .ip_src ,
45
- ip_dst = self .ip_dst ,
46
- ip_tos = tos ,
47
- tcp_sport = sport ,
48
- tcp_dport = dport ,
49
- ip_ttl = 64 )
50
- exp_pkt = simple_tcp_packet (
51
- eth_src = self .router_mac ,
52
- ip_src = self .ip_src ,
53
- ip_dst = self .ip_dst ,
54
- ip_tos = tos ,
55
- tcp_sport = sport ,
56
- tcp_dport = dport ,
57
- ip_ttl = 63 )
58
- masked_exp_pkt = Mask (exp_pkt )
59
- masked_exp_pkt .set_do_not_care_scapy (scapy .Ether , "dst" )
50
+ if self .port_type == "portchannel" :
51
+ for x in range (0 , self .pkt_count ):
52
+ sport = random .randint (0 , 65535 )
53
+ dport = random .randint (0 , 65535 )
54
+ ip_src = socket .inet_ntoa (struct .pack ('>I' , random .randint (1 , 0xffffffff )))
55
+ ip_src = ipaddress .IPv4Address (unicode (ip_src ,'utf-8' ))
56
+ while ip_src == ipaddress .IPv4Address (unicode (self .ip_dst ,'utf-8' )) or ip_src .is_multicast or ip_src .is_private or ip_src .is_global or ip_src .is_reserved :
57
+ ip_src = socket .inet_ntoa (struct .pack ('>I' , random .randint (1 , 0xffffffff )))
58
+ ip_src = ipaddress .IPv4Address (unicode (ip_src ,'utf-8' ))
59
+
60
+ ip_src = str (ip_src )
61
+ pkt = simple_tcp_packet (
62
+ eth_dst = self .router_mac ,
63
+ eth_src = src_mac ,
64
+ ip_src = ip_src ,
65
+ ip_dst = self .ip_dst ,
66
+ ip_tos = tos ,
67
+ tcp_sport = sport ,
68
+ tcp_dport = dport ,
69
+ ip_ttl = 64 )
70
+ exp_pkt = simple_tcp_packet (
71
+ eth_src = self .router_mac ,
72
+ ip_src = ip_src ,
73
+ ip_dst = self .ip_dst ,
74
+ ip_tos = tos ,
75
+ tcp_sport = sport ,
76
+ tcp_dport = dport ,
77
+ ip_ttl = 63 )
78
+ masked_exp_pkt = Mask (exp_pkt )
79
+ masked_exp_pkt .set_do_not_care_scapy (scapy .Ether , "dst" )
80
+
81
+ send_packet (self , self .port_src , pkt , 1 )
82
+ else :
83
+ sport = random .randint (0 , 65535 )
84
+ dport = random .randint (0 , 65535 )
85
+ ip_src = "1.1.1.1"
86
+
87
+ pkt = simple_tcp_packet (
88
+ eth_dst = self .router_mac ,
89
+ eth_src = src_mac ,
90
+ ip_src = ip_src ,
91
+ ip_dst = self .ip_dst ,
92
+ ip_tos = tos ,
93
+ tcp_sport = sport ,
94
+ tcp_dport = dport ,
95
+ ip_ttl = 64 )
96
+ exp_pkt = simple_tcp_packet (
97
+ eth_src = self .router_mac ,
98
+ ip_src = ip_src ,
99
+ ip_dst = self .ip_dst ,
100
+ ip_tos = tos ,
101
+ tcp_sport = sport ,
102
+ tcp_dport = dport ,
103
+ ip_ttl = 63 )
104
+ masked_exp_pkt = Mask (exp_pkt )
105
+ masked_exp_pkt .set_do_not_care_scapy (scapy .Ether , "dst" )
60
106
61
- send_packet (self , self .port_src , pkt , self .pkt_count )
107
+ send_packet (self , self .port_src , pkt , self .pkt_count )
62
108
63
109
if self .wd_action == 'drop' :
64
110
return verify_no_packet_any (self , masked_exp_pkt , dst_port_list )
0 commit comments