5.5.2.3 How to obtain Card IP-Addresses the Hard Way |
The SP-ICE-3 Card supports dual-stack operation with both IPv4 and IPv6.
It implements a variant of UPnP Discovery which, in combination with the SP-ICE-3 Configuration Tool (SPICE3Config.exe), makes it relatively easy to obtain a particular card's address(es), should you ever need to do so: please refer to 12.4.1 How to Connect to a Card using Discovery.
Nevertheless, it is possible to get a card's address by hand[Note 1], using only the built-in tools available on the Host-PC: we discuss some of the more "interesting" aspects of this below.
If a card is installed without access to a DHCP Server, and you do not assign a static IPv4 address to it, it will automatically assign itself an address in the IPv4 Private Range: 169.254.*.*/16.
Note |
---|
Since the card implements only a variant of the UPnP Discovery mechanism, it will not appear as an icon in the Host-PC's Network Folder, so we can't simply obtain the address by inspection.[Note 2] However, should the need ever arise, we can predict the card's IPv4 private address with almost complete certainty[Note 3], even though it's not nearly as convenient as having the Discovery mechanism do it for us. |
Obtain the card's Serial Number.
For instance, you could read the production label on the back of the card:
It should match the pattern SP3#####, where each # represents a single digit in the range 0..9, and there are five digits altogether.
Now extract just the five digit "#####" part of the serial number, and use it as input to the following algorithm, which is shown in simplified form.
sn = #####; // Your 5-digit serial number goes here. a = 1; if (sernum > 0) a = sernum << 2; if ( interface == eth1 ) { a = a + 2; } address = "169.254." + MSB(a) + "." + LSB(a)
For example: if SP300046 is installed internally in a Host-PC, the eth1 interface will be active via the PCIe bus, and will have the IPv4 Private Range Address 169.254.0.186
Tip |
---|
The SP-ICE-3 IPv4 Calculator Tool (SPICE3IPv4Calc.exe) demonstrates an implemention of the algorithm. C:\path\to\spice3\tools> SPICE3IPv4Calc.exe
SP300046 eth1
|
Once we have armed ourselves with the card's predicted address, we can attempt to make contact with it:
using RAYLASE.SPICE3; using RAYLASE.SPICE3.ClientLib; class myProgram { string SerialNumberToIPv4Address( string serNum = "00001", string ethif = "eth0") { int sn = int.Parse(serNum); int cardAddr = 1; // If necessary, fold the serial number at this value // to keep the assigned address within the available IPv4 Private Range. const int MAX_USABLE_SERIAL_NUMBER = (16384 - 2); // ie: (2**14) - 2 if ( sn < 1 ) { // serNum < 1 does not respresent a valid serial number, // so just keep cardAddr == 1. // The returned string value will then be "1" (or "3"), // thus avoiding "[169.254.0.]0" which is not a valid endpoint address. } else { // Fold serial number, if necessary. cardAddr = ( ( sn - 1 ) % MAX_USABLE_SERIAL_NUMBER ) + 1; // Shift two bits left, leaving room for the interface bit and the anti-collision bit. cardAddr *= 4; } // Add in the interface bit, if necessary. if ( ethif.Contains( "eth1" ) ) cardAddr += 2; return string.Format("169.254.{0:d}.{1:d}", ((cardAddr & 0xFF00)/256), (cardAddr & 0x00FF)); } void CheckCardIsPresent(string fiveDigitSerialNumber) { using ( ClientAPI client = new ClientAPI() ) { string cardIP = SerialNumberToIPv4Address(fiveDigitSerialNumber); client.Connect( cardIP ); if ( client.Connected ) { string serialNumber = client.System.GetCardSerialNumber(); Console.WriteLine( "Connected to SN {0} at {1}", serialNumber, cardIP ); client.Disconnect(); } } } // etc. }
Internally installed cards initially have IPv6 Link-Local ("LL") addresses in the range FE80::/64.
IPv6 LL address are autoconfigured: there is no need, and indeed no simple way, to assign them by hand.
The mechanisms and algorithms for autoconfiguration are specified by RFC 4291 et al..
In a nutshell, the IPv6 LL address for a given card is derived from the card's MAC (Ethernet) Address.
Should you ever need the MAC address in order to predict the LL address for a card, please refer to the data manual supplied with the card, or connect to its serial console (X803 USB Console) and read the MAC Address from the EEPROM.
Note |
---|
The IPv6 LL address of a given card is not directly predictable from the card's serial number. |
Do yourself a favour: let the SP-ICE-3 Configuration Tool (SPICE3Config.exe) do it for you instead.
Seriously.
A poor workman always blames his tools.
[English proverb]
In the very unlikely, but unfortunately not completely impossible, event that the card initially assigns itself a private address which conflicts with that chosen by the Host-PC, it will keep trying successive addresses until it identifies one which does not conflict.
If you are having difficulty contacting the card at the predicted address, it may be wise to obtain the Host-PC's private address (using e.g. the Windows� command line tool ipconfig), and check for potential conflict against the card's predicted address.