There are several situations when it is necessary and/or useful to let the simulated target machine interact with the host system, or even other systems accessible to the host via networking. Probably the most common situation is the need to transfer files between the target and the host.
This section will describe a few ways of transferring data between the simulation and the real world:
File transfer can be done in several ways. The preferred method is to use the Simics Agent, which is piece of software that must be present on the target machine. The Clear Linux distribution for the QSP-x86
machine has the agent pre-installed. If the agent is not present, it must be transferred to the target machine using one of the methods described later. The Simics Agent is preferred since it is the fastest and least intrusive method.
The Simics Agent manager is a single global manager in Simics, used to manage all connections to all agents on all targets. When a connection is set up to a specific agent on a target, a Simics Agent handle is created. The handle is used to do actual operations. There can be multiple handles in use at once, connected to different agents.
Here is an example of using the Simics Agent for transferring files, when running the
%simics%/targets/qsp-x86/firststeps.simics
target.
$ bin/simics targets/qsp-x86/firststeps.simics
simics> $m = (start-agent-manager name = mgr0)
simics@cl-qsp ~ $ simics-agent qsp &
qsp connected (1b90f02e10d5a84c)
simics> $m.connect-to-agent name = agent0 identifier = qsp
agent0 connected to qsp0 (0x1b90f02e10d5a84c)
The agent0
object is the new agent handle.
simics> agent0.upload from = "%simics%/targets/qsp-x86/firststeps.simics" to = /tmp
agent0:job 1 (upload firststeps.simics)
simics> agent0.run-until-job 1
agent0:job 1 (upload firststeps.simics) finished
simics> agent0.download -overwrite from = "/tmp/firststeps.simics" to = /tmp
agent0:job 2 (download firststeps.simics)
simics> agent0.run-until-job 2
agent0:job 2 (download firststeps.simics) finished
Note that the agent operations are necessarily asynchronous, which is why we must wait for them to finish. However, there is no need to wait after each command; several commands can be queued up before a wait is issued.
The Simics Agent can also perform other operations, such as
There are other methods for transferring data in and out of the simulation. If the Simics Agent is not already present on the target machine, one of them must be used first to copy the agent software.
Here is an example of transferring the Simics Agent to the target using USB, when running the
%simics%/targets/qsp-x86/firststeps.simics
target machine.
$ bin/simics targets/qsp-x86/firststeps.simics
Boot the target machine, log in as simics.
Create and connect a virtual USB disk using the Simics Agent disk images provided with Simics.
simics> $usb_img = "%simics%/targets/common/images/simics_agent_binaries.img"
simics> $usb_disk = (new-usb-disk-comp file = $usb_img name = usb_disk)
simics> $usb_disk.connect-to $system
Connecting usb_disk.usb_host to board.mb.sb.usb_port[10]
simics@cl-qsp ~ $ sudo mount /dev/sdc1 /media
simics@cl-qsp ~ $ find /media -name simics_agent_x86_linux64
/media/simics_agent_x86_linux64
simics@cl-qsp ~ $ cp /media/simics_agent_x86_linux64 .
simics@cl-qsp ~ $ ./simics_agent_x86_linux64 qsp &
Here is another example of transferring the Simics Agent to the target using a second hard disk, when running the
%simics%/targets/qsp-x86/firststeps.simics
target machine. This machine is already set up to allow easy addition of an extra disk, using the disk1_image
parameter.
$ bin/simics targets/qsp-x86/firststeps.simics disk1_image=targets/common/images/simics_agent_binaries.img
simics@cl-qsp ~ $ sudo mount /dev/sdb1 /media
simics@cl-qsp ~ $ find /media -name simics_agent_x86_linux64
/media/simics_agent_x86_linux64
simics@cl-qsp ~ $ cp /media/simics_agent_x86_linux64 .
simics@cl-qsp ~ $ ./simics_agent_x86_linux64 qsp &
Simics is a full system simulator, which can also simulate a network of machines. It includes a feature called the service node which acts like a separate machine on the simulated network, with its own IP address. The service node can expose common useful network services, such as DHCP, DNS, NTP as well as an FTP server that facilitates connecting to the host system and transfer files.
The Clear Linux distribution for the QSP-x86
machine uses the service node DHCP and DNS servers during boot, to set up its network services.
Here is an example of transferring the Simics Agent to the target machine over FTP, when running the
%simics%/targets/qsp-x86/firststeps.simics
target machine.
$ bin/simics targets/qsp-x86/firststeps.simics
Boot the target machine, log in as simics.
Notice that the service node and the target machine is set up in the service node DNS. The IP and MAC addresses are internal to the simulated network.
simics> $service_node.sn.list-host-info
┌───────────┬───────────────────┬─────────────────┐
│ IP │ name.domain │ MAC │
├───────────┼───────────────────┼─────────────────┤
│10.10.0.1 │simics0.network.sim│20:20:20:20:20:00│
│10.10.0.100│board.network.sim │00:17:a0:00:00:00│
└───────────┴───────────────────┴─────────────────┘
simics@cl-qsp ~ $ host simics0
simics0.network.sim has address 10.10.0.1
simics> $img_dir = "%simics%/targets/common/images"
simics> $service_node.set-ftp-directory dir = $img_dir
simics@cl-qsp ~ $ lftpget ftp://simics0/simics_agent_binaries.zip
simics@cl-qsp ~ $ unzip -q simics_agent_binaries.zip
simics@cl-qsp ~ $ ./simics_agent_x86_linux64 qsp &
Simics can let the target machine connect to any network that the host system has access to. This can be achieved in several ways, where NAPT is the simplest option. Simics then acts similarly like a regular home router, performing network address translation between the simulated network and the network that the host is connected to. The service node DNS server can also act as a proxy for real DNS.
The Clear Linux distribution for the QSP-x86
machine is set up to allow such usage.
Here is an example of transferring data from the host to the target using regular networking, when running the
%simics%/targets/qsp-x86/firststeps.simics
target machine.
$ bin/simics targets/qsp-x86/firststeps.simics
Boot the target machine, log in as simics.
Enable real time mode, to avoid network timeouts. This makes sure that Simics will not run the simulation faster than real time.
simics> enable-real-time-mode
Real-time mode enabled.
shell
command from within Simics.simics> $python = (lookup-file "%simics%/bin/mini-python")
simics> $imgs = (lookup-file "%simics%/targets/common/images")
simics> shell -bg ($python + " -m http.server --directory " + $imgs)
simics> $service_node.sn.add-host name = "host0" ip = (sim->host_ipv4)
simics@cl-qsp ~ $ curl -s http://host0:8000/simics_agent_binaries.zip
simics@cl-qsp ~ $ ls simics_agent_binaries.zip
simics_agent_binaries.zip
In this example we only connected to the host itself, but in fact the same technique can be used to connect to any other system that the host can access. Also note that the HTTP server we open on the host will be accessible by any web browser.
Using port forwarding, the target can also be accessed from the host, and potentially from any system that can access the host, so this should be used with care. Here is an example of transferring a file to the target from the host over ssh, when running the
%simics%/targets/qsp-x86/firststeps.simics
target machine. This assumes that the host has ssh installed.
Install ssh on your host, if not already present.
Start Simics with the mentioned target.
$ bin/simics targets/qsp-x86/firststeps.simics
simics> $service_node.sn.list-host-info
┌───────────┬───────────────────┬─────────────────┐
│ IP │ name.domain │ MAC │
├───────────┼───────────────────┼─────────────────┤
│10.10.0.1 │simics0.network.sim│20:20:20:20:20:00│
│10.10.0.100│board.network.sim │00:17:a0:00:00:00│
└───────────┴───────────────────┴─────────────────┘
simics> connect-real-network target-ip = 10.10.0.100
NAPT already enabled.
Host TCP port 4021 -> 10.10.0.100:21
Host TCP port 4022 -> 10.10.0.100:22
Host TCP port 4023 -> 10.10.0.100:23
Host TCP port 4080 -> 10.10.0.100:80
Warning: This can expose the target system on the host local network.
Boot the target machine, log in as simics.
Enable real time mode, to avoid network timeouts.
simics> enable-real-time-mode
Real-time mode enabled.
simics> $fn = (lookup-file "%simics%/targets/common/images/simics_agent_binaries.zip")
simics> shell -bg "scp -P 4022 " + $fn + " simics@localhost:agent.zip"
simics@cl-qsp ~ $ ls agent.zip
agent.zip
In this example we only copied a file, but using port forwarding, we can connect to other network service available on the target, such as web servers.