[−][src]Macro portus::start
Convenience macro for starting the portus runtime in the common single-algorithm case. The 3-argument form will use blocking IPC sockets. Arguments are:
- ipc, a &str specifying the IPC type
(either "unix", "netlink", or "char"): see
ipc
. - log, an instance of
Option<slog::Logger>
. - alg, an instance of
impl CongAlg<T: Ipc>
. - blk, optional argument, either
Blocking
orNonblocking
.
Example
Using the example algorithm from above:
extern crate portus; use std::collections::HashMap; use portus::{CongAlg, Flow, Config, Datapath, DatapathInfo, DatapathTrait, Report}; use portus::ipc::Ipc; use portus::lang::Scope; use portus::lang::Bin; #[derive(Clone, Default)] struct MyCongestionControlAlgorithm(Scope); impl<I: Ipc> CongAlg<I> for MyCongestionControlAlgorithm { type Flow = Self; fn name() -> &'static str { "My congestion control algorithm" } fn datapath_programs(&self) -> HashMap<&'static str, String> { let mut h = HashMap::default(); h.insert( "MyProgram", " (def (Report (volatile minrtt +infinity) )) (when true (:= Report.minrtt (min Report.minrtt Flow.rtt_sample_us)) ) (when (> Micros 42000) (report) (reset) ) ".to_owned(), ); h } fn new_flow(&self, mut control: Datapath<I>, info: DatapathInfo) -> Self::Flow { let sc = control.set_program("MyProgram", None).unwrap(); MyCongestionControlAlgorithm(sc) } } impl Flow for MyCongestionControlAlgorithm { fn on_report(&mut self, sock_id: u32, m: Report) { println!("minrtt: {:?}", m.get_field("Report.minrtt", &self.0).unwrap()); } } fn main() { portus::start!("unix", None, MyCongestionControlAlgorithm(Default::default())); }