mirror of https://github.com/dswd/vpncloud.git
Fixed benches
This commit is contained in:
parent
32abf1a34c
commit
82b7e5f18b
|
@ -6,19 +6,20 @@ use test::Bencher;
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::net::{UdpSocket, ToSocketAddrs, Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{UdpSocket, ToSocketAddrs, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
use std::os::unix::io::AsRawFd;
|
|
||||||
|
|
||||||
use super::MAGIC;
|
use super::MAGIC;
|
||||||
use super::config::Config;
|
use super::config::Config;
|
||||||
use super::cloud::GenericCloud;
|
use super::cloud::GenericCloud;
|
||||||
use super::device::{Device, Type};
|
use super::device::Type;
|
||||||
use super::udpmessage::{Message, encode, decode};
|
use super::udpmessage::{Message, encode, decode};
|
||||||
use super::crypto::{Crypto, CryptoMethod};
|
use super::crypto::{Crypto, CryptoMethod};
|
||||||
use super::ethernet::{Frame, SwitchTable};
|
use super::ethernet::{self, SwitchTable};
|
||||||
use super::types::{Address, Table, Protocol};
|
use super::types::{Address, Table, Protocol};
|
||||||
use super::ip::Packet;
|
use super::ip::Packet;
|
||||||
use super::util::now as util_now;
|
use super::util::{TimeSource, SystemTimeSource, MockTimeSource};
|
||||||
use super::poll::{Poll, Flags};
|
use super::poll::WaitImpl;
|
||||||
|
use super::device::TunTapDevice;
|
||||||
|
use super::net::MockSocket;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn crypto_chacha20(b: &mut Bencher) {
|
fn crypto_chacha20(b: &mut Bencher) {
|
||||||
|
@ -73,7 +74,7 @@ fn message_decode(b: &mut Bencher) {
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn switch_learn(b: &mut Bencher) {
|
fn switch_learn(b: &mut Bencher) {
|
||||||
let mut table = SwitchTable::new(10, 0);
|
let mut table = SwitchTable::<SystemTimeSource>::new(10, 0);
|
||||||
let addr = Address::from_str("12:34:56:78:90:ab").unwrap();
|
let addr = Address::from_str("12:34:56:78:90:ab").unwrap();
|
||||||
let peer = "1.2.3.4:5678".to_socket_addrs().unwrap().next().unwrap();
|
let peer = "1.2.3.4:5678".to_socket_addrs().unwrap().next().unwrap();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
|
@ -84,7 +85,7 @@ fn switch_learn(b: &mut Bencher) {
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn switch_lookup(b: &mut Bencher) {
|
fn switch_lookup(b: &mut Bencher) {
|
||||||
let mut table = SwitchTable::new(10, 0);
|
let mut table = SwitchTable::<SystemTimeSource>::new(10, 0);
|
||||||
let addr = Address::from_str("12:34:56:78:90:ab").unwrap();
|
let addr = Address::from_str("12:34:56:78:90:ab").unwrap();
|
||||||
let peer = "1.2.3.4:5678".to_socket_addrs().unwrap().next().unwrap();
|
let peer = "1.2.3.4:5678".to_socket_addrs().unwrap().next().unwrap();
|
||||||
table.learn(addr.clone(), None, peer);
|
table.learn(addr.clone(), None, peer);
|
||||||
|
@ -99,7 +100,7 @@ fn ethernet_parse(b: &mut Bencher) {
|
||||||
let mut data = [0; 1500];
|
let mut data = [0; 1500];
|
||||||
data[5] = 45;
|
data[5] = 45;
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
Frame::parse(&data).unwrap()
|
ethernet::Frame::parse(&data).unwrap()
|
||||||
});
|
});
|
||||||
b.bytes = 1400;
|
b.bytes = 1400;
|
||||||
}
|
}
|
||||||
|
@ -127,30 +128,37 @@ fn ipv6_parse(b: &mut Bencher) {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn now(b: &mut Bencher) {
|
fn now(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
util_now()
|
SystemTimeSource::now()
|
||||||
});
|
});
|
||||||
b.bytes = 1400;
|
b.bytes = 1400;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn epoll_wait(b: &mut Bencher) {
|
fn epoll_wait(b: &mut Bencher) {
|
||||||
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
let socketv4 = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||||
let mut poll_handle = Poll::new(1).unwrap();
|
let socketv6 = UdpSocket::bind("[::]:0").unwrap();
|
||||||
let fd = socket.as_raw_fd();
|
let device = TunTapDevice::dummy("dummy", "/dev/zero", Type::Dummy).unwrap();
|
||||||
poll_handle.register(fd, Flags::WRITE).unwrap();
|
let mut waiter = WaitImpl::testing(&socketv4, &socketv6, &device, 1000).unwrap();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
assert_eq!(poll_handle.wait(1000).unwrap().len(), 1)
|
assert!(waiter.next().is_some())
|
||||||
});
|
});
|
||||||
b.bytes = 1400;
|
b.bytes = 1400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestNode = GenericCloud<TunTapDevice, ethernet::Frame, SwitchTable<MockTimeSource>, MockSocket, MockTimeSource>;
|
||||||
|
|
||||||
|
fn create_test_node() -> TestNode {
|
||||||
|
TestNode::new(
|
||||||
|
&Config::default(),
|
||||||
|
TunTapDevice::dummy("dummy", "/dev/null", Type::Tap).unwrap(),
|
||||||
|
SwitchTable::new(1800, 10),
|
||||||
|
true, true, vec![], Crypto::None, None
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn handle_interface_data(b: &mut Bencher) {
|
fn handle_interface_data(b: &mut Bencher) {
|
||||||
let config = Config::default();
|
let mut node = create_test_node();
|
||||||
let mut node = GenericCloud::<Frame, SwitchTable>::new(
|
|
||||||
&config, Device::dummy("vpncloud0", "/dev/null", Type::Tap).unwrap(),
|
|
||||||
SwitchTable::new(300, 10), true, true, vec![], Crypto::None, None
|
|
||||||
);
|
|
||||||
let mut data = [0; 1500];
|
let mut data = [0; 1500];
|
||||||
data[105] = 45;
|
data[105] = 45;
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
|
@ -161,11 +169,7 @@ fn handle_interface_data(b: &mut Bencher) {
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn handle_net_message(b: &mut Bencher) {
|
fn handle_net_message(b: &mut Bencher) {
|
||||||
let config = Config::default();
|
let mut node = create_test_node();
|
||||||
let mut node = GenericCloud::<Frame, SwitchTable>::new(
|
|
||||||
&config, Device::dummy("vpncloud0", "/dev/null", Type::Tap).unwrap(),
|
|
||||||
SwitchTable::new(300, 10), true, true, vec![], Crypto::None, None
|
|
||||||
);
|
|
||||||
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 1));
|
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 1));
|
||||||
let mut data = [0; 1500];
|
let mut data = [0; 1500];
|
||||||
data[105] = 45;
|
data[105] = 45;
|
||||||
|
|
|
@ -23,6 +23,14 @@ pub struct EpollWait {
|
||||||
|
|
||||||
impl EpollWait {
|
impl EpollWait {
|
||||||
pub fn new<S: Socket>(socketv4: &S, socketv6: &S, device: &Device, timeout: u32) -> io::Result<Self> {
|
pub fn new<S: Socket>(socketv4: &S, socketv6: &S, device: &Device, timeout: u32) -> io::Result<Self> {
|
||||||
|
Self::create(socketv4, socketv6, device, timeout, libc::EPOLLIN as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn testing<S: Socket>(socketv4: &S, socketv6: &S, device: &Device, timeout: u32) -> io::Result<Self> {
|
||||||
|
Self::create(socketv4, socketv6, device, timeout, ( libc::EPOLLIN | libc::EPOLLOUT ) as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create<S: Socket>(socketv4: &S, socketv6: &S, device: &Device, timeout: u32, flags: u32) -> io::Result<Self> {
|
||||||
let mut event = libc::epoll_event{u64: 0, events: 0};
|
let mut event = libc::epoll_event{u64: 0, events: 0};
|
||||||
let poll_fd = unsafe { libc::epoll_create(3) };
|
let poll_fd = unsafe { libc::epoll_create(3) };
|
||||||
if poll_fd == -1 {
|
if poll_fd == -1 {
|
||||||
|
@ -35,7 +43,7 @@ impl EpollWait {
|
||||||
};
|
};
|
||||||
for fd in raw_fds {
|
for fd in raw_fds {
|
||||||
event.u64 = fd as u64;
|
event.u64 = fd as u64;
|
||||||
event.events = libc::EPOLLIN as u32;
|
event.events = flags;
|
||||||
let res = unsafe { libc::epoll_ctl(poll_fd, libc::EPOLL_CTL_ADD, fd, &mut event) };
|
let res = unsafe { libc::epoll_ctl(poll_fd, libc::EPOLL_CTL_ADD, fd, &mut event) };
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
return Err(io::Error::last_os_error());
|
return Err(io::Error::last_os_error());
|
||||||
|
|
|
@ -20,6 +20,7 @@ macro_rules! assert_message4 {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! assert_message6 {
|
macro_rules! assert_message6 {
|
||||||
($from: expr, $from_addr: expr, $to: expr, $to_addr: expr, $message: expr) => {
|
($from: expr, $from_addr: expr, $to: expr, $to_addr: expr, $message: expr) => {
|
||||||
let (addr, mut data) = msg6_get(&mut $from);
|
let (addr, mut data) = msg6_get(&mut $from);
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub use super::ip::{self, RoutingTable};
|
||||||
type TestNode<P, T> = GenericCloud<MockDevice, P, T, MockSocket, MockTimeSource>;
|
type TestNode<P, T> = GenericCloud<MockDevice, P, T, MockSocket, MockTimeSource>;
|
||||||
|
|
||||||
type TapTestNode = TestNode<ethernet::Frame, SwitchTable<MockTimeSource>>;
|
type TapTestNode = TestNode<ethernet::Frame, SwitchTable<MockTimeSource>>;
|
||||||
|
#[allow(dead_code)]
|
||||||
type TunTestNode = TestNode<ip::Packet, RoutingTable>;
|
type TunTestNode = TestNode<ip::Packet, RoutingTable>;
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ fn create_tap_node() -> TapTestNode {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn create_tun_node(addresses: Vec<Range>) -> TunTestNode {
|
fn create_tun_node(addresses: Vec<Range>) -> TunTestNode {
|
||||||
TestNode::new(
|
TestNode::new(
|
||||||
&Config { port: NEXT_PORT.with(|p| p.fetch_add(1, Ordering::Relaxed)) as u16, ..Config::default() },
|
&Config { port: NEXT_PORT.with(|p| p.fetch_add(1, Ordering::Relaxed)) as u16, ..Config::default() },
|
||||||
|
@ -56,6 +58,7 @@ fn msg4_get<P: Protocol, T: Table>(node: &mut TestNode<P, T>) -> (SocketAddr, Ve
|
||||||
msg.unwrap()
|
msg.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn msg6_get<P: Protocol, T: Table>(node: &mut TestNode<P, T>) -> (SocketAddr, Vec<u8>) {
|
fn msg6_get<P: Protocol, T: Table>(node: &mut TestNode<P, T>) -> (SocketAddr, Vec<u8>) {
|
||||||
let msg = node.socket6().pop_outbound();
|
let msg = node.socket6().pop_outbound();
|
||||||
assert!(msg.is_some());
|
assert!(msg.is_some());
|
||||||
|
|
Loading…
Reference in New Issue