Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 1 | |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 2 | import scapy.all as scapy |
| 3 | |
Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 4 | import oftest.controller as controller |
| 5 | import oftest.cstruct as ofp |
| 6 | import oftest.message as message |
| 7 | import oftest.dataplane as dataplane |
| 8 | import oftest.action as action |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 9 | import oftest.parse as parse |
Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 10 | import logging |
| 11 | |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 12 | def 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 Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 19 | logger.info("Deleting all flows") |
| 20 | msg = message.flow_mod() |
| 21 | msg.match.wildcards = ofp.OFPFW_ALL |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 22 | msg.out_port = ofp.OFPP_NONE |
Dan Talayco | c901f4d | 2010-03-07 21:55:45 -0800 | [diff] [blame] | 23 | msg.command = ofp.OFPFC_DELETE |
| 24 | msg.buffer_id = 0xffffffff |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 25 | return ctrl.message_send(msg) |
| 26 | |
| 27 | def 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 | |
| 58 | def do_barrier(ctrl): |
| 59 | b = message.barrier_request() |
| 60 | ctrl.transact(b) |