Sei sulla pagina 1di 27

EMBEDDED, REALT IME SOLUTIONS AND SERVICES

TCP/IP in Embedded
Systems

Mike Anderson
CTO/Chief Scientist
The PTR Group, Inc.

www.ThePTRGroup.com
www.ThePTRGroup.com RTC/GB-1
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

What We’ll Talk About


• Networking 101
– Stacks
– Protocols
– Routing
• Drivers
• Embedded Stacks
• Porting

www.ThePTRGroup.com RTC/GB-2
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Connected Systems
• 10 years ago, it was unusual
to find embedded systems
that had network connectivity
• Today, it’s difficult to find
systems that don’t have
network connectivity
requirements
• Ranges from use during
development to heavily
network-centric internet
appliances
www.ThePTRGroup.com RTC/GB-3
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

What is a “Network”
• Anything connected to anything else!

www.ThePTRGroup.com RTC/GB-4
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

What is a “Stack”?
Specialized network functions such as file transfer, virtual terminal,
7 Application electronic mail, and file servers.
Protocols: DNS, TFTP, BOOTP, SNMP, RLOGIN, FTP, SMTP, MIME, NFS

6 Presentation Data formatting and character code conversion and data encryption.
Protocols: Null

5 Session Negotiation and establishment of a connection with another node.


Protocols: Null

4 Transport Provision for reliable or end-to-end delivery of data.


Protocols: TCP, UDP

3 Network Routing of packets of information across multiple networks


Protocols: IP, ARP, RARP, ICMP, RIP, OSPF, BGP, IGMP

2 Data Link Transfer of addressable units of information, frames, and error checking.
Protocols: SLIP, CSLIP, PPP, IEEE 802.2

1 Physical Transmission of binary data over a communications network.


Protocols: ISO 2110, IEEE 802

The ISO Reference Model


www.ThePTRGroup.com RTC/GB-5
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

The Internet Protocol


7 Application Application
6 Presentation
5 Session
4 Transport TCP/
3 Network IP
2 Data Link Enet MAC
1 Physical 100BaseT

www.ThePTRGroup.com RTC/GB-6
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Example WRS VxWorks® Stack


User Applications

WDB Network Services


NFS Agen rlogin, netdrv, FTP/TFTP , etc.
t
RPC
AlternateStack
Alternate Stack
Alternate Stack Sockets/Streams

TCP UDP
IP ICMP

Mux BSD 4.3

Ethernet Custom
Serial Ethernet Older
Ethernet Interface SM Backplane
Ethernet

www.ThePTRGroup.com RTC/GB-7
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Let’s Get Physical


• The Physical and DataLink
layers can be made out of
anything
– Ethernet
• 10, 100, Gig
– Telcom
• T1, SONET, Fiber
– Serial
• PPP, SLIP
– Wireless
• 802.11, Bluetooth
• For the most part you only
need the right driver!
www.ThePTRGroup.com RTC/GB-8
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Protocols Inside Protocols


• “Layered” Protocols are wrapped in
each other
• Ethernet -> IP -> TCP -> Your Data
Ethernet
IP
TCP

Payload

Enet Cksum
www.ThePTRGroup.com RTC/GB-9
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Communication Types
• There are two primary
styles of network
communications
– Connection-based
• Virtual-circuit oriented
– Connection-less
• Datagram oriented
• Which type you pick
depends on the
application

www.ThePTRGroup.com RTC/GB-10
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

IP Routing
• One of IP’s jobs is packet routing
– Remember, best effort only
• Static routing is typically handled with
either files or memory-based tables
• Dynamic routing is done either via RIP,
OSPF or BGP protocols

www.ThePTRGroup.com RTC/GB-11
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Routing Example
Application Application

TCP TCP
IP Router

IP IP IP

Ethernet Enet1 Enet2 Ethernet


192.168.1.175 192.168.1.1 10.0.0.1 10.0.0.2

Default Explicit
Routing Table Routing Table
Route Route
ARPs may be
Network Gateway Network Gateway
required along the way
0.0.0.0 192.168.1.1 192.168.1.0 10.0.0.1

www.ThePTRGroup.com RTC/GB-12
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

What is a “Socket”
• All this network stuff
seems pretty
complicated
• Sockets are a way to
use a stack for the
application
programmer
• They make a network
connection look like a
file
www.ThePTRGroup.com RTC/GB-13
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Where Does A Driver Fit In?


Application

TCP/ Right Here Usually


IP
Enet MAC
100BaseT

www.ThePTRGroup.com RTC/GB-14
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Network Device Drivers


(Inbound)
• The requirements for network device driver
develop vary widely from one O/S to another
• In general, packets will arrive on the interface
as a contiguous block of data
– An interrupt is signaled and the ISR must move
the data from the interface H/W buffer into a
format that is compatible with the stack
• Clusters, mblks or mbufs
– This collection of smaller buffers is then moved up
through the stack by changing pointers into the
buffer chain

www.ThePTRGroup.com RTC/GB-15
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Buffer Movement
Enet Hdr mbuf hdr
IP
Header
TCP
Header mbuf hdr
IP Stack

mbuf hdr

Payload TCP Stack


mbuf hdr

Socket Interface
.
.
.
www.ThePTRGroup.com RTC/GB-16
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Network Device Drivers


(Outbound)
• To move the data outbound, the network
driver must walk the mbuf/mblk/cluster chain
to produce a contiguous buffer for the
hardware to transfer
• Some NICs provide DMA engines that can
handle this transfer
– Memory must be marked as uncacheable unless
the architecture supports bus snooping
• These mbuf/mblk/cluster structures are
usually pre-allocated to maximize
performance
www.ThePTRGroup.com RTC/GB-17
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

How Much Stack do we Need?


• It depends…
– Simple configuration
• The PIC or similar device
• Serial interface
– Web-based user interface
• Ipsil or similar
• Ethernet interface
– Network Router/VoIP
• General purpose CPU w/
RTOS or Linux

www.ThePTRGroup.com RTC/GB-18
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Fat
User Applications

WDB Network Services


NFS Agen rlogin, netdrv, FTP/TFTP , etc.
t
RPC
AlternateStack
Alternate Stack
Alternate Stack Sockets/Streams

TCP UDP
IP ICMP

Mux BSD 4.3

Ethernet Custom
Serial Ethernet Older
Ethernet Interface SM Backplane
Ethernet

www.ThePTRGroup.com RTC/GB-19
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Skinny
User Application

Webserver

Sockets/Streams

TCP UDP

IP

Ethernet

www.ThePTRGroup.com RTC/GB-20
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Trimming the Fat


• Performance?
• Footprint?
• You probably don’t need all of those
protocols
• Sometimes the stack is
modular/configurable
• Sometimes you can “buy” a “lite” stack
• Not all stacks are created equal!
www.ThePTRGroup.com RTC/GB-21
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

The Stack Spectrum

P L ininuuxx BlackDiamond 6816


SSMMP Latedd
Speed/PPS

gr te TCP Hardware
InIntetegarcak
SSt tack 192 Million pps
orkss
PIC 12C509 VVxxWWodrkstatacckk
TCP Firmware a d XX// te g rarateted s
e d
TThhr reaichee n
IInte g
118 pps rn ch
InInteteranci k
SSt tack

0
Cost/Complexity
www.ThePTRGroup.com RTC/GB-22
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Porting a Stack
• Third-party stacks are often designed to run
with or without a kernel
– They simply require memory allocation, a timer
and a means to get control of the CPU e.g., ISR or
tasking
• You’ll still need to write a device driver for the
NIC
• For best performance the use of interrupts
and DMA is recommended, but polling is
possible for simpler processor architectures

www.ThePTRGroup.com RTC/GB-23
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Example Stack Size


• Intel 8088
Bytes Use

14,743 TCP code space


276 TCP static data
10,233 Sockets code space
148 Sockets static data
6,414 IP Module w/ ICMP, UDP, queues, timers, etc.
392 IP module data
2,232 ARP code space
236 ARP data space
=======
34,674
www.ThePTRGroup.com RTC/GB-24
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Example HTTP Server


Bytes Use

34,674 TCP/IP protocol & sockets


1,838 Packet driver interface code space
3,092 ODI driver interface code space
12,653 Web server code space w/ CGI interface
2,008 Web server static data
23,863 Web server VFS (compressed HTML, etc.)
11,277 FTP code space (server & client)
1,292 FTP static data space
67,165 Other (C runtime, MS C libraries, glue code, etc.)
=======
157,862

www.ThePTRGroup.com RTC/GB-25
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

What About Web Servers?


• HTTP is a stream-oriented protocol
– TCP support, usually with sockets API is a must
– Simple web interface does not require an O/S
• If we want to launch applications from the
web interface
– We’ll probably need task schedulers
• RTOS or Linux, etc.
– JVM or CGI or Perl/JavaScript support
– Our applications are then free to use UDP for
applications like live video

www.ThePTRGroup.com RTC/GB-26
©Copyright 2002 The PTR Group, Inc.
EMBEDDED, REALT IME SOLUTIONS AND SERVICES

Summary
• We have only begun to scratch the surface
here…
• There are many approaches to TCP/IP
support depending on your needs
• Higher speeds and more sophisticated
protocol support typically require an O/S
• Highest performances are achieved by
marrying O/S with dedicated H/W
• Just because you’re networked doesn’t mean
you can’t be “lite”
www.ThePTRGroup.com RTC/GB-27
©Copyright 2002 The PTR Group, Inc.

Potrebbero piacerti anche