From c43f6ed97544191ca804a8885caa3af8906e7f65 Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Wed, 16 Oct 2024 18:55:00 -0400 Subject: [PATCH 1/3] Move optional steps for testing VMs out of README.md file This may help avoid new users being confused that they must follow those instructions. Signed-off-by: Andy Fingerhut --- vm-ubuntu-20.04/README.md | 217 +--------------- vm-ubuntu-20.04/create-vm-image-for-others.md | 210 ++++++++++++++++ vm-ubuntu-24.04/README.md | 235 +----------------- vm-ubuntu-24.04/create-vm-image-for-others.md | 214 ++++++++++++++++ 4 files changed, 435 insertions(+), 441 deletions(-) create mode 100644 vm-ubuntu-20.04/create-vm-image-for-others.md create mode 100644 vm-ubuntu-24.04/create-vm-image-for-others.md diff --git a/vm-ubuntu-20.04/README.md b/vm-ubuntu-20.04/README.md index ade3084c..6a1eb7ff 100644 --- a/vm-ubuntu-20.04/README.md +++ b/vm-ubuntu-20.04/README.md @@ -1,10 +1,12 @@ # Creating the VM + + Below are the steps to create a brand new VM using Vagrant: + Install [Vagrant](https://developer.hashicorp.com/vagrant/docs/installation) on your system if it's not already installed. - + Navigate to the directory where you want to create the new VM. + + In a shell/terminal window, change to this `vm-ubuntu-20.04` + directory inside the `tutorials` directory. + Run the below command in the terminal. - ``` + ```bash vagrant up ``` @@ -13,214 +15,9 @@ - You can update these packages using `apt upgrade` within the VM. + Alternatively, a development VM can be created by running - ``` + ```bash vagrant up dev ``` -*Note* : that creating a development VM can take one to several -hours, depending upon the speed of your computer and Internet -connection. - -Below are steps that were performed _after_ one of the commands above -was run on the host OS, before creating the VM images. Some of these -steps could probably be automated with programs, and changes to the -`vagrant` scripts that can do so are welcome. I performed these steps -manually to create a VM image, simply to avoid the experimentation and -time required to automate them. I typically only create new VM images -once per month. - -+ Log in as user p4 (password p4) -+ Click "Upgrade" in the pop-up window asking if you want to upgrade - the system, if asked. This will download the latest Linux kernel - version released for Ubuntu 20.04, and other updated packages. -+ Reboot the system. -+ This is optional, but if you want to save a little disk space, use - - ``` - sudo apt purge - ``` - - to remove older version of Linux - kernel, if the upgrade installed a newer one. -+ Clean the local repository of retrieved package files to free up disk space - - ``` - sudo apt clean - ``` - -+ Log in as user p4 (password p4) -+ Start menu -> Preferences -> LXQt settings -> Monitor settings - + Change resolution from initial 800x600 to 1024x768. Apply the changes. - + Close monitor settings window - + *Note*: For some reason I do not know, these settings seem to be - undone, even if I use the "Save" button. They are temporarily in - effect if I shut down the system and log back in, but then in a few - seconds it switches back to 800x600. Strange. -+ Start menu -> Preferences -> LXQt settings -> Desktop - + In "Wallpaper mode" popup menu, choose "Center on the screen". - + Click Apply button - + Close "Desktop preferences" window -+ Several of the icons on the desktop have an exclamation mark on - them. If you try double-clicking those icons, it pops up a window - saying "This file 'Wireshark' seems to be a desktop entry. What do - you want to do with it?" with buttons for "Open", "Execute", and - "Cancel". Clicking "Execute" executes the associated command. - If you do a mouse middle click on one of these desktop icons, a - popup menu appears where the second-to-bottom choice is "Trust this - executable". Selecting that causes the exclamation mark to go away, - and future double-clicks of the icon execute the program without - first popping up a window to choose between Open/Execute/Cancel. I - did that for each of these desktop icons: - + Terminal - + Wireshark -+ Log off - -+ Log in as user vagrant (password vagrant) -+ Change monitor settings and wallpaper mode as described above for - user p4. -+ Open a terminal. - + Run the command - - ``` - ./clean.sh - ``` - which removes about 6 to 7 GBytes of - files created while building the projects. -+ Log off - - -# Notes on test results for the VM - -I have run the tests below on every VM image I release, before -releasing it. You need not run them again, unless you are curious how -to do so. - - -## p4c testing results - -Steps to run the p4c tests: - -+ Log in as user vagrant (password vagrant) -+ In a new terminal, execute these commands: - -If you are testing on a Release VM image, first get a copy of the p4c -source code using the following command. This is unnecessary with a -Development VM image, as there is already a `p4c` directory with the -version of source code used to create that image already included in -the home directory of the `vagrant` user account: - -```bash -# for Release VM image only -git clone --recursive https://github.com/p4lang/p4c -``` - -The following steps are common for both Release and Development VM -images: - -```bash -# Compile p4c again from source, since the clean.sh step reduced disk -# space by deleting the p4c/build directory. -git clone https://github.com/jafingerhut/p4-guide -cd p4c -~/p4-guide/bin/build-p4c.sh - -# Run the p4c tests -cd build -make -j2 check |& tee make-check-out.txt -``` - -As of 2024-08-01, the p4c compiler passes all of its included tests, -except for some of the p4testgen tests (if those are enabled). - - -## Send ping packets in the solution to `basic` exercise of `p4lang/tutorials` repository - -With the version of the [tutorials](https://github.com/p4lang/tutorials) repository -that comes pre-installed in the `p4` user account of this VM, the -following tests pass. - -First log in as the user `p4` (password `p4`) and open a terminal -window. -```bash -$ cd tutorials/exercises/basic -$ cp solution/basic.p4 basic.p4 -$ make run -``` - -If at the end of many lines of logging output you see a prompt -`mininet>`, you can try entering the command `h1 ping h2` to ping from -virtual host `h1` in the exercise to `h2`, and it should report a -successful ping every second. It will not stop on its own. You can -type Control-C to stop it and return to the `mininet>` prompt, and you -can type Control-D to exit from mininet and get back to the original -shell prompt. To ensure that any processes started by the above steps -are terminated, you can run this command: -```bash -$ make stop -``` - - -# Creating a single file image of the VM - -These notes are primarily here as a reminder for people creating VM -images for distribution. If you downloaded a VM image, these steps -were already performed, and there is no reason you need to perform -them again. - -For the particular case of creating the VM named: - -+ 'P4 Tutorial Development 2024-08-01' -+ created on August 1, 2024 - -here were the host OS details, in case it turns out that matters to -the finished VM image for some reason: - -+ Windows 10 Enterprise -+ VirtualBox 6.1.30 r148432 -+ Vagrant 2.2.18 - -In the VirtualBox GUI interface: - -+ Choose menu item File -> Export Appliance ... -+ Select the VM named 'P4 Tutorial Development 2024-08-01' and click - Continue button - -+ Format - + I used: Open Virtualization Format 1.0 - + Other available options were: - + Open Virtualization Format 0.9 - + Open Virtualization Format 2.0 -+ Target file - + I used: /Users/andy/Documents/P4 Tutorials Development 2024-08-01.ova -+ Mac Address Policy - + I used: Include only NAT network adapter MAC addresses - + Other available options were: - + Include all network adapter MAC addresses - + Strip all network adapter MAC addresses -+ Additionally - + Write Manifest file: checked - + Include ISO image files: unchecked - -Clicked "Continue" button. - -Virtual system settings: - -+ Name: P4 Tutorial 2024-08-01 -+ Product: I left this blank -+ Product-URL: I left this blank -+ Vendor: P4.org - P4 Language Consortium -+ Vendor-URL: https://p4.org -+ Version: 2024-08-01 -+ Description: - -``` -Open source P4 development tools built from latest source code as of 2024-Aug-01 and packaged into an Ubuntu 20.04 Desktop Linux VM for the AMD64 architecture. -``` - -+ License - -``` -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. -``` - -Clicked "Export" button. +*Note* that creating a development VM can take several hours, +depending upon the speed of your computer and Internet connection. diff --git a/vm-ubuntu-20.04/create-vm-image-for-others.md b/vm-ubuntu-20.04/create-vm-image-for-others.md new file mode 100644 index 00000000..6f050d1f --- /dev/null +++ b/vm-ubuntu-20.04/create-vm-image-for-others.md @@ -0,0 +1,210 @@ +# Creating a VM image for distribution to others + +If you want to run `p4c` tests, see the next section on how to do so, +_before_ running the commands in this section, since the commands in +this section will delete files that take one to several hours to +create while compiling p4c, needed for running p4c tests. + +Below are steps that were performed _after_ the commands in the +README.md file were run on the host OS, before creating the VM images. +Some of these steps could probably be automated with programs, and +changes to the `vagrant` scripts that can do so are welcome. I +performed these steps manually to create a VM image, simply to avoid +the experimentation and time required to automate them. I typically +only create new VM images once per month. + ++ Log in as user p4 (password p4) ++ Click "Upgrade" in the pop-up window asking if you want to upgrade + the system, if asked. This will download the latest Linux kernel + version released for Ubuntu 20.04, and other updated packages. ++ Reboot the system. ++ This is optional, but if you want to save a little disk space, use + + ``` + sudo apt purge + ``` + + to remove older version of Linux + kernel, if the upgrade installed a newer one. ++ Clean the local repository of retrieved package files to free up disk space + + ``` + sudo apt clean + ``` + ++ Log in as user p4 (password p4) ++ Start menu -> Preferences -> LXQt settings -> Monitor settings + + Change resolution from initial 800x600 to 1024x768. Apply the changes. + + Close monitor settings window + + *Note*: For some reason I do not know, these settings seem to be + undone, even if I use the "Save" button. They are temporarily in + effect if I shut down the system and log back in, but then in a few + seconds it switches back to 800x600. Strange. ++ Start menu -> Preferences -> LXQt settings -> Desktop + + In "Wallpaper mode" popup menu, choose "Center on the screen". + + Click Apply button + + Close "Desktop preferences" window ++ Several of the icons on the desktop have an exclamation mark on + them. If you try double-clicking those icons, it pops up a window + saying "This file 'Wireshark' seems to be a desktop entry. What do + you want to do with it?" with buttons for "Open", "Execute", and + "Cancel". Clicking "Execute" executes the associated command. + If you do a mouse middle click on one of these desktop icons, a + popup menu appears where the second-to-bottom choice is "Trust this + executable". Selecting that causes the exclamation mark to go away, + and future double-clicks of the icon execute the program without + first popping up a window to choose between Open/Execute/Cancel. I + did that for each of these desktop icons: + + Terminal + + Wireshark ++ Log off + ++ Log in as user vagrant (password vagrant) ++ Change monitor settings and wallpaper mode as described above for + user p4. ++ Open a terminal. + + Run the command + + ``` + ./clean.sh + ``` + which removes about 6 to 7 GBytes of + files created while building the projects. ++ Log off + + +# Notes on test results for the VM + +I have run the tests below on every VM image I release, before +releasing it. You need not run them again, unless you are curious how +to do so. + + +## p4c testing results + +Steps to run the p4c tests: + ++ Log in as user vagrant (password vagrant) ++ In a new terminal, execute these commands: + +If you are testing on a Release VM image, first get a copy of the p4c +source code using the following command. This is unnecessary with a +Development VM image, as there is already a `p4c` directory with the +version of source code used to create that image already included in +the home directory of the `vagrant` user account: + +```bash +# for Release VM image only +git clone --recursive https://github.com/p4lang/p4c +``` + +The following steps are common for both Release and Development VM +images: + +```bash +# Compile p4c again from source, since the clean.sh step reduced disk +# space by deleting the p4c/build directory. +git clone https://github.com/jafingerhut/p4-guide +cd p4c +~/p4-guide/bin/build-p4c.sh + +# Run the p4c tests +cd build +make -j2 check |& tee make-check-out.txt +``` + +As of 2024-08-01, the p4c compiler passes all of its included tests, +except for some of the p4testgen tests (if those are enabled). + + +## Send ping packets in the solution to `basic` exercise of `p4lang/tutorials` repository + +With the version of the [tutorials](https://github.com/p4lang/tutorials) repository +that comes pre-installed in the `p4` user account of this VM, the +following tests pass. + +First log in as the user `p4` (password `p4`) and open a terminal +window. +```bash +$ cd tutorials/exercises/basic +$ cp solution/basic.p4 basic.p4 +$ make run +``` + +If at the end of many lines of logging output you see a prompt +`mininet>`, you can try entering the command `h1 ping h2` to ping from +virtual host `h1` in the exercise to `h2`, and it should report a +successful ping every second. It will not stop on its own. You can +type Control-C to stop it and return to the `mininet>` prompt, and you +can type Control-D to exit from mininet and get back to the original +shell prompt. To ensure that any processes started by the above steps +are terminated, you can run this command: +```bash +$ make stop +``` + + +# Creating a single file image of the VM + +These notes are primarily here as a reminder for people creating VM +images for distribution. If you downloaded a VM image, these steps +were already performed, and there is no reason you need to perform +them again. + +For the particular case of creating the VM named: + ++ 'P4 Tutorial Development 2024-08-01' ++ created on August 1, 2024 + +here were the host OS details, in case it turns out that matters to +the finished VM image for some reason: + ++ Windows 10 Enterprise ++ VirtualBox 6.1.30 r148432 ++ Vagrant 2.2.18 + +In the VirtualBox GUI interface: + ++ Choose menu item File -> Export Appliance ... ++ Select the VM named 'P4 Tutorial Development 2024-08-01' and click + Continue button + ++ Format + + I used: Open Virtualization Format 1.0 + + Other available options were: + + Open Virtualization Format 0.9 + + Open Virtualization Format 2.0 ++ Target file + + I used: /Users/andy/Documents/P4 Tutorials Development 2024-08-01.ova ++ Mac Address Policy + + I used: Include only NAT network adapter MAC addresses + + Other available options were: + + Include all network adapter MAC addresses + + Strip all network adapter MAC addresses ++ Additionally + + Write Manifest file: checked + + Include ISO image files: unchecked + +Clicked "Continue" button. + +Virtual system settings: + ++ Name: P4 Tutorial 2024-08-01 ++ Product: I left this blank ++ Product-URL: I left this blank ++ Vendor: P4.org - P4 Language Consortium ++ Vendor-URL: https://p4.org ++ Version: 2024-08-01 ++ Description: + +``` +Open source P4 development tools built from latest source code as of 2024-Aug-01 and packaged into an Ubuntu 20.04 Desktop Linux VM for the AMD64 architecture. +``` + ++ License + +``` +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. +``` + +Clicked "Export" button. diff --git a/vm-ubuntu-24.04/README.md b/vm-ubuntu-24.04/README.md index 31466a58..9a2fb11c 100644 --- a/vm-ubuntu-24.04/README.md +++ b/vm-ubuntu-24.04/README.md @@ -1,10 +1,7 @@ # Introduction -This directory is still new and a bit experimental at this point. -Feel free to try it out and report problems if you find any. - -Known issues that anyone who knows how to fix is welcome to suggest -improvements: +Known minor issues that anyone who knows how to fix is welcome to +suggest improvements: + The desktop icon for the Wireshark application does not seem to exist, at least not under the name that worked for Ubuntu 20.04, so @@ -15,7 +12,8 @@ improvements: + Below are the steps to create a brand new VM using Vagrant: + Install [Vagrant](https://developer.hashicorp.com/vagrant/docs/installation) on your system if it's not already installed. - + Navigate to the directory where you want to create the new VM. + + In a shell/terminal window, change to this `vm-ubuntu-24.04` + directory inside the `tutorials` directory. + Run the below command in the terminal. ```bash @@ -30,228 +28,3 @@ improvements: *Note* that creating a development VM can take several hours, depending upon the speed of your computer and Internet connection. - - -# Creating a VM image for distribution to others - -If you are creating the VM for your own use, there is no need to read -further below. All later instructions are for those who wish to -create a VM image for others to download and use. - -Some of these steps could probably be automated with programs, and -changes to the `vagrant` scripts that can do so are welcome. I -perform these steps manually to create a VM image, simply to avoid the -experimentation and time required to automate them. I typically only -create new VM images once per month. - -+ Log in as user p4 (password p4) -+ Upgrade Ubuntu packages if newer ones are available: - - ```bash - sudo apt update - sudo apt upgrade - ``` - -+ Reboot the system. -+ This is optional, but if you want to save a little disk space, use - - ```bash - sudo apt purge - ``` - - to remove older version of Linux - kernel, if the upgrade installed a newer one. -+ Clean the local repository of retrieved package files to free up disk space - - ```bash - sudo apt clean - ``` - -+ Log in as user p4 (password p4) -+ Start menu -> Preferences -> LXQt settings -> Monitor settings - + Change resolution from initial 800x600 to 1024x768. Apply the changes. - + Close monitor settings window - + *Note*: For some reason I do not know, these settings seem to be - undone, even if I use the "Save" button. They are temporarily in - effect if I shut down the system and log back in, but then in a few - seconds it switches back to 800x600. Strange. -+ Start menu -> Preferences -> LXQt settings -> Desktop - + Click "Background" tab - + To the right of "Wallpaper image file" name, click "Browse" - button. Find and choose "lxqt-default-wallpaper.png" from the - list and click "Open". - + In "Wallpaper mode" popup menu, choose "Center on the screen". - + Click Apply button - + Close "Desktop preferences" window -+ Start menu -> Preferences -> LXQt settings -> Appearance - + Click "Icons Theme" in left column - + Click "Ubuntu-Mono-Light ..." in right column. - + Click "Apply" button, then "Close" button. -+ Several of the icons on the desktop have an exclamation mark on - them. If you try double-clicking those icons, it pops up a window - saying "This file 'Wireshark' seems to be a desktop entry. What do - you want to do with it?" with buttons for "Open", "Execute", and - "Cancel". Clicking "Execute" executes the associated command. - If you do a mouse middle click on one of these desktop icons, a - popup menu appears where the second-to-bottom choice is "Trust this - executable". Selecting that causes the exclamation mark to go away, - and future double-clicks of the icon execute the program without - first popping up a window to choose between Open/Execute/Cancel. I - did that for each of these desktop icons: - + Terminal - + Wireshark -+ Log off - -+ Log in as user vagrant (password vagrant) -+ Change monitor settings and wallpaper mode as described above for - user p4. -+ Open a terminal. - + Run the command - - ```bash - ./clean.sh - ``` - which removes about 6 to 7 GBytes of - files created while building the projects. -+ Log off - - -# Notes on test results for the VM - -I have run the tests below on every VM image I release, before -releasing it. You need not run them again, unless you are curious how -to do so. - - -## p4c testing results - -Steps to run the p4c tests: - -+ Log in as user vagrant (password vagrant) -+ In a new terminal, execute these commands: - -If you are testing on a Release VM image, first get a copy of the p4c -source code using the following command. This is unnecessary with a -Development VM image, as there is already a `p4c` directory with the -version of source code used to create that image already included in -the home directory of the `vagrant` user account: - -```bash -# for Release VM image only -git clone --recursive https://github.com/p4lang/p4c -``` - -The following steps are common for both Release and Development VM -images: - -```bash -# Compile p4c again from source, since the clean.sh step reduced disk -# space by deleting the p4c/build directory. -git clone https://github.com/jafingerhut/p4-guide -cd p4c -~/p4-guide/bin/build-p4c.sh - -# Run the p4c tests -cd build -make -j2 check |& tee out1.txt - -# The above fails about 500 tests that require root. Re-run those tests -# as root using the next command. -sudo PATH=${PATH} VIRTUAL_ENV=${VIRTUAL_ENV} ${P4GUIDE_SUDO_OPTS} make -j2 recheck |& tee out2.txt -``` - -As of 2024-08-01, the p4c compiler passes all but about 15 of its -included tests when built using the steps above. - - -## Send ping packets in the solution to `basic` exercise of `p4lang/tutorials` repository - -With the version of the [tutorials](https://github.com/p4lang/tutorials) repository -that comes pre-installed in the `p4` user account of this VM, the -following tests pass. - -First log in as the user `p4` (password `p4`) and open a terminal -window. -```bash -$ cd tutorials/exercises/basic -$ cp solution/basic.p4 basic.p4 -$ make run -``` - -If at the end of many lines of logging output you see a prompt -`mininet>`, you can try entering the command `h1 ping h2` to ping from -virtual host `h1` in the exercise to `h2`, and it should report a -successful ping every second. It will not stop on its own. You can -type Control-C to stop it and return to the `mininet>` prompt, and you -can type Control-D to exit from mininet and get back to the original -shell prompt. To ensure that any processes started by the above steps -are terminated, you can run this command: -```bash -$ make stop -``` - - -# Creating a single file image of the VM - -These notes are primarily here as a reminder for people creating VM -images for distribution. If you downloaded a VM image, these steps -were already performed, and there is no reason you need to perform -them again. - -For the particular case of creating the VM named: - -+ 'P4 Tutorial Development 2024-08-01' -+ created on August 1, 2024 - -here were the host OS details, in case it turns out that matters to -the finished VM image for some reason: - -+ Windows 10 Enterprise -+ VirtualBox 6.1.30 r148432 -+ Vagrant 2.2.18 - -In the VirtualBox GUI interface: - -+ Choose menu item File -> Export Appliance ... -+ Select the VM named 'P4 Tutorial Development 2024-08-01' and click - Continue button - -+ Format - + I used: Open Virtualization Format 1.0 - + Other available options were: - + Open Virtualization Format 0.9 - + Open Virtualization Format 2.0 -+ Target file - + I used: /Users/andy/Documents/P4 Tutorials Development 2024-08-01.ova -+ Mac Address Policy - + I used: Include only NAT network adapter MAC addresses - + Other available options were: - + Include all network adapter MAC addresses - + Strip all network adapter MAC addresses -+ Additionally - + Write Manifest file: checked - + Include ISO image files: unchecked - -Clicked "Continue" button. - -Virtual system settings: - -+ Name: P4 Tutorial 2024-08-01 -+ Product: I left this blank -+ Product-URL: I left this blank -+ Vendor: P4.org - P4 Language Consortium -+ Vendor-URL: https://p4.org -+ Version: 2024-08-01 -+ Description: - -``` -Open source P4 development tools built from latest source code as of 2024-Aug-01 and packaged into an Ubuntu 24.04 Desktop Linux VM for the AMD64 architecture. -``` - -+ License - -``` -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. -``` - -Clicked "Export" button. diff --git a/vm-ubuntu-24.04/create-vm-image-for-others.md b/vm-ubuntu-24.04/create-vm-image-for-others.md new file mode 100644 index 00000000..2e38ca84 --- /dev/null +++ b/vm-ubuntu-24.04/create-vm-image-for-others.md @@ -0,0 +1,214 @@ +# Creating a VM image for distribution to others + +If you want to run `p4c` tests, see the next section on how to do so, +_before_ running the commands in this section, since the commands in +this section will delete files that take one to several hours to +create while compiling p4c, needed for running p4c tests. + +If you are creating the VM for your own use, there is no need to read +further below. All later instructions are for those who wish to +create a VM image for others to download and use. + +Some of these steps could probably be automated with programs, and +changes to the `vagrant` scripts that can do so are welcome. I +perform these steps manually to create a VM image, simply to avoid the +experimentation and time required to automate them. I typically only +create new VM images once per month. + ++ Log in as user p4 (password p4) ++ Upgrade Ubuntu packages if newer ones are available: + + ```bash + sudo apt update + sudo apt upgrade + ``` + ++ Reboot the system. ++ This is optional, but if you want to save a little disk space, use + + ```bash + sudo apt purge + ``` + + to remove older version of Linux + kernel, if the upgrade installed a newer one. ++ Clean the local repository of retrieved package files to free up disk space + + ```bash + sudo apt clean + ``` + ++ Log in as user p4 (password p4) ++ Start menu -> Preferences -> LXQt settings -> Monitor settings + + Change resolution from initial 800x600 to 1024x768. Apply the changes. + + Close monitor settings window + + *Note*: For some reason I do not know, these settings seem to be + undone, even if I use the "Save" button. They are temporarily in + effect if I shut down the system and log back in, but then in a few + seconds it switches back to 800x600. Strange. ++ Start menu -> Preferences -> LXQt settings -> Desktop + + Click "Background" tab + + To the right of "Wallpaper image file" name, click "Browse" + button. Find and choose "lxqt-default-wallpaper.png" from the + list and click "Open". + + In "Wallpaper mode" popup menu, choose "Center on the screen". + + Click Apply button + + Close "Desktop preferences" window ++ Start menu -> Preferences -> LXQt settings -> Appearance + + Click "Icons Theme" in left column + + Click "Ubuntu-Mono-Light ..." in right column. + + Click "Apply" button, then "Close" button. ++ Several of the icons on the desktop have an exclamation mark on + them. If you try double-clicking those icons, it pops up a window + saying "This file 'Wireshark' seems to be a desktop entry. What do + you want to do with it?" with buttons for "Open", "Execute", and + "Cancel". Clicking "Execute" executes the associated command. + If you do a mouse middle click on one of these desktop icons, a + popup menu appears where the second-to-bottom choice is "Trust this + executable". Selecting that causes the exclamation mark to go away, + and future double-clicks of the icon execute the program without + first popping up a window to choose between Open/Execute/Cancel. I + did that for each of these desktop icons: + + Terminal + + Wireshark ++ Log off + ++ Log in as user vagrant (password vagrant) ++ Change monitor settings and wallpaper mode as described above for + user p4. ++ Open a terminal. + + Run the command + + ```bash + ./clean.sh + ``` + which removes about 6 to 7 GBytes of + files created while building the projects. ++ Log off + + +# Notes on test results for the VM + +I have run the tests below on every VM image I release, before +releasing it. You need not run them again, unless you are curious how +to do so. + + +## p4c testing results + +Steps to run the p4c tests: + ++ Log in as user vagrant (password vagrant) ++ In a new terminal, execute these commands: + +```bash +# Compile p4c again from source, since the clean.sh step reduced disk +# space by deleting the p4c/build directory. +git clone https://github.com/jafingerhut/p4-guide +cd p4c +~/p4-guide/bin/build-p4c.sh + +# Run the p4c tests +cd build +make -j2 check |& tee out1.txt + +# The above fails about 500 tests that require root. Re-run those tests +# as root using the next command. +sudo PATH=${PATH} VIRTUAL_ENV=${VIRTUAL_ENV} ${P4GUIDE_SUDO_OPTS} make -j2 recheck |& tee out2.txt +``` + +As of 2024-08-01, the p4c compiler passes all but about 15 of its +included tests when built using the steps above. + + +## Send ping packets in the solution to `basic` exercise of `p4lang/tutorials` repository + +With the version of the [tutorials](https://github.com/p4lang/tutorials) repository +that comes pre-installed in the `p4` user account of this VM, the +following tests pass. + +First log in as the user `p4` (password `p4`) and open a terminal +window. +```bash +$ cd tutorials/exercises/basic +$ cp solution/basic.p4 basic.p4 +$ make run +``` + +If at the end of many lines of logging output you see a prompt +`mininet>`, you can try entering the command `h1 ping h2` to ping from +virtual host `h1` in the exercise to `h2`, and it should report a +successful ping every second. It will not stop on its own. You can +type Control-C to stop it and return to the `mininet>` prompt, and you +can type Control-D to exit from mininet and get back to the original +shell prompt. To ensure that any processes started by the above steps +are terminated, you can run this command: +```bash +$ make stop +``` + + +# Creating a single file image of the VM + +These notes are primarily here as a reminder for people creating VM +images for distribution. If you downloaded a VM image, these steps +were already performed, and there is no reason you need to perform +them again. + +For the particular case of creating the VM named: + ++ 'P4 Tutorial Development 2024-08-01' ++ created on August 1, 2024 + +here were the host OS details, in case it turns out that matters to +the finished VM image for some reason: + ++ Windows 10 Enterprise ++ VirtualBox 6.1.30 r148432 ++ Vagrant 2.2.18 + +In the VirtualBox GUI interface: + ++ Choose menu item File -> Export Appliance ... ++ Select the VM named 'P4 Tutorial Development 2024-08-01' and click + Continue button + ++ Format + + I used: Open Virtualization Format 1.0 + + Other available options were: + + Open Virtualization Format 0.9 + + Open Virtualization Format 2.0 ++ Target file + + I used: /Users/andy/Documents/P4 Tutorials Development 2024-08-01.ova ++ Mac Address Policy + + I used: Include only NAT network adapter MAC addresses + + Other available options were: + + Include all network adapter MAC addresses + + Strip all network adapter MAC addresses ++ Additionally + + Write Manifest file: checked + + Include ISO image files: unchecked + +Clicked "Continue" button. + +Virtual system settings: + ++ Name: P4 Tutorial 2024-08-01 ++ Product: I left this blank ++ Product-URL: I left this blank ++ Vendor: P4.org - P4 Language Consortium ++ Vendor-URL: https://p4.org ++ Version: 2024-08-01 ++ Description: + +``` +Open source P4 development tools built from latest source code as of 2024-Aug-01 and packaged into an Ubuntu 24.04 Desktop Linux VM for the AMD64 architecture. +``` + ++ License + +``` +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. +``` + +Clicked "Export" button. From 322494984d045d085562715f3e7fb3fece7ff1d5 Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Thu, 30 Jan 2025 21:17:19 +0000 Subject: [PATCH 2/3] Add 2025-Jan-30 versions of source code for install.sh Signed-off-by: Andy Fingerhut --- vm-ubuntu-24.04/install.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vm-ubuntu-24.04/install.sh b/vm-ubuntu-24.04/install.sh index ccc7728f..a7eae56b 100755 --- a/vm-ubuntu-24.04/install.sh +++ b/vm-ubuntu-24.04/install.sh @@ -27,11 +27,12 @@ print_usage() { 1>&2 echo "" 1>&2 echo "Dates supported:" 1>&2 echo " 2025-Jan-01" + 1>&2 echo " 2025-Jan-30" } if [ $# -eq 0 ] then - VERSION="2025-Jan-01" + VERSION="2025-Jan-30" echo "No version specified. Defaulting to ${VERSION}" elif [ $# -eq 1 ] then @@ -49,6 +50,13 @@ case ${VERSION} in export INSTALL_P4C_SOURCE_VERSION="1dc0afae2207f4bb9f5ab45f105ed569cc1ac89b" export INSTALL_PTF_SOURCE_VERSION="c554f83685186be4cfa9387eb5d6d700d2bbd7c0" ;; + 2025-Jan-30) + # 2025-Jan-01 versions: + export INSTALL_BEHAVIORAL_MODEL_SOURCE_VERSION="892c42198082d3252f4c6facc7363c02ca1d71d2" + export INSTALL_PI_SOURCE_VERSION="2bb40f7ab800b91b26f3aed174bbbfc739a37ffa" + export INSTALL_P4C_SOURCE_VERSION="2776b1948529bc7e8ccfb2f6ea2a9c1ab1f68796" + export INSTALL_PTF_SOURCE_VERSION="c554f83685186be4cfa9387eb5d6d700d2bbd7c0" + ;; latest) echo "Using the latest version of all p4lang repository source code." ;; From dc86bbf5556929d613dd66e38a7700577850539c Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Wed, 14 Oct 2026 23:28:11 -0400 Subject: [PATCH 3/3] Copy vim and Emacs P4 mode definition files to vm-ubuntu-26.04 Also remove p4-logo.png from vm-ubuntu-24.04 directory, as it is not used there. Signed-off-by: Andy Fingerhut --- vm-ubuntu-24.04/p4-logo.png | Bin 5329 -> 0 bytes vm-ubuntu-24.04/p4-logo.png.license | 3 - vm-ubuntu-26.04/p4.vim | 135 +++++++++++++ vm-ubuntu-26.04/p4_16-mode.el | 289 ++++++++++++++++++++++++++++ 4 files changed, 424 insertions(+), 3 deletions(-) delete mode 100644 vm-ubuntu-24.04/p4-logo.png delete mode 100644 vm-ubuntu-24.04/p4-logo.png.license create mode 100644 vm-ubuntu-26.04/p4.vim create mode 100644 vm-ubuntu-26.04/p4_16-mode.el diff --git a/vm-ubuntu-24.04/p4-logo.png b/vm-ubuntu-24.04/p4-logo.png deleted file mode 100644 index cc36615baf0a191916b2ca98909398315bd12f70..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5329 zcmV;?6fWzDP)002A)1^@s6;cKxK00009a7bBm000XU z000XU0RWnu7ytkYPiaF#P*7-ZbZ>KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++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hXtHUa}I%0ozA=&O-%u)FX!k>wG@>@pS!tuhbI18L#@9UA9|I0VV{ zU8KnOT0ER`6wF~H;8%dk9JFtq8tVS6Nb#Zi&V1G)**c?00Hs%W7?_OMq0GsYo&xUF z)X6`L1S~<)koETX8b3q!rnSqJ{Bxi}{XGZxfd|)2BO9gkrm^#BDR(qVANMl$1BXH|1_q>*srADNBYqRPXdC3{7mxj{JW7=QGK&WN3*i}G_t0)x%dlWD7}xy zTT@NfDPPpg>pg}h@sgEXRvo_r*XdyV!9$>!bH9^O8RLOAOS&E ziQU@_64oL<<^eYKTge^(>L!a$wHkhJMYakvVz$e3X#|Xb8Qp4}OC4&XI^J$eho(Y$ zoZ17=ASvbAsh7owgUFs38UclyJb(+73B&0FU9P@Mu-?3{sa+&@;B3>sg=)CI6AAe? jF0h}4xc)Q(ivJG)FVKzXEy&1200000NkvXXu0mjf2r%= 508 || !exists("did_p4_syntax_inits") + if version <= 508 + let did_p4_syntax_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink p4ObjectKeyword Repeat + HiLink p4UserType Type + HiLink p4ObjectAttributeKeyword Keyword + HiLink p4TypeAttribute StorageClass + HiLink p4Annotation Special + HiLink p4MatchTypeKeyword Keyword + HiLink p4TODO Todo + HiLink p4Comment Comment + HiLink p4BlockComment Comment + HiLink p4Preprocessor PreProc + HiLink p4SizedType Type + HiLink p4Type Type + HiLink p4DecimalInt Number + HiLink p4HexadecimalInt Number + HiLink p4OctalInt Number + HiLink p4BinaryInt Number + HiLink p4Int Number + HiLink p4Operators Operator + HiLink p4Primitive Function + HiLink p4Conditional Conditional + HiLink p4Statement Statement + HiLink p4Constant Constant + HiLink p4Boolean Boolean + + delcommand HiLink +endif + +let b:current_syntax = "p4" diff --git a/vm-ubuntu-26.04/p4_16-mode.el b/vm-ubuntu-26.04/p4_16-mode.el new file mode 100644 index 00000000..b9db28bf --- /dev/null +++ b/vm-ubuntu-26.04/p4_16-mode.el @@ -0,0 +1,289 @@ +;;; p4_16-mode.el --- Support for the P4_16 programming language +;; SPDX-FileCopyrightText: 2016 Barefoot Networks, Inc. +;; SPDX-License-Identifier: Apache-2.0 + +;; Author: Vladimir Gurevich +;; Maintainer: Vladimir Gurevich +;; Created: 15 April 2017 +;; Version: 0.2 +;; Keywords: languages p4_16 +;; Homepage: https://p4.org + +;; This file is not part of GNU Emacs. + +;; This file is free software… + +;; This mode has preliminary support for P4_16. It covers the core language, +;; but it is not clear yet, how we can highlight the identifiers, defined +;; for a particular architecture. Core library definitions are included + +;; Placeholder for user customization code +(defvar p4_16-mode-hook nil) + +(defun p4_16-electric-brace (arg) + "Insert a brace." + (interactive "*P") + (self-insert-command (prefix-numeric-value arg)) + (save-excursion + (move-beginning-of-line nil) + (indent-for-tab-command))) + +;; Define the keymap (for now it is pretty much default) +(defvar p4_16-mode-map + (let ((map (make-keymap))) + (define-key map "\C-j" 'newline-and-indent) + (define-key map "{" 'p4_16-electric-brace) + (define-key map "}" 'p4_16-electric-brace) + (define-key map "\C-c\C-c" 'comment-region) + map) + "Keymap for P4_16 major mode") + +;; Syntactic HighLighting + +;; Main keywords (declarations and operators) +(setq p4_16-keywords + '("action" "apply" + "control" + "default" + "else" "enum" "extern" "exit" + "header" "header_union" + "if" + "match_kind" + "package" "parser" + "return" + "select" "state" "struct" "switch" + "table" "transition" "tuple" "typedef" "type" + "verify" + )) + +(setq p4_16-annotations + '("@name" "@metadata" "@alias" + )) + +(setq p4_16-attributes + '("const" "in" "inout" "out" + ;; Tables + "key" "actions" "default_action" "entries" "implementation" + "counters" "meters" + )) + +(setq p4_16-variables + '("packet_in" "packet_out" + )) + +(setq p4_16-operations + '("&&&" ".." "++" "?" ":")) + +(setq p4_16-constants + '( + ;;; Don't care + "_" + ;;; bool + "false" "true" + ;;; error + "NoError" "PacketTooShort" "NoMatch" "StackOutOfBounds" + "OverwritingHeader" "HeaderTooShort" "ParserTiimeout" + ;;; match_kind + "exact" "ternary" "lpm" "range" + ;;; We can add constants for supported architectures here + )) + +(setq p4_16-types + '("bit" "bool" "int" "varbit" "void" "error" + )) + +(setq p4_16-primitives + '( + ;;; Header methods + "isValid" "setValid" "setInvalid" + ;;; Table Methods + "hit" "action_run" + ;;; packet_in methods + "extract" "lookahead" "advance" "length" + ;;; packet_out methods + "emit" + ;;; Known parser states + "accept" "reject" + ;;; misc + "NoAction" + )) + +(setq p4_16-cpp + '("#include" + "#define" "#undef" + "#if" "#ifdef" "#ifndef" + "#elif" "#else" + "#endif" + "defined" + "#line" "#file")) + +(setq p4_16-cppwarn + '("#error" "#warning")) + +;; Optimize the strings +(setq p4_16-keywords-regexp (regexp-opt p4_16-keywords 'words)) +(setq p4_16-annotations-regexp (regexp-opt p4_16-annotations 1)) +(setq p4_16-attributes-regexp (regexp-opt p4_16-attributes 'words)) +(setq p4_16-variables-regexp (regexp-opt p4_16-variables 'words)) +(setq p4_16-operations-regexp (regexp-opt p4_16-operations 'words)) +(setq p4_16-constants-regexp (regexp-opt p4_16-constants 'words)) +(setq p4_16-types-regexp (regexp-opt p4_16-types 'words)) +(setq p4_16-primitives-regexp (regexp-opt p4_16-primitives 'words)) +(setq p4_16-cpp-regexp (regexp-opt p4_16-cpp 1)) +(setq p4_16-cppwarn-regexp (regexp-opt p4_16-cppwarn 1)) + + +;; create the list for font-lock. +;; each category of keyword is given a particular face +(defconst p4_16-font-lock-keywords + (list + (cons p4_16-cpp-regexp font-lock-preprocessor-face) + (cons p4_16-cppwarn-regexp font-lock-warning-face) + (cons p4_16-types-regexp font-lock-type-face) + (cons p4_16-constants-regexp font-lock-constant-face) + (cons p4_16-attributes-regexp font-lock-builtin-face) + (cons p4_16-variables-regexp font-lock-variable-name-face) + ;;; This is a special case to distinguish the method from the keyword + (cons "\\.apply" font-lock-function-name-face) + (cons p4_16-primitives-regexp font-lock-function-name-face) + (cons p4_16-operations-regexp font-lock-builtin-face) + (cons p4_16-keywords-regexp font-lock-keyword-face) + (cons p4_16-annotations-regexp font-lock-keyword-face) + (cons "\\(\\w*_t +\\)" font-lock-type-face) + (cons "[^A-Z_][A-Z] " font-lock-type-face) ;; Total hack for templates + (cons "<[A-Z, ]*>" font-lock-type-face) + (cons "\\(<[^>]+>\\)" font-lock-string-face) + (cons "\\([^_A-Za-z]\\([0-9]+w\\)?0x[0-9A-Fa-f]+\\)" font-lock-constant-face) + (cons "\\([^_A-Za-z]\\([0-9]+w\\)?0b[01]+\\)" font-lock-constant-face) + (cons "\\([^_A-Za-z][+-]?\\([0-9]+w\\)?[0-9]+\\)" font-lock-constant-face) + ;;(cons "\\(\\w*\\)" font-lock-variable-name-face) + ) + "Default Highlighting Expressions for P4_16") + +(defvar p4_16-mode-syntax-table + (let ((st (make-syntax-table))) + (modify-syntax-entry ?_ "w" st) + (modify-syntax-entry ?/ ". 124b" st) + (modify-syntax-entry ?* ". 23" st) + (modify-syntax-entry ?\n "> b" st) + st) + "Syntax table for p4_16-mode") + +;;; Indentation +(defvar p4_16-indent-offset 4 + "Indentation offset for `p4_16-mode'.") + +(defun p4_16-indent-line () + "Indent current line for any balanced-paren-mode'." + (interactive) + (let ((indent-col 0) + (indentation-increasers "[{(]") + (indentation-decreasers "[})]") + ) + (save-excursion + (beginning-of-line) + (condition-case nil + (while t + (backward-up-list 1) + (when (looking-at indentation-increasers) + (setq indent-col (+ indent-col p4_16-indent-offset)))) + (error nil))) + (save-excursion + (back-to-indentation) + (when (and (looking-at indentation-decreasers) + (>= indent-col p4_16-indent-offset)) + (setq indent-col (- indent-col p4_16-indent-offset)))) + (indent-line-to indent-col))) + +;;; Imenu support +(require 'imenu) + +;; regex to optionally match a name annotation, e.g. like this example: +;; @name(".process_replication.nop") +(setq opt-name-annotation-regex + "\\(@name[(] *\"[A-Za-z0-9_. ]+\" *[)]\\)\?") + +(setq p4_16-imenu-generic-expression + (list + (list "Controls" + (concat "^ *" + opt-name-annotation-regex + " *control +\\([A-Za-z0-9_]*\\)") + 2) + (list "Externs" + (concat "^ *" + opt-name-annotation-regex + " *extern +\\([A-Za-z0-9_]*\\) *\\([A-Za-z0-9_]*\\)") + 3) + (list "Tables" + (concat "^ *" + opt-name-annotation-regex + " *table +\\([A-Za-z0-9_]*\\)") + 2) + (list "Actions" + (concat "^ *" + opt-name-annotation-regex + " *action +\\([A-Za-z0-9_]*\\)") + 2) + (list "Parsers" + (concat "^ *" + opt-name-annotation-regex + " *parser +\\([A-Za-z0-9_]*\\)") + 2) + (list "Parser States" + (concat "^ *" + opt-name-annotation-regex + " *state +\\([A-Za-z0-9_]*\\)") + 2) + (list "Headers" + (concat "^ *" + opt-name-annotation-regex + " *header +\\([A-Za-z0-9_]*\\)") + 2) + (list "Header Unions" + (concat "^ *" + opt-name-annotation-regex + " *header_union +\\([A-Za-z0-9_]*\\)") + 2) + (list "Structs" + (concat "^ *" + opt-name-annotation-regex + " *struct +\\([A-Za-z0-9_]*\\)") + 2) + )) + +;;; Cscope Support +(require 'xcscope) + +;; The following version was generated by Google AI assistant with the +;; original version p4_16-mode as input, with the request that it be +;; updated to work with Emacs version 30. Further questioning about +;; how far back in Emacs versions this ought to work claimed it should +;; work back to Emacs 25 and Emacs 24.x for some x > 0. +;; Put everything together +;;;###autoload +(define-derived-mode p4_16-mode prog-mode "P4_16" + "Major mode for editing P4_16 programs." + :syntax-table p4_16-mode-syntax-table + + ;; Comments + (setq-local comment-start "// ") + (setq-local comment-end "") + + ;; Font-lock (Syntax Highlighting) + (setq font-lock-defaults '(p4_16-font-lock-keywords)) + + ;; Indentation + (setq-local indent-line-function #'p4_16-indent-line) + (setq-local indent-tabs-mode nil) + + ;; Imenu + (setq imenu-generic-expression p4_16-imenu-generic-expression) + (imenu-add-to-menubar "P4_16") + + ;; Cscope minor mode + (when (fboundp 'cscope-minor-mode) + (cscope-minor-mode))) + +;; The most important line +(provide 'p4_16-mode)