What is a packet checksum? Here we investigate the NIC’s capabilities for computing and detecting errors using checksums.

Slides:



Advertisements
Similar presentations
Lecture 12 Layer 2 – Data Link Layer Protocols
Advertisements

Repeaters can Mix PHY Standards Repeater NIC BNC AUI Connectors RJ-45 UTPDrop Cables 10Base5 Trunk Cable 10Base2 10Base-T.
Data and Computer Communications
Chapter 6 Errors, Error Detection, and Error Control.
Traceroute Assignment. Base64 Encoding The SMTP protocol only allows 7 bit ASCII data, so how can you send me a picture of Avril Lavigne, which is an.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
CSCI 4550/8556 Computer Networks Comer, Chapter 7: Packets, Frames, And Error Detection.
PART III DATA LINK LAYER. Position of the Data-Link Layer.
Assembly Language and Computer Architecture Using C++ and Java
Source Port # (16)Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Flags (6)Window Size (16) Options (if.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
Error Detection and Correction
Adapted from Tanenbaum's Slides for Computer Networking, 4e The Data Link Layer Chapter 3.
Building TCP/IP packets A look at the computation-steps which need to be performed for utilizing the TCP/IP protocol.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Programmable Logic Controllers
Simple Data Type Representation and conversion of numbers
Lecture 6 Topics Character codes Error Detection and Correction
Chapter 1-3 The Ethernet LAN. Ethernet The networking protocol used in most modern computer networks is Ethernet. Ethernet is a CSMA/CD LAN protocol.
Part.7.1 Copyright 2007 Koren & Krishna, Morgan-Kaufman FAULT TOLERANT SYSTEMS Part 7 - Coding.
It is physically impossible for any data recording or transmission medium to be 100% perfect 100% of the time over its entire expected useful life. As.
Computer Science 111 Fundamentals of Programming I Number Systems.
COM342 Networks and Data Communications
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Core 3: Communication Systems. There are three terms that we will consider in relation to the speed of communication. Bits per second (bps) Baud Rate.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
1 Data Link Layer Lecture 20 Imran Ahmed University of Management & Technology.
PART III DATA LINK LAYER. Position of the Data-Link Layer.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
CPU Internal memory I/O interface circuit System bus
Transmission Control Protocol
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Error Coding Transmission process may introduce errors into a message.  Single bit errors versus burst errors Detection:  Requires a convention that.
Topic 1 – Number Systems. What is a Number System? A number system consists of an ordered set of symbols (digits) with relations defined for addition,
Part 2: Packet Transmission Packets, frames Local area networks (LANs) Wide area networks (LANs) Hardware addresses Bridges and switches Routing and protocols.
10.1 Chapter 10 Error Detection and Correction Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Lecture 6: Framing and Error Detection-Data Link Layer Functions
Chapter 1 - Local Area Network Technologies. How IP Datagrams are Encapsulated IP datagrams are found at the OSI Network layer IP datagrams are sent to.
TCP/IP Protocol Suite 1 Chapter 8 Upon completion you will be able to: Internet Protocol Understand the format and fields of a datagram Understand the.
Communications Services Connection Oriented Service  A connection is established  Data is sent or received over this connection  Connection may be terminated.
CSNB374: Microprocessor Systems Chapter 1: Introduction to Microprocessor.
1 2.1 Introduction A bit is the most basic unit of information in a computer. –It is a state of “on” or “off” in a digital circuit. –Sometimes these states.
1 © Unitec New Zealand CRC calculation and Hammings code.
Error Detection.
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
10.1 Chapter 10 Error Detection and Correction Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MECH1500 Chapter 3.
PHY 201 (Blum)1 Shift registers and Floating Point Numbers Chapter 11 in Tokheim.
Internet Protocol Version 4 VersionHeader Length Type of Service Total Length IdentificationFragment Offset Time to LiveProtocolHeader Checksum Source.
10.1 Chapter 10 Error Detection and Correction Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
PHY 201 (Blum)1 Shift registers and Floating Point Numbers Chapter 11 in Tokheim.
Network Layer4-1 Chapter 5: The Data Link Layer Our goals: r understand principles behind data link layer services: m error detection, correction m sharing.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Number Systems & Binary Arithmetic
Cosc 2150: Computer Organization
MIPS Arithmetic is 32 bits
CS4470 Computer Networking Protocols
Simple Parity Check The simplest form of error detection is the parity check used with ASCII codes, originally on asynchronous modem links Each 7 bit ASCII.
2.8 Error Detection and Correction
Data Link Layer.
Part III. Data Link Layer
Cyclic Redundancy Check (CRC)
Dr. Clincy Professor of CS
Advanced Computer Networks
Error Detection and Correction
Chapter 1 Number Systems, Number Representations, and Codes
Internet Protocol (IP)
COMPUTER NETWORKS CS610 Lecture-5 Hammad Khalid Khan.
2.8 Error Detection and Correction
Data Link Layer. Position of the data-link layer.
Presentation transcript:

What is a packet checksum? Here we investigate the NIC’s capabilities for computing and detecting errors using checksums

Gigabit Ethernet frame-format Preamble Destination Address Start-Of-Frame Delimiter Source AddressType/Lenth Data Frame Check Sequence Carrier Extension Frame is extended to occupy a slot-time of 512 bytes

Some lowest-level details The frame’s Preamble consists of 7 bytes of an alternating bit-pattern of 1’s and 0’s The Start-of-Frame Delimiter is a one-byte bit-pattern which continues the alternation of 1’s and 0’s until the final bit is reached (which ‘breaks’ the pattern-of-alternation) In hexadecimal notation: 0xAA 0xAA 0xAA 0xAA 0xAA 0xAA 0xAA 0xAB The 64-bit Preamble and SFD The Start-of-Frame Delimiter

The FCS field The Frame Check Sequence is a four-byte integer, usually computed by the hardware according to a sophisticated mathematical error-detection scheme known as Cyclic- Redundancy Check (CRC): The CRC is calculated by performing a modulo 2 division of the data by a generator polynomial and recording the remainder after division CRC-32 = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1

The CRCERRS register Our Intel Pro1000 ethernet controller has a statistical counter register (the first one, at offset 0x4000 in the memory-mapped I/O- space) which counts any received frames which arrived with a CRC-error indicated Our ‘nic2.c’ was programmed to ‘strip’ the 4-byte FCS field from all received frames, by setting the SECRC-bit in register RCTL

Another (simpler) checksum Base-address (64-bits) status Packet- length Packet- checksum VLAN tag errors 16 bytes The device-driver initializes this ‘base-address’ field with the physical address of a packet-buffer The network controller will ‘write-back’ the values for these fields when it has transferred a received packet’s data into the packet-buffer The Pro1000’s ‘legacy-format’ Receive-Descriptor

What is this ‘packet checksum’? According to the Intel documentation, the packet checksum is “the unadjusted 16-bit ones complement of the packet” (page 24) Now what exactly does that mean? And why did Intel’s hardware designers believe that device-driver software would need this value to be available for every ethernet packet that the NIC receives?

The idea of ‘complements’ Whenever a whole object gets divided into two parts, those pieces often referred to as complements Example: complementary angles in a right-triangle A B C ABC + BAC = 90°

Set Theory B A Venn Diagram Within the ‘universe’ represented here by the box, the orange set B is the complement of the green set A.

Arithmetic Among the digits in our ‘base ten’ system: –the values 1 and 9 are complements –the values 2 and 8 are complements –the values 3 and 7 are complements –the values 4 and 6 are complements Complements are useful when performing subtractions in modular arithmetic: (mod 10) = (mod 10)

Two’s complement Digital computers use modular arithmetic in the ‘base two’ number system Two 8-bit numbers are ‘complements’ if their sum equals 2 8 (= 256): is the twos-complement of is the twos-complement of is the twos-complement of As a consequence, subtractions can be done with the same circuits as additions

One’s complement But for some purposes there is a different kind of ‘complement’ that results in better arithmetical properties – it’s known as the ‘diminished radix’ complement For the case of radix ten, it’s called ‘nine’s complement’, and for the case of radix two it’s called ‘one’s complement’

Nine’s complements A pair of 3-digit numbers x and y in the radix ten number system would be called nine’s complements if x+y = = 999 –Thus 321 and 678 are nines-complements A pair of 3-digit numbers x and y in the radix two number system would be called one’s complements if x+y = = 111 –Thus 110 and 001 are ones-complements

‘end-around-carry’ When you want to add two binary numbers using the one’s complement system, you can do it by first performing ordinary binary addition, and then adding in the carry-bit: (8-bit number) (8-bit number) (9-bits in the normal total) + 1 (apply ‘end-around carry’) (8-bits in the ones-complement total)

NIC uses ‘one’s complement’ For network programming nowadays it is common practice for ‘one’s complement’ to be used when computing checksums It is also common practice for multi-byte integers to be ‘sent out over the wire’ in so called ‘big-endian’ byte-order (i.e., the most significant byte goes out ahead of the bytes having lesser significance)

Intel’s cpu uses ‘little endian’ Whenever our x86 processor ‘stores’ a multi-byte value into a series of cells in memory, it puts the least significant byte first (i.e., at the earliest memory address), followed by the remaining bytes having greater significance) 0x3456 AX = 0x56 buf: 0x34 mov %ax, buf

Checksum using C { unsigned char*cp = phys_to_virt( rxring[ rxhead ].base_address ); unsigned intnbytes = rxring[ rxhead ].packet_length; unsigned intnwords = ( nbytes / 2 ); unsigned short*wp = (unsigned short*)cp; unsigned inti, checksum = 0; if ( nbytes & 1 ) { cp[ nbytes ] = 0; ++nwords; }// pad odd length packet for ( i = 0; i < nwords; i++ ) checksum += wp[ i ];// two’s complement sum checksum += (checksum >> 16);// do ‘end-around carries’ checksum = htons( checksum )// -- adjustment #1: swap the bytes checksum = ~checksum;// -- adjustment #2: and flip the bits checksum &= 0xFFFF;// mask to lowest 16-bits // Let’s compare our checksum-calculation with the one done by the PRO1000 printk( “ cpu-computed checksum=%04X “, checksum ); printk( “ nic’s rx packet-checksum=%04X “, rxring[ rxhead ].packet_chksum ); printk( “\n” ); }

In-class demonstration #1 TIMEOUT We will insert into our ‘nic2.c’ device-driver’s ‘read()’ function our C code that computes and displays the “unadjusted 16-bit ones complement sum” for each received packet and compare our calculation with the NIC’s ‘packet_checksum’

Checksum ‘offloading’ Our Intel 82573L network controller has the capability of performing several useful checksum calculations on normal network packets – if this desired by a device-driver reserved (=0) RXCSUM (0x5000) Receive CheckSum control register PCSS IPOFLDIPOFLD TUOFLDTUOFLD Legend:PCSS = Packet Checksum Start (default=0x00) IPOFLD = IP-checksum Off-load Enable (1=yes, 0=no) TUOFLD = TCP/UDP checksum Off-load Enable (1=yes, 0=no)

Using ‘nicecho.c’ To compensate for the modifications made to the DA and SA fields by our ‘echo.c’, we can omit the first six words (12 bytes) from the checksum-calculations done both by our read() code and by the nic hardware // we start our addition-loop at i=6 instead of i=0 for ( i = 6; i < nwords; i++ ) checksum += wp[ i ]; AND // we initialize the CRXCSUM register with PCSS=12 iowrite( 0x C, io + E1000_RXCSUM );

In-class demonstration #2 TIMEOUT We will modify the nic’s RXCSUM register (as well as our own previous checksum computation) and observe the resulting effects

The ‘Legacy’ Transmit-Descriptor Base-address (64-bits) status Packet- length specialCSS 16 bytes cmdCSO CSO = CheckSum Offset CSS = CheckSum Start IDEIDE VLEVLE 00 WBWB ICIC IFCSIFCS EOPEOP Command-Byte Format

Our driver’s packet-layout destn-addresssource-address TYPE/ LENGTH count -- data data – -- data -- Let’s make room for a new 16-bit field at offset 0x0010, by starting our packet’s data-payload at offset 0x0012 instead of offset 0x0010

Further driver modifications… We can demonstrate ‘Checksum Insertion’ performed by the NIC with these changes: #define HDR_LEN (14+4) // two more bytes precede packet’s data enum{ E1000_RXCSUM = 0x5000, };// define symbolic register-offset ssize_t my_write( struct file *file, const char *buf, size_t len, loff_t *pos ) { // add these assignments in our driver’s ‘write()’ function txring[ txtail ].cksum_offset = 16;// where to insert the checksum txring[ txtail ].cksum_origin = 12;// where to start its calculation txring[ txtail ].desc_command |= (1<<2); // IC-bit (Insert Checksum) }

In-class demonstration #3 TIMEOUT We will modify the packet-layout used in our device-driver’s ‘write()’ and ‘read()’ functions, and then program our TX descriptors to utilize the IC command-option and the CSO and CSS descriptor fields and then observe the resulting effects