Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ NERPA (Network Programming with Relational and Procedural Abstractions) seeks to
0. Clone this repository. We will call its top-level directory `$NERPA_DIR`. I would recommend using a fresh Ubuntu 18.04 VM for painless P4 installation.
1. Install DDlog using the provided [installation instructions](https://github.com/vmware/differential-datalog/blob/master/README.md#installation). This codebase used version [v0.36.0](https://github.com/vmware/differential-datalog/releases/tag/v0.36.0).
2. Install P4 using these [installation instructions](https://github.com/jafingerhut/p4-guide/blob/master/bin/README-install-troubleshooting.md#quick-instructions-for-successful-install-script-run). We used the install script `install-p4dev-v2.sh`. It is much more usable than the P4 README installation, and clones all necessary repositories and installs dependencies.
For better organization, run it in a dedicated directory for dependencies, called `$NERPA_DEPS`. This directory should be outside your clone of this repository.

For better organization, create a dedicated directory for these dependencies, outside your clone of this repository. Run the installation script within this directory. Set `$NERPA_DEPS` equal to this directory's path.

3. Generate the DDlog crate using the [setup script](nerpa_controlplane/generate.sh). We do not commit this crate so that small differences in developer toolchains do not create significant hassle.
```
Expand All @@ -37,10 +38,7 @@ cargo build
```

### Test
1. Start `simple_switch_grpc` from its build directory (`$NERPA_DEPS/targets/simple_switch_grpc`).
```
./simple_switch_grpc --log-console --no-p4 -- --grpc-server-addr 0.0.0.0:50051 --cpu-port 1010
```
1. Set the environmental variable `NERPA_DEPS` to the directory containing Nerpa dependencies, including `behavioral-model`. In other words, the `simple_switch_grpc` binary should have the following path: `$NERPA_DEPS/behavioral-model/targets/simple_switch_grpc/simple_switch_grpc`.

2. Run the P4 Runtime library tests.
```
Expand All @@ -49,7 +47,7 @@ cargo test
```

### Run
1. Start `simple_switch_grpc` from its build directory (`$NERPA_DEPS/targets/simple_switch_grpc`).
1. Start `simple_switch_grpc` from its build directory (`$NERPA_DEPS/behavioral-model/targets/simple_switch_grpc`).
```
./simple_switch_grpc --log-console --no-p4 -- --grpc-server-addr 0.0.0.0:50051 --cpu-port 1010
```
Expand Down
28 changes: 28 additions & 0 deletions nerpa_controller/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions p4ext/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions p4ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ itertools = "0.10.0"
proto = {path = "../proto"}
protobuf = "2.22.0"
protobuf-codegen = "2.22.0"
rusty-fork = "0.3.0"
tokio = { version = "1.2.0", features = ["full"] }

[dev-dependencies]
rusty-fork = "0.3.0"
91 changes: 85 additions & 6 deletions p4ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SOFTWARE.

use byteorder::{BigEndian, WriteBytesExt};

use grpcio::WriteFlags;
use grpcio::{ChannelBuilder, EnvBuilder, WriteFlags};

use itertools::Itertools;

Expand All @@ -43,11 +43,14 @@ use proto::p4types;
use protobuf::{Message, RepeatedField};

use std::collections::HashMap;
use std::env;
use std::ffi::OsStr;
use std::fmt::{self, Display};
use std::fs;
use std::process::Command;
use std::str::FromStr;
use std::string::String;
use std::sync::Arc;

#[derive(Clone)]
pub struct SourceLocation {
Expand Down Expand Up @@ -658,6 +661,75 @@ impl fmt::Display for P4Error {
}
}

pub struct TestSetup {
pub p4info: String,
pub opaque: String,
pub cookie: String,
pub action: String,
pub device_id: u64,
pub role_id: u64,
pub target: String,
pub client: P4RuntimeClient,
pub table_name: String,
pub action_name: String,
pub params_values: HashMap<String, u16>,
pub match_fields_map: HashMap<String, u16>,
}

impl TestSetup {
pub fn new() -> Self {
let deps_var = "NERPA_DEPS";
let switch_path = "behavioral-model/targets/simple_switch_grpc/simple_switch_grpc";

let nerpa_deps = match env::var(deps_var) {
Ok(val) => val,
Err(err) => panic!("Set env var ${} before running tests (error: {})!", deps_var, err),
};

let filepath = format!("{}/{}", nerpa_deps, switch_path);
let mut command = Command::new(filepath);
command.args(&[
"--no-p4",
"--",
"--grpc-server-addr",
"0.0.0.0:50051",
"--cpu-port",
"1010"
]);

match command.spawn() {
Ok(child) => println!("server process id: {}", child.id()),
Err(e) => panic!("server didn't start: {}", e),
}

let target = "localhost:50051";
let env = Arc::new(EnvBuilder::new().build());
let ch = ChannelBuilder::new(env).connect(target);
let client = P4RuntimeClient::new(ch);

let mut params_values : HashMap<String, u16> = HashMap::new();
params_values.insert("port".to_string(), 11);
let mut match_fields_map : HashMap<String, u16> = HashMap::new();
match_fields_map.insert("standard_metadata.ingress_port".to_string(), 11);
match_fields_map.insert("hdr.vlan.vid".to_string(), 1);


Self {
p4info: "examples/vlan/vlan.p4info.bin".to_string(),
opaque: "examples/vlan/vlan.json".to_string(),
cookie: "".to_string(),
action: "verify-and-commit".to_string(),
device_id: 0,
role_id: 0,
target: target.to_string(),
client: client,
table_name: "MyIngress.vlan_incoming_exact".to_string(),
action_name: "MyIngress.vlan_incoming_forward".to_string(),
params_values: params_values,
match_fields_map: match_fields_map,
}
}
}

pub fn set_pipeline(
p4info_str: &str,
Expand Down Expand Up @@ -899,12 +971,19 @@ pub async fn stream_channel(
use futures::SinkExt;
let send_result = sink.send((request, WriteFlags::default())).await;
match send_result {
Err(e) => return Err(P4Error{
message: format!("could not send stream message to sink: ({})", e)
Err(err) => return Err(P4Error{
message: format!("could not send stream message to sink: ({})", err)
}),
Ok(r) => {},
}
sink.close();
Ok(_) => {},
};

let close_result = sink.close().await;
match close_result {
Err(err) => return Err(P4Error{
message: format!("could not close sink: ({})", err)
}),
Ok(_) => {},
};

use futures::StreamExt;
let (_, receive_result) = receiver.enumerate().next().await.unwrap();
Expand Down
Loading