|
| 1 | +## Mission: Run Tor in a Box |
| 2 | + |
| 3 | +| ❗ Notice | |
| 4 | +|--------------------------------------------------------------------------------------------------------------| |
| 5 | +| This overview describes Shadow's original<br>architecture (version 1.x) and not the current<br>architecture. | |
| 6 | + |
| 7 | +<br> |
| 8 | + |
| 9 | +<!--[[https://raw.githubusercontent.com/wiki/shadow/shadow/assets/torinabox.png|align=right|width=175px]]--> |
| 10 | +<!--[Run Tor in a box with Shadow!][image-torinabox]--> |
| 11 | +<!--[image-torinabox]: https://raw.githubusercontent.com/wiki/shadow/shadow/assets/torinabox.png--> |
| 12 | + |
| 13 | +<a href="https://raw.githubusercontent.com/wiki/shadow/shadow/assets/torinabox.png"><img align="right" width="225" alt="Run Tor in a box with Shadow!" src="https://raw.githubusercontent.com/wiki/shadow/shadow/assets/torinabox.png"></a> |
| 14 | + |
| 15 | +Shadow was developed because there was a recognized need for an accurate, |
| 16 | +efficient, and scalable tool for Tor experimentation: using the PlanetLab |
| 17 | +platform is undesirable due to management overhead and lack of control; existing |
| 18 | +emulators are far too inefficient when scaling to thousands of virtual hosts; |
| 19 | +roll-your-own simulators are often too inaccurate or generic to be useful for |
| 20 | +multiple projects; and experiments on the live Tor network are often infeasible |
| 21 | +due to privacy risks. |
| 22 | + |
| 23 | +Our goal was to provide a tool that can be used by anyone with a Linux machine |
| 24 | +or access to EC2 to hasten the development of research prototypes and reduce the |
| 25 | +time to deployment. Although originally written with Tor experimentation in |
| 26 | +mind, Shadow can also run Bitcoin and is useful for researching or prototyping |
| 27 | +other distributed or peer-to-peer systems including multi-party computation |
| 28 | +protocols. |
| 29 | + |
| 30 | +## Feature Overview |
| 31 | + |
| 32 | +Shadow does the following: |
| 33 | + |
| 34 | + + creates an isolated simulation environment where virtual hosts may |
| 35 | + communicate with each other but not with the Internet |
| 36 | + + natively executes **real applications** like Tor and Bitcoin |
| 37 | + + provides efficient, accurate, and **controlled** experiments |
| 38 | + + models network topology, latency, and bandwidth |
| 39 | + + runs without root on a single Linux machine |
| 40 | + + simulates multiple virtual hosts in virtual time |
| 41 | + + simulates the network (TCP stack) and CPU processing delays |
| 42 | + + can run private Tor networks with user/traffic models based on [Tor |
| 43 | + metrics][tormetrics] |
| 44 | + + much, much more! |
| 45 | + |
| 46 | +## Real Applications as Shadow Plug-ins |
| 47 | + |
| 48 | +Shadow is a discrete-event simulator that runs **real applications** like |
| 49 | +[Tor][tor] . Shadow links to real application software and **natively executes |
| 50 | +the application code** during simulation, providing faithful experiments and |
| 51 | +accurate results. Shadow models and runs distributed networks using these |
| 52 | +applications on a single Linux machine, easing experiment management while |
| 53 | +keeping the focus on the results. |
| 54 | + |
| 55 | +#### What are Plug-ins? |
| 56 | + |
| 57 | +Plug-ins are shared library shims that are linked to real applications. Shadow |
| 58 | +dynamically loads these libraries to natively execute the application code. |
| 59 | +Shadow intercepts a selective set of system calls to enable seamless integration |
| 60 | +of an application to the simulated environment. In this way, the application may |
| 61 | +be unaware that it is running in the simulator and will function as if it was |
| 62 | +running in a standard UNIX environment. |
| 63 | + |
| 64 | +Visit [this page on the wiki][wiki-custom-plugin] for more information about how |
| 65 | +to write your own custom Shadow plug-in. |
| 66 | + |
| 67 | +#### What is shadow-plugin-tor? |
| 68 | + |
| 69 | +shadow-plugin-tor is a Shadow plug-in for simulating the [Tor][tor] anonymity |
| 70 | +network. shadow-plugin-tor integrates Tor into Shadow by wrapping the [Tor |
| 71 | +source code][torsource] with the necessary hooks that allow it to communicate |
| 72 | +with the Shadow simulator, thereby leveraging Shadow's unique functionality to |
| 73 | +allow rapid prototyping and experimentation of Tor. shadow-plugin-tor also |
| 74 | +contains scripts that assist in analyzing results, generating Tor topologies, |
| 75 | +and running experiments using the generated topologies. |
| 76 | + |
| 77 | +Visit [the shadow-plugin-tor wiki page][wiki-scallion] for more information on |
| 78 | +the Tor plug-in and its memory requirements. |
| 79 | + |
| 80 | +## Simulation Blueprint |
| 81 | + |
| 82 | +The first step to using Shadow is to create a blueprint of an experiment. The |
| 83 | +format of the blueprint is standard XML. The XML file tells Shadow when it |
| 84 | +should create each virtual host, what software each virtual host should run. It |
| 85 | +also specifies the structure of the network topology, and network properties |
| 86 | +such as link latency, jitter, and packet loss rates. Shadow contains example XML |
| 87 | +files to help get started! |
| 88 | + |
| 89 | +<a href="https://raw.githubusercontent.com/wiki/shadow/shadow/assets/design1.png"><img title="design1" src="https://raw.githubusercontent.com/wiki/shadow/shadow/assets/design1.png" alt="" width="520" /></a> |
| 90 | + |
| 91 | +_Shadow takes a simulation blueprint as input. This XML file specifies the |
| 92 | +structure of the topology and the general flow of the experiment. Shadow's event |
| 93 | +engine initializes hosts using the blueprint, and runs events on their behalf |
| 94 | +until the simulation is complete._ |
| 95 | + |
| 96 | +## Discrete Time Events |
| 97 | + |
| 98 | +Shadow creates several bootstrapping events after extracting the information |
| 99 | +from the supplied XML blueprint file. Each of these events are executed at a |
| 100 | +discrete time instant during the experiment. Each of these bootstrapping events |
| 101 | +will cause the virtual hosts to start executing the specified software, which in |
| 102 | +turn will spawn additional events for Shadow to process. Shadow tracks the time |
| 103 | +each virtual host spends processing inside the application, and delays events |
| 104 | +according to the host's configured virtual CPU speed. Events are continuously |
| 105 | +executed until the simulation end time. |
| 106 | + |
| 107 | +As applications send data to each other, Shadow packages that data into an |
| 108 | +internal type and transfers the pointer between various queues. This process |
| 109 | +involves the use of the main Shadow event queue to transfer the packet events |
| 110 | +between virtual hosts, and rate-limiting to ensure each host has the desired |
| 111 | +bandwidth capacity. The following image, courtesy of Steven Murdoch, may help |
| 112 | +visualize this process: |
| 113 | + |
| 114 | +<a href="https://raw.githubusercontent.com/wiki/shadow/shadow/assets/shadow_packet_flow.pdf"><img title="shadow_packet_flow" src="https://raw.githubusercontent.com/wiki/shadow/shadow/assets/shadow_packet_flow.png" alt="" width="520" /></a> |
| 115 | + |
| 116 | +_End-to-end application data flows through Shadow socket and interface buffers, |
| 117 | +while the discrete event queue facilitates the transfer of data between virtual |
| 118 | +hosts._ |
| 119 | + |
| 120 | +## Virtual Host Management |
| 121 | + |
| 122 | +Each virtual host in Shadow runs real software, which are linked as Shadow |
| 123 | +plug-ins. For each instance of the plug-in that a host is configured to run, |
| 124 | +Shadow loads the plug-in into a private namespace container using a custom |
| 125 | +loader and `dlmopen()`. The loader takes care to minimize duplicated memory |
| 126 | +usage on multiple loads of the same plug-in. |
| 127 | + |
| 128 | +With the virtual host's plug-in loaded, execution is then passed to the |
| 129 | +application by calling the `main()` function using a version of [GNU portable |
| 130 | +threads (pth)][gnu-pth]. Pth is an application-space non-preemptive |
| 131 | +priority-based threading library that can jump call stacks to support plug-ins |
| 132 | +that run multiple threads and block during execution. Shadow runs the plug-in |
| 133 | +instance until it would block, and then moves on to execute other plug-ins and |
| 134 | +hosts. |
| 135 | + |
| 136 | +## Function Interposition |
| 137 | + |
| 138 | +Shadow runs real applications that run on regular UNIX-type systems. These |
| 139 | +applications expect a wide range of kernel libraries to be available for use. |
| 140 | +For example, sending and receiving data over the network, system time, and |
| 141 | +device polling are all generally handled by the kernel at some level. These |
| 142 | +system functions (and others) are intercepted and redirected through |
| 143 | +Shadow-specific versions. In this way, Shadow provides the ability for hosts to |
| 144 | +seamlessly communicate with each other over the virtual network without |
| 145 | +requiring any changes to the application code. |
| 146 | + |
| 147 | +## More information |
| 148 | + |
| 149 | +See [the original Shadow webcast][youtube-shadow-design] for more information |
| 150 | +about Shadow's original design, and for an explanation of some experiments that |
| 151 | +utilize this unique architecture. An explanation of recent architecture updates |
| 152 | +to support blocking system calls (read/write/send/recv/sleep) and applications |
| 153 | +that spawn threads [can be found here][cset-rpth-slides]. Checkout [Google |
| 154 | +Scholar](https://scholar.google.com/scholar?oi=bibs&hl=en&cites=12341442653770148265) |
| 155 | +for research publications that cite Shadow. |
| 156 | + |
| 157 | +<!--<iframe width="420" height="315" src="http://www.youtube-nocookie.com/embed/Tb7m8OdpD8A" frameborder="0" allowfullscreen></iframe>--> |
| 158 | + |
| 159 | +[tor]: https://www.torproject.org/ |
| 160 | +[tormetrics]: https://metrics.torproject.org/ |
| 161 | +[torsource]: https://gitweb.torproject.org/tor.git |
| 162 | +[wiki-scallion]: https://github.com/shadow/shadow-plugin-tor/wiki |
| 163 | +[wiki-custom-plugin]: https://github.com/shadow/shadow/wiki/2-Simulation-Execution-and-Analysis#shadow-plug-ins |
| 164 | +[youtube-shadow-design]: http://youtu.be/Tb7m8OdpD8A |
| 165 | +[cset-rpth-slides]: http://www.robgjansen.com/talks/shadowbitcoin-cset-20150810.pdf |
| 166 | +[gnu-pth]: https://www.gnu.org/software/pth/ |
0 commit comments