Browse Source

Trace eviction and fill in SliceArpCache.

whitequark 8 years ago
parent
commit
4e364d816a
2 changed files with 21 additions and 3 deletions
  1. 10 2
      src/iface/arp_cache.rs
  2. 11 1
      src/lib.rs

+ 10 - 2
src/iface/arp_cache.rs

@@ -97,6 +97,15 @@ impl<'a> Cache for SliceCache<'a> {
     fn fill(&mut self, protocol_addr: &IpAddress, hardware_addr: &EthernetAddress) {
         if let None = self.find(protocol_addr) {
             let lru_index = self.lru();
+
+            if net_trace_enabled!() {
+                let (old_protocol_addr, old_hardware_addr, _counter) = self.storage[lru_index];
+                if !old_protocol_addr.is_unspecified() {
+                    net_trace!("evicting {} => {}", old_protocol_addr, old_hardware_addr);
+                }
+                net_trace!("filling {} => {}", protocol_addr, hardware_addr);
+            }
+
             self.counter += 1;
             self.storage[lru_index] =
                 (*protocol_addr, *hardware_addr, self.counter);
@@ -106,8 +115,7 @@ impl<'a> Cache for SliceCache<'a> {
 
     fn lookup(&mut self, protocol_addr: &IpAddress) -> Option<EthernetAddress> {
         if let Some(index) = self.find(protocol_addr) {
-            let (_protocol_addr, hardware_addr, ref mut counter) =
-                self.storage[index];
+            let (_protocol_addr, hardware_addr, ref mut counter) = self.storage[index];
             self.counter += 1;
             *counter = self.counter;
             Some(hardware_addr)

+ 11 - 1
src/lib.rs

@@ -77,7 +77,7 @@ extern crate libc;
 #[cfg(feature = "alloc")]
 extern crate alloc;
 #[cfg(any(test, feature = "log"))]
-#[macro_use(trace, log)]
+#[macro_use(trace, log, log_enabled)]
 extern crate log;
 
 macro_rules! net_trace {
@@ -89,6 +89,16 @@ macro_rules! net_trace {
     }
 }
 
+macro_rules! net_trace_enabled {
+    () => ({
+        #[cfg(feature = "log")]
+        fn enabled() -> bool { log_enabled!($crate::log::LogLevel::Trace) }
+        #[cfg(not(feature = "log"))]
+        fn enabled() -> bool { false }
+        enabled()
+    })
+}
+
 use core::fmt;
 
 pub mod phy;