11.3. NAT Traversal Reference

This section provides a reference on NAT traversal in the Pia library.

Glossary

NAT Type

The NAT type is determined by the router's NAT port mapping and filtering specifications. You can check the NAT type by running sampledemos\session\Mesh.

u8 mappingType = nn::pia::inet::NexFacade::GetInstance()->GetNatPropertyMapping();
u8 filteringType = nn::pia::inet::NexFacade::GetInstance()->GetNatPropertyFiltering();
u32 portIncrement = nn::pia::inet::NexFacade::GetInstance()->GetNatPropertyPortIncrement();
mapping  
1 Endpoint-Independent Mapping (EIM)
2 Endpoint Dependent Mapping, Symmetric (EDM)
filtering  
1 Port-Independent Filtering (PIF)
2 Port-Dependent Filtering (PDF)

A router that uses endpoint dependent mapping (EDM) as its NAT-type mapping is called an EDM router. This document refers to a connection that goes through at least one EDM router as an EDM connection. EDM connections account for approximately eight percent of worldwide connections (according to Nintendo research).

Port Increment

The port increment is the value added to the WAN port number that the EDM router assigns to each device. If the port increment is 1, this value increases by 1 each time; if it is –1, the value decreases by 1 each time.

Support Code

The NAT type can be checked from the support code that is displayed when a connection test is run on the device menu. The support code is a five-digit numerical code. The first three digits indicate the NAT type, and the last two digits indicate the result code of the NAT type determination process. For information about the meaning of each digit, see the Checking the NAT Type section in the NEX Programming Manual.

Limitations of NAT Traversal in the Pia Library

If NAT traversal fails, one of the following error values can be retrieved by using the session::Session::GetJoinSessionResult() function, which is the result of asynchronous processing by the session::Session::JoinSessionAsync() function.

Error Constant Error Codes Description
ResultStationConnectionNatTraversalFailedUnknown 0510 NAT traversal failed on a connection with an unknown mapping type.
ResultNatTraversalFailedBothEim 0513 NAT traversal failed on a connection between EIMs.
ResultNatTraversalFailedBothEdm 0514 NAT traversal failed on a connection between EDMs.
ResultNatTraversalFailedLocalEimRemoteEdm 0515 NAT traversal failed because the local station is using EIM while the remote (partner) station is using EDM.
ResultNatTraversalFailedLocalEdmRemoteEim 0516 NAT traversal failed because the local station is using EDM while the remote (partner) station is using EIM.
ResultNatTraversalRequestTimeout 0521 Timed out while waiting for a response to the request sent to the remote (partner) station during NAT traversal.

This section describes limitations of NAT traversal in the Pia library for each network configuration.

EDM Router With a Port Increment Other Than 1

Pia avoids the affect from errors that occur when detecting the port increment by always using a port increment of 1 for port prediction. This improves the success rate of NAT traversal on EDM connections. For this reason, NAT traversal fails for a device connecting through an EDM router with a port increment other than 1, and on devices using other connections. Very few EDM routers have a port increment other than 1.

Parallel Routers on a Single Network

NAT traversal fails when there are parallel routers on a single local network (using a single global IP address) because NAT traversal packets do not reach the other router. (This same limitation exists for NetZ.)

Example:

NAT traversal fails between NAT21 and NAT22.

Internet - NAT1 - NAT21

                        | - NAT22

 

Pia supports NAT traversal between serially connected routers. (NetZ does not support this.)

Example:

NAT traversal always succeeds between NAT1 and NAT2, NAT2 and NAT3, and NAT1 and NAT3.

Internet - NAT1 - NAT2 - NAT3

Multiple Devices Connecting Through the Same EDM Router Simultaneously Join a Session Host

If multiple devices on a LAN that connect through the same EDM router simultaneously join a session host on another network, port prediction (and thus NAT traversal) may fail. (NetZ has the same limitation.) You can decrease the potential for port-prediction failure by having the devices join a few seconds apart.

Conversely, Pia usually succeeds if multiple devices on a LAN that connect through the same EDM router join an existing session one at a time. (With NetZ, this always fails.)

Example:

NAT traversal may fail if Station2 and Station3 join at the same time.

Internet - NAT - Station1 (Session Host)

Internet - EDM - Station2

                       |- Station3

Devices on Nearby Routers With SPI Mode Enabled

If a packet with a TTL value of 4 arrives from a router with SPI mode enabled, NAT traversal may fail because the SPI mode is triggered when the NAT-table update packet reaches that router.

Devices on Routers Connected Serially Four or More Hops From a Router With SPI Mode Enabled

If a device on a router is serially connected four or more hops from a router with SPI mode enabled, NAT traversal may fail because a packet for updating the NAT table with a TTL value of 4 will not reach the WAN of the router with SPI mode enabled.

Stations Connected to Routers With Privacy Separator Enabled

NAT traversal fails between terminals connected to a router that has privacy separator enabled because direct communication is blocked.

Reference for Using EDM Routers

Take the following into account if you are using an EDM router during development.

If you are using an EDM router during development, you can avoid EDM by replacing it with an EIM router. However, some Internet service providers have EDM central terminal units (CTUs). In such cases, you cannot avoid EDM because there is no way to replace them.

Even on an EDM connection, NAT traversal no longer fails if you only perform P2P connections among devices on the router because, in that case, NAT traversal is not performed in the first place.

When making a P2P connection across a combination of EDM and non-EDM routers, you may get an error because of NAT-traversal failure, depending on the connection conditions. You can reduce the failure rate by taking the following into account.

  • Minimize communication with other nodes during NAT traversal (when forming P2P connections). Specifically, make sure that no other devices or PCs are communicating through the router. The more frequently other devices are communicating (sending data to a new address), the more likely it is that NAT traversal will fail.
  • When forming P2P connections with more than one device, connect to each device one at a time rather than simultaneously.