blob: b97ab5ae31ca8ae7f54cf434c263a069a00da1ec [file] [log] [blame]
alshabibcde318b2016-03-01 22:49:13 -08001from oftest.testutils import *
2import oftest.packet as scapy
3from oftest import config
4
5import ofp
6
7# These parameters can be altered from the command line using the -t or --test-params= options.
8# Example: -t 'onu_port=129;olt_port=288;device_type=pmc'
9#
10onu_port = test_param_get("onu_port", 130)
11onu_port2 = test_param_get("onu_port2", 131)
12olt_port = test_param_get("olt_port", 258)
13device_type = test_param_get("device_type", "normal") # options: "normal", "pmc", "cpqd"
14
15
16def createAllGroupAdd(group_id, ports=[]):
17 buckets = []
18
19 for portNum in ports:
20 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Adminb3bae672016-03-02 13:00:08 -080021 actions=[ofp.action.output(port=portNum)]))
alshabibcde318b2016-03-01 22:49:13 -080022
23 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
24
25 return group_add
26
27
28def createAllGroupMod(group_id, ports=[]):
29 buckets = []
30
31 for portNum in ports:
32 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
33 actions=[ofp.action.output(port=portNum)]))
34
35 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
36 buckets=buckets)
37
38 return group_mod
39
alshabibcde318b2016-03-01 22:49:13 -080040def double_vlan_udp_packet(pktlen=100,
41 eth_dst='00:01:02:03:04:05',
42 eth_src='00:06:07:08:09:0a',
43 dl_vlan_enable=False,
44 c_vlan_vid=0,
45 c_vlan_pcp=0,
46 s_vlan_vid=0,
47 s_vlan_pcp=0,
48 ip_src='192.168.0.1',
49 ip_dst='192.168.0.2',
50 ip_tos=0,
51 ip_ttl=64,
52 udp_sport=1234,
53 udp_dport=80,
54 ip_ihl=None,
55 ip_options=False,
56 eth_type=0x8100
57 ):
58 """
59 Return a double vlan tagged dataplane UDP packet
60 Supports a few parameters:
61 @param len Length of packet in bytes w/o CRC
62 @param eth_dst Destination MAC
63 @param eth_src Source MAC
64 @param dl_vlan_enable True if the packet is with vlan, False otherwise
65 @param c_vlan_vid CVLAN ID
66 @param c_vlan_pcp CVLAN priority
67 @param s_vlan_vid SVLAN ID
68 @param s_vlan_pcp SVLAN priority
69 @param ip_src IP source
70 @param ip_dst IP destination
71 @param ip_tos IP ToS
72 @param ip_ttl IP TTL
73 @param udp_dport UDP destination port
74 @param udp_sport UDP source port
75
76 Generates a simple UDP packet. Users shouldn't assume anything about
77 this packet other than that it is a valid ethernet/IP/UDP frame.
78 """
79
80 if MINSIZE > pktlen:
81 pktlen = MINSIZE
82
83 # Note Dot1Q.id is really CFI
84 if (dl_vlan_enable):
85 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
86 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
87 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
88 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
89 scapy.UDP(sport=udp_sport, dport=udp_dport)
90 else:
91 if not ip_options:
92 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
93 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
94 scapy.UDP(sport=udp_sport, dport=udp_dport)
95
96 else:
97 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
98 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
99 scapy.UDP(sport=udp_sport, dport=udp_dport)
100
101 pkt = pkt / ("D" * (pktlen - len(pkt)))
102
Adminb3bae672016-03-02 13:00:08 -0800103 return pkt