Skip to content

Commit 9c2f5d6

Browse files
authored
Add vm-ubuntu-24.04 directory (#615)
* Support negative-valued action parameters by converting them in the Python helper code into a positive value whose bit pattern is the 2's complement representation of the negative value. * Add initial version of vm-ubuntu-24.04 directory
1 parent e0dae13 commit 9c2f5d6

14 files changed

+1235
-0
lines changed

vm-ubuntu-24.04/README.md

+255
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# Introduction
2+
3+
This directory is still new and a bit experimental at this point.
4+
Feel free to try it out and report problems if you find any.
5+
6+
Known issues that anyone who knows how to fix is welcome to suggest
7+
improvements:
8+
9+
+ The VM created has a GUI desktop with icons, but the icon images are
10+
"blank".
11+
12+
13+
# Creating the VM
14+
15+
+ Below are the steps to create a brand new VM using Vagrant:
16+
+ Install [Vagrant](https://developer.hashicorp.com/vagrant/docs/installation) on your system if it's not already installed.
17+
+ Navigate to the directory where you want to create the new VM.
18+
+ Run the below command in the terminal.
19+
20+
```bash
21+
vagrant up dev
22+
```
23+
24+
- This command will initiate the creation of a development VM.
25+
- The VM will include P4 software installed built from source code.
26+
27+
+ `vagrant up` is not supported, as there are not currently
28+
pre-compiled Ubuntu 24.04 packages being created by anyone.
29+
30+
*Note* that creating a development VM can take several hours,
31+
depending upon the speed of your computer and Internet connection.
32+
33+
34+
# Creating a VM image for distribution to others
35+
36+
If you are creating the VM for your own use, there is no need to read
37+
further below. All later instructions are for those who wish to
38+
create a VM image for others to download and use.
39+
40+
Some of these steps could probably be automated with programs, and
41+
changes to the `vagrant` scripts that can do so are welcome. I
42+
perform these steps manually to create a VM image, simply to avoid the
43+
experimentation and time required to automate them. I typically only
44+
create new VM images once per month.
45+
46+
+ Log in as user p4 (password p4)
47+
+ Upgrade Ubuntu packages if newer ones are available:
48+
49+
```bash
50+
sudo apt update
51+
sudo apt upgrade
52+
```
53+
54+
+ Reboot the system.
55+
+ This is optional, but if you want to save a little disk space, use
56+
57+
```bash
58+
sudo apt purge <list of packages>
59+
```
60+
61+
to remove older version of Linux
62+
kernel, if the upgrade installed a newer one.
63+
+ Clean the local repository of retrieved package files to free up disk space
64+
65+
```bash
66+
sudo apt clean
67+
```
68+
69+
+ Log in as user p4 (password p4)
70+
+ Start menu -> Preferences -> LXQt settings -> Monitor settings
71+
+ Change resolution from initial 800x600 to 1024x768. Apply the changes.
72+
+ Close monitor settings window
73+
+ *Note*: For some reason I do not know, these settings seem to be
74+
undone, even if I use the "Save" button. They are temporarily in
75+
effect if I shut down the system and log back in, but then in a few
76+
seconds it switches back to 800x600. Strange.
77+
+ Start menu -> Preferences -> LXQt settings -> Desktop
78+
+ Click "Background" tab
79+
+ To the right of "Wallpaper image file" name, click "Browse"
80+
button. Find and choose "lxqt-default-wallpaper.png" from the
81+
list and click "Open".
82+
+ In "Wallpaper mode" popup menu, choose "Center on the screen".
83+
+ Click Apply button
84+
+ Close "Desktop preferences" window
85+
+ The desktop "icons" are some kind of strange invisible or
86+
non-existent icon images. If you know how to fix this, please let
87+
me know.
88+
+ Several of the icons on the desktop have an exclamation mark on
89+
them. If you try double-clicking those icons, it pops up a window
90+
saying "This file 'Wireshark' seems to be a desktop entry. What do
91+
you want to do with it?" with buttons for "Open", "Execute", and
92+
"Cancel". Clicking "Execute" executes the associated command.
93+
If you do a mouse middle click on one of these desktop icons, a
94+
popup menu appears where the second-to-bottom choice is "Trust this
95+
executable". Selecting that causes the exclamation mark to go away,
96+
and future double-clicks of the icon execute the program without
97+
first popping up a window to choose between Open/Execute/Cancel. I
98+
did that for each of these desktop icons:
99+
+ Terminal
100+
+ Wireshark
101+
+ Log off
102+
103+
+ Log in as user vagrant (password vagrant)
104+
+ Change monitor settings and wallpaper mode as described above for
105+
user p4.
106+
+ Open a terminal.
107+
+ Run the command
108+
109+
```bash
110+
./clean.sh
111+
```
112+
which removes about 6 to 7 GBytes of
113+
files created while building the projects.
114+
+ Log off
115+
116+
117+
# Notes on test results for the VM
118+
119+
I have run the tests below on every VM image I release, before
120+
releasing it. You need not run them again, unless you are curious how
121+
to do so.
122+
123+
124+
## p4c testing results
125+
126+
Steps to run the p4c tests:
127+
128+
+ Log in as user vagrant (password vagrant)
129+
+ In a new terminal, execute these commands:
130+
131+
If you are testing on a Release VM image, first get a copy of the p4c
132+
source code using the following command. This is unnecessary with a
133+
Development VM image, as there is already a `p4c` directory with the
134+
version of source code used to create that image already included in
135+
the home directory of the `vagrant` user account:
136+
137+
```bash
138+
# for Release VM image only
139+
git clone --recursive https://github.com/p4lang/p4c
140+
```
141+
142+
The following steps are common for both Release and Development VM
143+
images:
144+
145+
```bash
146+
# Compile p4c again from source, since the clean.sh step reduced disk
147+
# space by deleting the p4c/build directory.
148+
git clone https://github.com/jafingerhut/p4-guide
149+
cd p4c
150+
~/p4-guide/bin/build-p4c.sh
151+
152+
# Run the p4c tests
153+
cd build
154+
make -j2 check |& tee out1.txt
155+
156+
# The above fails about 500 tests that require root. Re-run those tests
157+
# as root using the next command.
158+
sudo PATH=${PATH} VIRTUAL_ENV=${VIRTUAL_ENV} ${P4GUIDE_SUDO_OPTS} make -j2 recheck |& tee out2.txt
159+
```
160+
161+
As of 2024-05-30, the p4c compiler passes all but about 15 of its
162+
included tests when built using the steps above.
163+
164+
165+
## Send ping packets in the solution to `basic` exercise of `p4lang/tutorials` repository
166+
167+
With the version of the [tutorials](https://github.com/p4lang/tutorials) repository
168+
that comes pre-installed in the `p4` user account of this VM, the
169+
following tests pass.
170+
171+
First log in as the user `p4` (password `p4`) and open a terminal
172+
window.
173+
```bash
174+
$ cd tutorials/exercises/basic
175+
$ cp solution/basic.p4 basic.p4
176+
$ make run
177+
```
178+
179+
If at the end of many lines of logging output you see a prompt
180+
`mininet>`, you can try entering the command `h1 ping h2` to ping from
181+
virtual host `h1` in the exercise to `h2`, and it should report a
182+
successful ping every second. It will not stop on its own. You can
183+
type Control-C to stop it and return to the `mininet>` prompt, and you
184+
can type Control-D to exit from mininet and get back to the original
185+
shell prompt. To ensure that any processes started by the above steps
186+
are terminated, you can run this command:
187+
```bash
188+
$ make stop
189+
```
190+
191+
192+
# Creating a single file image of the VM
193+
194+
These notes are primarily here as a reminder for people creating VM
195+
images for distribution. If you downloaded a VM image, these steps
196+
were already performed, and there is no reason you need to perform
197+
them again.
198+
199+
For the particular case of creating the VM named:
200+
201+
+ 'P4 Tutorial Development 2024-06-01'
202+
+ created on June 1, 2024
203+
204+
here were the host OS details, in case it turns out that matters to
205+
the finished VM image for some reason:
206+
207+
+ Windows 10 Enterprise
208+
+ VirtualBox 6.1.30 r148432
209+
+ Vagrant 2.2.18
210+
211+
In the VirtualBox GUI interface:
212+
213+
+ Choose menu item File -> Export Appliance ...
214+
+ Select the VM named 'P4 Tutorial Development 2024-06-01' and click
215+
Continue button
216+
217+
+ Format
218+
+ I used: Open Virtualization Format 1.0
219+
+ Other available options were:
220+
+ Open Virtualization Format 0.9
221+
+ Open Virtualization Format 2.0
222+
+ Target file
223+
+ I used: /Users/andy/Documents/P4 Tutorials Development 2024-06-01.ova
224+
+ Mac Address Policy
225+
+ I used: Include only NAT network adapter MAC addresses
226+
+ Other available options were:
227+
+ Include all network adapter MAC addresses
228+
+ Strip all network adapter MAC addresses
229+
+ Additionally
230+
+ Write Manifest file: checked
231+
+ Include ISO image files: unchecked
232+
233+
Clicked "Continue" button.
234+
235+
Virtual system settings:
236+
237+
+ Name: P4 Tutorial 2024-06-01
238+
+ Product: I left this blank
239+
+ Product-URL: I left this blank
240+
+ Vendor: P4.org - P4 Language Consortium
241+
+ Vendor-URL: https://p4.org
242+
+ Version: 2024-06-01
243+
+ Description:
244+
245+
```
246+
Open source P4 development tools built from latest source code as of 2024-Jun-01 and packaged into an Ubuntu 20.04 Desktop Linux VM for the AMD64 architecture.
247+
```
248+
249+
+ License
250+
251+
```
252+
Open source code available hosted at https://github.com/p4lang is released under the Apache 2.0 license. Libraries it depends upon, such as Protobuf, Thrift, gRPC, Ubuntu Linux, etc. are released under their own licenses.
253+
```
254+
255+
Clicked "Export" button.

vm-ubuntu-24.04/Vagrantfile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure(2) do |config|
5+
config.vm.box = "bento/ubuntu-24.04"
6+
7+
config.vm.synced_folder '.', '/vagrant', disabled: true
8+
config.vm.hostname = "p4"
9+
config.vm.provision "file", source: "p4-logo.png", destination: "/home/vagrant/p4-logo.png"
10+
config.vm.provision "file", source: "p4_16-mode.el", destination: "/home/vagrant/p4_16-mode.el"
11+
config.vm.provision "file", source: "p4.vim", destination: "/home/vagrant/p4.vim"
12+
13+
config.vm.define "dev", autostart: false do |dev|
14+
dev.vm.provider "virtualbox" do |v|
15+
v.name = "P4 Tutorial Development" + Time.now.strftime(" %Y-%m-%d")
16+
end
17+
dev.vm.provision "file", source: "patches/behavioral-model-support-venv.patch", destination: "/home/vagrant/patches/behavioral-model-support-venv.patch"
18+
dev.vm.provision "file", source: "patches/mininet-patch-for-2023-jun-enable-venv.patch", destination: "/home/vagrant/patches/mininet-patch-for-2023-jun-enable-venv.patch"
19+
dev.vm.provision "file", source: "patches/tutorials-support-venv.patch", destination: "/home/vagrant/patches/tutorials-support-venv.patch"
20+
dev.vm.provision "file", source: "patches/p4runtime-shell-2023-changes.patch", destination: "/home/vagrant/patches/p4runtime-shell-2023-changes.patch"
21+
dev.vm.provision "file", source: "clean.sh", destination: "/home/vagrant/clean.sh"
22+
dev.vm.provision "shell", inline: "chmod 755 /home/vagrant/clean.sh"
23+
dev.vm.provision "shell", path: "root-dev-bootstrap.sh"
24+
dev.vm.provision "shell", path: "root-common-bootstrap.sh"
25+
dev.vm.provision "shell", privileged: false, path: "user-dev-bootstrap.sh"
26+
dev.vm.provision "shell", privileged: false, path: "user-common-bootstrap.sh"
27+
# Install p4 logo as wallpaper
28+
dev.vm.provision "shell", inline: "mv /home/vagrant/p4-logo.png /usr/share/lubuntu/wallpapers/lubuntu-default-wallpaper.png"
29+
end
30+
31+
config.vm.provider "virtualbox" do |vb|
32+
vb.gui = true
33+
# Larger memory and vcpus helps build p4c from source
34+
# significantly faster. Reduce this using VirtualBox settings
35+
# before creating VM image if desired.
36+
vb.memory = 8192
37+
vb.cpus = 4
38+
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
39+
vb.customize [
40+
"storageattach", :id,
41+
"--storagectl", "IDE Controller",
42+
"--port", "0",
43+
"--device", "0",
44+
"--type", "dvddrive",
45+
"--medium", "emptydrive"
46+
]
47+
vb.customize ["modifyvm", :id, "--vram", "64"]
48+
end
49+
50+
end

vm-ubuntu-24.04/clean.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /bin/bash
2+
3+
# To reduce disk space used by the virtual machine, delete many build
4+
# files created during execution of install scripts.
5+
6+
# This script is _not_ automatically run during creation of the VM, so
7+
# that if anything goes wrong during the build, all of the resulting
8+
# files are left behind for examination.
9+
10+
DF1_BEFORE=`df -h .`
11+
DF2_BEFORE=`df -BM .`
12+
13+
# Remove protobuf and grpc sources completely, since they are large
14+
# and easily downloadable.
15+
/bin/rm -fr protobuf grpc
16+
17+
cd behavioral-model
18+
make clean
19+
cd ..
20+
21+
cd p4c
22+
/bin/rm -fr build
23+
cd ..
24+
25+
/bin/rm usr-local-*.txt pip3-list-2b-*.txt
26+
27+
sudo apt autoremove
28+
sudo apt clean
29+
30+
# Zero out unused disk blocks. Results in significantly smaller VM
31+
# image files.
32+
33+
echo "Writing zeros to unused disk blocks (be patient) ..."
34+
FNAME=`mktemp --tmpdir big-empty-zero-file-XXXXXXXX`
35+
dd if=/dev/zero of=${FNAME} bs=4096k
36+
/bin/rm -f ${FNAME}
37+
38+
echo "Disk usage before running this script:"
39+
echo "$DF1_BEFORE"
40+
echo "$DF2_BEFORE"
41+
42+
echo ""
43+
echo "Disk usage after running this script:"
44+
df -h .
45+
df -BM .

vm-ubuntu-24.04/p4-logo.png

5.2 KB
Loading

0 commit comments

Comments
 (0)