Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#[macro_use] | ||
extern crate net_literals; | ||
extern crate netsim; | ||
extern crate tokio_core; | ||
extern crate futures; | ||
#[macro_use] | ||
extern crate unwrap; | ||
|
||
use netsim::{node, Ipv4Range, Network}; | ||
use futures::sync::oneshot; | ||
use futures::Future; | ||
use tokio_core::reactor::Core; | ||
|
||
#[test] | ||
fn spawn_ipv4_tree() { | ||
let mut evloop = unwrap!(Core::new()); | ||
let network = Network::new(&evloop.handle()); | ||
|
||
let (addr_tx, addr_rx) = oneshot::channel(); | ||
|
||
let node_recipe = node::ipv4::machine(|ip| { | ||
unwrap!(addr_tx.send(ip)); | ||
}); | ||
let (spawn_complete, _ipv4_plug) = network.spawn_ipv4_tree(Ipv4Range::new(ipv4!("78.100.10.1"), 30), node_recipe); | ||
|
||
let addr = unwrap!(evloop.run(spawn_complete.and_then(|()| addr_rx.map_err(|e| panic!(e))))); | ||
assert_eq!(addr.octets()[0..3], [78, 100, 10]); | ||
} |