![]() |
Synergy Software Package User's Manual
|
The IP Network Address Translation (NAT) solves the problem of a limited number of Internet IPv4 addresses that arises when multiple devices need access to the Internet, but only one IPv4 Internet address is assigned by the Internet Service Provider (ISP). A NAT-enabled router is installed between the public and private network to translate between internal private IPv4 addresses and assigned public IPv4 address, so devices on the private network can share the same public IPv4 address.
The NetX Duo NAT Module defines APIs for creating, deleting and enabling operations. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
NetX Duo NAT Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| nx_nat_create | nx_nat_create(nat_ptr, ip_ptr, global_interface_index, nat_cache, NX_NAT_ENTRY_CACHE_SIZE); Create a NAT Instance in which the network interface is the global interface (not the local/private network) with the specified network index. |
| nx_nat_delete | nx_nat_delete (nat_ptr);Delete a NAT instance. |
| nx_nat_enable | nx_nat_enable (nat_ptr);Enable the NAT server. |
| nx_nat_disable | nx_nat_disable (nat_ptr);Disable the NAT server. |
| nx_nat_cache_notify_set | nx_nat_cache_notify_set(nat_ptr, cache_full_notify_cb);Set the NAT cache full notify function to a user‑defined notify function. |
| nx_nat_inbound_entry_create | nx_nat_inbound_entry_create(nat_ptr, entry_ptr, IP_ADDRESS(192,168,2,2), 5001, 5001, NX_PROTOCOL_TCP);Create an inbound translation table entry. This is typically used by application servers to allow clients to initiate a connection externally. |
| nx_nat_inbound_entry_delete | nx_nat_inbound_entry_delete(nat_ptr, delete_entry_ptr);Delete an inbound translation table entry. |
Status Return Values
| Name | Description |
|---|---|
| NX_SUCCESS | Successful NAT function |
| NX_PTR_ERROR* | Invalid input pointer parameter |
| NX_CALLER_ERROR* | Invalid caller (for example, must be a thread) of a service |
| NX_NAT_PARAM_ERROR* | Invalid non pointer input |
| NX_NAT_CACHE_ERROR* | Cache memory not 4 byte aligned, or is too small |
| NX_NAT_PORT_UNAVAILABLE | Invalid external port for creating static entry |
| NX_NAT_ENTRY_NOT_FOUND | Entry to delete is not found in Cache table |
| NX_NAT_ENTRY_TYPE_ERROR* | Invalid entry (not static) to delete |
A NAT-enabled router typically has two network interfaces: one connected to the public Internet, the other connected to the private network. A typical router in this setup is responsible for routing IP datagrams between the private network and the public network based on the destination IP address. A NAT-enabled router performs address translation before routing an IPv4 datagram between the public and the private interface. Translation is established for each TCP or UDP session, based the internal source address and source port number, as well as the external destination address and destination port number. For the ICMP echo request and response datagram, the Internet Control Message Protocol (ICMP) query ID is used instead of the port number.
Typically, connections across the NAT boundary are initiated by the hosts on the private network sending outbound packets to an external host. In these cases, hosts are usually assigned dynamic (temporary) IP addresses. It is also possible to have connections initiated in the opposite direction if the private network has 'servers' (such as HTTP or FTP) that accept client requests from the external network. NAT applications typically assign these local hosts a static (permanent) IP address port.
The following three illustrations and accompanying steps illustrate the sequence of events when sending packets through a NAT router.
Step 1. Client transmits a TCP SYN message to the web server. The Client address on the private network is 192.168.1.15, port number 6732; the destination address is 128.15.54.3, port number 80.
Step 2. The packet from the Client is received on the private network interface by the NAT router. The outbound traffic rule applies to the packet: the sender's (Client's) address is translated to the NAT router's public IP address 202.151.25.14, and sender (Client) source port number is translated to the TCP port number 2015 for transmission out on the public interface.
Step 3. The packet is then transmitted over the Internet and ultimately reaches its destination host 128.15.54.3. On the receiving side, notice in the following figure that the packet appears to have originated from 202.151.25.14, port number 2015 when it was in fact relayed from that IP address and port.
Step 4. Host 128.15.54.3 sends back a response packet with the NAT router's Internet address as its destination.
Step 5. The packet reaches the NAT router. Since this is an in-bound packet, the in-bound translation rules apply: the destination address is changed back (translated) to the original sender's (Client's) IP address: 192.168.1.15, destination port number 6732.
Step 6. The packet is then forwarded to the Client through the interface connected to the internal network.
When sending packets through a NAT router, the sender's Internet network address and port number is not exposed to other hosts on the public Internet.
To keep track of the network address translations for all active connections between local and external networks, the NetX Duo NAT-enabled router maintains a translation table with information about each private host connection that includes source and destination IP address and port number.
NetX Duo NAT is intended for use on an IPv4 router. For the NAT to work, the NetX Duo must be configured to forward-receive packets to an internal NetX Duo NAT handler. The handler determines whether the packet is received from the global network (inbound) or from the private network (outbound).
nx_ip_interface_status_check API (see the module guide project example for how this is done).nx_nat_cache_notify_set service.nx_nat_inbound_entry_create service. These entries can only be created for inbound packets and are sometimes referred to as 'inbound rules.' The entries are intended for server applications, to allow clients to initiate connection sessions with the server. Internally, the NAT verifies whether the global and local ports requested in the inbound rule are available. To delete these entries, the application calls the nx_nat_inbound_entry_delete service.nx_nat_enable service. To suspend NetX forwarding, the application calls the nx_nat_disable service.This section describes how to include either or both the NetX Duo NAT module in an application using the SSP configurator.
To add the NetX Duo NAT module to an application, simply add it to a thread using the stacks selection sequence given in the following table.
NetX Duo NAT Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_nat0NetX Duo NAT | Threads | New Stack> X-Ware> NetX Duo> Protocols> NetX Duo NAT |
When the NetX Duo NAT module is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
In the stack above, the NetX Network Driver (or NetX Duo Network Driver in a NetX Duo stack) has not been populated yet. There are multiple possible selections for the Network Driver; they are not all provided so as not to needlessly complicate the figure and the following configuration tables. The available options depend on the MCU target, but some typical options include:
The NetX Duo NAT module must be configured by the user for the desired operation. The SSP configuration window automatically identifies (by highlighting the block in red) any required configuration selections, such as interrupts or operating modes, which must be configured for lower-level modules for successful operation. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the NetX Duo NAT Module
| ISDE Property | Value | Description |
|---|---|---|
| Minimum count for translation entry | 3 | Minimum count for translation entry selection |
| Timeout for translation entry (ticks) | 240 | Timeout for translation entry selection |
| Minimum assigned port number for outbound TCP packets | 20000 | Minimum assigned port number for outbound TCP packets selection |
| Maximum assigned port number for outbound TCP packets | 30000 | Maximum assigned port number for outbound TCP packets selection |
| Minimum assigned port number for outbound UDP packets | 20000 | Minimum assigned port number for outbound UDP packets selection |
| Maximum assigned port number for outbound UDP packets | 30000 | Maximum assigned port number for outbound UDP packets selection |
| Minimum ICMP query identifier | 20000 | Minimum ICMP query identifier selection |
| Maximum ICMP query identifier | 30000 | Maximum ICMP query identifier selection |
| Name | g_nat0 | Module name |
| Cache size (bytes) | 1024 | Cache size selection |
| Private IPv4 Address (use commas for separation) | 192,168,0,2 | Private IPv4 Address selection |
| Private IPv4 Netmask (use commas for separation) | 255, 255, 255, 0 | Private IPv4 Netmask selection |
| Global network interface index | 0 | Global network interface index selection |
| Name of generated initialization function | nat_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection |
In some cases, settings other than the defaults for stack modules can be desirable. For example, it might be useful to select different IP addresses and subnet masks. The configurable properties for the lower-level stack modules are given in the following sections for completeness and as a reference.
Only a small number of settings must be modified from the default for the IP layer and lower-level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and are locked to prevent user modification. The following table identifies all the settings within the properties section for the module:
Configuration Settings for the NetX Duo IP Instance
| ISDE Property | Value | Description |
|---|---|---|
| Name | g_ip0 | Module name |
| IPv4 Address (use commas for separation) | 0,0,0,0 | IPv4 Address selection |
| Subnet Mask (use commas for separation) | 255,255,255,0 | Subnet Mask selection |
| IPv6 Global Address (use commas for separation) | 0x2001, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 | IPv6 global address selection |
| IPv6 Link Local Address (use commas for separation, All zeros means use MAC address) | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 | IPv6 link local address selection |
| IP Helper Thread Stack Size (bytes) | 2048 | IP Helper Thread Stack Size (bytes) selection |
| IP Helper Thread Priority | 3 | IP Helper Thread Priority selection |
| ARP | Enable | ARP selection |
| ARP Cache Size in Bytes | 512 | ARP Cache Size in Bytes selection |
| Reverse ARP | Enable, Disable Default: Disable | Reverse ARP selection |
| TCP | Enable, Disable Default: Enable | TCP selection |
| UDP | Enable, Disable Default: Enable | UDP selection |
| ICMP | Enable, Disable Default: Enable | ICMP selection |
| IGMP | Enable, Disable Default: Enable | IGMP selection |
| IP fragmentation | Enable, Disable Default: Disable | IP fragmentation selection |
| Name of generated initialization function | ip_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection |
Configuration Settings for the NetX Duo Common Instance
| ISDE Property | Value | Description |
|---|---|---|
| Name of generated initialization function | nx_common_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection |
Configuration Settings for the NetX Duo Packet Pool Instance
| ISDE Property | Value | Description |
|---|---|---|
| Name | g_packet_pool0 | Module name |
| Packet Size in Bytes | 640 | Packet size selection |
| Number of Packets in Pool | 16 | Number of packets in pool selection |
| Name of generated initialization function | packet_pool_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection |
The ETHERC peripheral module uses PCLKA as its clock source. The PCLKA frequency is set using the SSP configurator clock tab prior to a build, or by using the CGC interface at run-time.
The ETHERC peripheral module uses pins on the MCU device to communicate to external devices. I/O pins must be selected and configured by the external device as required. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the I2C pins.
Pin Selection for the ETHERC Module
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| ETHERC | Pins | Select Peripherals > Connectivity:ETHERC > ETHERC1.RMII |
Pin Configuration Settings for the ETHERC1
| Property | Value | Description |
|---|---|---|
| Operation Mode | Disabled, Custom, RMII Default: Disabled | Select RMII as the Operation Mode for ETHERC1 |
| Pin Group Selection | Mixed, _A only Default: _A only | Pin group selection |
| REF50CK | P701 | REF50CK Pin |
| TXD0 | P700 | TXD0 Pin |
| TXD1 | P406 | TXD1 Pin |
| TXD_EN | P405 | TXD_EN Pin |
| RXD0 | P702 | RXD0 Pin |
| RXD1 | P703 | RXD1 Pin |
| RX_ER | P704 | RX_ER Pin |
| CRS_DV | P705 | CRS_DV Pin |
| MDC | P403 | MDC Pin |
| MDIO | P404 | MDIO Pin |
The following example assumes that a system is already established with a working IP, ARP, ICMP, TCP and UDP enabled, and that the link is running.
The steps in using the NetX Duo NAT module in a typical application are:
nx_ip_status_check API for the primary ("global") interface.nx_ip_interface_status_check API.nx_nat_cache_notify_set API [Optional].nx_nat_enable API. The IP thread task and NAT services handle the rest.nx_nat_inbound_entry_create [Optional]. Note this can be done before or after enabling NAT services.nx_nat_disable API.nx_nat_delete API.The following figure illustrates common steps in a typical operational flow diagram: