Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 1 | import logging |
| 2 | import struct |
| 3 | |
| 4 | from oftest import config |
Rich Lane | e717c6e | 2013-03-12 10:25:50 -0700 | [diff] [blame] | 5 | import ofp |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 6 | import oftest.base_tests as base_tests |
| 7 | |
| 8 | from oftest.testutils import * |
| 9 | |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 10 | @nonstandard |
| 11 | class TtlDecrement(base_tests.SimpleDataPlane): |
| 12 | def runTest(self): |
| 13 | of_ports = config["port_map"].keys() |
| 14 | of_ports.sort() |
| 15 | self.assertTrue(len(of_ports) >= 3, "Not enough ports for test") |
| 16 | portA = of_ports[0] |
| 17 | portB = of_ports[1] |
| 18 | portC = of_ports[2] |
| 19 | |
Rich Lane | 75ea24d | 2013-01-30 15:27:19 -0800 | [diff] [blame] | 20 | # Test using flow mods (does not test drop) |
| 21 | flow_match_test(self, config["port_map"], |
| 22 | pkt=simple_tcp_packet(pktlen=100, ip_ttl=2), |
| 23 | exp_pkt=simple_tcp_packet(pktlen=100, ip_ttl=1), |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 24 | action_list=[ofp.action.nicira_dec_ttl()]) |
Rich Lane | 75ea24d | 2013-01-30 15:27:19 -0800 | [diff] [blame] | 25 | |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 26 | outpkt = simple_tcp_packet(pktlen=100, ip_ttl=3) |
| 27 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
| 28 | data=str(outpkt), |
Rich Lane | 19c9d76 | 2013-08-05 16:42:21 -0700 | [diff] [blame] | 29 | buffer_id=0xffffffff, |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 30 | actions=[ |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 31 | ofp.action.nicira_dec_ttl(), |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 32 | ofp.action.output(port=portA), |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 33 | ofp.action.nicira_dec_ttl(), |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 34 | ofp.action.output(port=portB), |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 35 | ofp.action.nicira_dec_ttl(), |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 36 | ofp.action.output(port=portC)]) |
| 37 | self.controller.message_send(msg) |
| 38 | |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 39 | verify_packet(self, simple_tcp_packet(ip_ttl=2), portA) |
| 40 | verify_packet(self, simple_tcp_packet(ip_ttl=1), portB) |
| 41 | verify_no_packet(self, simple_tcp_packet(ip_ttl=0), portC) |
| 42 | verify_no_other_packets(self) |
Rich Lane | 33be15e | 2013-08-05 16:42:44 -0700 | [diff] [blame] | 43 | |
| 44 | @nonstandard |
| 45 | class TtlDecrementZeroTtl(base_tests.SimpleDataPlane): |
| 46 | def runTest(self): |
| 47 | of_ports = config["port_map"].keys() |
| 48 | of_ports.sort() |
| 49 | self.assertTrue(len(of_ports) >= 2, "Not enough ports for test") |
| 50 | portA = of_ports[0] |
| 51 | portB = of_ports[1] |
| 52 | |
| 53 | outpkt = simple_tcp_packet(pktlen=100, ip_ttl=0) |
| 54 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
| 55 | data=str(outpkt), |
| 56 | buffer_id=0xffffffff, |
| 57 | actions=[ |
| 58 | ofp.action.output(port=portA), |
| 59 | ofp.action.nicira_dec_ttl(), |
| 60 | ofp.action.output(port=portB)]) |
| 61 | self.controller.message_send(msg) |
| 62 | |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 63 | verify_packet(self, simple_tcp_packet(ip_ttl=0), portA) |
| 64 | verify_no_packet(self, simple_tcp_packet(ip_ttl=0), portB) |
| 65 | verify_no_other_packets(self) |