Skip to content

Commit 7bb416c

Browse files
authored
Merge pull request #1 from mohamed-arm/mohamed_parsec_execute
Add parsec provisionsing example
2 parents e087ad7 + a830f04 commit 7bb416c

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"dpu/dpu-runtime-manager",
44
"host/examples/attestation",
55
"host/examples/provision_execute",
6+
"host/examples/parsec_execute",
67
]
78

89
resolver = "2"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
authors = ["The Veracruz Development Team"]
3+
description = "The test program to demonstrate provisioning parsec-client and executing remotely with DPU runtime manager"
4+
name = "parsec_execute"
5+
version = "0.1.0"
6+
edition = "2018"
7+
8+
[dependencies]
9+
anyhow = "1.0.14"
10+
env_logger = { version = "0.10.0" }
11+
log = "0.4.13"
12+
transport = { path = "../../../common/transport" }
13+
utils = { path = "../../../common/utils" }
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//! Provision and execute parsec.
2+
3+
use anyhow::anyhow;
4+
use log::{error, info};
5+
use utils::attestation;
6+
use transport::{messages::{Request, Response, Status}, session::Session};
7+
8+
use std::fs;
9+
use std::fs::File;
10+
use std::io::Read;
11+
12+
const DPU_SERVER_URL: &str = "127.0.0.1:6666";
13+
const ATTESTATION_SERVER_URL: &str = "127.0.0.1:3010";
14+
15+
const PARSEC_APP_NAME: &str = "/tmp/dpu/parsec_app";
16+
const PARSEC_PERM_CMD: &str = "chmod +x /tmp/dpu/parsec_app";
17+
const PARSEC_EXECUTE_CMD: &str = "PARSEC_SERVICE_CONN_TYPE=tcp PARSEC_SERVICE_CONN_IP_ADDR=172.28.97.222 PARSEC_SERVICE_CONN_PORT_NO=8002 /tmp/dpu/parsec_app ping";
18+
19+
// Read program file
20+
fn get_file_data(filename: &String) -> anyhow::Result<Vec<u8>> {
21+
22+
let mut file = File::open(&filename).unwrap();
23+
let metadata = fs::metadata(&filename).unwrap();
24+
let mut file_content = vec![0; metadata.len() as usize];
25+
file.read(&mut file_content).unwrap();
26+
27+
Ok(file_content)
28+
}
29+
30+
fn main() -> anyhow::Result<()> {
31+
env_logger::init();
32+
33+
// TODO: Parse arguments with clap
34+
let dpu_server_url = DPU_SERVER_URL;
35+
let proxy_attestation_server_url = ATTESTATION_SERVER_URL;
36+
37+
let dpu_session_id = Session::from_url(dpu_server_url)?;
38+
39+
attestation::request_attestation(dpu_session_id, proxy_attestation_server_url)?;
40+
info!("Successfully attested DPU.");
41+
42+
info!("Preparing parsec-tool executable data...");
43+
let filename = PARSEC_APP_NAME.to_owned();
44+
let data = get_file_data(&filename).unwrap();
45+
46+
info!("Provisioning parsec-tool to DPU...");
47+
Session::send_message(dpu_session_id, &Request::UploadFile(filename, data))
48+
.map_err(|e| {
49+
error!("Failed to send provisioning message to DPU. Error returned: {:?}.", e);
50+
e
51+
})?;
52+
let response = Session::receive_message(dpu_session_id).map_err(|e| {
53+
error!("Failed to receive response to provisioning message. Error received: {:?}.", e);
54+
e
55+
})?;
56+
match response {
57+
Response::Status(Status::Success(_)) => {
58+
info!("Successfully provisioned DPU.");
59+
},
60+
_ => {
61+
error!("Error provisioning DPU.");
62+
return Err(anyhow!("Provisioning failure."));
63+
},
64+
}
65+
66+
info!("Requesting permission change...");
67+
Session::send_message(dpu_session_id, &Request::Execute(PARSEC_PERM_CMD.to_owned()))
68+
.map_err(|e| {
69+
error!("Failed to send execution message to DPU. Error returned: {:?}.", e);
70+
e
71+
})?;
72+
let response = Session::receive_message(dpu_session_id).map_err(|e| {
73+
error!("Failed to receive response to execution message. Error received: {:?}.", e);
74+
e
75+
})?;
76+
match response {
77+
Response::Status(Status::Success(output)) => {
78+
info!("Successfully executed code remotely. Output: \n{}", output);
79+
},
80+
_ => {
81+
error!("Error executing code remotely.");
82+
return Err(anyhow!("Remote execution failure."));
83+
},
84+
}
85+
86+
info!("Requesting parsec-tool execution..");
87+
Session::send_message(dpu_session_id, &Request::Execute(PARSEC_EXECUTE_CMD.to_owned()))
88+
.map_err(|e| {
89+
error!("Failed to send execution message to DPU. Error returned: {:?}.", e);
90+
e
91+
})?;
92+
let response = Session::receive_message(dpu_session_id).map_err(|e| {
93+
error!("Failed to receive response to execution message. Error received: {:?}.", e);
94+
e
95+
})?;
96+
match response {
97+
Response::Status(Status::Success(output)) => {
98+
info!("Successfully executed code remotely. Output: \n{}", output);
99+
},
100+
_ => {
101+
error!("Error executing code remotely.");
102+
return Err(anyhow!("Remote execution failure."));
103+
},
104+
}
105+
106+
Ok(())
107+
}

0 commit comments

Comments
 (0)