📄 devs-eth-synth-ecosynth.html
字号:
network interface. Usually this will be <TTCLASS="VARNAME">tap0</TT> but ifother software is using the ethertap facility, for example toimplement a VPN, then a different number may be allocated. Usually itwill be better to specify the particular tap device that should beused for each eCos device, for example: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet { eth0 ethertap tap3 eth1 ethertap tap4 …}</PRE></TD></TR></TABLE><P>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: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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 instantiatethe various network devices. This will cause the I/O auxiliary to loadthe <TTCLASS="FILENAME">ethernet.tcl</TT> script and spawn<BCLASS="COMMAND">rawether</B> processes, which in turn will<TTCLASS="FUNCTION">open</TT> <TTCLASS="FILENAME">/dev/net/tun</TT> andperform the appropriate <TTCLASS="FILENAME">ioctl</TT> calls. On the Linuxside there will now be new network interfaces such as<TTCLASS="VARNAME">tap3</TT>, and these can be configured like any othernetwork interface using commands such as <BCLASS="COMMAND">ifconfig</B>.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<TTCLASS="FILENAME">/etc/sysconfig/network-scripts/ifcfg-tap3</TT>,containing data like: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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"</PRE></TD></TR></TABLE><P>This gives the Linux interface the address <TTCLASS="LITERAL">10.2.2.1</TT>on the network <TTCLASS="LITERAL">10.2.2.0</TT>. The eCos network deviceshould be configured with a compatible address. One way of doing thiswould be to enable <TTCLASS="VARNAME">CYGHWR_NET_DRIVER_ETH0_ADDRS</TT>,set <TTCLASS="VARNAME">CYGHWR_NET_DRIVER_ETH0_ADDRS_IP</TT> to<TTCLASS="LITERAL">10.2.2.2</TT>, and similarly update the<TTCLASS="VARNAME">NETMASK</TT>, <TTCLASS="VARNAME">BROADCAST</TT>,<TTCLASS="VARNAME">GATEWAY</TT> and <TTCLASS="VARNAME">SERVER</TT> configurationoptions. </P><P>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. </P><P>An alternative approach would be to set up the Linux box as a networkbridge, using commands like <BCLASS="COMMAND">brctl</B> to connect thevirtual network interface <TTCLASS="VARNAME">tap3</TT> to a physicalnetwork interface such as <TTCLASS="VARNAME">eth0</TT>. 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. </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-LOGGING"></A><H2>Packet Logging</H2><P>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. </P><P>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<SPANCLASS="APPLICATION">ethereal</SPAN> and<SPANCLASS="APPLICATION">tcpdump</SPAN>. 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<TTCLASS="FILENAME">printf</TT> calls from the application. That may makeit easier to understand the sequence of events. </P><P>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: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet { … logging 1}</PRE></TD></TR></TABLE><P>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. </P><P>The target definition file can contain the following entries for thevarious packet logging filters: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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<TTCLASS="LITERAL">eth0</TT>, and the direction relative to the eCosapplication. Some of the filters will show packet headers, for example<TTCLASS="LITERAL">ether</TT> gives details of the ethernet packet headerand <TTCLASS="LITERAL">tcp</TT> 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 <TTCLASS="FILENAME">/etc/hosts</TT>: doing full DNSlookups while the data is being captured would add significantly tocomplexity and overhead. The <TTCLASS="LITERAL">hexdata</TT> and<TTCLASS="LITERAL">asciidata</TT> filters show the remainder of the packetsafter 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 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. </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet { … max_show 128}</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-GUI"></A><H2>User Interface Additions</H2><P>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<SPANCLASS="GUIMENU">Help</SPAN> menu for the ethernet-specific documentation. </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-ARGS"></A><H2>Command Line Arguments</H2><P>The synthetic target ethernet support does not use any command linearguments. All configuration is handled through the target definitionfile. </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-HOOKS"></A><H2>Hooks</H2><P>The ethernet support defines two hooks that can be used by otherscripts, especially user scripts: <TTCLASS="LITERAL">ethernet_tx</TT> and<TTCLASS="LITERAL">ethernet_rx</TT>. 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: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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 <TTCLASS="VARNAME">my_ethernet_tx_packets</TT> etc. willnow be updated whenever there is ethernet traffic. Other code,probably running at regular intervals by use of the Tcl<BCLASS="COMMAND">after</B> procedure, can then use this information toupdate a graphical monitor of some sort. </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-TCL"></A><H2>Additional Tcl Procedures</H2><P>The ethernet support provides one additional Tcl procedure that can beused by other scripts; </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">ethernet::devices_get_list </PRE></TD></TR></TABLE><P>This procedure returns a list of the ethernet devices that have beeninstantiated, for example <TTCLASS="LITERAL">{eth0 eth1}</TT>. </P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="devs-eth-synth-ecosynth-ref.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="devs-watchdog-synth-ref.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Synthetic Target Ethernet Driver</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="devs-eth-synth-ecosynth-ref.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Synthetic Target Watchdog Device</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -