Title: Protocol Debug
1Protocol Debug
- Review Ethernet
- Debug Techniques
2Ethernet
3Overview
- History
- Developed by Xerox PARC in mid-1970s
- Roots in Aloha packet-radio network
- Standardized by Xerox, DEC, and Intel in 1978
- Similar to IEEE 802.3 standard
- Manchester encoding, synchronous transmission
4Frame Format
- Addresses
- Unique, 48-bit unicast address assigned to each
adaptor - Example 802be4b12
- Broadcast all 1s
- Multicast first bit is 1
5Addressing
- Adaptor receives all frames it accepts (passes
to host) - Frames addressed to its own unicast address
- Frames addressed to the broadcast address
- Frames addressed to any multicast address it has
been programmed to accept - All frames when in promiscuous mode
6Transmitter Algorithm
- If line is idle
- Send immediately
- Upper bound message size of 1500 bytes
- Must wait 51?s between back-to-back frames
- If line is busy
- Wait until idle and transmit immediately
- Called 1-persistent (special case of
p-persistent) - Detect collision when transmitter differs from
receiver
7Collision
- jam for 512 bits, then stop transmitting frame
- minimum frame is 64 bytes (header 46 bytes of
data) - delay and try again
- 1st time uniformly distributed between 0 and
51.2?s - 2nd time uniformly distributed between 0 and
102.4?s - 3rd time uniformly distributed between 0 and
204.8?s - give up after several tries (usually 16)
- exponential backoff
8Collisions
Jam
9Minimum Packet Size
- Packet must fill whole pipe in order to block
other hosts from starting transmission - The packet must continue until a collision is
detected from a transmission starting just before
the original frame arrived - The minimum packet size is twice the number of
bits needed to fill the pipe
10Example
- 10 base T- 2500 meter length, 10Mbps
- At Speed of Light 2108m/s
11Experiences
- Observe in Practice
- 10-200 hosts (not 1024)
- Length shorter than 2500m (RTT closer to 5? than
51?) - Packet length is bimodal
- High-level flow control and host performance
limit load - Recommendations
- Do not overload (30 utilization is about max)
- Implement controllers correctly
- Use large packets
- Get the rest of the system right (broadcast,
retransmission)
12Protocol Testing
- Hardware Testing
- Sniffers
- Debug Statements
13Hardware Testing
- Loopback testing
- Modems normally have this option
- RS232 cables can send output back to the input
pins - Analog Test Equipment
- Network analyzers will display and capture in a
non-intrusive way
14Sniffers
- Ethernet card is placed in promiscuous mode
- Packets are decoded at each level
- Normally the raw data is displayed.
- Example netmon for NT, tcpdump for linux
- Can isolate attacks
15Debugging your code
- Posted Code in physical lab description gives you
a familiar format
00 01 02 03 04 05 06 07Â 08 09 0a 0b 0c 0d 0e
0f  ........ ........10 11 12 13 14 15 16 17Â
18 19 1a 1b 1c 1d 1e 1f  ........ ........20 21
22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f  Â
!"' (),-./30 31 32 33 34 35 36 37Â 38 39
3a 3b 3c 3d 3e 3f  01234567 89ltgt?
16Dont delete your debug code!
define DEBUG_PHYS 0x01 define
DEBUG_ETH_BITSTUFFED 0x02 define DEBUG_ETH_SANE
0x04 define DEBUG_ETH_ADDRS 0x08 if (blabby
DEBUG_ETH_SANE) print_chars(ethernet, buff,
length)
17Assert
- Protect yourself from insanity later in life by
visiting a psychiatrist in kindergarten - DESCRIPTION
- assert() prints an error message to
standard output and terminates the program by
calling abort() if expression is false (i.e.,
compares equal to zero). This only happens when
the macro NDEBUG is undefined.
18Assert Example
- You know that the pop from the physical routine
should be less than 90 bytes. - pop ( char buf, int len)
- assert(len lt 90)
-
- If len is ever greater than 90, an error will be
printed out an the code will exit.
19Printf(error d\n,__LINENO__)
20Test for boundary conditions
- Check for 0xff ff ff ff ff ff addresses
- Test for zero byte and max length messages
- Test Harness above and below layer
- Smoke Test
21Debug Techniques
- Real Men use gdb
- g -g foo.cc o foo (turn on debug flag)
- gdb ./foo
- run arguments (run 460one 1234 s)
- When is crashes
- where will give you a backtrace of what was
called - break lets you set breakpoints
- s single steps
- print prints out variables
- There are also guis (xxgdb, kdevelop)
22What about segmentation faults?
- The segmentation fault can occur in something
like libc, but that doesnt mean you are absolved
from finding it. - Most problems come when you are writing beyond
the end of the buffer or have an uninitialized
pointer - Look at hosed pointer and see if you can spot a
pattern (like the data you were receiving)
23An ounce of prevention
- The best way to avoid these problems is to fix
every anomaly - Even if it doesnt seem critical it will bite you
later - Debug each layer thoroughly