Trace eviction and fill in SliceArpCache.
This commit is contained in:
parent
0f2b05ede7
commit
b305797cb4
|
@ -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)
|
||||
|
|
12
src/lib.rs
12
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;
|
||||
|
|
Loading…
Reference in New Issue