Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonch authored May 17, 2024
1 parent a71ba7f commit 72cd726
Showing 1 changed file with 65 additions and 17 deletions.
82 changes: 65 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# The Lucid / DPT (data plane threads) language

Lucid is a language for programming the Intel Tofino, and eventually other data plane platforms. Compared to P4, Lucid provides higher-level abstractions, a specialized type system, a relatively fast (and semantically accurate) software interpreter, and an optimizing compiler. All of these features are designed to make it easier to prototype and develop complex data plane applications that compile to real hardware.
Lucid is a processing / data plane programming language that focuses on simple, general, and modular abstractions. This makes it easier to express a range of data-plane algorithms and data structures, like specialized hash tables (e.g., cuckoo hashing), sketches, and custom telemetry caches. Programs are often 10X fewer lines of code in Lucid compared to P4, and read much more like Go, Python, or C, than equivalent implementations in P4.

Lucid is especially useful for programs that feature *complex, user-defined data structures* (e.g., data-plane writeable cuckoo hash tables, approximate data structures), *packet recirculation*, or *integrated network control*.
Lucid also has a type-and-effect system that guarantees the ordering of operations on global state (state that persists across packets). Programs that pass Lucid's ordering check can be laid out as a pipeline (important for targets like the Tofino) and also have a convenient memory model: each packet's updates to all the global state can be viewed as an atomic transaction, and a stream of packets can be viewed as a serial sequence of such atomic transactions that executes in the order of packet arrivals. In other words, you don't need to worry about concurrency or race conditions at the packet level for Lucid programs that pass the ordering check.

## Getting Started
There are 3 implementations of Lucid:

The easiest way to use Lucid is with the Lucid docker image.
1. The Lucid interpreter. This defines the semantics of the language in a target-independent way. It is relatively fast and works on simple json events, either from a file given at startup or piped from stdin.

2. The Lucid-Tofino compiler. This backend compiles a Lucid program to a p416 program for the Tofino 1. It does many target-specific optimizations drawn from our many years of programming the Tofino.

3. A DPDK-C compiler. This backend produces a C program that uses DPDK for packet IO. It is a work in progress and currently single threaded.

## Installation

The easiest way to run Lucid is with the pre-built binaries in the `release` directory.
This should work for recent macos and ubuntu/debian systems.
```
git clone https://github.com/PrincetonUniversity/lucid/
cd lucid
./release/unpack.sh
./release/dpt.sh -h
```

Note: there is only a pre-built binary for the Interpreter at this time.

### Docker

There is also a docker image that can run the Lucid interpreter and Tofino compiler.

**1. Install docker**
- if you are on a laptop/desktop, just install the docker desktop app: [docker desktop](https://www.docker.com/products/docker-desktop/)
Expand All @@ -18,21 +39,32 @@ Run this in your terminal:
```
git clone https://github.com/PrincetonUniversity/lucid/
cd lucid
./lucid.sh pull
./docker_lucid.sh pull
```

This will download about 400MB of data and should take < 5 minutes.

That's it! Once the pull is done, you are ready to run the Lucid interpreter and P4 compiler inside the lucid docker container. The `lucid.sh` script makes this easy.
Once finished, you can run `./docker_lucid.sh interpret` to run the interpreter or `./docker_lucid.sh compile` to run the Tofino compiler. The `docker_lucid` script takes care of forwarding all arguments, files, and directories to / from the docker image.

### Building from source

Finally, you can also build Lucid from source. Its main dependencies are ocaml and z3.
On macos or linux, you should be able to do:
```
./install dependencies
make
```
to build the Lucid interpreter (`dpt`) and tofino compiler (`dptc`).


### Run the interpreter
## Run the interpreter

Run the interpreter with `./lucid.sh interpret <lucid program name>`. The interpreter type checks your program, then runs it in a simulated network defined by a specification file.
Using the docker container, you can run the interpreter with `./docker_lucid.sh interpret <lucid program name>`. The interpreter type checks your program, then runs it in a simulated network defined by a specification file.

Try it out with one of the tutorial programs ([monitor.dpt](https://github.com/PrincetonUniversity/lucid/blob/main/tutorials/interp/01monitor/monitor.dpt)):

```
jsonch@jsonchs-MBP lucid % ./lucid.sh interp tutorials/interp/01monitor/monitor.dpt
jsonch@jsonchs-MBP lucid % ./docker_lucid.sh interp tutorials/interp/01monitor/monitor.dpt
# ... startup output elided ...
t=0: Handling event eth_ip(11,22,2048,1,2,128) at switch 0, port 0
t=600: Handling event prepare_report(11,22,2048,1,2,128) at switch 0, port 196
Expand Down Expand Up @@ -60,13 +92,13 @@ Switch 0 : {

### Run the compiler

Finally, to compile Lucid programs to P4 for the Intel tofino, run the compiler with `./lucid.sh compile <lucid program name> -o <build directory name>`.
Finally, to compile Lucid programs to P4 for the Intel tofino, run the compiler with `./docker_lucid.sh compile <lucid program name> -o <build directory name>`.

The compiler translates a Lucid program into P4, optimizes it, and produces a build directory with a P4 program, Python control plane, and a directory that maps control-plane modifiable Lucid object names to their associated P4 object names.
Try it out with the tutorial application:

```
jsonch@jsonchs-MBP lucid % ./lucid.sh compile tutorials/interp/01monitor/monitor.dpt -o monitor_build
jsonch@jsonchs-MBP lucid % ./docker_lucid.sh compile tutorials/interp/01monitor/monitor.dpt -o monitor_build
build dir: monitor_build
build dir: /Users/jsonch/Desktop/gits/lucid/monitor_build
# ... output elided ...
Expand Down Expand Up @@ -100,13 +132,29 @@ lucid.cpp -- c control plane (currently unused)
```


### What to do next
### What to look at next

There are many [example programs](https://github.com/PrincetonUniversity/lucid/tree/main/examples) in our test suite, including some for the [Tofino](https://github.com/PrincetonUniversity/lucid/tree/main/examples/tofino_apps).

Lucid has been used to implement a number of interesting [applications](https://github.com/PrincetonUniversity/lucid/tree/main/examples/apps).

Lucid's [wiki](https://github.com/PrincetonUniversity/lucid/wiki) documents all of Lucid's well-supported features.

There are also a number of publications about Lucid, listed below.

## Publications

### About Lucid or its components:

- Lucid, a Language for Control in the Data Plane ([SIGCOMM 2021](https://conferences.sigcomm.org/sigcomm/2021/program.html) -- The SIGCOMM 2021 artifact is in the ``sigcomm21_artifact`` branch).

- Safe, modular packet pipeline programming ([POPL 2022](https://dl.acm.org/doi/pdf/10.1145/3498699))

- Lucid, a high-level easy-to-use dataplane programming language ([Devon K. Loehr's PhD Thesis](https://dkloehr.github.io/files/Thesis.pdf))

Lucid is a simple language. You might want to just play around with some [examples](https://github.com/PrincetonUniversity/lucid/tree/main/examples/interp_tests) in our interpreter test suite, or some [tofino examples](https://github.com/PrincetonUniversity/lucid/tree/main/examples/tofino_apps) that we use to test the tofino compiler.
Alternately, you can take a look at the [tutorials](tutorials/readme.md).
- Automated Optimiation of Parameterized Data-Plane Programs with Parasol ([arxiv preprint](https://arxiv.org/pdf/2402.11155))

### Using Lucid:

## More details
For more information about Lucid, check out our paper and talk at [SIGCOMM 2021](https://conferences.sigcomm.org/sigcomm/2021/program.html)
- SwitchLog: A Logic Programming Language for Network Switches ([PADL 2023](https://par.nsf.gov/servlets/purl/10430321))

The SIGCOMM 2021 artifact is in the ``sigcomm21_artifact`` branch.

0 comments on commit 72cd726

Please sign in to comment.