VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Automatic Service Discovery

Automatic Service Discovery feature enables possibility to discover VSMs in case UgCS server and VSM is using dynamic addresses. Used SSDP protocol (https://tools.ietf.org/html/draft-cai-ssdp-v1-03) as basis and actual data from packet captures when Windows and iOS searches for various stuff on my LAN.

Protocol Description

There are three messages invloved. They are HTTP messages without body, formatted according to HTTP specs, rfc7230.

  1. Search. Issued by locator (UgCS server, in our case) on all interfaces using multicast address 239.198.46.46 to locate the requested service by type (ST). For example:
    M-SEARCH * HTTP/1.1
    Host: 239.198.46.46:1900
    Man: "ssdp:discover"
    ST: ugcs:vsm:ardupilot
    MX: 3
    
  2. Response to search. Sent by service as a response to M-SEARCH. Unicast. Contains service type (ST), unique service name (USN) and location (Location). For example:
    HTTP/1.1 200 OK
    ST: ugcs:vsm:ardupilot
    USN: Ardupilot VSM
    Location: 192.168.1.33:5556
    ID: 12345678
    
  3. Notification. Sent by service when it becomes available. Multicast. Contains service type (NT), unique service name (USN) and location (Location). For example:
    NOTIFY * HTTP/1.1
    Host: 239.198.46.46:1900
    NT: ugcs:vsm:ardupilot
    NTS: ssdp:alive
    USN: Ardupilot VSM
    Location: 192.168.1.33:5556
    ID: 12345678
    

There is a field "ID" added to the response and notify message. It specifies the service instance. Service client can use the ID field to distinguish between several locations of the same service instance to avoud multiple simultaneous connections. The ID is randomly generated on VSM startup and does change with each restart.

Service discovery support in SDK

VSM SDK has support of automatic service discovery based on the above protocol.

Both ends are implemented in SDK, so developer can create both service advertisers and service locators with minimal effort. Five functions provide interface to service discovery protocol:

Function Description
ugcs::vsm::Service_discovery_processor::Advertise_service Starts advertising the given service. Issues NOTIFY ssdp:alive message on all connected interfaces and then on each newly connected interface. From now on, vsm will respond to M-SEARCH requests for given service type.
ugcs::vsm::Service_discovery_processor::Unadvertise_service Stop advertising of given service. Issues NOTIFY ssdp:byebye on all interfaces.
ugcs::vsm::Service_discovery_processor::Subscribe_for_service Start subscription of given service type. Issues M-SEARCH request on all interfaces. Calls user specified callback when a response message NOTIFY message is received for given service type.
ugcs::vsm::Service_discovery_processor::Unsubscribe_from_service Stop subscription
ugcs::vsm::Service_discovery_processor::Search_for_service Send out M-SEARCH request for given service type on all interfaces. Use this to force re-query of subscribed service.

See file service_discovery_processor.h for details.

Service advertise support is already enabled by default and can be used by any VSM by adding lines to vsm.conf file.

Service discovery related vsm.conf file parameters

All parameters are optional:

Parameter name Description
service_discovery.address Multicast IP address which is used as destination address when sending out M_SEARCH and NOTIFY messages. Default: 239.198.46.46
service_discovery.port UDP port on which service discovery protocol will listen. Default: 1991
service_discovery.advertise.[<service_id>.]name Service name.
service_discovery.advertise.[<service_id>.]type Type of service. This is the string by which the services are located. Type is case sensitive.
service_discovery.advertise.[<service_id>.]location URI of service. Location in form: <protocol>://<host>:<port> where host can be ip address or dns name. Host can be replaced by special token "{local_address}". It will be replaced by IP of the local interface when sending out search response packets or NOTIFY packets.
service_discovery.vsm_name Automatically enables VSM dicovery on specified port (ucs.local_listening_port)

The parameteer service_discovery.vsm_name can be used to easily enable service discovery with default values.

service_discovery.vsm_name = Ardupilot VSM

The above line is equivalent of the following config:

service_discovery.advertise.name = Ardupilot VSM
service_discovery.advertise.type = ugcs:vsm
service_discovery.advertise.location = tcp://{local_address}:<value of ucs.local_listening_port parameter>

Example vsm.conf:

service_discovery.address = 239.198.46.46
service_discovery.port = 1991
service_discovery.advertise.1.name = Ardupilot VSM
service_discovery.advertise.1.type = ugcs:vsm
service_discovery.advertise.1.location = tcp://{local_address}:5556