@@ -517,6 +517,24 @@ impl<'a, DeviceT> Interface<'a, DeviceT>
517517 & mut self . inner . routes
518518 }
519519
520+ /// Trigger the startup sequence for the interface.
521+ ///
522+ /// This method will call [Device::up] on the backing device.
523+ ///
524+ /// [Device::up]: ../phy/trait.Device.html#method.up
525+ pub fn up ( & mut self ) -> Result < ( ) > {
526+ self . device . up ( )
527+ }
528+
529+ /// Trigger the shutdown sequence for the interface.
530+ ///
531+ /// This method will call [Device::down] on the backing device.
532+ ///
533+ /// [Device::down]: ../phy/trait.Device.html#method.down
534+ pub fn down ( & mut self ) -> Result < ( ) > {
535+ self . device . down ( )
536+ }
537+
520538 /// Transmit packets queued in the given sockets, and receive packets queued
521539 /// in the device.
522540 ///
@@ -1862,9 +1880,11 @@ mod test {
18621880 #[ cfg( feature = "proto-igmp" ) ]
18631881 let iface_builder = iface_builder
18641882 . ipv4_multicast_groups ( BTreeMap :: new ( ) ) ;
1865- let iface = iface_builder
1883+ let mut iface = iface_builder
18661884 . finalize ( ) ;
18671885
1886+ iface. up ( ) . expect ( "Failed to bring device up!" ) ;
1887+
18681888 ( iface, SocketSet :: new ( vec ! [ ] ) )
18691889 }
18701890
@@ -1888,9 +1908,11 @@ mod test {
18881908 #[ cfg( feature = "proto-igmp" ) ]
18891909 let iface_builder = iface_builder
18901910 . ipv4_multicast_groups ( BTreeMap :: new ( ) ) ;
1891- let iface = iface_builder
1911+ let mut iface = iface_builder
18921912 . finalize ( ) ;
18931913
1914+ iface. up ( ) . expect ( "Failed to bring device up!" ) ;
1915+
18941916 ( iface, SocketSet :: new ( vec ! [ ] ) )
18951917 }
18961918
@@ -1924,6 +1946,34 @@ mod test {
19241946 InterfaceBuilder :: new ( Loopback :: new ( Medium :: Ethernet ) ) . finalize ( ) ;
19251947 }
19261948
1949+ #[ test]
1950+ #[ cfg( feature = "medium-ethernet" ) ]
1951+ fn test_iface_updown ( ) {
1952+ let ( mut iface, _) = create_loopback_ethernet ( ) ;
1953+
1954+ iface. down ( ) . unwrap ( ) ;
1955+
1956+ assert ! ( iface. device_mut( ) . transmit( ) . is_none( ) ) ;
1957+
1958+ iface. up ( ) . unwrap ( ) ;
1959+
1960+ let tx_token = match iface. device_mut ( ) . transmit ( ) {
1961+ Some ( token) => token,
1962+ None => panic ! ( "Failed to bring up device!" ) ,
1963+ } ;
1964+
1965+ let buf = [ 0x00 ; 42 ] ;
1966+
1967+ tx_token. consume ( Instant :: from_millis ( 0 ) , buf. len ( ) , |tx_buf| {
1968+ tx_buf. copy_from_slice ( & buf[ ..] ) ;
1969+ Ok ( ( ) )
1970+ } ) . unwrap ( ) ;
1971+
1972+ iface. down ( ) . unwrap ( ) ;
1973+
1974+ assert ! ( iface. device_mut( ) . receive( ) . is_none( ) ) ;
1975+ }
1976+
19271977 #[ test]
19281978 #[ cfg( feature = "proto-ipv4" ) ]
19291979 fn test_no_icmp_no_unicast_ipv4 ( ) {
0 commit comments