blob: 3e6d03c7e07a42e393bf26e16f8372659bd1ca42 [file] [log] [blame]
alshabib8292c852016-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,
21 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
22
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
40def buildIgmp(payload):
41 pkt = pkt = IGMPv3.fixup(scapy.Ether() / scapy.IP() / payload)
42 if len(pkt) < 60:
43 pad_len = 60 - len(pkt)
44 pad = scapy.scapy.layers.l2.Padding()
45 pad.load = '\x00' * pad_len
46 pkt = pkt / pad
47 return pkt
48
49def double_vlan_udp_packet(pktlen=100,
50 eth_dst='00:01:02:03:04:05',
51 eth_src='00:06:07:08:09:0a',
52 dl_vlan_enable=False,
53 c_vlan_vid=0,
54 c_vlan_pcp=0,
55 s_vlan_vid=0,
56 s_vlan_pcp=0,
57 ip_src='192.168.0.1',
58 ip_dst='192.168.0.2',
59 ip_tos=0,
60 ip_ttl=64,
61 udp_sport=1234,
62 udp_dport=80,
63 ip_ihl=None,
64 ip_options=False,
65 eth_type=0x8100
66 ):
67 """
68 Return a double vlan tagged dataplane UDP packet
69 Supports a few parameters:
70 @param len Length of packet in bytes w/o CRC
71 @param eth_dst Destination MAC
72 @param eth_src Source MAC
73 @param dl_vlan_enable True if the packet is with vlan, False otherwise
74 @param c_vlan_vid CVLAN ID
75 @param c_vlan_pcp CVLAN priority
76 @param s_vlan_vid SVLAN ID
77 @param s_vlan_pcp SVLAN priority
78 @param ip_src IP source
79 @param ip_dst IP destination
80 @param ip_tos IP ToS
81 @param ip_ttl IP TTL
82 @param udp_dport UDP destination port
83 @param udp_sport UDP source port
84
85 Generates a simple UDP packet. Users shouldn't assume anything about
86 this packet other than that it is a valid ethernet/IP/UDP frame.
87 """
88
89 if MINSIZE > pktlen:
90 pktlen = MINSIZE
91
92 # Note Dot1Q.id is really CFI
93 if (dl_vlan_enable):
94 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
95 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
96 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
97 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
98 scapy.UDP(sport=udp_sport, dport=udp_dport)
99 else:
100 if not ip_options:
101 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
102 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
103 scapy.UDP(sport=udp_sport, dport=udp_dport)
104
105 else:
106 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
107 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
108 scapy.UDP(sport=udp_sport, dport=udp_dport)
109
110 pkt = pkt / ("D" * (pktlen - len(pkt)))
111
112 return pkt