11#define SENSOR_ETH_USE_DHCP
17static const byte kMac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0x2A, 0x3C};
36 Ethernet.dhcp_should_succeed =
false;
55 TEST_ASSERT_EQUAL_INT(0,
Ethernet.static_begin_calls);
72 const byte rtd[6] = {0x4a, 0x27, 0xe2, 0x3a, 0xad, 0x71};
76 const byte lo[6] = {0, 0, 0, 0, 0x00, 0x00};
77 const byte fe[6] = {0, 0, 0, 0, 0xFE, 0xFF};
78 const byte ff[6] = {0, 0, 0, 0, 0xFF, 0x01};
97 TEST_ASSERT_FALSE(
Ethernet.localIP()[0] == 192);
107 Ethernet.dhcp_should_succeed =
true;
111 TEST_ASSERT_EQUAL_STRING(
"DHCP (assigned by the server)",
120 const int asked =
Ethernet.dhcp_begin_calls;
124 TEST_ASSERT_EQUAL_INT(asked,
Ethernet.dhcp_begin_calls);
129 const int asked =
Ethernet.dhcp_begin_calls;
134 TEST_ASSERT_EQUAL_INT(asked + 1,
Ethernet.dhcp_begin_calls);
143 Ethernet.dhcp_should_succeed =
true;
154 const int asked =
Ethernet.dhcp_begin_calls;
157 TEST_ASSERT_EQUAL_INT(asked,
Ethernet.dhcp_begin_calls);
163 const int asked =
Ethernet.dhcp_begin_calls;
169 TEST_ASSERT_EQUAL_INT(asked,
Ethernet.dhcp_begin_calls);
177 Ethernet.dhcp_should_succeed =
true;
182 TEST_ASSERT_EQUAL_INT(1,
Ethernet.maintain_calls);
188 TEST_ASSERT_EQUAL_INT(0,
Ethernet.maintain_calls);
193 Ethernet.dhcp_should_succeed =
true;
201 TEST_ASSERT_EQUAL_INT(0,
Ethernet.maintain_calls);
215 TEST_ASSERT_TRUE(changed);
218 TEST_ASSERT_TRUE(server ==
IPAddress(192, 168, 2, 77));
230 Ethernet.dhcp_should_succeed =
true;
233 int writes =
Ethernet.set_local_ip_calls;
240 TEST_ASSERT_EQUAL_INT(writes,
Ethernet.set_local_ip_calls);
267 TEST_ASSERT_EQUAL_UINT8(0xDE, s.
mac[0]);
268 TEST_ASSERT_EQUAL_UINT8(0x3C, s.
mac[5]);
void stub_set_millis(unsigned long v)
static EthernetClass Ethernet
#define SENSOR_ZEROCONF_SERVER_SILENCE_MS
#define SENSOR_ETH_DHCP_RETRY_INTERVAL_MS
void configure(State &s, const byte mac[6])
AddressSource begin(State &s, IPAddress dns, IPAddress gateway)
Bring the interface up: ask the ground station for an address, and take the recovery address only if ...
void printMac(const State &s)
Print the MAC as aa:bb:cc:dd:ee:ff.
IPAddress recoveryAddress(const byte mac[6])
The board's recovery address, from its MAC: 169.254.
uint8_t boardId(const State &s)
The board's ID: the last octet of the address the server assigned (192.168.2.31 -> 31).
void beginOtaHold(State &s)
Called when an OTA transfer starts, so the address cannot move under it.
bool retryDhcp(State &s, IPAddress dns, IPAddress gateway)
On the recovery address, ask for a lease again every SENSOR_ETH_DHCP_RETRY_INTERVAL_MS.
bool usingDhcp(const State &s)
bool serverWentSilent(const State &s)
Server has stopped talking — forget it and resume discovery broadcasts.
AddressSource
How the board ended up with the address it is using.
@ Recovery
no DHCP answer: 169.254.x.y from the MAC, reflash-only
@ Dhcp
assigned by the ground station — the normal case
bool onServerPacket(State &s, IPAddress remote_ip, IPAddress &serverIP)
A server packet arrived from remote_ip; adopt it as the server address.
void maintainLease(State &s)
Renew the lease as it expires.
bool hasAddress(const State &s)
const char * sourceName(AddressSource s)
bool serverLearned
server IP adopted from an inbound packet
unsigned long lastServerPacketMillis
static const IPAddress kDns(192, 168, 2, 1)
static const IPAddress kGateway(0, 0, 0, 0)
static const IPAddress kRecoveryIP(169, 254, 43, 60)
static BoardNet::State recoveringState()
void test_no_retry_during_an_ota(void)
void test_retry_waits_for_the_interval(void)
void test_lease_is_renewed_only_on_a_lease(void)
static const IPAddress kDefaultServer(192, 168, 2, 20)
void test_ota_suspends_renewal(void)
void test_server_silence_trips_after_timeout(void)
static BoardNet::State makeState()
void test_recovery_address_formula(void)
void test_mac_is_stored_for_reporting(void)
void test_no_answer_puts_the_board_on_its_recovery_address(void)
void test_repeat_server_packet_is_not_a_change(void)
void test_dhcp_lease_is_adopted(void)
void test_server_silence_only_after_it_was_learned(void)
void test_learning_a_server_never_moves_our_address(void)
void test_board_id_is_the_assigned_address(void)
void test_source_is_reported_honestly(void)
void test_retry_that_gets_a_lease_moves_the_board(void)
static const IPAddress kLeasedIP(192, 168, 2, 137)
static const byte kMac[6]
void test_server_is_learned_from_its_packets(void)
void test_failed_retry_stays_reflashable(void)