@@ -34,7 +34,7 @@ use crate::devices::virtio::net::{
34
34
gen, NetError , NetQueue , MAX_BUFFER_SIZE , NET_QUEUE_SIZES , RX_INDEX , TX_INDEX ,
35
35
} ;
36
36
use crate :: devices:: virtio:: queue:: { DescriptorChain , Queue } ;
37
- use crate :: devices:: virtio:: { ActivateError , TYPE_NET } ;
37
+ use crate :: devices:: virtio:: { ActivateError , ResetError , TYPE_NET } ;
38
38
use crate :: devices:: { report_net_event_fail, DeviceError } ;
39
39
use crate :: dumbo:: pdu:: arp:: ETH_IPV4_FRAME_LEN ;
40
40
use crate :: dumbo:: pdu:: ethernet:: { EthernetFrame , PAYLOAD_OFFSET } ;
@@ -870,6 +870,15 @@ impl VirtioDevice for Net {
870
870
fn is_activated ( & self ) -> bool {
871
871
self . device_state . is_activated ( )
872
872
}
873
+
874
+ fn reset ( & mut self ) -> Result < ( ) , ResetError > {
875
+ self . device_state = DeviceState :: Inactive ;
876
+ self . rx_bytes_read = 0 ;
877
+ self . rx_deferred_frame = false ;
878
+ self . rx_frame_buf = [ 0u8 ; MAX_BUFFER_SIZE ] ;
879
+ self . metrics = NetMetricsPerDevice :: alloc ( self . id . clone ( ) ) ;
880
+ Ok ( ( ) )
881
+ }
873
882
}
874
883
875
884
#[ cfg( test) ]
@@ -2015,17 +2024,29 @@ pub mod tests {
2015
2024
th. activate_net ( ) ;
2016
2025
let net = th. net . lock ( ) . unwrap ( ) ;
2017
2026
2018
- // Test queues count (TX and RX).
2019
- let queues = net. queues ( ) ;
2020
- assert_eq ! ( queues. len( ) , NET_QUEUE_SIZES . len( ) ) ;
2021
- assert_eq ! ( queues[ RX_INDEX ] . size, th. rxq. size( ) ) ;
2022
- assert_eq ! ( queues[ TX_INDEX ] . size, th. txq. size( ) ) ;
2027
+ let validate = |net : & Net | {
2028
+ // Test queues count (TX and RX).
2029
+ let queues = net. queues ( ) ;
2030
+ assert_eq ! ( queues. len( ) , NET_QUEUE_SIZES . len( ) ) ;
2031
+ assert_eq ! ( queues[ RX_INDEX ] . size, th. rxq. size( ) ) ;
2032
+ assert_eq ! ( queues[ TX_INDEX ] . size, th. txq. size( ) ) ;
2033
+
2034
+ // Test corresponding queues events.
2035
+ assert_eq ! ( net. queue_events( ) . len( ) , NET_QUEUE_SIZES . len( ) ) ;
2036
+
2037
+ // Test interrupts.
2038
+ assert ! ( !& net. irq_trigger. has_pending_irq( IrqType :: Vring ) ) ;
2039
+ } ;
2040
+
2041
+ validate ( & net) ;
2023
2042
2024
- // Test corresponding queues events.
2025
- assert_eq ! ( net. queue_events( ) . len( ) , NET_QUEUE_SIZES . len( ) ) ;
2043
+ // Test reset.
2044
+ let mut net = net;
2045
+ assert ! ( net. device_state. is_activated( ) ) ;
2046
+ net. reset ( ) . unwrap ( ) ;
2047
+ assert ! ( !net. device_state. is_activated( ) ) ;
2026
2048
2027
- // Test interrupts.
2028
- assert ! ( !& net. irq_trigger. has_pending_irq( IrqType :: Vring ) ) ;
2049
+ validate ( & net) ;
2029
2050
}
2030
2051
2031
2052
#[ test]
0 commit comments