espressif / esp-protocols

Collection of ESP-IDF components related to networking protocols
166 stars 115 forks source link

mdns add browse support (IDFGH-12512) #522

Closed zwx1995esp closed 2 months ago

zwx1995esp commented 4 months ago

This MR introduces a new query mode: browse(like the avahi-browse -r _test._tcp).

mdns_browse_new is used for starting a browse, it will add a browse in the link list of _mdns_server, if there is some service start or leave, it will be notified by the callback passed in the API. When the service is leaved, the ttl will be 0, the related result will be freed after syncing to the notifier callback.

mdns_browse_delete is used for stop the browse query and free the related memory.

All apis are followed the mdns action mechanism.

jonsmirl commented 3 months ago

The algorithm for doing this is described in the MDNS specification. Is it being followed? https://datatracker.ietf.org/doc/html/rfc6762#section-5.2

I just encountered this inability to monitor when trying to build a matter controller. esp-matter needs this feature.

zwx1995esp commented 3 months ago

The algorithm for doing this is described in the MDNS specification. Is it being followed? https://datatracker.ietf.org/doc/html/rfc6762#section-5.2

I just encountered this inability to monitor when trying to build a matter controller. esp-matter needs this feature.

No, I just send the query once and then listen for the service which has been queried.

jonsmirl commented 3 months ago

For esp-matter with just need to do a query on something like _matterc._tcp and then monitor add/deletes. This is the event interface. https://github.com/project-chip/connectedhomeip/blob/master/src/lib/dnssd/platform/DnssdBrowseDelegate.h

There is no requirement to implement everything in the MDNS spec, all that is needed is enough to implement this interface.

chshu commented 3 months ago

@jonsmirl This MR introduces a continuous browse feature which is similar to avahi-browse, it will send the query once, then monitor the incoming responses, and trigger the callbacks immediately once the service changes.

It was required by Thread BR project, while it should also works for your Matter controller use case. Let us know If there are any functionalities missing.

zwx1995esp commented 3 months ago

just left few nitpicks and of course we need to test the changes properly.

Hi, @david-cermak @gabsuren . I do these tests manually in my locally.

And in my local test, I test for these scenarios manually:

  1. Start browsing with the service _test._udp on S3, and start/stop publishing these services via linux host using avahi
    (S-A) avahi-publish-service test _test._udp 12347 test=4444 dn="for_ci_br_test1010"
    (S-B) avahi-publish-service aaa _test._udp 20617 zwx=esp dn="for_ci_br_test"

    case-1: Start browsing with the service _test._udp, start (S-A), stop (S-A), Stop browsing with the service _test._udp (check the heap usage during the test). case-2: Start browsing with the service _test._udp, start (S-A), start (S-B), stop (S-A), stop (S-B), Stop browsing with the service _test._udp (check the heap usage during the test). case-3: Start browsing with the service _test._udp, start (S-A), start (S-B), stop (S-B), stop (S-A), Stop browsing with the service _test._udp (check the heap usage during the test). case-4: start (S-A), start (S-B), start browsing with the service _test._udp, stop (S-B), stop (S-A), Stop browsing with the service _test._udp (check the heap usage during the test).

  2. Start browsing with the service _test._udp and _testtt._udp, and start/stop publishing these services via linux host using avahi
    
    (S-A) avahi-publish-service test _test._udp 12347 test=4444 dn="for_ci_br_test1010"
    (S-B) avahi-publish-service aaa _test._udp 20617 zwx=esp dn="for_ci_br_test"

(S-C) avahi-publish-service testxxx _testtt._udp 1234 test=1235 dn="for_ci_br_test"


case-1: Start browsing with the service `_test._udp`, Start browsing with the service `_testtt._udp`, start (S-A), stop (S-A), , start (S-C), stop (S-C), Stop browsing with the service `_test._udp`, Stop browsing with the service `_testtt._udp` (check the heap usage during the test).
case-2:  Start browsing with the service `_test._udp`, Start browsing with the service `_testtt._udp`, start (S-A), start (S-B), start (S-C), stop (S-A), stop (S-B), stop (S-C), Stop browsing with the service `_test._udp` , Stop browsing with the service `_testtt._udp`  (check the heap usage during the test).
3. The API `mdns_browse_new` and  `mdns_browse_delete`
case-1:  Start browsing with the service `_test._udp` for several times, check the heap usage during the test.
case-2: Stop browsing with the service `_test._udp` for several times, check the heap usage during the test.
case-3: Start browsing with the service `_test._udp`, then sop browsing with the service `_test._udp`. Rerun for several times,  check the heap usage during the test.

All the test case seems work fine in my local test env.