📄 devs-eth-synth-ecosynth.html
字号:
application is run it will have different MAC addresses, which makes
it more difficult to compare the results of different runs. To get
more deterministic behaviour it is possible to specify the MAC
addresses in the target definition file:
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>synth_device ethernet {
eth0 ethertap tap3 00:01:02:03:FE:05
eth1 ethertap tap4 00:01:02:03:FE:06
…
}</PRE
></TD
></TR
></TABLE
><P
>During the initialization phase the eCos application will instantiate
the various network devices. This will cause the I/O auxiliary to load
the <TT
CLASS="FILENAME"
>ethernet.tcl</TT
> script and spawn
<B
CLASS="COMMAND"
>rawether</B
> processes, which in turn will
<CODE
CLASS="FUNCTION"
>open</CODE
> <TT
CLASS="FILENAME"
>/dev/net/tun</TT
> and
perform the appropriate <TT
CLASS="FILENAME"
>ioctl</TT
> calls. On the Linux
side there will now be new network interfaces such as
<CODE
CLASS="VARNAME"
>tap3</CODE
>, and these can be configured like any other
network interface using commands such as <B
CLASS="COMMAND"
>ifconfig</B
>.
In addition, if the Linux system is set up with hotplug support then
it may be possible to arrange for the network interface to become
active automatically. On a Red Hat Linux system this would require
files such as
<TT
CLASS="FILENAME"
>/etc/sysconfig/network-scripts/ifcfg-tap3</TT
>,
containing data like:
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>DEVICE="tap3"
BOOTPROTO="none"
BROADCAST=10.2.2.255
IPADDR="10.2.2.1"
NETMASK="255.255.255.0"
NETWORK=10.2.2.0
ONBOOT="no"</PRE
></TD
></TR
></TABLE
><P
>This gives the Linux interface the address <TT
CLASS="LITERAL"
>10.2.2.1</TT
>
on the network <TT
CLASS="LITERAL"
>10.2.2.0</TT
>. The eCos network device
should be configured with a compatible address. One way of doing this
would be to enable <CODE
CLASS="VARNAME"
>CYGHWR_NET_DRIVER_ETH0_ADDRS</CODE
>,
set <CODE
CLASS="VARNAME"
>CYGHWR_NET_DRIVER_ETH0_ADDRS_IP</CODE
> to
<TT
CLASS="LITERAL"
>10.2.2.2</TT
>, and similarly update the
<CODE
CLASS="VARNAME"
>NETMASK</CODE
>, <CODE
CLASS="VARNAME"
>BROADCAST</CODE
>,
<CODE
CLASS="VARNAME"
>GATEWAY</CODE
> and <CODE
CLASS="VARNAME"
>SERVER</CODE
> configuration
options.
</P
><P
>It should be noted that the ethertap facility provides a virtual
network, and any packets transmitted by the eCos application will
not appear on a real network. Therefore usually there will no
accessible DHCP server, and eCos cannot use DHCP or BOOTP to obtain IP
address information. Instead the eCos configuration should use manual
or static addresses.
</P
><P
>When <B
CLASS="COMMAND"
>rawether</B
> exits, the tap interface is removed
by the kernel. By adding the parameter persistent
<B
CLASS="COMMAND"
>rawether</B
> will set the persistent flag on the tap
device.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>synth_device ethernet {
eth0 ethertap tap3 00:01:02:03:FE:05
eth1 ethertap tap4 00:01:02:03:FE:06 persistent
…
}</PRE
></TD
></TR
></TABLE
><P
>With this flag set the kernel will not remove the interface when
<B
CLASS="COMMAND"
>rawether</B
> exits. This means applications such as
<B
CLASS="COMMAND"
>dhcpd</B
>, <B
CLASS="COMMAND"
>radvd</B
>, and
<B
CLASS="COMMAND"
>tcpdump</B
> will continue to run on the interface
between invocations of synthetic targets. As a result the target can
dynamically obtain its IP addresses from these daemons. Note it is a
good idea to specify a MAC address otherwise a different random MAC
address will be used each time and the dhcpd daemon will not be able
to reissue the same IP address.
</P
><P
>Host daemons like dhcpd, ntpd, radvd etc are started at boot
time. Since the tap device does not exists at this point in time it is
not possible for these daemons to bind to the tap device. A simple
solution is to use the program
<B
CLASS="COMMAND"
>install/bin/mktap</B
>. This takes one parameter, the
name of the tap device it should create. eg,
<TT
CLASS="LITERAL"
>tap3</TT
>.
</P
><P
>An alternative approach would be to set up the Linux box as a network
bridge, using commands like <B
CLASS="COMMAND"
>brctl</B
> to connect the
virtual network interface <CODE
CLASS="VARNAME"
>tap3</CODE
> to a physical
network interface such as <CODE
CLASS="VARNAME"
>eth0</CODE
>. Any packets sent by
the eCos application will get forwarded automatically to the real
network, and some packets on the real network will get forwarded over
the virtual network to the eCos application. Note that the eCos
application might also get some packets that were not intended for it,
but usually those will just be discarded by the eCos TCP/IP stack. The
exact details of setting up a network bridge are left as an exercise
to the reader.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="DEVS-ETH-ECOSYNTH-LOGGING"
></A
><H2
>Packet Logging</H2
><P
>The ethernet support comes with support for logging the various
packets that are transferred, including a simple protocol analyser.
This generates simple text output using the filter mechanisms provided
by the I/O auxiliary, so it is possible to control the appearance and
visibility of different types of output. For example the user might
want to see IPv4 headers and all ICMPv4 and ARP operations, but not
TCP headers or any of the packet data.
</P
><P
>The protocol analyser is not intended to be a fully functional
analyser with knowledge of many different TCP/IP protocols, advanced
search facilities, graphical traffic displays, and so on.
Functionality like that is already provided by other tools such as
<SPAN
CLASS="APPLICATION"
>ethereal</SPAN
> and
<SPAN
CLASS="APPLICATION"
>tcpdump</SPAN
>. Achieving similar levels of
functionality would require a lot of work, for very little gain. It is
still useful to have some protocol analysis functionality available
because the output will be interleaved with other output, for example
<TT
CLASS="FILENAME"
>printf</TT
> calls from the application. That may make
it easier to understand the sequence of events.
</P
><P
>One problem with logging ethernet traffic is that it can involve very
large amounts of data. If the application is expected to run for a
long time or is very I/O intensive then it is easy to end up with many
megabytes. When running in graphical mode all the logging data will be
held in memory, even data that is not currently visible. At some point
the system will begin to run low on memory and performance will
suffer. To avoid problems, the ethernet script maintains a flag that
controls whether or not packet logging is active. The default is to
run with logging disabled, but this can be changed in the target
definition file:
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>synth_device ethernet {
…
logging 1
}</PRE
></TD
></TR
></TABLE
><P
>The ethernet script will add a toolbar button that allows this flag to
be changed at run-time, allowing the user to capture traffic for
certain periods of time while the application continues running.
</P
><P
>The target definition file can contain the following entries for the
various packet logging filters:
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>synth_device ethernet {
…
filter ether -hide 0 -background LightBlue -foreground "#000080"
filter arp -hide 0 -background LightBlue -foreground "#000050"
filter ipv4 -hide 0 -background LightBlue -foreground "#000040"
filter ipv6 -hide 1 -background LightBlue -foreground "#000040"
filter icmpv4 -hide 0 -background LightBlue -foreground "#000070"
filter icmpv6 -hide 1 -background LightBlue -foreground "#000070"
filter udp -hide 0 -background LightBlue -foreground "#000030"
filter tcp -hide 0 -background LightBlue -foreground "#000020"
filter hexdata -hide 1 -background LightBlue -foreground "#000080"
filter asciidata -hide 1 -background LightBlue -foreground "#000080"
}</PRE
></TD
></TR
></TABLE
><P
>All output will show the eCos network device, for example
<TT
CLASS="LITERAL"
>eth0</TT
>, and the direction relative to the eCos
application. Some of the filters will show packet headers, for example
<TT
CLASS="LITERAL"
>ether</TT
> gives details of the ethernet packet header
and <TT
CLASS="LITERAL"
>tcp</TT
> gives information about TCP headers such as
whether or not the SYN flag is set. The TCP and UDP filters will also
show source and destination addresses, using numerical addresses and
if possible host names. However, host names will only be shown if the
host appears in <TT
CLASS="FILENAME"
>/etc/hosts</TT
>: doing full DNS
lookups while the data is being captured would add significantly to
complexity and overhead. The <TT
CLASS="LITERAL"
>hexdata</TT
> and
<TT
CLASS="LITERAL"
>asciidata</TT
> filters show the remainder of the packets
after the ethernet, IP and TCP or UDP headers have been stripped.
</P
><P
>Some of the filters will provide raw dumps of some of the packet data.
Showing up to 1500 bytes of data for each packet would be expensive,
and often the most interesting information is near the start of the
packet. Therefore it is possible to set a limit on the number of bytes
that will be shown using the target definition file. The default limit
is 64 bytes.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>synth_device ethernet {
…
max_show 128
}</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="DEVS-ETH-ECOSYNTH-GUI"
></A
><H2
>User Interface Additions</H2
><P
>When running in graphical mode the ethernet script extends the user
interface in two ways: a button is added to the toolbar so that users
can enable or disable packet logging; and an entry is added to the
<SPAN
CLASS="GUIMENU"
>Help</SPAN
> menu for the ethernet-specific documentation.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="DEVS-ETH-ECOSYNTH-ARGS"
></A
><H2
>Command Line Arguments</H2
><P
>The synthetic target ethernet support does not use any command line
arguments. All configuration is handled through the target definition
file.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="DEVS-ETH-ECOSYNTH-HOOKS"
></A
><H2
>Hooks</H2
><P
>The ethernet support defines two hooks that can be used by other
scripts, especially user scripts: <TT
CLASS="LITERAL"
>ethernet_tx</TT
> and
<TT
CLASS="LITERAL"
>ethernet_rx</TT
>. The tx hook is called whenever eCos
tries to transmit a packet. The rx hook is called whenever an incoming
packet is passed to the eCos application. Note that this may be a
little bit after the packet was actually received by the I/O auxiliary
since it can buffer some packets. Both hooks are called with two
arguments, the name of the network device and the packet being
transferred. Typical usage might look like:
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> proc my_tx_hook { arg_list } {
set dev [lindex $arg_list 0]
incr ::my_ethernet_tx_packets($dev)
incr ::my_ethernet_tx_bytes($dev) [string length [lindex $arg_list 1]]
}
proc my_rx_hook { arg_list } {
set dev [lindex $arg_list 0]
incr ::my_ethernet_rx_packets($dev)
incr ::my_ethernet_rx_bytes($dev) [string length [lindex $arg_list 1]]
}
synth::hook_add "ethernet_tx" my_tx_hook
synth::hook_add "ethernet_rx" my_rx_hook</PRE
></TD
></TR
></TABLE
><P
>The global arrays <CODE
CLASS="VARNAME"
>my_ethernet_tx_packets</CODE
> etc. will
now be updated whenever there is ethernet traffic. Other code,
probably running at regular intervals by use of the Tcl
<B
CLASS="COMMAND"
>after</B
> procedure, can then use this information to
update a graphical monitor of some sort.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="DEVS-ETH-ECOSYNTH-TCL"
></A
><H2
>Additional Tcl Procedures</H2
><P
>The ethernet support provides one additional Tcl procedure that can be
used by other scripts;
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ethernet::devices_get_list </PRE
></TD
></TR
></TABLE
><P
>This procedure returns a list of the ethernet devices that have been
instantiated, for example <TT
CLASS="LITERAL"
>{eth0 eth1}</TT
>.
</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="devs-eth-synth-ecosynth-ref.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="devs-eth-m68k-mcfxxxx-part.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Synthetic Target Ethernet Driver</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="devs-eth-synth-ecosynth-ref.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Freescale ColdFire Ethernet Driver</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -