15  Address resolution

org.arl.unet.Services.ADDRESS_RESOLUTION

15.1 Overview

The ADDRESS_RESOLUTION service is responsible for address allocation (assigning an address to a new node) and address resolution (finding the address assigned to a named node). It is consumed at startup by the NODE_INFO provider (Chapter 14) to obtain the node’s own address, and at runtime by applications and agents that need to translate node names to addresses — the shell’s host('name') function is backed by this service. The size of the address space is determined by the addressSize parameter of the NODE_INFO service.

Tip

The default ADDRESS_RESOLUTION service provider in UnetStack uses a hashing function to map node names to addresses. This enables it to allocate and resolve addresses without generating network traffic, as the hashing function generates the same address for a given name on each node. Because the hashing maps a large name space to a small address space, there is always the chance that two names map to the same address; we require that the network architect check this manually, and assign node names such that there are no address conflicts.

Caution

Network designers and protocol developers should not rely on the ADDRESS_RESOLUTION service provider being based on a hashing function for correct operation of the network.

15.2 Messages

Agents providing this service honor the following requests:

  • AddressAllocReq – allocate address to node

    Field Type Default Remarks
    addressSize int leave empty to use default address size
    name string node name
  • AddressResolutionReq – resolve node name to address

    Field Type Default Remarks
    name string node name to resolve

with the following responses:

If the request is invalid (e.g. no node name is given), a REFUSE response is generated. If the request fails, a FAILURE response may be generated.

While the allocation and resolution requests look very similar, there is a conceptual difference between the two. Address allocation is performed once for a new node without an address, and associates the node with an address; the requester may suggest an addressSize to allocate from. Address resolution is performed any number of times, by any node, to find the address that was (or would be) assigned to a named node. A provider must ensure the two are consistent: resolving a name must yield the same address that allocation for that name produced.

15.3 Parameters

This service defines no parameters.

15.4 Commands

The following convenience commands are supported by the org.arl.unet.addr.ArpShellExt shell extension:

  • host – resolve hostname to address

    Examples:

    host 'redstar'         // get address for host named "redstar"
    rs = host('redstar')   // save address of "redstar" in variable "rs"

15.5 Examples

Address allocation is typically required at startup, and usually initiated by the agent providing the NODE_INFO service to populate the address parameter of that service. To ask the ADDRESS_RESOLUTION service provider to allocate an address, an agent sends it an AddressAllocReq. The allocation may depend on the node name, and so the request must contain the node name.

We can start the 2-node-network, and manually test this on the shell of node A:

> a = agentForService(org.arl.unet.Services.ADDRESS_RESOLUTION);
> a << new AddressAllocReq(name: 'A')
AddressAllocRsp:INFORM[address:232]

Address resolution is performed via the AddressResolutionReq message. The host command sends this message on your behalf, and shows you the response:

> a << new AddressResolutionReq(name: 'B')
AddressResolutionRsp:INFORM[address:31 name:B]
> ans.address
31
> host('B')
31

15.6 Implementation

15.6.1 AddressResolution (arp)

Class Services Capabilities Availability
AddressResolution ADDRESS_RESOLUTION default stack

The default implementation is the arp agent, loaded as part of the default stack (Chapter 13). It allocates and resolves node addresses by mapping node names to addresses using a deterministic hash, so that every node computes the same name→address mapping without exchanging any network traffic.

15.6.1.1 How it works

A purely numeric node name that fits the address space is used directly as the address. Any other name is hashed with a CRC-style polynomial into the configured address space — 1–255 for 8-bit addresses, 1–65535 for 16-bit addresses, as set by addressSize on the NODE_INFO service (address 0 is reserved for broadcast). Because the hash is deterministic and computed identically on every node, address allocation and resolution require no coordination and generate no traffic. The trade-off is that the hash maps a large name space onto a small address space, so two different names can collide on the same address; the network designer is responsible for choosing names that do not.

15.6.1.2 Usage notes

  • Use host('name') to check the address a name hashes to, and verify that your chosen node names do not collide.
  • Protocol code should treat addresses as opaque and not rely on the hashing scheme (see the caution at the start of this chapter).