blob: 6f8e0b4d2d39ef3164695fcedb4571e2847b65d2 [file] [log] [blame]
Dan Talaycoc901f4d2010-03-07 21:55:45 -08001
Dan Talayco41eae8b2010-03-10 13:57:06 -08002import scapy.all as scapy
3
Dan Talaycoc901f4d2010-03-07 21:55:45 -08004import oftest.controller as controller
5import oftest.cstruct as ofp
6import oftest.message as message
7import oftest.dataplane as dataplane
8import oftest.action as action
Dan Talayco41eae8b2010-03-10 13:57:06 -08009import oftest.parse as parse
Dan Talaycoc901f4d2010-03-07 21:55:45 -080010import logging
11
Dan Talayco41eae8b2010-03-10 13:57:06 -080012def delete_all_flows(ctrl, logger):
13 """
14 Delete all flows on the switch
15 @param ctrl The controller object for the test
16 @param logger Logging object
17 """
18
Dan Talaycoc901f4d2010-03-07 21:55:45 -080019 logger.info("Deleting all flows")
20 msg = message.flow_mod()
21 msg.match.wildcards = ofp.OFPFW_ALL
Dan Talayco41eae8b2010-03-10 13:57:06 -080022 msg.out_port = ofp.OFPP_NONE
Dan Talaycoc901f4d2010-03-07 21:55:45 -080023 msg.command = ofp.OFPFC_DELETE
24 msg.buffer_id = 0xffffffff
Dan Talayco41eae8b2010-03-10 13:57:06 -080025 return ctrl.message_send(msg)
26
27def simple_tcp_packet(pktlen=100,
28 dl_dst='00:01:02:03:04:05',
29 dl_src='00:06:07:08:09:0a',
30 ip_src='192.168.0.1',
31 ip_dst='192.168.0.2',
32 tcp_sport=1234,
33 tcp_dport=80
34 ):
35 """
36 Return a simple dataplane TCP packet
37
38 Supports a few parameters:
39 @param len Length of packet in bytes w/o CRC
40 @param dl_dst Destinatino MAC
41 @param dl_src Source MAC
42 @param ip_src IP source
43 @param ip_dst IP destination
44 @param tcp_dport TCP destination port
45 @param ip_sport TCP source port
46
47 Generates a simple TCP request. Users
48 shouldn't assume anything about this packet other than that
49 it is a valid ethernet/IP/TCP frame.
50 """
51 pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \
52 scapy.IP(src=ip_src, dst=ip_dst)/ \
53 scapy.TCP(sport=tcp_sport, dport=tcp_dport)
54 pkt = pkt/("D" * (pktlen - len(pkt)))
55
56 return pkt
57
58def do_barrier(ctrl):
59 b = message.barrier_request()
60 ctrl.transact(b)