Hi,
I need some help to figure out how to build a sort of DHCP protocol for moteino.
I want to use some not permanently linked nodes. They will be powered only when needed and will be used on different gateways depending of the situation.
So at startup, the node won't know its network, nor its nodeID nor any other detail (exact frequency value...)
Below is how I intend to build the system, please feel free to advise me about guessed problems of such configuration, or better way to do it.
Situation :
- I could have undefined number of nodes per gateway (1-50, probably <10 most of the time)
- I could have undefined number of gateways in same area (1-10, probably <3 most of the time)
- a new node without a previous valid configuration shouldn't be started with more than one running gateway because we can't decide on which gateway it will be affected, but the system should deal with this case
The protocol will be the same as TCP/IP DHCP protocol :
- DHCPDISCOVER (node): broadcast request on DHCP network (new node or no DHCPACK received after a DHCPREQUEST request)
- DHCPOFFER (server): configuration proposal from the DHCP server depending of free leases
- DHCPREQUEST (node): specific configuration request based on last used configuration or from DHCPOFFER proposal
- DHCPACK (server): validation of the proposed configuration
I will have only one gateway per networkID.
For each gateway, I need 2 radios (on same node, or one gateway and a second node as a dedicated DHCP server to listen on DHCP network while the gateway communicate on its own network)
In my case, gateways will be permanently powered so there's no lowpower consideration for them.
the DHCP servers will be on a specific networkID (255 ?), so any DHCP request will be broadcasted on this network and be received by all DHCP servers.
At this point, I wonder which configuration could be better (if any):
- 1st : any DHCP server use 1 different ID, the node will broadcast the DHCPDISCOVER request, then DHCPREQUEST will be sent to the first DHCP server responding
- 2nd : all the DHCP servers use same ID, the node will broadcast any request, DHCPREQUEST with bad configuration will be ignored by servers, so only one could reply
- 3th : all the DHCP servers use same ID, the node will send any request to this address, DHCPREQUEST with bad configuration will be ignored by servers, so only one could reply
First question, in case of more than 1 running gateway, with same code, all servers will try to answer to a DHCPDISCOVER request at same time, it will cause collisions and probably not a readable answer... How to deal with that ? A specific delay based on node ID (if all servers have a specific ID) before answering ? It will produce a prioritisation list of servers and possibly a long delay for an ID like 250. A random delay, so there will be good probabilities than one server will reply before others (depending of how many servers are running), at first or even at later tries.
2nd question, is there a difference between broadcasting the request, or sending the request on a shared address since only one server will have a compatible configuration with the DHCPREQUEST and will reply ? What's the best way to achieve this ? Using a specific address is one more parameter to configure in each DHCP servers (but each one should be set anyway)
So, in an ideal world, the node will send a DHCPDISCOVER request, will receive at least one readable answer with an DHCP offer (and will ignore others), will send a DHCPREQUEST for a specific configuration, and the only server with compatible configuration (because it's the one who sent the DHCPOFFER) will reply with DHCPACK if everything is ok.
Then the radio of the node will be set with the new configuration and will communicate with its gateway.
With only one running gateway, it should works. If there are more than one gateway, but if the node was on one of them last time, it should received a DHCPACK from the DHCP server with the correct configuration on the DHCPREQUEST sent.
If it doesn't receive any positive answer, a DHCPDISCOVER request will be sent, and this is the only "correct" way to be in the situation where a DHCPDISCOVER request could be sent with more than one running gateway (and will produce an unpredictable behavior).
If the looked gateway is not running, but there are more than one running gateway, this is not the right way to start the node.
Thks for reading !