Rich Lane | dacbe73 | 2013-01-29 17:32:11 -0800 | [diff] [blame^] | 1 | import logging |
| 2 | import struct |
| 3 | |
| 4 | from oftest import config |
| 5 | import of10 as ofp |
| 6 | import oftest.base_tests as base_tests |
| 7 | |
| 8 | from oftest.testutils import * |
| 9 | |
| 10 | class action_nx_dec_ttl(ofp.action.action_vendor): |
| 11 | def __init__(self): |
| 12 | ofp.action.action_vendor.__init__(self) |
| 13 | self.vendor = 0x00002320 |
| 14 | |
| 15 | def pack(self): |
| 16 | return ofp.action.action_vendor.pack(self) + struct.pack("!HHL", 18, 0x0, 0x0) |
| 17 | |
| 18 | def __len__(self): |
| 19 | return 16 |
| 20 | |
| 21 | def show(self, prefix=''): |
| 22 | return prefix + 'dec_ttl: ' + '\n' + ofp.action.action_vendor.show(self) |
| 23 | |
| 24 | @nonstandard |
| 25 | class TtlDecrement(base_tests.SimpleDataPlane): |
| 26 | def runTest(self): |
| 27 | of_ports = config["port_map"].keys() |
| 28 | of_ports.sort() |
| 29 | self.assertTrue(len(of_ports) >= 3, "Not enough ports for test") |
| 30 | portA = of_ports[0] |
| 31 | portB = of_ports[1] |
| 32 | portC = of_ports[2] |
| 33 | |
| 34 | outpkt = simple_tcp_packet(pktlen=100, ip_ttl=3) |
| 35 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
| 36 | data=str(outpkt), |
| 37 | actions=[ |
| 38 | action_nx_dec_ttl(), |
| 39 | ofp.action.output(port=portA), |
| 40 | action_nx_dec_ttl(), |
| 41 | ofp.action.output(port=portB), |
| 42 | action_nx_dec_ttl(), |
| 43 | ofp.action.output(port=portC)]) |
| 44 | self.controller.message_send(msg) |
| 45 | |
| 46 | receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=2), [portA], [], self) |
| 47 | receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=1), [portB], [], self) |
| 48 | receive_pkt_check(self.dataplane, simple_tcp_packet(ip_ttl=0), [], [portC], self) |