Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
README.md | D | 06-Sep-2024 | 6.4 KiB | 242 | 180 |
README.md
1# Network Simulator Development 2 3This section walks you through building netsim from source. 4 5Netsim can be built as part of emulator or cuttlefish and best practice is to 6setup both and switch between repo directories to test each build environment. 7 8* To build with emulator, follow the [netsim with emulator](#netsim_with_emulator) 9section to build netsim by `cmake` in `emu-master-dev` manifest branch. 10 11* To build with cuttlefish, follow the [netsim with 12cuttlefish](#netsim_with_cuttlefish) to build netsim by `soong` in `aosp-master` 13manifest branch. 14 15## Emulator and cuttlefish build branches 16 17The *netsim* network simulator is built as a component of 18[emulator](https://source.android.com/docs/setup/create/avd) 19and 20[cuttlefish](https://source.android.com/docs/setup/create/cuttlefish) 21virtual devices. 22 23*Emulator* allows you to run emulations of Android devices on Windows, macOS or 24Linux machines. Emulator runs the Android operating system in a virtual machine 25called an Android Virtual Device (AVD). 26The emulator is typically used from 27[Android Studio](https://developer.android.com/studio). 28 29*Cuttlefish* is a configurable virtual Android device that can be run on Linux 30x86 machines both remotely (using third-party cloud offerings such as Google 31Cloud Engine) and locally. Cuttlefish runs the Android operating system in a 32virtual machine called a Cuttlefish Virtual Device (CVD). 33Cuttlefish is typically used by developers working with AOSP code to [launch 34AOSP builds](https://source.android.com/docs/setup/create/cuttlefish-use). 35 36The table below summarizes the two virtual device environments: 37 38| | emulator | cuttlefish | 39|:----------------|:---------------------:|:----------------: | 40| AOSP branch | `emu-master-dev` | `aosp-master` | 41| launcher | `emulator` app and<br>Android Studio | `launch_cvd` and<br>`cvd` app | 42| best for | App developer | Platform developer | 43| Supported OS | Linux, MacOS, Windows | Linux | 44| Build system | CMake (CMakeLists.txt) | Soong (Android.bp) | 45| Virtual device | AVD | CVD | 46 47Netsim is the default networking backplane for AVD and CVD emulated Android 48devices. 49 50## <a name="netsim_with_emulator"></a>Build netsim with emulator 51 52For developing netsim alongside emulator, start with the OS specific build 53instructions: 54* [Android emulator Windows Development]( 55https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android/docs/WINDOWS-DEV.md 56) 57* [Android emulator MacOS Development]( 58https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android/docs/DARWIN-DEV.md 59) 60* [Android emulator Linux Development]( 61https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android/docs/LINUX-DEV.md 62) 63 64In general changes should be built and tested on all three operating systems. 65 66Follow the instructions above links for workstation setup. Linux setup and build 67is summarized below: 68 69### Linux workstation set up 70 71Install cmake and ninja: 72 73``` 74sudo apt-get install -y cmake ninja-build 75``` 76 77### Initialize and sync the code 78 79Download the emu-master-dev branch: 80 81``` 82mkdir /repo/emu-master-dev; cd /repo/emu-master-dev 83repo init -u https://android.googlesource.com/platform/manifest -b emu-master-dev 84``` 85Sync the source code: 86 87``` 88repo sync -j8 89``` 90 91### Emulator full build 92 93Use Android emulator toolchain script to run the build: 94``` 95cd /repo/emu-master-dev/external/qemu 96sh android/rebuild.sh 97``` 98 99The output can be found in: 100``` 101/repo/emu-master-dev/external/qemu/objs/distribution/emulator 102``` 103 104### Emulator incremental netsim build 105 106The `emulator` rebuild script does a complete clean build of all emulator components. 107For incrmental builds of the `netsimd` component, you can use the `cmake_setup` script: 108``` 109cd /repo/emu-master-dev/tools/netsim 110sh scripts/cmake_setup.sh 111``` 112 113Then use `ninja` for a partial netsim build: 114``` 115ninja -C objs netsimd 116``` 117 118If the build fails with rust errors it may be necessary to issue this command: 119 120``` 121rm rust/Cargo.lock 122``` 123 124Copy Web UI assets into `objs/netsim-ui`. 125``` 126sh scripts/build_ui.sh 127``` 128If you wish to change the source code of the ui and rebuild, use the `-b` flag. 129 130The output can be found in 131 132``` 133/repo/emu-master-dev/tools/netsim/objs 134``` 135 136## <a name="netsim_with_cuttlefish"></a>Build netsim with cuttlefish 137 138The [Android Developer Codelab](https://source.android.com/docs/setup/start) 139provides instructions for building and running cuttlefish AVDs. 140 141Follow the instructions in the codelab for workstation setup. 142 143### Initialize and sync the code 144 145Initialize the repo: 146``` 147mkdir /repo/aosp-master; cd /repo/aosp-master 148repo init -u https://android.googlesource.com/platform/manifest -b aosp-master 149``` 150 151Sync the source code: 152``` 153repo sync -j8 154``` 155 156### Build cuttlefish 157 158Set up build environment: 159``` 160source build/envsetup.sh 161``` 162 163Set the target device type: 164``` 165lunch aosp_cf_x86_64_phone 166``` 167 168Start the build: 169``` 170m -j64 171``` 172 173The netsim executable can be found in: 174``` 175/repo/aosp-master/out/host/linux-x86/bin 176``` 177 178### Cuttlefish incremental netsim build 179 180 181Start the build with netsimd target: 182``` 183m netsimd -j64 184``` 185 186## Unit Testing 187 188Unit tests can be run from the `aosp-master` branch using the `atest` command: 189``` 190atest --host-unit-test-only --test-filter netsim 191``` 192 193Rust tests can also be run for individual Rust modules using the `cargo test` command: 194``` 195cd tools/netsim/rust/netsim-cxx/ 196cargo test transport 197``` 198 199## Build Tips 200 201### Building across repository directories 202 203You will need to verify that any changes in `tools/netsim` can be built from 204both manifest branches. To temporarily copy changes between repositories we often 205use: 206 207``` 208git diff HEAD^ > /tmp/git.diff 209cd /repo/emu-master-dev 210git apply /tmp/git.diff 211``` 212 213### Repo workflow 214 215The repo workflow for creating and uploading a change request: 216``` 217repo start new-branch 218git add <files> 219git commit 220repo upload --branch=new-branch 221``` 222 223Subsequent commits: 224``` 225git add <files> 226git commit --amend --no-edit 227repo upload --branch=new-branch 228``` 229 230## Documentation 231 232The developer and user documentation for netsim is stored in the `guide` 233directory in `mdbook` format. Refer to 234[install](https://rust-lang.github.io/mdBook/guide/installation.html) 235for instructions on how to install `mdbook`. 236 237Use this command to start a local web server with the netsim guide: 238``` 239mdbook serve guide 240``` 241 242