syntheth.sgml

来自「eCos操作系统源码」· SGML 代码 · 共 554 行 · 第 1/2 页

SGML
554
字号
    <para>The user now knows exactly which eCos device is mapped onto whichLinux device, avoiding much potential confusion. Because the virtualdevices are emulated ethernet devices, they require MAC addresses.There is no physical hardware to provide these addresses, so normallyMAC addresses will be invented. That means that each time the eCosapplication is run it will have different MAC addresses, which makesit more difficult to compare the results of different runs. To getmore deterministic behaviour it is possible to specify the MACaddresses in the target definition file:    </para>    <programlisting>synth_device ethernet {    eth0 ethertap tap3 00:01:02:03:FE:05    eth1 ethertap tap4 00:01:02:03:FE:06    &hellip;}</programlisting>    <para>During the initialization phase the eCos application will instantiatethe various network devices. This will cause the I/O auxiliary to loadthe <filename>ethernet.tcl</filename> script and spawn<command>rawether</command> processes, which in turn will<function>open</function> <filename>/dev/net/tun</filename> andperform the appropriate <filename>ioctl</filename> calls. On the Linuxside there will now be new network interfaces such as<varname>tap3</varname>, and these can be configured like any othernetwork interface using commands such as <command>ifconfig</command>.In addition, if the Linux system is set up with hotplug support thenit may be possible to arrange for the network interface to becomeactive automatically. On a Red Hat Linux system this would requirefiles such as<filename>/etc/sysconfig/network-scripts/ifcfg-tap3</filename>,containing data like:    </para>    <programlisting>DEVICE="tap3"BOOTPROTO="none"BROADCAST=10.2.2.255IPADDR="10.2.2.1"NETMASK="255.255.255.0"NETWORK=10.2.2.0ONBOOT="no"</programlisting>    <para>This gives the Linux interface the address <literal>10.2.2.1</literal>on the network <literal>10.2.2.0</literal>. The eCos network deviceshould be configured with a compatible address. One way of doing thiswould be to enable <varname>CYGHWR_NET_DRIVER_ETH0_ADDRS</varname>,set <varname>CYGHWR_NET_DRIVER_ETH0_ADDRS_IP</varname> to<literal>10.2.2.2</literal>, and similarly update the<varname>NETMASK</varname>, <varname>BROADCAST</varname>,<varname>GATEWAY</varname> and <varname>SERVER</varname> configurationoptions.     </para>    <para>It should be noted that the ethertap facility provides a virtualnetwork, and any packets transmitted by the eCos application willnot appear on a real network. Therefore usually there will noaccessible DHCP server, and eCos cannot use DHCP or BOOTP to obtain IPaddress information. Instead the eCos configuration should use manualor static addresses.    </para>    <para>When <command>rawether</command> exits, the tap interface is removedby the kernel. By adding the parameter persistent<command>rawether</command> will set the persistent flag on the tapdevice.    </para>    <programlisting>synth_device ethernet {    eth0 ethertap tap3 00:01:02:03:FE:05    eth1 ethertap tap4 00:01:02:03:FE:06 persistent    &hellip;}</programlisting>    <para>With this flag set the kernel will not remove the interface when<command>rawether</command> exits. This means applications such as<command>dhcpd</command>, <command>radvd</command>, and<command>tcpdump</command> will continue to run on the interfacebetween invocations of synthetic targets. As a result the target candynamically obtain its IP addresses from these daemons. Note it is agood idea to specify a MAC address otherwise a different random MACaddress will be used each time and the dhcpd daemon will not be ableto reissue the same IP address.    </para>    <para>Host daemons like dhcpd, ntpd, radvd etc are started at boottime. Since the tap device does not exists at this point in time it isnot possible for these daemons to bind to the tap device. A simplesolution is to use the program<command>install/bin/mktap</command>. This takes one parameter, thename of the tap device it should create. eg,<literal>tap3</literal>.     </para>    <para>An alternative approach would be to set up the Linux box as a networkbridge, using commands like <command>brctl</command> to connect thevirtual network interface <varname>tap3</varname> to a physicalnetwork interface such as <varname>eth0</varname>. Any packets sent bythe eCos application will get forwarded automatically to the realnetwork, and some packets on the real network will get forwarded overthe virtual network to the eCos application. Note that the eCosapplication might also get some packets that were not intended for it,but usually those will just be discarded by the eCos TCP/IP stack. Theexact details of setting up a network bridge are left as an exerciseto the reader.    </para>  </refsect1>  <refsect1 id="devs-eth-ecosynth-logging"><title>Packet Logging</title>    <para>The ethernet support comes with support for logging the variouspackets that are transferred, including a simple protocol analyser.This generates simple text output using the filter mechanisms providedby the I/O auxiliary, so it is possible to control the appearance andvisibility of different types of output. For example the user mightwant to see IPv4 headers and all ICMPv4 and ARP operations, but notTCP headers or any of the packet data.    </para>    <para>The protocol analyser is not intended to be a fully functionalanalyser with knowledge of many different TCP/IP protocols, advancedsearch facilities, graphical traffic displays, and so on.Functionality like that is already provided by other tools such as<application>ethereal</application> and<application>tcpdump</application>. Achieving similar levels offunctionality would require a lot of work, for very little gain. It isstill useful to have some protocol analysis functionality availablebecause the output will be interleaved with other output, for example<filename>printf</filename> calls from the application. That may makeit easier to understand the sequence of events.    </para>    <para>One problem with logging ethernet traffic is that it can involve verylarge amounts of data. If the application is expected to run for along time or is very I/O intensive then it is easy to end up with manymegabytes. When running in graphical mode all the logging data will beheld in memory, even data that is not currently visible. At some pointthe system will begin to run low on memory and performance willsuffer. To avoid problems, the ethernet script maintains a flag thatcontrols whether or not packet logging is active. The default is torun with logging disabled, but this can be changed in the targetdefinition file:    </para>    <programlisting>synth_device ethernet {    &hellip;    logging 1}</programlisting>    <para>The ethernet script will add a toolbar button that allows this flag tobe changed at run-time, allowing the user to capture traffic forcertain periods of time while the application continues running.    </para>    <para>The target definition file can contain the following entries for thevarious packet logging filters:    </para>    <programlisting width=72>synth_device ethernet {    &hellip;    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"}</programlisting>    <para>All output will show the eCos network device, for example<literal>eth0</literal>, and the direction relative to the eCosapplication. Some of the filters will show packet headers, for example<literal>ether</literal> gives details of the ethernet packet headerand <literal>tcp</literal> gives information about TCP headers such aswhether or not the SYN flag is set. The TCP and UDP filters will alsoshow source and destination addresses, using numerical addresses andif possible host names. However, host names will only be shown if thehost appears in <filename>/etc/hosts</filename>: doing full DNSlookups while the data is being captured would add significantly tocomplexity and overhead. The <literal>hexdata</literal> and<literal>asciidata</literal> filters show the remainder of the packetsafter the ethernet, IP and TCP or UDP headers have been stripped.    </para>    <para>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 thepacket. Therefore it is possible to set a limit on the number of bytesthat will be shown using the target definition file. The default limitis 64 bytes.    </para>    <programlisting width=72>synth_device ethernet {    &hellip;    max_show 128}</programlisting>  </refsect1>  <refsect1 id="devs-eth-ecosynth-gui"><title>User Interface Additions</title>    <para>When running in graphical mode the ethernet script extends the userinterface in two ways: a button is added to the toolbar so that userscan enable or disable packet logging; and an entry is added to the<guimenu>Help</guimenu> menu for the ethernet-specific documentation.    </para>  </refsect1>  <refsect1 id="devs-eth-ecosynth-args"><title>Command Line Arguments</title>    <para>The synthetic target ethernet support does not use any command linearguments. All configuration is handled through the target definitionfile.     </para>  </refsect1>  <refsect1 id="devs-eth-ecosynth-hooks"><title>Hooks</title>    <para>The ethernet support defines two hooks that can be used by otherscripts, especially user scripts: <literal>ethernet_tx</literal> and<literal>ethernet_rx</literal>. The tx hook is called whenever eCostries to transmit a packet. The rx hook is called whenever an incomingpacket is passed to the eCos application. Note that this may be alittle bit after the packet was actually received by the I/O auxiliarysince it can buffer some packets. Both hooks are called with twoarguments, the name of the network device and the packet beingtransferred. Typical usage might look like:    </para>    <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</programlisting>    <para>The global arrays <varname>my_ethernet_tx_packets</varname> etc. willnow be updated whenever there is ethernet traffic. Other code,probably running at regular intervals by use of the Tcl<command>after</command> procedure, can then use this information toupdate a graphical monitor of some sort.    </para>    </refsect1>  <refsect1 id="devs-eth-ecosynth-tcl"><title>Additional Tcl Procedures</title>    <para>The ethernet support provides one additional Tcl procedure that can beused by other scripts;    </para>    <programlisting>ethernet::devices_get_list    </programlisting>    <para>This procedure returns a list of the ethernet devices that have beeninstantiated, for example <literal>{eth0 eth1}</literal>.    </para>  </refsect1></refentry></part><!-- /reference -->

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?