blob: b03ace7cebf20ea65ced22365f0591127b1100a0 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Lanedacbe732013-01-29 17:32:11 -080017import logging
18import struct
19
20from oftest import config
Rich Lanee717c6e2013-03-12 10:25:50 -070021import ofp
Rich Lanedacbe732013-01-29 17:32:11 -080022import oftest.base_tests as base_tests
23
24from oftest.testutils import *
25
Rich Lanedacbe732013-01-29 17:32:11 -080026@nonstandard
27class 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 Lane75ea24d2013-01-30 15:27:19 -080036 # 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 Laneb659c762013-03-11 23:08:36 -070040 action_list=[ofp.action.nicira_dec_ttl()])
Rich Lane75ea24d2013-01-30 15:27:19 -080041
Rich Lanedacbe732013-01-29 17:32:11 -080042 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 Lane19c9d762013-08-05 16:42:21 -070045 buffer_id=0xffffffff,
Rich Lanedacbe732013-01-29 17:32:11 -080046 actions=[
Rich Laneb659c762013-03-11 23:08:36 -070047 ofp.action.nicira_dec_ttl(),
Rich Lanedacbe732013-01-29 17:32:11 -080048 ofp.action.output(port=portA),
Rich Laneb659c762013-03-11 23:08:36 -070049 ofp.action.nicira_dec_ttl(),
Rich Lanedacbe732013-01-29 17:32:11 -080050 ofp.action.output(port=portB),
Rich Laneb659c762013-03-11 23:08:36 -070051 ofp.action.nicira_dec_ttl(),
Rich Lanedacbe732013-01-29 17:32:11 -080052 ofp.action.output(port=portC)])
53 self.controller.message_send(msg)
54
Rich Lanee4b384d2013-09-13 14:33:40 -070055 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 Lane33be15e2013-08-05 16:42:44 -070059
60@nonstandard
61class 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 Lanee4b384d2013-09-13 14:33:40 -070079 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)