forked from stevelorenz/comnetsemu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
168 lines (140 loc) · 6.02 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- mode: ruby -*-
# vi: set ft=ruby :
# About: Vagrant file for the development environment
###############
# Variables #
###############
CPUS = 2
# - 2GB RAM SHOULD be sufficient for most examples and applications.
# - Currently only YOLOv2 object detection application requires 4GB RAM to run smoothly.
# - Reduce the memory number (in MB) here if you physical machine does not have enough physical memory.
RAM = 4096
# Bento: Packer templates for building minimal Vagrant baseboxes
# The bento/ubuntu-XX.XX is a small image of about 500 MB, fast to download
BOX = "bento/ubuntu-20.04"
VM_NAME = "ubuntu-20.04-comnetsemu"
# When using libvirt as the provider, use this box, bento boxes do not support libvirt.
BOX_LIBVIRT = "generic/ubuntu2004"
######################
# Provision Script #
######################
# Common bootstrap
$bootstrap= <<-SCRIPT
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
APT_PKGS=(
bash-completion
dfc
gdb
git
htop
iperf
iperf3
make
pkg-config
python3
python3-dev
python3-pip
sudo
tmux
)
apt-get install -y --no-install-recommends "${APT_PKGS[@]}"
SCRIPT
$setup_x11_server= <<-SCRIPT
apt-get install -y --no-install-recommends xorg openbox
SCRIPT
# Ubuntu 20.04 LTS uses v5.4 LTS, EOL: Dec, 2025
# This script is uncommented and used when there's a requirement to manually install a special Linux kernel
# A special kernel (version) is needed sometimes for special latest kernel features (e.g. eBPF, AF_XDP)
# $install_kernel= <<-SCRIPT
# # Install libssl1.1 from https://packages.ubuntu.com/bionic/amd64/libssl1.1/download
# echo "deb http://cz.archive.ubuntu.com/ubuntu bionic main" | tee -a /etc/apt/sources.list > /dev/null
# apt update
# apt install -y libssl1.1
# cd /tmp || exit
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-headers-5.4.70-050470_5.4.70-050470.202010070732_all.deb
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-headers-5.4.70-050470-generic_5.4.70-050470.202010070732_amd64.deb
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-image-unsigned-5.4.70-050470-generic_5.4.70-050470.202010070732_amd64.deb
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-modules-5.4.70-050470-generic_5.4.70-050470.202010070732_amd64.deb
# dpkg -i *.deb
# update-initramfs -u -k 5.4.70-050470-generic
# update-grub
# SCRIPT
$setup_comnetsemu= <<-SCRIPT
# Apply Xterm profile, looks nicer.
cp /home/vagrant/comnetsemu/util/Xresources /home/vagrant/.Xresources
# xrdb can not run directly during vagrant up. Auto-works after reboot.
xrdb -merge /home/vagrant/.Xresources
cd /home/vagrant/comnetsemu/util || exit
PYTHON=python3 ./install.sh -a
# Install development tools
PYTHON=python3 ./install.sh -d
# Run the customization shell script (for distribution $BOX) if it exits.
cd /home/vagrant/comnetsemu/util || exit
if [ -f "./vm_customize.sh" ]; then
echo "*** Run VM customization script."
bash ./vm_customize.sh
fi
SCRIPT
$post_installation= <<-SCRIPT
# Allow vagrant user to use Docker without sudo
usermod -aG docker vagrant
if [ -d /home/vagrant/.docker ]; then
chown -R vagrant:vagrant /home/vagrant/.docker
fi
apt-get autoclean -y
apt-get autoremove -y
SCRIPT
####################
# Vagrant Config #
####################
Vagrant.configure("2") do |config|
config.vm.define "comnetsemu" do |comnetsemu|
comnetsemu.vm.box = BOX
# Sync ./ to home directory of vagrant to simplify the install script
comnetsemu.vm.synced_folder ".", "/vagrant", disabled: true
comnetsemu.vm.synced_folder ".", "/home/vagrant/comnetsemu"
# For virtualbox provider
comnetsemu.vm.provider "virtualbox" do |vb|
vb.name = VM_NAME
vb.cpus = CPUS
vb.memory = RAM
# MARK: The vCPUs should have SSE4 to compile DPDK applications.
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
end
# For libvirt provider
comnetsemu.vm.provider "libvirt" do |libvirt, override|
# Overrides are used to modify default options that do not work for libvirt provider.
override.vm.box = BOX_LIBVIRT
libvirt.driver = "kvm"
libvirt.cpus = CPUS
libvirt.memory = RAM
end
comnetsemu.vm.hostname = "comnetsemu"
comnetsemu.vm.box_check_update = true
comnetsemu.vm.post_up_message = '
VM already started! Run "$ vagrant ssh comnetsemu" to ssh into the runnung VM.
**IMPORTANT!!!**: For all ComNetsEmu users and developers:
**Please** run the upgrade process described [here](https://git.comnets.net/public-repo/comnetsemu#upgrade-comnetsemu-and-dependencies) when there is a new release
published [here](https://git.comnets.net/public-repo/comnetsemu/-/tags).
New features, fixes and other improvements require run the upgrade script **manually**.
But the script will check and perform upgrade automatically and it does not take much time if you have a good network connection.
'
comnetsemu.vm.provision :shell, inline: $bootstrap, privileged: true
comnetsemu.vm.provision :shell, inline: $setup_x11_server, privileged: true
comnetsemu.vm.provision :shell, inline: $setup_comnetsemu, privileged: false
comnetsemu.vm.provision :shell, inline: $post_installation, privileged: true
# VM networking
comnetsemu.vm.network "forwarded_port", guest: 8888, host: 8888, host_ip: "127.0.0.1"
comnetsemu.vm.network "forwarded_port", guest: 8082, host: 8082
comnetsemu.vm.network "forwarded_port", guest: 8083, host: 8083
comnetsemu.vm.network "forwarded_port", guest: 8084, host: 8084
# - Uncomment the underlying line to add a private network to the VM.
# If VirtualBox is used as the hypervisor, this means adding or using (if already created) a host-only interface to the VM.
# comnetsemu.vm.network "private_network", ip: "192.168.0.2"
# Enable X11 forwarding
comnetsemu.ssh.forward_agent = true
comnetsemu.ssh.forward_x11 = true
end
end