Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 17 | import logging |
| 18 | import struct |
| 19 | |
| 20 | from oftest import config |
Rich Lane | e717c6e | 2013-03-12 10:25:50 -0700 | [diff] [blame] | 21 | import ofp |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 22 | import oftest.base_tests as base_tests |
| 23 | |
| 24 | from oftest.testutils import * |
| 25 | |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 26 | @nonstandard |
| 27 | class TtlDecrement(base_tests.SimpleDataPlane): |
| 28 | def runTest(self): |
| 29 | of_ports = config["port_map"].keys() |
| 30 | of_ports.sort() |
| 31 | self.assertTrue(len(of_ports) >= 3, "Not enough ports for test") |
| 32 | portA = of_ports[0] |
| 33 | portB = of_ports[1] |
| 34 | portC = of_ports[2] |
| 35 | |
Rich Lane | 75ea24d | 2013-01-30 15:27:19 -0800 | [diff] [blame] | 36 | # Test using flow mods (does not test drop) |
| 37 | flow_match_test(self, config["port_map"], |
| 38 | pkt=simple_tcp_packet(pktlen=100, ip_ttl=2), |
| 39 | exp_pkt=simple_tcp_packet(pktlen=100, ip_ttl=1), |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 40 | action_list=[ofp.action.nicira_dec_ttl()]) |
Rich Lane | 75ea24d | 2013-01-30 15:27:19 -0800 | [diff] [blame] | 41 | |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 42 | outpkt = simple_tcp_packet(pktlen=100, ip_ttl=3) |
| 43 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
| 44 | data=str(outpkt), |
Rich Lane | 19c9d76 | 2013-08-05 16:42:21 -0700 | [diff] [blame] | 45 | buffer_id=0xffffffff, |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 46 | actions=[ |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 47 | ofp.action.nicira_dec_ttl(), |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 48 | ofp.action.output(port=portA), |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 49 | ofp.action.nicira_dec_ttl(), |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 50 | ofp.action.output(port=portB), |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 51 | ofp.action.nicira_dec_ttl(), |
Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame] | 52 | ofp.action.output(port=portC)]) |
| 53 | self.controller.message_send(msg) |
| 54 | |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 55 | verify_packet(self, simple_tcp_packet(ip_ttl=2), portA) |
| 56 | verify_packet(self, simple_tcp_packet(ip_ttl=1), portB) |
| 57 | verify_no_packet(self, simple_tcp_packet(ip_ttl=0), portC) |
| 58 | verify_no_other_packets(self) |
Rich Lane | 33be15e | 2013-08-05 16:42:44 -0700 | [diff] [blame] | 59 | |
| 60 | @nonstandard |
| 61 | class TtlDecrementZeroTtl(base_tests.SimpleDataPlane): |
| 62 | def runTest(self): |
| 63 | of_ports = config["port_map"].keys() |
| 64 | of_ports.sort() |
| 65 | self.assertTrue(len(of_ports) >= 2, "Not enough ports for test") |
| 66 | portA = of_ports[0] |
| 67 | portB = of_ports[1] |
| 68 | |
| 69 | outpkt = simple_tcp_packet(pktlen=100, ip_ttl=0) |
| 70 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
| 71 | data=str(outpkt), |
| 72 | buffer_id=0xffffffff, |
| 73 | actions=[ |
| 74 | ofp.action.output(port=portA), |
| 75 | ofp.action.nicira_dec_ttl(), |
| 76 | ofp.action.output(port=portB)]) |
| 77 | self.controller.message_send(msg) |
| 78 | |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 79 | verify_packet(self, simple_tcp_packet(ip_ttl=0), portA) |
| 80 | verify_no_packet(self, simple_tcp_packet(ip_ttl=0), portB) |
| 81 | verify_no_other_packets(self) |