Mod Bus
Mod Bus
Mod Bus
ACROMAG INCORPORATED 30765 South Wixom Road P.O. BOX 437 Wixom, MI 48393-7037 U.S.A.
Copyright 2005, Acromag, Inc., Printed in the USA. Data and specifications are subject to change without notice.
8500-765-A05C000
TABLE OF CONTENTS
This information is provided as a service to our customers and to others interested in learning more about Modbus TCP/IP. Acromag assumes no responsibility for any errors that may occur in this document, and makes no commitment to update, or keep this information current. Be sure to visit Acromag on the web at www.acromag.com. Windows is a registered trademark of Microsoft Corporation. Modbus is a registered trademark of Modicon, Incorporated. All trademarks are the property of their respective owners. ______________________________________________________________________________________ Acromag, Inc. Tel:248-624-1541 Fax:248-624-9234 Email:[email protected] http://www.acromag.com
What is Modbus?
Address
Data
Checksum
Data
Modbus Application Protocol (MBAP) Header (7 Bytes) Transaction Identifier (2 Bytes) Protocol Identifier (2 Bytes) Length Field (2 Bytes) Unit ID (1 Byte)
Protocol Data Unit (PDU) Function Code (1 Byte) Data Varies Modbus Frame With TCP/IP Transmission
Modbus TCP/IP ADU (This information is embedded into the data portion of the TCP frame)
The Modbus commands and user data are themselves encapsulated into the data container of a TCP/IP telegram without being modified in any way. However, the Modbus error checking field (checksum) is not used, as the standard Ethernet TCP/IP link layer checksum methods are instead used to guaranty data integrity. Further, the Modbus frame address field is supplanted by the unit identifier in Modbus TCP/IP, and becomes part of the Modbus Application Protocol (MBAP) header (more on this later).
The complete Modbus TCP/IP Application Data Unit is embedded into the data field of a standard TCP frame and sent via TCP to well-known system port 502, which is specifically reserved for Modbus applications. Modbus TCP/IP clients and servers listen and receive Modbus data via port 502. We can see that the operation of Modbus over Ethernet is nearly transparent to the Modbus register/command structure. Thus, if you are already familiar with the operation of traditional Modbus, then you are already very with the operation of Modbus TCP/IP. IEEE 802.3 Ethernet is a long-standing office networking protocol that has gained universal world-wide acceptance. It is also an open standard that is supported by many manufacturers and its infrastructure is widely available and largely installed. Consequently, its TCP/IP suite of protocols is used world-wide and even serves as the foundation for access to the World Wide Web. As many devices already support Ethernet, it is only natural to augment it for use in industrial applications. Just as with Ethernet, Modbus is freely available, accessible to anyone, and widely supported by many manufacturers of industrial equipment. It is also easy to understand and a natural candidate for use in building other industrial communication standards. With so much in common, the marriage of the Modbus application protocol with traditional IEEE 802.3 Ethernet transmission forms a powerful industrial communication standard in Modbus TCP/IP. And because Modbus TCP/IP shares the same physical and data link layers of traditional IEEE 802.3 Ethernet and uses the same TCP/IP suite of protocols, it remains fully compatible with the already installed Ethernet infrastructure of cables, connectors, network interface cards, hubs, and switches.
The OSI Model represents the basic network architecture. Each layer of this model uses the services provided by the layer immediately below it. TCP/IP has no specific mappings to layers 5 and 6 of this model and these layers are often omitted when referring to the TCP/IP stack.
Transport Layer
10
To better understand stack operation, the following table illustrates the flow of data from a sender to a receiver using the TCP/IP stack (weve renamed the Host-to-Network layer to the more commonly used Data Link Layer): SENDER Application Transport Internet/Network Data Link Layer Physical Hardware
Virtual Connection Equivalent Message Equivalent Message Equivalent Message Equivalent Message
Each layer on the sending stack communicates with the corresponding layer of the receiving stack through information stored in headers. As you move the data down the stack of the sender, each stack layer adds its own header to the front of the message that it receives from the next higher layer. That is, the higher layers are encapsulated by the lower layers. Conversely, this header information is removed by the corresponding layer at the Receiver. In this way, the headers are essentially peeled off as the data packet moves up the receiving stack to the receiver application. MODBUS TCP/IP COMMUNICATION STACK # MODEL IMPORTANT PROTOCOLS 7 Application Modbus 6 Presentation 5 Session 4 Transport TCP 3 Network IP, ARP, RARP 2 Data Link Ethernet, CSMA/CD, MAC 1 Physical Ethernet Physical Layer
Reference
11
TCP/IP Stack
TCP Header TCP Data Array (Port Numbers) (20 Bytes) IP Data Array
To illustrate, with Modbus TCP/IP, the host (master/client) application forms its request, then passes its data down to the lower layers, which add their own control information to the packet in the form of protocol headers and sometimes footers. Finally the packet reaches the physical layer where it is electronically transmitted to the destination (slave/server). The packet then travels up through the different layers of its destination with each layer decoding its portion of the message and removing the header and footer that was attached by the same layer of the sending client computer. Finally the packet reaches the destination application. Although each layer only communicates with the layer just above or just below it, this process can be viewed as one layer at one end talking to its partner (peer) layer at the opposite end.
12
13
APPLICATION LAYER
14
The leading character is generally implied by the function code and omitted from the address specifier for a given function. The leading character also identifies the I/O data type.
3xxxx 4xxxx
IMPORTANT: The reference addresses noted in the memory map are not explicit hard-coded memory addresses. Internally, all Modbus devices use a zero-based memory offset computed from the reference address. However, the system interface of Modbus systems (software) will vary in this regard and may require you to enter the actual reference address, drop the leading number, or enter an absolute memory offset from 1, or a memory address offset from 0. This is system dependent and a common source of programming errors. Be wary of this when writing higher-level application programs to access these registers. Note that not all Modbus functions operate on register map registers. All data addresses in Modbus messages are referenced to 0, with the first occurrence of a data item addressed as item number zero. Further, a function code field already specifies which register group it operates on (i.e. 0x, 1x, 3x, or 4x reference addresses). For example, holding register 40001 is addressed as register 0000 in the data address field of the message. The function code that operates on this register specifies a holding register operation and the 4xxxx reference group is implied. Thus, holding register 40108 is actually addressed as register 006BH (107 decimal). The function code field of the message (PDU) will contain one byte that tells the slave what kind of action to take. Valid function codes are from 1-255, but not all codes will apply to a module and some codes are reserved for future use. Additionally, the Modbus specification allocates function codes 65-72 and 100-110 for user-defined services. The following table highlights a subset of standard Modbus functions commonly supported by Acromag modules (the reference register addresses that the function operates on are also indicated). The functions below are used to access the registers outlined in the register map of the module for sending and receiving data. The Report Slave ID command does not operate on a register map register.
15
The client request data field provides the slave (server) with any additional information required by the slave to complete the action specified by the function code in the clients request. The data field typically includes register addresses, count values, and written data. For some messages, this field may not exist (has zero length), as not all messages will require data. When the slave device responds to the master, it uses the function code field to indicate either a normal (error-free) response, or that some kind of error has occurred (an exception response). A normal response simply echoes the original function code of the query, while an exception response returns a code that is equivalent to the original function code with its most significant bit (msb) set to logic 1. For example, the Read Holding Registers command has the function code 0000 0011 (03H). If the slave device takes the requested action without error, it returns the same code in its response. However, if an exception occurs, it returns 1000 0011 (83H) in the function code field and appends a unique code in the data field of the response message that tells the master device what kind of error occurred, or the reason for the exception (see Modbus Exceptions). The client application program must handle the exception response. It may choose to post subsequent retries of the original message, it may try sending a diagnostic query, or it may simply notify the operator of the exception error. The following paragraphs describe some of the Modbus functions commonly supported by Acromag 9xxEN modules. These examples are depicted from a Modbus TCP/IP perspective (the unit ID replaces the slave address, the traditional serial CRC/LRC error checking field is dropped). Only the first example will include the MBAP header information. You should refer to the Modbus specification for a complete description of all Modbus functions. To gain a better understanding of Modbus, please refer to your modules register map as you review this material. When you review these examples and compare them to traditional serial Modbus commands, note that the slave address is supplanted by the unit identifier in Modbus TCP/IP (normally set to 00H or FFH). In addition, the error check field (CRC/LRC) is removed, as TCP/IP already applies its own error checking. For commands that support broadcast transmission, this applies to serial Modbus only, as Modbus TCP/IP is unicast only (except where an Ethernet-to-serial bridge is used).
16
This command will read the ON/OFF status of discrete outputs or coils (0x reference addresses) in the slave/server. For Acromag modules, its response is equivalent to reading the on/off status of solid-state output relays or switches. Broadcast transmission is not supported. The Read Coil Status query specifies the starting coil (output channel) and quantity of coils to be read. Coils correspond to the discrete solid-state relays of this device and are addressed starting from 0 (up to 4 coils addressed as 0-3 for this model). The Read Coil Status in the response message is packed as one coil or channel per bit of the data field. For Acromag modules, the output status is indicated as 1 for ON (conducting current), and 0 for OFF (not conducting). The LSB of the first data byte corresponds to the status of the coil addressed in the query. The other coils follow sequentially, moving toward the high order end of the byte. Since this example has only 4 outputs, the remaining bits of the data byte will be set to zero toward the unused high order end of the byte. Modbus Request ADU Example Header MBAP Header Fields Example Decimal (Hexadecimal) Transaction ID High Order 0 (00) Client sets, unique value. Transaction ID Low Order 1 (01) Client sets, unique value. Protocol Identifier High Order 0 (00) Specifies Modbus service. Protocol Identifier Low Order 0 (00) Specifies Modbus service. Length High Order 0 (00) Client calculates. Length Low Order 6 (06) Client calculates. Unit Identifier 255 (FF) or 0 (00) Do not bridge. The transaction identifier is used to match the response with the query when the client sends multiple queries without waiting for a prior response. It is typically a number from 1 to 16, but the maximum number of client transactions and the maximum number of server transactions will vary according to the device. The protocol identifier is always 0 for Modbus. The length is a count of the number of bytes contained in the data plus the function code (1 byte) and unit identifier (1 byte). The unit identifier is 00H or FFH, as this module is Modbus TCP/IP. If this module was a traditional serial Modbus type (no Ethernet port), and it was being addressed via a bridge or gateway from an Ethernet client (an Ethernet-to-serial bridge), then the unit identifier is equivalent to the traditional serial Modbus slave address (1-247). Using 00H or FFH as shown here will cause the any serial bridge/gateway device to block the passage of this client message across the bridge. This is why some text will show the unit identifier as part of the query itself since it supplants the traditional slave address (note that the length includes the unit identifier byte), while others show it as part of the MBAP header as is done here.
17
18
Reads the binary contents of holding registers (4x reference addresses) in the slave device. Broadcast transmission is not supported. The Read Holding Registers query specifies the starting register and quantity of registers to be read. Note that registers are addressed starting at 0 (registers 1-16 addressed as 0-15). The Read Holding Registers response message is packed as two bytes per register, with the binary contents right-justified in each byte. For each register, the first byte contains the high order bits and the second byte the low order bits.
This example reads holding registers 4000640008 (Channel 0 high limit value, low limit value, & deadband value).
Modbus PDU Example - Read Holding Register Query Field Name Example Decimal (Hexadecimal) Function Code 3 (03) Starting Address High Order 0 (00) Starting Address Low Order 5 (05) Number Of Points High Order 0 (00) Number Of Points Low Order 3 (03) Modbus PDU Example - Read Holding Register Response Field Name Example Decimal (Hexadecimal) Function Code 3 (03) Byte Count 6 (06) Data High (Register 40006) (3A) Data Low (Register 40006) 75%=15000 (98) Data High (Register 40007) (13) Data Low (Register 40007) 25%=5000 (88) Data High (Register 40008) (00) Data Low (Register 40008) 1%=200 (C8) To summarize our example, the contents of register 40006 (2 bytes) is the channel 0 high limit of 75% (15000=3A98H). The contents of register 40007 (2 bytes) is the channel 0 low limit of 25% (5000=1388H). The contents of register 40008 is the channel 0 deadband value (2 bytes) of 1% (200=00C8H).
This command will read the binary contents of input registers (3x reference addresses) in the slave device. Broadcast transmission is not supported. The Read Input Registers query specifies the starting register and quantity of registers to be read. Note that registers are addressed starting at 0. That is, registers 1-16 are addressed as 0-15. The Read Input Registers response message is packed as two bytes per register, with the binary contents right-justified in each byte. For each register, the first byte contains the high order bits and the second byte the low order bits.
19
20
This example writes a baud rate of 9600bps to holding register 40002 (Baud Rate).
Modbus PDU Example - Preset Holding Register Query and Response Field Name Example Decimal (Hexadecimal) Function Code 6 (06) Register Address High Order 0 (00) Register Address Low Order 1 (01) Preset Data High Order 0 (00) Preset Data Low Order 2 (02) The response message is simply an echo (copy) of the query as shown above, but returned after the register contents have been preset. No response is returned to broadcast queries from a master (serial Modbus only).
Simultaneously forces a series of coils (0x reference address) either ON or OFF. Broadcast transmission is supported by this command (serial Modbus only) and will act to force the same block of coils in all networked slaves. The Force Multiple Coils query specifies the starting coil reference address to be forced, the number of coils, and the force data to be written in ascending order. The ON/OFF states are specified by the contents in the query data field. A logic 1 in a bit position of this field requests that the coil turn ON, while a logic 0 requests that the corresponding coil be turned OFF. Unused bits in a data byte should be set to zero. Note that coils are referenced starting at 0up to 4 coils are addressed as 0-3 for this example and this also corresponds to the discrete output channel number.
This example forces outputs 1 & 3 OFF, and 0 & 2 ON for coils 0-3.
Modbus PDU Example - Force Multiple Coils Query Field Name Example Decimal (Hexadecimal) Function Code 15 (0F) Coil Address High Order 0 (00) Coil Address Low Order 0 (00) Number Of Coils High Order 0 (00) Number Of Coils Low Order 4 (04) Byte Count 01 Force Data High (First Byte) 5 (05) Note that the leading character of the 0x reference address is implied by the function code and omitted from the address specified. In this example, the first address is 00001 corresponding to coil 0 and referenced via 0000H. Thus, in this example the data byte transmitted will address coils 3...0, with the least significant bit addressing the lowest coil in this set as follows (note that the four unused upper bits of the data byte are set to zero):
21
Modbus PDU Example - Force Multiple Coils Response Field Name Example Decimal (Hexadecimal) Function Code 15 (0F) Coil Address High Order 0 (00) Coil Address Low Order 0 (00) Number Of Coils High Order 0 (00) Number Of Coils Low Order 4 (04) The Force Multiple Coils normal response message returns the slave address, function code, starting address, and the number of coils forced, after executing the force instruction. Note that it does not return the byte count or force value. No response is returned to broadcast queries from a master device (serial Modbus). Presets a block of holding registers (4x reference addresses) to specific values. Broadcast transmission is supported by this command and will act to preset the same block of registers in all networked slaves (serial Modbus only). The Preset Multiple Registers query specifies the starting register reference address, the number of registers, and the data to be written in ascending order. Note that registers are addressed starting at 0--registers 1-16 are addressed as 0-15. Modbus PDU Example - Preset Multiple Registers Query Field Name Example Decimal (Hexadecimal) Function Code 16 (10) Starting Register High Order 0 (00) Starting Register Low Order 0 (00) Number Of Registers High Order 0 (00) Number Of Registers Low Order 3 (03) Preset Data High (First Register) 0 (00) Preset Data Low (First Register) 200 (C8) Preset Data High (Second Reg) 0 (00) Preset Data Low (Second Reg) 5 (05) Preset Data High (Third Reg) 0 (00) Preset Data Low (Third Reg) 2 (02) Modbus PDU Example - Preset Multiple Registers Response Field Name Example Decimal (Hexadecimal) Function Code 16 (10) Starting Register High Order 0 (00) Starting Register Low Order 0 (00) Number Of Registers High Order 0 (00) Number Of Registers Low Order 3 (03) This example writes a new slave address of 200, a baud rate of 28800bps, and sets parity to even, by writing to holding registers 40001 through 40003 (changes to slave address, baud rate, and parity will take effect following the next software or power-on reset).
22
The command query simply sends the unit identifier and function code.
All I/O values are accessed via 16-bit Input Registers or 16-bit Holding Registers (see Register Map). Input registers contain information that is read-only. For example, the current input value read from a channel, or the states of a group of digital inputs. Holding registers contain read/write information that may be configuration data or output data. For example, the high limit value of an alarm function operating at an input, or an output value for an output channel. I/O values of Acromag modules take the following common forms of data to represent temperature, percentage, and discrete on/off, as required. This is not a Modbus standard and will vary between devices.
23
Modbus Exceptions
24
Modbus Exceptions
25
7 BYTES
H E A D E A R
Transaction ID Protocol ID Length Unit ID Function Code Modbus Data 8 Bytes (MIN) Modbus PDU (1 Byte MIN) Variable From 0 to Max Bytes MBAP Header (7 Bytes)
D VARIABLE A T BYTES A
26
The Protocol Data Unit (PDU) is the Modbus function code and data field in their original form. The original Modbus error checking field (checksum) is not used, as the standard ethernet TCP/IP link layer checksum methods are instead used to guaranty data integrity. Further, the original Modbus device address field is supplanted by the unit identifier in Modbus TCP/IP and becomes part of the Modbus Application Protocol (MBAP) header. The original device address is not needed because Ethernet devices already contain their own unique MAC addresses. However, it is used if a serial bridge or gateway is being used to bridge Ethernet to a serial sub-network of Modbus devices. With traditional serial Modbus, a client can only send one request at a time and must wait for an answer before sending a second request. However, Modbus TCP/IP devices may send several requests to the same server without waiting for the prior response. In this instance, the transaction identifier is use to match a future response with its originating request and must be unique per transaction. It is commonly a TCP sequence number driven by a counter that is incremented by each request. The maximum number of client transactions will vary from device to device, but is generally a number from 1 to 16. Likewise the maximum number of server transactions also varies. For Acromag 9xxEN-4 modules, this number is 10. The unit identifier field was intended to facilitate communication between Modbus TCP/IP Ethernet devices and traditional Modbus serial devices by using a bridge or gateway to route traffic from one network to a serial line sub-network. In this case, the destination IP address identifies the bridge or gateway device to send the message to, while the bridge device itself uses the Modbus Unit Identifier to forward the request to the specific slave device of the sub network. Recall that serial Modbus uses addresses 1 to 247 decimal, and reserves 0 as a broadcast address. Thus, the unit identifier assumes the same assignment for these applications. Further, this is the only way that broadcast messages are supported with Modbus TCP/IP, as TCP alone only sends unicast (point-to-point) messages.
27
Because TCP is a connection-oriented protocol, a TCP connection must first be established before a message can be sent via Modbus TCP/IP. Following the client-server principle, this connection is established by the client (master). This connection can be handled explicitly by the client userapplication software, or automatically by the client TCP connection manager. More commonly, this is handled automatically by the client protocol software via the TCP socket interface and this operation remains transparent to the application. All Modbus TCP/IP message connections are point-to-point communication paths between two devices, which require a source address, a destination address, and a connection ID in each direction. Thus Modbus TCP/IP communication is restricted to unicast messages only. Well-known port 502 has been specifically reserved for Modbus applications. A Modbus server will listen for communication on port 502. When a Modbus client wants to send a message to a remote Modbus server, it opens a connection with remote port 502. As soon as a connection is established, the same connection can be used to transfer user data in either direction between a client and server. A client and server may also establish several TCP/IP connections simultaneously. When a connection is established, all the transmissions that are part of that connection are associated with a Connection ID (CID). If this connection involves transmission in both directions, then two Connection IDs are assigned. The maximum number of connections allowed is dependent on the specifications of the particular TCP/IP interface (for Acromag 9xxEN modules, this number is 10). In the case of cyclic transmission between a client and server, a permanent connection can also be employed. If it is only necessary to transfer parameter or diagnostic information when a special event occurs, then this connection can be closed after each data transmission and reopened as needed.
Connection Manager
28
Connection Manager
Of course, a process must also exist to establish connections between devices that are not connected yet. This is the purpose of the Unconnected Message Manager (UCMM), which serves to process these connection requests. Once the UCMM has established a connection, then all the connection resources needed between the two devices (including bridges/routers) are reserved for that connection.
29
TRANSPORT LAYER
30
32-bit Sequence Number 32-bit Acknowledgment Number HLEN (4) Resrvd (6) U A P R S F 16-bit Window Size 16-bit Urgent Pointer 20 Bytes Options (Variable Bits) - Optional (Rarely Used) TCP USER DATA . . . Variable Up To 1460 Bytes 24 Bytes
31
TCP Example
32
TCP Example
SAP TCP
TCP
IP (Network Layer) Ethernet (Data Link Layer) Physical Layer (CAT5 Cable)
IP (Network Layer) Ethernet (Data Link Layer) Physical Layer (CAT5 Cable) Acromag 983EN-4012
Acromag
ETHERNET
Note that a web browser always uses TCP for communication with a web server. The web browser (client application) starts by making a service request to TCP of its transport layer for the opening of a connection for reliable data transport. It uses the IP address of the remote server combined with the well-known port number 80 (HTTP Protocol) as its socket address. TCP opens the connection to its peer entity at the web server by initiating a three-way handshake. If this handshake can complete and the connection successfully open, then data can flow between the web browser (client) and the web server (Acromag module). Once the connection is made, the web browser and remote server assume that a reliable open data pipe has formed between them and they begin transporting their data in sequence, and without errors, as long as TCP does not close the connection. TCP will monitor the transaction for missing packets and retransmit them as necessary to ensure reliability. Note that in the figure above, an observer in the data paths at either side of the router would actually see the beginning of the message from the client to the web server begin only in the third data frame exchanged (the clients request message is combined with the connection acknowledge of the third exchange).
33
NETWORK LAYER
IP Internet Protocol
IP HEADER/PACKET CONTENTS
0 8 16 24 32 Bits
Version
HLEN
32-bit Source IP Address For Packet 32-bit Destination IP Address For Packet 20 Bytes Options (Variable Bits) - Optional (Rarely Used) IP USER DATA . . . Variable Number of Bytes
34
IP Internet Protocol
35
IP Internet Protocol
A Network's Infrastructure includes the physical hardware used to transmit data electronically such as routers, switches, gateways, bridges, and hubs. A router is located at the gateway where it directs the flow of network traffic and determines the route of packets as they travel from one network to another network(s). A router can be either a hardware device or a software application.
36
A Subnet Mask is used to subdivide the host portion of the IP address into two or more subnets. The subnet mask will flag the bits of the IP address that belong to the network address, and the remaining bits correspond to the host portion of the address. The unique subnet to which an IP address refers to is recovered by performing a bitwise AND operation between the IP address and the mask itself, with the result being the sub-network address.
A Subnet is a contiguous string of IP addresses. The first IP address in a subnet is used to identify the subnet and usually addresses the server for the subnet. The last IP address in a subnet is always used as a broadcast address and anything sent to the last IP address of a subnet is sent to every host on that subnet. Subnets are further broken down into three size classes based on the 4 octets that make up the IP address. A Class A subnet is any subnet that shares the first octet of the IP address. The remaining 3 octets of a Class A subnet will define up to 16,777,214 possible IP addresses (224 2). A Class B subnet shares the first two octets of an IP address (providing 216 2, or 65534 possible IP addresses). Class C subnets share the first 3 octets of an IP address, giving 254 possible IP addresses. Recall that the first and last IP addresses are always used as a network number and broadcast address respectively, and this is why we subtract 2 from the total possible unique addresses that are defined via the remaining octet(s). A Subnet Mask is used to determine which subnet an IP address belongs to. The use of a subnet mask allows the network administrator to further divide the host part of this address into two or more subnets. The subnet mask flags the network address part of the IP address, plus the bits of the host part, that are used for identifying the sub-network. By mask convention, the bits of the mask that correspond to the sub-network address are all set to 1s (it would also work if the bits were set exactly as in the network address). Its called a mask because it can be used to identify the unique subnet to which an IP address belongs to by performing a bitwise AND operation between the mask itself, and the IP address, with the result being the subnetwork address, and the remaining bits the host or node address. For our example, the default IP address of this module is 128.1.1.100. If we assume that this is a Class C network address (based on the default Class C subnet mask of 255.255.255.0), then the first three numbers represent this Class C network at address 128.1.1.0, the last number identifies a unique host/node on this network (node 100) at address 128.1.1.100.
37
For our example, if we wish to further divide this network into 14 subnets, then the first 4 bits of the host address will be required to identify the subnetwork (0110), then we would use 11111111.11111111.11111111. 11110000 as our subnet mask. This would effectively subdivide our Class C network into 14 subnetworks of up to 14 possible nodes each. With respect to the default settings of Acromag 9xxEN modules: Subnet Mask 255.255.255.0 (11111111.11111111.11111111.00000000) IP Address: 128.1.1.100 (10000000.00000001.00000001.01100100) Subnet Address: 128.1.1.0 (1000000.00000001.00000001.00000000) Subnetwork address 128.1.1.0 has 254 possible unique node addresses. We are using node 100 of 254 possible for our module. At this point, we see that each layer (application, transport, network, and data link layer) uses its own address method. The application layer uses socket numbers, which combine the IP address with the port number. The transport layer uses port numbers to differentiate simultaneous applications. The network layer uses the IP address, and the Data Link layer uses the MAC address. The Address Resolution Protocol (ARP) is a TCP/IP function that resides at the network layer (layer 3) with the Internet Protocol (IP), and its function is to map Ethernet addresses (the MAC ID) to IP addresses, and maintain a mapping table within the network device itself. This protocol allows a sending station to gather address information used to form a layer 2 frame complete with the IP address and hardware (MAC) address. Every TCP/IPbased device contains an ARP Table (or ARP cache) that is referred to by a router when it is looking up the hardware address of a device for which it knows the IP address and needs to forward a datagram to. If this device wants to transmit an IP packet to another device, it first attempts to look-up the Ethernet address of that device in its ARP table. If it finds a match, it will pass the IP packet and Ethernet address to the Ethernet driver (physical layer). If no hardware address is found in the ARP table, then an ARP broadcast is sent onto the network. The ARP protocol will query the network via a local broadcast message to ask the device with the corresponding IP address to return its Ethernet address. This broadcast is read by every connected station, including the destination station. The destination station sends back an ARP reply with its hardware address attached so that the IP datagram can now be forwarded to it by the router. The hardware address of the ARP response is then placed in an internal table and used for subsequent communication. It is important to note that when we used the term local broadcast message above, that Ethernet broadcast messages will pass through hubs, switches, and bridges, but will not pass through routers. As such, broadcast messages are confined to the subnet on which they originate and will not propagate out onto the worldwide web.
ARP is used to search for another stations MAC address knowing only its IP address. RARP is used to search for a local stations IP address knowing only its MAC address.
38
RARP essentially allows a node in a local area network to request its IP address from a gateway servers ARP table. The ARP table normally resides in the LANs gateway router and maps physical machine addresses (MAC addresses) to their corresponding Internet Protocol (IP) addresses. When a new machine is added to a LAN, its RARP client program requests its IP address from the RARP server on the router. Assuming that an entry has been set up in the router table, the RARP server will return the IP address to the machine which will then store it for future use. ARP and its variant RARP are needed because IP uses logical host addresses (the IP address), while media access control protocols (Ethernet, Token-Ring, FDDI, etc.) need MAC addresses. The IP addresses are assigned by network managers to IP hosts and this is usually accomplished by configuration file options and driver software. That is why these are sometimes referred to as software addresses. LAN topologies cannot use these software addresses and they require that the IP addresses be mapped to their corresponding MAC addresses. For example, a diskless workstation cannot read its own IP address from configuration files. They will send an RARP request (or BOOTP request) to a RARP server (or BOOTP server). The RARP server will find the corresponding IP address in its configuration files using the requesting stations MAC address as a lookup, and then send this IP address back in a RARP reply packet.
39
ARP/RARP Header Field Definitions (Left-to-Right, Top-to-Bottom): Hardware Type Specifies a hardware interface type from which the sender requires a response. This is 1 for Ethernet. Protocol Type This is the protocol type used at the network layer and is used to specify the type of high-level protocol address the sender has supplied. Hardware Address Length (HALEN) This is the hardware address length in bytes which is 6 for an Ethernet (MAC Address). Protocol Address Length (PALEN) This is the protocol address length in bytes which is 4 for a TCP/IP (IP Address). Operation Code This code is commonly used to indicate whether the packet is an ARP request (1), or an ARP response (2). Valid codes are as follows: 1 = ARP Request; 2 = ARP Response; 3 = RARP Request; 4 = RARP Response; 5 = Dynamic RARP Request; 6 = Dynamic RARP Reply; 7 = Dynamic RARP Error; 8 = InARP Request; 9 = InARP Reply. Sender Hardware (MAC) Address This is the 48-bit hardware (MAC) address of the source node. Sender Protocol (Software) Address This is the 32-bit senders protocol address (the layer 3/network layer addressthe IP address). Target/Destination Hardware (MAC) Address Used in an RARP request. The RARP request response carries both the target hardware address (MAC address) and layer 3 address (IP address). Target/Destination Protocol (Software) Address Used in an ARP request. The ARP response carries both the target hardware address (MAC address) and layer 3 address (IP address).
40
CSMA/CD
The data link layer also uses the CSMA/CD protocol (Carrier Sense Multiple Access w/ Collision Detection) to arbitrate access to the shared Ethernet medium. Recall that with CSMA/CD, any network device can try to send a data frame at any time, but each device will first try to sense whether the line is idle and available for use. If the line is available, the device will begin to transmit its first frame. If another device also tries to send a frame at approximately the same time (perhaps because of cable signaling delay), then a collision occurs and both frames are subsequently discarded. Each device then waits a random amount of time and retries its transmission until it is successfully sent. With switched Ethernet, a deliberate effort has been made to suppress CSMA/CD in order to increase determinism. This is done by using Ethernet switches to interconnect devices, connecting only one device per switch port. With only one device per switch port, there is no chance of collisions and devices will communicate full-duplex, at effectively double the base data rate.
The Medium Access Control (MAC) protocol provides the services required to form the data link layer of Ethernet. This protocol encapsulates its data by adding a 14-byte header containing the protocol control information before the data, and appending a 4 byte CRC value after the data. The entire frame is preceded by a short idle period (the minimum inter-frame gap), and an 8-byte preamble.
41
56-bit PREAMBLE
8-bit SFD
8 Bytes
64-1518 BYTES
Variable From 46 to 1500 Bytes 1522 Bytes (MAX) 32-bit FCS 72 Bytes (MIN) 1526 Bytes (MAX) (Includes PREAMBLE)
Ethernet (MAC) Frame Definitions (Left-to-Right & Top-to-Bottom): Preamble & SFD (56-bits+8-bits SFD) Technically, the preamble is not part of the Ethernet frame, but is used to synchronize signals between stations. It is comprised of a pattern of 62 alternating 1s & 0s, followed by two set bits 11 (the last 8-bits of this pattern are actually referred to as the Start-of-Frame Delimiter or SFD byte). This 8-byte preamble/SFD is also preceded by a small idle period that corresponds to the minimum inter-frame gap period of 9.6us (at 10Mbps). After transmitting a frame, the transmitter must wait for this period to allow the signal to propagate through the receiver of its destination. The preamble allows the receiver at each station to lock into the Digital Phase Lock Loop used to synchronize the receive data clock to the transmit data clock. When the first bit of the preamble arrives, the receiver may be in an arbitrary state (out of phase) with respect to its local clock. It corrects this phase during the preamble and may miss/gain a number of bits in the process. That is why the special pattern of two set bits (11) is used to mark the last two bits of the preamble. When it receives these two bits, it starts assembling the bits into bytes for processing by the MAC layer. When using Manchester encoding at 10Mbps, the 62 alternating 1/0 bits of the preamble will resemble a 5MHz square wave.
42