ThreadX docsThreadX docs
ThreadX
ThreadX Modules
NetX Duo
FileX
GUIX
USBX
TraceX
LevelX
ThreadX
ThreadX Modules
NetX Duo
FileX
GUIX
USBX
TraceX
LevelX
  • NetX Duo Documentation

    • Understand NetX Duo
    • NetX Duo documentation
    • Chapter 1 - Introduction to NetX Duo
    • Chapter 2 - Installation and Use of NetX Duo
    • Chapter 3 - Functional Components of NetX Duo
    • Chapter 4 - Description of NetX Duo Services
    • Chapter 5 - NetX Duo Network Drivers
    • Appendix A - NetX Duo Services
    • Appendix B - NetX Duo Constants
    • Appendix C - NetX Duo Data Types
    • Appendix D - NetX Duo BSD-Compatible Socket API
    • Appendix E - NetX Duo ASCII Character Codes
    • Auto-IP

      • Chapter 1 - Introduction to NetX Duo AutoIP
      • Chapter 2 - Installation and use of NetX Duo AutoIP
      • Chapter 3 - Description of NetX Duo AutoIP services
    • BSD

      • Chapter 1 - Introduction to NetX Duo BSD
      • Chapter 2 - Installation and use of NetX Duo BSD
      • Chapter 3 - NetX Duo BSD Services
    • Crypto

      • Chapter 1 - Introduction to NetX Duo Crypto
      • Chapter 2 - Installation and use of NetX Duo Crypto
      • Chapter 3 - Functional description of NetX Duo Crypto
      • Chapter 4 - NetX Duo Crypto API description
      • Appendix - NetX Duo Crypto CAVS test
    • DHCP Client

      • Chapter 1 - Introduction to the NetX Duo DHCP Client
      • Chapter 2 - Installation and use of NetX Duo DHCP Client
      • Chapter 3 - Description of NetX Duo DHCP Client services
      • Appendix A - Description of the Restore state feature for NetX Duo DHCP Client services
    • DHCP Server

      • Chapter 1 - Introduction to NetX Duo DHCP Server
      • Chapter 2 - Installation and Use of the NetX Duo DHCP Server
      • Chapter 3 - Description of NetX Duo DHCP server services
    • DHCPv6 Client

      • Chapter 1 - Introduction to NetX Duo DHCPv6 Client
      • Chapter 2 - Installation and use of NetX Duo DHCPv6 Client
      • Chapter 3 - NetX Duo DHCPv6 configuration options
      • Chapter 4 - NetX Duo DHCPv6 Client services
      • Appendix A - Description of the Restore State Feature for NetX Duo DHCPv6 Client
    • DHCPv6 Server

      • Chapter 1 - Introduction to NetX Duo DHCPv6 server
      • Chapter 2 - Installation and use of NetX Duo DHCPv6 server
      • Chapter 3 - NetX Duo DHCPv6 server configuration options
      • Chapter 4 - NetX Duo DHCPv6 server services
      • Appendix A – NetX Duo DHCPv6 option codes
      • Appendix B - NetX Duo DHCPv6 server status codes
      • Appendix C - NetX Duo DHCPv6 unique identifiers (DUIDs)
      • Appendix D - NetX Duo Advanced DHCPv6 server example
    • DNS

      • Chapter 1 - Introduction to the NetX Duo DNS Client
      • Chapter 2 - Installation and Use of NetX Duo DNS Client
      • Chapter 3 - Description of NetX Duo DNS Client Services
    • FTP

      • Chapter 1 - Introduction to NetX Duo FTP
      • Chapter 2 - Installation and use of FTP
      • Chapter 3 - Description of FTP services
    • HTTP

      • Chapter 1 - Introduction to NetX Duo HTTP
      • Chapter 2 - Installation and Use of NetX Duo HTTP
      • Chapter 3 - Description of NetX Duo HTTP Services
    • iperf

      • Chapter 1 - Introduction to NetX Duo Iperf
      • Chapter 2 - Installing and using NetX Duo Iperf
      • Chapter 3 - Running the UDP Transmit Test
    • mDNS

      • Chapter 1 - Introduction to NetX Duo mDNS/DNS-SD
      • Chapter 2 - Installation and use of mDNS
      • Chapter 3 - Description of internal service cache
      • Chapter 4 - Description of mDNS services
    • mqtt

      • Chapter 1 - Introduction to NetX Duo MQTT
      • Chapter 2 - Installation and use of NetX Duo MQTT client
      • Chapter 3 - Description of NetX Duo MQTT Client Services
    • NAT

      • Chapter 1 - An introduction to Network Address Translation
      • Chapter 2 - Installation and use of NAT
      • Chapter 3 - NAT configuration options
      • Chapter 4 - Description of NAT services
    • POP3 Client

      • Chapter 1 - Introduction to NetX Duo POP3
      • Chapter 2 - Installation and use of NetX Duo POP3 Client
      • Chapter 3 - Description of POP3 Client services
    • PPP

      • Chapter 1 - Introduction to the NetX Duo Point-to-Point Protocol (PPP)
      • Chapter 2 - Installation and use of NetX Duo Point-to-Point Protocol (PPP)
      • Chapter 3 - Description of NetX Duo Point-to-Point Protocol (PPP) services
    • PTP Client

      • Chapter 1 - Introduction to NetX Duo PTP Client
      • Chapter 2 - Installation and Use of NetX Duo PTP Client
      • Chapter 3 - Description of NetX Duo PTP Client Services
    • rtp

      • Chapter 1 - Introduction to the NetX Duo RTP Sender
      • Chapter 2 - Installation and use of NetX Duo RTP Sender
      • Chapter 3 - Description of NetX Duo RTP Sender Services
    • rtsp

      • Chapter 1 - Introduction to the NetX Duo RTSP Server
      • Chapter 2 - Installation and use of NetX Duo RTSP Server
      • Chapter 3 - Description of NetX Duo RTSP Server Services
    • Secure DTLS

      • Chapter 1 - Introduction to NetX Duo Secure DTLS
      • Chapter 2 - Installation and use of NetX Duo Secure DTLS
      • Chapter 3 - Functional description of NetX Duo Secure DTLS
      • Chapter 4 - Description of NetX Duo Secure DTLS services
      • Appendix A - NetX Duo Secure DTLS return/error codes
    • Secure TLS

      • Chapter 1 - Introduction to NetX Duo Secure
      • Chapter 2 - Installation and use of NetX Duo Secure
      • Chapter 3 - Functional description of NetX Duo Secure
      • Chapter 4 - Description of NetX Duo Secure services
      • Appendix A - NetX Duo Secure return/error codes
    • SMTP Client

      • Chapter 1 - Introduction to NetX Duo SMTP client
      • Chapter 2 - Installation and use of NetX Duo SMTP client
      • Chapter 3 - Client description of SMTP Client services
    • snmp

      • Chapter 1 - Introduction to NetX Duo SNMP
      • Chapter 2 - Installation and use of the NetX Duo SNMP agent
      • Chapter 3 - Description of NetX Duo SNMP agent services
    • sntp client

      • Chapter 1 - Introduction to NetX Duo SNTP
      • Chapter 2 - Installation and Use of NetX Duo SNTP Client
      • Chapter 3 - Description of NetX Duo SNTP Client Services
      • Appendix A - NetX Duo SNTP Fatal Error Codes
    • telnet

      • Chapter 1 - Introduction to NetX Duo Telnet
      • Chapter 2 - Installation and use of NetX Duo Telnet
      • Chapter 3 - Description of NetX Duo Telnet services
    • TFTP

      • Chapter 1 - Introduction to NetX Duo TFTP
      • Chapter 2 - Installation and use of NetX Duo TFTP
      • Chapter 3 - Description of NetX Duo TFTP services
    • Web HTTP

      • Chapter 1 - Introduction to HTTP and HTTPS
      • Chapter 2 - Installation and use of HTTP and HTTPS
      • Chapter 3 - Description of HTTP services
    • About the NetX Duo User Guide

Chapter 2 - Installation and use of NetX Duo AutoIP

This chapter contains a description of various issues related to installation, setup, and usage of the NetX Duo AutoIP component.

Product Distribution

AutoIP can be obtained from our public source code repository at https://github.com/eclipse-threadx/netxduo/. The package includes three source files, one include files, and a PDF file that contains this document, as follows:

  • nx_auto_ip.h: Header file for NetX Duo AutoIP
  • nx_auto_ip.c: C Source file for NetX Duo AutoIP
  • demo_netx_auto_ip.c: C Source file for NetX Duo AutoIP Demo
  • nx_auto_ip.pdf: PDF description of NetX Duo AutoIP

AutoIP Installation

In order to use NetX Duo AutoIP, the entire distribution mentioned previously should be copied to the same directory where NetX Duo is installed. For example, if NetX Duo is installed in the directory "\threadx\arm7\green" then the nx_auto_ip.h, nx_auto_ip.c, and demo_netx_auto_ip.c files should be copied into this directory.

Using AutoIP

Using NetX Duo AutoIP is easy. Basically, the application code must include nx_auto_ip.h after it includes tx_api.h and nx_api.h, in order to use ThreadX and NetX Duo. Once nx_auto_ip.h is included, the application code is then able to make the AutoIP function calls specified later in this guide. The application must also include nx_auto_ip.c in the build process. These files must be compiled in the same manner as other application files and its object form must be linked along with the files of the application. This is all that is required to use NetX Duo AutoIP.

Note: Since AutoIP utilizes NetX Duo ARP services, ARP must be enabled with the nx_arp_enable call prior to using AutoIP.

Small Example System

An example of how easy it is to use NetX Duo AutoIP is described below. In this example, the AutoIP include file nx_auto_ip.h is brought in at line 002. Next, the NetX Duo AutoIP instance is created in "tx_application_define" at line 090. Note that the NetX Duo AutoIP control block "auto_ip_0" was defined previously as a global variable at line 015. After successful creation, an NetX Duo AutoIP is started at line 098. The IP address change callback function processing starts at line 105, which is used to handle subsequent conflicts or possible DHCP address resolution.

Note: The example below assumes the host device is a single-homed device. For a multihomed device, the host application can use the NetX Duo AutoIP service *nx_auto_ip_interface_*set to specify a secondary network interface to probe for an IP address. See the NetX Duo User Guide for more details on setting up multihomed applications. Note further that the host application should use the NetX Duo API nx_status_ip_interface_check to verify AutoIP has obtained an IP address.

#include "tx_api.h"
#include "nx_api.h"
#include "nx_auto_ip.h"

#define     DEMO_STACK_SIZE     4096

/* Define the ThreadX and NetX object control blocks... */

TX_THREAD              thread_0;
NX_PACKET_POOL         pool_0;
NX_IP                  ip_0;

/* Define the AUTO IP structures for the IP instance. */

NX_AUTO_IP             auto_ip_0;

/* Define the counters used in the demo application... */

ULONG                 thread_0_counter;
ULONG                 address_changes;
ULONG                 error_counter;

/* Define thread prototypes. */
void     thread_0_entry(ULONG thread_input);
void     ip_address_changed(NX_IP *ip_ptr, VOID *auto_ip_address);
void     _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);

/* Define main entry point. */

int main()
{

    /* Enter the ThreadX kernel. */
    tx_kernel_enter();
}

/* Define what the initial system looks like. */

void     tx_application_define(void *first_unused_memory)
{

CHAR     *pointer;
UINT     status;

    /* Setup the working pointer. */
    pointer = (CHAR *) first_unused_memory;

    /* Create the main thread. */
    tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
                    pointer, DEMO_STACK_SIZE,
                    16, 16, 1, TX_AUTO_START);

    pointer = pointer + DEMO_STACK_SIZE;

    /* Initialize the NetX system. */
    nx_system_initialize();

    /* Create a packet pool. */
    status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 128,
                                    pointer, 4096);
    pointer = pointer + 4096;

    if (status)
        error_counter++;

    /* Create an IP instance. */
    status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(0, 0, 0, 0),
                        0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
                        pointer, 4096, 1);
    pointer = pointer + 4096;

    if (status)
        error_counter++;

    /* Enable ARP and supply ARP cache memory for IP Instance 0. */
    status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
    pointer = pointer + 1024;

    /* Check ARP enable status. */
    if (status)
        error_counter++;

    /* Create the AutoIP instance for IP Instance 0. */
    status = nx_auto_ip_create(&auto_ip_0, "AutoIP 0", &ip_0, pointer, 4096, 1);
    pointer = pointer + 4096;

    /* Check AutoIP create status. */
    if (status)
        error_counter++;

    /* Start AutoIP instances. */
    status = **nx_auto_ip_start**(&auto_ip_0, 0 /*IP_ADDRESS(169,254,254,255)*/);

    /* Check AutoIP start status. */
    if (status)
        error_counter++;

    /* Register an IP address change function for IP Instance 0. */
    status = nx_ip_address_change_notify(&ip_0, ip_address_changed,
                                        (void *) &auto_ip_0);

    /* Check IP address change notify status. */
    if (status)
        error_counter++;
}

/* Define the test thread. */

void     thread_0_entry(ULONG thread_input)
{

UINT     status;
ULONG    actual_status;

    /* Wait for IP address to be resolved. */
    do
    {

        /* Call IP status check routine. */
        status = nx_ip_status_check(&ip_0, NX_IP_ADDRESS_RESOLVED,
            &actual_status, 10000);

    } while (status != NX_SUCCESS);

    /* Since the IP address is resolved at this point, the application can now fully utilize NetX! */

    while(1)
    {

        /* Increment thread 0's counter. */
        thread_0_counter++;

        /* Sleep... */
        tx_thread_sleep(10);
    }
}

void          ip_address_changed(NX_IP *ip_ptr, VOID *auto_ip_address)
{

ULONG         ip_address;
ULONG         network_mask;
NX_AUTO_IP    *auto_ip_ptr;

    /* Setup pointer to auto IP instance. */
    auto_ip_ptr = (NX_AUTO_IP *) auto_ip_address;

    /* Pickup the current IP address. */
    nx_ip_address_get(ip_ptr, &ip_address, &network_mask);

    /* Determine if the IP address has changed back to zero. If so, make sure the AutoIP instance is started. */
    if (ip_address == 0)
    {

        /* Get the last AutoIP address for this node. */
        nx_auto_ip_get_address(auto_ip_ptr, &ip_address);

        /* Start this AutoIP instance. */
        nx_auto_ip_start(auto_ip_ptr, ip_address);
        }

    /* Determine if IP address has transitioned to a non local IP address. */
    else if ((ip_address & 0xFFFF0000UL) != IP_ADDRESS(169, 254, 0, 0))
    {

        /* Stop the AutoIP processing. */
        nx_auto_ip_stop(auto_ip_ptr);
    }

    /* Increment a counter. */
    address_changes++;
}

Configuration Options

There are several configuration options for building NetX Duo AutoIP. Following is a list of all options, where each is described in detail:

  • NX_DISABLE_ERROR_CHECKING: Defined, this option removes the basic AutoIP error checking. It is typically used after the application has been debugged.
  • NX_AUTO_IP_PROBE_WAIT: The number of seconds to wait before sending first probe. By default, this value is defined as 1.
  • NX_AUTO_IP_PROBE_NUM: The number of ARP probes to send. By default, this value is defined as 3.
  • NX_AUTO_IP_PROBE_MIN: The minimum number of seconds to wait between sending probes. By default, this value is defined as 1.
  • NX_AUTO_IP_PROBE_MAX: The maximum number of seconds to wait between sending probes. By default, this value is defined as 2.
  • NX_AUTO_IP_MAX_CONFLICTS: The number of AutoIP conflicts before increasing processing delays. By default, this value is defined as 10.
  • NX_AUTO_IP_RATE_LIMIT_INTERVAL: The number of seconds to extend the wait period when the total number of conflicts is exceeded. By default, this value is defined as 60.
  • NX_AUTO_IP_ANNOUNCE_WAIT: The number of seconds to wait before sending announcement. By default, this value is defined as 2.
  • NX_AUTO_IP_ANNOUNCE_NUM: The number of ARP announces to send. By default, this value is defined as 2.
  • NX_AUTO_IP_ANNOUNCE_INTERVAL: The number of seconds to wait between sending announces. By default, this value is defined as 2.
  • NX_AUTO_IP_DEFEND_INTERVAL: The number of seconds to wait between defense announces. By default, this value is defined as 10.
Prev
Chapter 1 - Introduction to NetX Duo AutoIP
Next
Chapter 3 - Description of NetX Duo AutoIP services