Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 1 | |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 2 | import sys |
| 3 | |
| 4 | try: |
| 5 | import scapy.all as scapy |
| 6 | except: |
| 7 | try: |
| 8 | import scapy as scapy |
| 9 | except: |
| 10 | sys.exit("Need to install scapy for packet parsing") |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 11 | |
Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 12 | import oftest.controller as controller |
| 13 | import oftest.cstruct as ofp |
| 14 | import oftest.message as message |
| 15 | import oftest.dataplane as dataplane |
| 16 | import oftest.action as action |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 17 | import oftest.parse as parse |
Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 18 | import logging |
| 19 | |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 20 | def 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 Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 27 | logger.info("Deleting all flows") |
| 28 | msg = message.flow_mod() |
| 29 | msg.match.wildcards = ofp.OFPFW_ALL |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 30 | msg.out_port = ofp.OFPP_NONE |
Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 31 | msg.command = ofp.OFPFC_DELETE |
| 32 | msg.buffer_id = 0xffffffff |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 33 | return ctrl.message_send(msg) |
| 34 | |
| 35 | def simple_tcp_packet(pktlen=100, |
| 36 | dl_dst='00:01:02:03:04:05', |
| 37 | dl_src='00:06:07:08:09:0a', |
| 38 | ip_src='192.168.0.1', |
| 39 | ip_dst='192.168.0.2', |
| 40 | tcp_sport=1234, |
| 41 | tcp_dport=80 |
| 42 | ): |
| 43 | """ |
| 44 | Return a simple dataplane TCP packet |
| 45 | |
| 46 | Supports a few parameters: |
| 47 | @param len Length of packet in bytes w/o CRC |
| 48 | @param dl_dst Destinatino MAC |
| 49 | @param dl_src Source MAC |
| 50 | @param ip_src IP source |
| 51 | @param ip_dst IP destination |
| 52 | @param tcp_dport TCP destination port |
| 53 | @param ip_sport TCP source port |
| 54 | |
| 55 | Generates a simple TCP request. Users |
| 56 | shouldn't assume anything about this packet other than that |
| 57 | it is a valid ethernet/IP/TCP frame. |
| 58 | """ |
| 59 | pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 60 | scapy.IP(src=ip_src, dst=ip_dst)/ \ |
| 61 | scapy.TCP(sport=tcp_sport, dport=tcp_dport) |
| 62 | pkt = pkt/("D" * (pktlen - len(pkt))) |
| 63 | |
| 64 | return pkt |
| 65 | |
| 66 | def do_barrier(ctrl): |
| 67 | b = message.barrier_request() |
| 68 | ctrl.transact(b) |