blob: 862571f6ed35167e404edec11205326d3d66ae12 [file] [log] [blame]
Dan Talaycoc901f4d2010-03-07 21:55:45 -08001
Dan Talaycod2ca1032010-03-10 14:40:26 -08002import sys
3
4try:
5 import scapy.all as scapy
6except:
7 try:
8 import scapy as scapy
9 except:
10 sys.exit("Need to install scapy for packet parsing")
Dan Talayco41eae8b2010-03-10 13:57:06 -080011
Dan Talaycoc901f4d2010-03-07 21:55:45 -080012import oftest.controller as controller
13import oftest.cstruct as ofp
14import oftest.message as message
15import oftest.dataplane as dataplane
16import oftest.action as action
Dan Talayco41eae8b2010-03-10 13:57:06 -080017import oftest.parse as parse
Dan Talaycoc901f4d2010-03-07 21:55:45 -080018import logging
19
Dan Talayco41eae8b2010-03-10 13:57:06 -080020def delete_all_flows(ctrl, logger):
21 """
22 Delete all flows on the switch
23 @param ctrl The controller object for the test
24 @param logger Logging object
25 """
26
Dan Talaycoc901f4d2010-03-07 21:55:45 -080027 logger.info("Deleting all flows")
28 msg = message.flow_mod()
29 msg.match.wildcards = ofp.OFPFW_ALL
Dan Talayco41eae8b2010-03-10 13:57:06 -080030 msg.out_port = ofp.OFPP_NONE
Dan Talaycoc901f4d2010-03-07 21:55:45 -080031 msg.command = ofp.OFPFC_DELETE
32 msg.buffer_id = 0xffffffff
Dan Talayco41eae8b2010-03-10 13:57:06 -080033 return ctrl.message_send(msg)
34
35def simple_tcp_packet(pktlen=100,
36 dl_dst='00:01:02:03:04:05',
37 dl_src='00:06:07:08:09:0a',
Tatsuya Yabe460321e2010-05-25 17:50:49 -070038 dl_vlan_enable=False,
39 dl_vlan=0,
40 dl_vlan_pcp=0,
Dan Talayco41eae8b2010-03-10 13:57:06 -080041 ip_src='192.168.0.1',
42 ip_dst='192.168.0.2',
Tatsuya Yabe460321e2010-05-25 17:50:49 -070043 ip_tos=0,
Dan Talayco41eae8b2010-03-10 13:57:06 -080044 tcp_sport=1234,
45 tcp_dport=80
46 ):
47 """
48 Return a simple dataplane TCP packet
49
50 Supports a few parameters:
51 @param len Length of packet in bytes w/o CRC
52 @param dl_dst Destinatino MAC
53 @param dl_src Source MAC
Tatsuya Yabe460321e2010-05-25 17:50:49 -070054 @param dl_vlan_enable True if the packet is with vlan, False otherwise
55 @param dl_vlan VLAN ID
56 @param dl_vlan_pcp VLAN priority
Dan Talayco41eae8b2010-03-10 13:57:06 -080057 @param ip_src IP source
58 @param ip_dst IP destination
Tatsuya Yabe460321e2010-05-25 17:50:49 -070059 @param ip_tos IP ToS
Dan Talayco41eae8b2010-03-10 13:57:06 -080060 @param tcp_dport TCP destination port
61 @param ip_sport TCP source port
62
63 Generates a simple TCP request. Users
64 shouldn't assume anything about this packet other than that
65 it is a valid ethernet/IP/TCP frame.
66 """
Tatsuya Yabe460321e2010-05-25 17:50:49 -070067 if (dl_vlan_enable):
68 pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \
69 scapy.Dot1Q(prio=dl_vlan_pcp, id=0, vlan=dl_vlan)/ \
70 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \
71 scapy.TCP(sport=tcp_sport, dport=tcp_dport)
72 else:
73 pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \
74 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \
75 scapy.TCP(sport=tcp_sport, dport=tcp_dport)
76
Dan Talayco41eae8b2010-03-10 13:57:06 -080077 pkt = pkt/("D" * (pktlen - len(pkt)))
78
79 return pkt
80
81def do_barrier(ctrl):
82 b = message.barrier_request()
83 ctrl.transact(b)