Print stats about routing table size in UI
authorMatt Corallo <git@bluematt.me>
Fri, 23 Aug 2019 04:50:24 +0000 (00:50 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Aug 2019 04:50:24 +0000 (00:50 -0400)
src/bgp_client.rs
src/printer.rs

index 1fa92501c2601ee16ed28c4cec4661e935a44c83..ed07bdc46989c4257311aed443319317da37be25 100644 (file)
@@ -20,7 +20,7 @@ use tokio::timer::Delay;
 
 use futures::sync::mpsc;
 
 
 use futures::sync::mpsc;
 
-use crate::printer::Printer;
+use crate::printer::{Printer, Stat};
 
 struct Route {
        path: Vec<u32>,
 
 struct Route {
        path: Vec<u32>,
@@ -287,6 +287,8 @@ impl BGPClient {
                                                                        route_table.announce(r, Arc::clone(&path_arc));
                                                                }
                                                        }
                                                                        route_table.announce(r, Arc::clone(&path_arc));
                                                                }
                                                        }
+                                                       printer.set_stat(Stat::V4RoutingTableSize(route_table.v4_table.len()));
+                                                       printer.set_stat(Stat::V6RoutingTableSize(route_table.v6_table.len()));
                                                },
                                                _ => {}
                                        }
                                                },
                                                _ => {}
                                        }
index 0bea277e8d4f688bb345580ca398a52b5e0083f7..933603ccc440d65a3af97578b92875f8e9e5f5c8 100644 (file)
@@ -11,12 +11,16 @@ pub enum Stat {
        HeaderCount(u64),
        NewConnection,
        ConnectionClosed,
        HeaderCount(u64),
        NewConnection,
        ConnectionClosed,
+       V4RoutingTableSize(usize),
+       V6RoutingTableSize(usize),
 }
 
 struct Stats {
        lines: LinkedList<String>,
        header_count: u64,
        connection_count: u64,
 }
 
 struct Stats {
        lines: LinkedList<String>,
        header_count: u64,
        connection_count: u64,
+       v4_table_size: usize,
+       v6_table_size: usize,
 }
 
 pub struct Printer {
 }
 
 pub struct Printer {
@@ -29,6 +33,8 @@ impl Printer {
                        lines: LinkedList::new(),
                        header_count: 0,
                        connection_count: 0,
                        lines: LinkedList::new(),
                        header_count: 0,
                        connection_count: 0,
+                       v4_table_size: 0,
+                       v6_table_size: 0,
                }));
                let thread_arc = Arc::clone(&stats);
                std::thread::spawn(move || {
                }));
                let thread_arc = Arc::clone(&stats);
                std::thread::spawn(move || {
@@ -83,6 +89,10 @@ impl Printer {
                                                        ).as_bytes()).expect("stdout broken?");
                                }
 
                                                        ).as_bytes()).expect("stdout broken?");
                                }
 
+                               out.write_all(format!(
+                                               "\nBGP Routing Table: {} v4 paths, {} v6 paths\n",
+                                               stats.v4_table_size, stats.v6_table_size).as_bytes()).expect("stdout broken?");
+
                                out.write_all(b"\nCommands:\n").expect("stdout broken?");
                                out.write_all(b"q: quit\n").expect("stdout broken?");
                                out.write_all(format!(
                                out.write_all(b"\nCommands:\n").expect("stdout broken?");
                                out.write_all(b"q: quit\n").expect("stdout broken?");
                                out.write_all(format!(
@@ -124,6 +134,8 @@ impl Printer {
                        Stat::HeaderCount(c) => self.stats.lock().unwrap().header_count = c,
                        Stat::NewConnection => self.stats.lock().unwrap().connection_count += 1,
                        Stat::ConnectionClosed => self.stats.lock().unwrap().connection_count -= 1,
                        Stat::HeaderCount(c) => self.stats.lock().unwrap().header_count = c,
                        Stat::NewConnection => self.stats.lock().unwrap().connection_count += 1,
                        Stat::ConnectionClosed => self.stats.lock().unwrap().connection_count -= 1,
+                       Stat::V4RoutingTableSize(c) => self.stats.lock().unwrap().v4_table_size = c,
+                       Stat::V6RoutingTableSize(c) => self.stats.lock().unwrap().v6_table_size = c,
                }
        }
 }
                }
        }
 }