Skip to content

Commit

Permalink
Update crates
Browse files Browse the repository at this point in the history
  • Loading branch information
eshikafe committed Oct 12, 2024
1 parent bece139 commit 5fad636
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 265 deletions.
8 changes: 7 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
edition = "2021"
edition = "2021"

## Unstable features
# normalize_comments = true
# normalize_doc_attributes = true
# overflow_delimited_expr = true
# group_imports = "StdExternalCrate"
2 changes: 1 addition & 1 deletion src/bin/bessd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bess::bessd;
use bess::opts::*;
// use bess::bessctl;
use log::*;
use clap::Parser;
use log::*;

#[tokio::main]
async fn main() {
Expand Down
31 changes: 18 additions & 13 deletions src/core/bessctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#![allow(unused_imports)]

use log::*;
use std::net::SocketAddr;

use tonic::codegen::http::response;
use tonic::transport::server::Router;
use tonic::transport::Server;
use tonic::Code;
use tonic::{transport::Server, Request, Response, Status};
use tonic::{Request, Response, Status};

pub mod bess_pb {
tonic::include_proto!("bess.pb");
Expand All @@ -32,7 +34,7 @@ use crate::shared_obj;
use crate::traffic_class;
// #include "utils/ether.h"
// #include "utils/time.h"
use crate::worker::{self, WorkerStatus, Worker};
use crate::worker::{self, Worker, WorkerStatus};

// #include <rte_mempool.h>
// #include <rte_ring.h>
Expand Down Expand Up @@ -617,7 +619,7 @@ impl BessControl for BESSControlService {
let response = format!("Invalid core {}", core);
return Err(Status::invalid_argument(response));
}

if worker::is_worker_active(wid as usize) {
let response = format!("worker: {} is already active", wid);
return Err(Status::already_exists(response));
Expand All @@ -631,7 +633,6 @@ impl BessControl for BESSControlService {

worker::launch_worker(wid, core, scheduler);
return Ok(Response::new(EmptyResponse { error: None }));

}
// Status DestroyWorker(ServerContext*, const DestroyWorkerRequest* request,
// EmptyResponse* response) override {
Expand Down Expand Up @@ -1999,21 +2000,25 @@ impl BessControl for BESSControlService {
// server.listen('localhost:10514');
// server.run();
pub struct ApiServer {
builder: Server,
addr: Option<String>,
builder: Option<Server>,
}
struct ServerBuilder;

impl ApiServer {
pub fn new() -> Self {
Self {
builder: Server::builder(),
addr: None,
}
Self { builder: None }
}

// `addr` is a gRPC url
pub fn listen(&mut self, addr: String) {
self.addr = Some(addr.clone());
// `addr` is a gRPC url.
pub fn listen(&mut self, addr: &str) {
if self.builder.is_none() {
self.builder = Some(Server::builder());
}

log::info!("Server listening on {}", addr);

let addr = addr.parse::<SocketAddr>().expect("Invalid address");
self.builder.unwrap()
}

// Runs the API server until it is shutdown by KillBess RPC.
Expand Down
41 changes: 24 additions & 17 deletions src/core/bessd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ use env_logger::fmt::Color;
use env_logger::{Target, WriteStyle};
use exitcode;
use log::*;
use std::io::{self, BufRead,Write};
use std::process::exit;
use std::io::{self, BufRead, Write};
use std::path::Path;
use std::process::exit;

use libc::*;
use nix::*;
// #include "port.h"

use std::{fs::File};
use daemonize::Daemonize;
use std::fs::File;
// Utility routines for the main bess daemon.

// When Modules extend other Modules, they may reference a shared object
// that has not yet been loaded by the BESS daemon. kInheritanceLimit is
// the number of passes that will be made while loading Module shared objects,
// and thus the maximum inheritance depth of any Module.
pub const K_INHERITANCE_LIMIT: u32 = 10;
pub const STD_OUT_FILE_PATH:&str = "/tmp/bessd.out";
pub const STD_ERR_FILE_PATH:&str = "/tmp/bessd.err";
pub const PID_FILE_PATH:&str = "/tmp/bessd2.pid";
pub const STD_OUT_FILE_PATH: &str = "/tmp/bessd.out";
pub const STD_ERR_FILE_PATH: &str = "/tmp/bessd.err";
pub const PID_FILE_PATH: &str = "/tmp/bessd2.pid";

// Process command line arguments from gflags.
pub fn process_command_line_args() {
Expand Down Expand Up @@ -93,9 +93,8 @@ pub fn process_command_line_args() {
.write_style(WriteStyle::Always)
.target(Target::Stdout)
.init();
// env_logger::init();
// env_logger::init();
}

}

// Checks that we are running as superuser.
Expand All @@ -120,7 +119,12 @@ pub fn write_pid_file(fd: u32, pid: u32) {}
// value upon success. Returns false upon failure.
pub fn read_pid_file() -> (bool, u32) {
let mut pid_result = (false, 0);
if let Ok(pid) = read_file_lines(PID_FILE_PATH).unwrap().into_iter().nth(0).unwrap(){
if let Ok(pid) = read_file_lines(PID_FILE_PATH)
.unwrap()
.into_iter()
.nth(0)
.unwrap()
{
if pid != "" || pid.parse::<u32>().unwrap() > 0 {
pid_result = (true, pid.parse::<u32>().unwrap());
}
Expand Down Expand Up @@ -149,21 +153,21 @@ pub fn daemonize() -> u32 {
let std_err = File::create(STD_ERR_FILE_PATH).unwrap();
let daemonize = Daemonize::new()
.pid_file(PID_FILE_PATH) // Every method except `new` and `start`
.chown_pid_file(false) // is optional, see `Daemonize` documentation
.chown_pid_file(false) // is optional, see `Daemonize` documentation
.working_directory("/tmp") // for default behaviour.
.group("daemon") // Group name
.user("unknown")
.group(2) // or group id.
.umask(0o777) // Set umask, `0o027` by default.
.stdout(std_out) // Redirect stdout to `/tmp/daemon.out`.
.stderr(std_err) // Redirect stderr to `/tmp/daemon.err`.
.group(2) // or group id.
.umask(0o777) // Set umask, `0o027` by default.
.stdout(std_out) // Redirect stdout to `/tmp/daemon.out`.
.stderr(std_err) // Redirect stderr to `/tmp/daemon.err`.
.privileged_action(|| "Executed before drop privileges");

match daemonize.start() {
Ok(_) => println!("Success, started daemon successfully"),
Err(e) => eprintln!("Error, {}", e),
}
read_pid_file().1
}
read_pid_file().1
}

// Sets BESS's resource limit. Returns true upon success.
Expand Down Expand Up @@ -199,7 +203,10 @@ pub fn get_current_directory() -> String {
}

// Read Files
fn read_file_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>> where P: AsRef<Path>, {
fn read_file_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}
Loading

0 comments on commit 5fad636

Please sign in to comment.