autotest: Add tools for writing DHCP tests
Add dhcp_test_server, dhcp_packet, and dhcp_handling_rule.
dhcp_test_server starts up a thread to watch a given port for DHCP
packets, and can be programmed with instances of DhcpHandlingRule to
expect certain packets and report errors. dhcp_packet defines utility
logic to create and parse DHCP packets. There are much more elaborate
comments and example usages at the top of all three files.
Because this is a fairly elaborate piece of logic, I wrote some simple
sanity tests for both DhcpPacket and DhcpTestServer that may be run with
$ python dhcp_packet && echo Test passed.
$ python dhcp_test_server && echo Test passed.
The tests in dhcp_packet.py make sure that packet and serialization
works for discovery packets. Tests in dhcp_test_server.py walk through
a simple test case where the server expects a DISCOVERY packet, and the
client expects a valid response.
For debugging and sanity checking, I've taken packet logs of a
conversation between dhclient and dhcpd negotiating a ip lease. These
logs are in dhcp_test_data/*. I use these logs in the test for
DhcpPacket, but they could conceviably be useful in future testing.
BUG=chromium-os:32809
TEST=as described above
Change-Id: I04c6806e8b02446b0758e507c14ba85f6d10e30f
Reviewed-on: https://gerrit.chromium.org/gerrit/31134
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Christopher Wiley <wiley@chromium.org>
9 files changed