blob: 39b7f2193ce6f96a89b2431edd28acf1725a43a0 [file] [log] [blame]
Rich Lanedacbe732013-01-29 17:32:11 -08001import logging
2import struct
3
4from oftest import config
Rich Lanee717c6e2013-03-12 10:25:50 -07005import ofp
Rich Lanedacbe732013-01-29 17:32:11 -08006import oftest.base_tests as base_tests
7
8from oftest.testutils import *
9
Rich Lanedacbe732013-01-29 17:32:11 -080010@nonstandard
11class 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 Lane75ea24d2013-01-30 15:27:19 -080020 # 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 Laneb659c762013-03-11 23:08:36 -070024 action_list=[ofp.action.nicira_dec_ttl()])
Rich Lane75ea24d2013-01-30 15:27:19 -080025
Rich Lanedacbe732013-01-29 17:32:11 -080026 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 Lane19c9d762013-08-05 16:42:21 -070029 buffer_id=0xffffffff,
Rich Lanedacbe732013-01-29 17:32:11 -080030 actions=[
Rich Laneb659c762013-03-11 23:08:36 -070031 ofp.action.nicira_dec_ttl(),
Rich Lanedacbe732013-01-29 17:32:11 -080032 ofp.action.output(port=portA),
Rich Laneb659c762013-03-11 23:08:36 -070033 ofp.action.nicira_dec_ttl(),
Rich Lanedacbe732013-01-29 17:32:11 -080034 ofp.action.output(port=portB),
Rich Laneb659c762013-03-11 23:08:36 -070035 ofp.action.nicira_dec_ttl(),
Rich Lanedacbe732013-01-29 17:32:11 -080036 ofp.action.output(port=portC)])
37 self.controller.message_send(msg)
38
39 receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=2), [portA], [], self)
40 receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=1), [portB], [], self)
41 receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=0), [], [portC], self)
Rich Lane33be15e2013-08-05 16:42:44 -070042
43@nonstandard
44class TtlDecrementZeroTtl(base_tests.SimpleDataPlane):
45 def runTest(self):
46 of_ports = config["port_map"].keys()
47 of_ports.sort()
48 self.assertTrue(len(of_ports) >= 2, "Not enough ports for test")
49 portA = of_ports[0]
50 portB = of_ports[1]
51
52 outpkt = simple_tcp_packet(pktlen=100, ip_ttl=0)
53 msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE,
54 data=str(outpkt),
55 buffer_id=0xffffffff,
56 actions=[
57 ofp.action.output(port=portA),
58 ofp.action.nicira_dec_ttl(),
59 ofp.action.output(port=portB)])
60 self.controller.message_send(msg)
61
62 receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=0), [portA], [], self)
63 receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=0), [], [portB], self)