Author Topic: fnStartDHCP & sending UDP just after getting DHCP_SUCCESSFUL.  (Read 8034 times)

Offline thamanjd

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
My project starts in static IP mode.
I need to change it to dhcp without resetting the board.
Firstly, i was using fnStartDHCP like this:
fnStartDHCP(TASK_MY_TASK));
But using this method the task never picked up and interrupt_event_msg from dhcp

I had to follow the example from application.c to get the interrupt_event_msg.
fnStartDHCP((UTASK_TASK)(FORCE_INIT | TASK_MY_TASK));

What is it about the extra bits in there that make it work?

Secondly, I went to send a udp message after getting DHCP_SUCCESSFUL. The UDP message did not get sent and the function returned -1.
If i receive a UDP message in between that and attempting to send another UDP message, that second UDP transmission out is transmitted successfully.

Ive tried leaving three or four seconds in between getting DHCP_SUCCESSFUL and sending the UDP but that doesnt do anything.

I also tried releasing the socket then getting it again, also without success.

Any ideas?

John Dowdell

Offline thamanjd

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: fnStartDHCP & sending UDP just after getting DHCP_SUCCESSFUL.
« Reply #1 on: March 28, 2008, 08:27:10 AM »
OK. so the RETURN of -1 from fnSendUDP means NO_ARP_ENTRY. fnStartDHCP clears the arp cache i guess? Using ethereal i can now see ARP resolving for the IP after attempting that UDP Send.

So I dont need an incoming UDP to get it to work. Sending the first UDP prompts the ARP resolve and i i wait a bit and send another UDP packet, it goes that second time. 

Is there a way of prompting ARP to resolve for the IP sometime before i send the UDP?  The other method is to keep trying the fnSendUDP a couple of times between short intervals until arp has resolved.

With UDP, will the first transmission out to an ip (without having received anything from that ip) return with NO_ARP_ENTRY? Is this also the case with trying to make a TCP/IP connection to an IP for the first time?

John Dowdell

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: fnStartDHCP & sending UDP just after getting DHCP_SUCCESSFUL.
« Reply #2 on: March 28, 2008, 08:53:33 PM »
Hi John

The way that this works is described here:
http://www.utasker.com/forum/index.php?topic=41.msg171#msg171

Whether the destinate address is in the ARP cache depends on whether it was used before and whether it has timed out in the meantime - therefore the first transmission can always result in the resolver being restarted (and this not transmitted).

The technique is to use the ARP_RESOLUTION_SUCCESS event to resend the data as soon as the IP address has been resolved, which means that one frame needs to be backed up if it is important that it is not lost. [Voice over IP type frames, for example, wouldn't repeat because it doesn't make sense but other uses may want to do it as standard. Don't forget that delivery of a UDP frame is never guarantied by UDP itself]

It is possible to add a fixed IP address to the ARP cache if the destination is known and doesn't change - thus avoiding any ARP resolution: see http://www.utasker.com/forum/index.php?topic=195.msg716#msg716

At the moment there is no method to prompt ARP resolution, apart from sending a test frame, but I think that it could be added quite easily. However this will not necessarily exclude the NO_ARP_ENTRY case because, on a VERY busy network, it is possible that the ARP entry is flushed very quickly when other addresses need to be recorded. A larger ARP table helps (ARP_TABLE_ENTRIES) as does adding the define ARP_IGNORE_FOREIGN_ENTRIES [note - not in all packages since added on 21.08.2007].

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: fnStartDHCP & sending UDP just after getting DHCP_SUCCESSFUL.
« Reply #3 on: March 28, 2008, 09:17:49 PM »
John

I am not sure why the first method didn't get work but the explanation is probably due to the value in network.ucOurIP.

DHCP can either start fresh (this is forced by using the FORCE_INIT flag, regardless of the value in network.ucOurIP - which is a trick and not necessarily following RFCs) which happens when it has no knowledge of its IP address (network.ucOurIP must be 0.0.0.0). If network.ucOurIP has an IP address programmed, DHCP starts in the INIT_REBOOT state - this means that it will FIRST attempt to get an IP address which it has 'known' to have used before - a sort of preferred IP address. This is often not successful since a lot of DHCP servers will refuse to give it. The result is that it first has to try a few times before giving upand then starting fresh, which should then work.

Since FORCE_INIT avoids the attempt to get a specified address, wich often is not accepted, it means that the time it takes to get a the network details is faster (it can save maybe 10s).

Therefore I expect in fact the same results with FORCE_INIT or without it, when the network.ucOurIP is first flushed to zero.

Regards

Mark


Offline thamanjd

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: fnStartDHCP & sending UDP just after getting DHCP_SUCCESSFUL.
« Reply #4 on: March 31, 2008, 12:32:04 AM »
Maybe i'm being impatient and not waiting long enough when i tried using fnStartDHCP without the FORCE_INIT. I'll play around with it without using FORCE_INIT.