Compare commits

..

2 Commits

Author SHA1 Message Date
Dennis Schwerdel 73fd3134a5 Build chain for deb packages 2019-03-01 16:37:43 +01:00
Dennis Schwerdel c5ba4b197b Improved tests 2019-03-01 16:36:18 +01:00
9 changed files with 141 additions and 7 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ deb/vpncloud/vpncloud
deb/vpncloud/vpncloud.1* deb/vpncloud/vpncloud.1*
Stats.ods Stats.ods
dist dist
builder/cache

2
builder/.dockerignore Normal file
View File

@ -0,0 +1,2 @@
cache
build.sh

27
builder/Dockerfile-deb Normal file
View File

@ -0,0 +1,27 @@
FROM debian:stable
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl ruby-ronn build-essential gcc-arm-linux-gnueabihf libc6-dev-armhf-cross \
&& rm -rf /var/cache/dpkg
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user
ENV RUST=1.32.0
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST}
ENV PATH=/home/user/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN rustup target add i686-unknown-linux-gnu \
&& rustup target add armv7-unknown-linux-gnueabihf
RUN cargo install cargo-deb \
&& rm -rf /home/user/.cargo/{git,tmp,registry}
VOLUME /home/user/.cargo/tmp
VOLUME /home/user/.cargo/git
VOLUME /home/user/.cargo/registry

32
builder/build.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
function docker_cmd() {
DIST=$1
CMD=$2
docker run -it --rm -v $(pwd)/..:/home/user/code \
-v $CACHE/registry:/home/user/.cargo/registry \
-v $CACHE/git:/home/user/.cargo/git \
-v $CACHE/tmp:/home/user/.cargo/tmp \
vpncloud-builder-$DIST bash -c "$CMD"
}
set -e
cd $(dirname $0)
VERSION=$(grep -e '^version =' ../Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
mkdir -p cache/{git,tmp,registry}
CACHE=$(pwd)/cache
mkdir -p ../dist
docker build --rm -f=Dockerfile-deb -t vpncloud-builder-deb .
# x86_64 deb
docker_cmd deb 'cd code && cargo deb'
cp ../target/debian/vpncloud_${VERSION}_amd64.deb ../dist/vpncloud_${VERSION}_amd64.deb
# arm7hf deb
docker_cmd deb 'cd code && cargo deb --target armv7-unknown-linux-gnueabihf'
cp ../target/armv7-unknown-linux-gnueabihf/debian/vpncloud_${VERSION}_armhf.deb ../dist/vpncloud_${VERSION}_armhf.deb

View File

@ -12,7 +12,7 @@ use std::marker::PhantomData;
use fnv::FnvHasher; use fnv::FnvHasher;
use super::types::{Error, Table, Protocol, Address}; use super::types::{Error, Table, Protocol, Address};
use super::util::{TimeSource, Time, Duration, MockTimeSource}; use super::util::{TimeSource, Time, Duration};
/// An ethernet frame dissector /// An ethernet frame dissector
/// ///
@ -165,6 +165,7 @@ impl<TS: TimeSource> Table for SwitchTable<TS> {
#[cfg(test)] use std::str::FromStr; #[cfg(test)] use std::str::FromStr;
#[cfg(test)] use std::net::ToSocketAddrs; #[cfg(test)] use std::net::ToSocketAddrs;
#[cfg(test)] use super::util::MockTimeSource;
#[test] #[test]
fn decode_frame_without_vlan() { fn decode_frame_without_vlan() {

View File

@ -3,10 +3,11 @@
// This software is licensed under GPL-3 or newer (see LICENSE.md) // This software is licensed under GPL-3 or newer (see LICENSE.md)
#[macro_use] mod helper; #[macro_use] mod helper;
mod connect; mod peers;
mod payload; mod payload;
pub use std::net::SocketAddr; pub use std::net::SocketAddr;
use std::sync::atomic::{Ordering, AtomicUsize};
pub use super::ethernet::{self, SwitchTable}; pub use super::ethernet::{self, SwitchTable};
pub use super::util::MockTimeSource; pub use super::util::MockTimeSource;
@ -26,9 +27,13 @@ type TapTestNode = TestNode<ethernet::Frame, SwitchTable<MockTimeSource>>;
type TunTestNode = TestNode<ip::Packet, RoutingTable>; type TunTestNode = TestNode<ip::Packet, RoutingTable>;
thread_local! {
static NEXT_PORT: AtomicUsize = AtomicUsize::new(1);
}
fn create_tap_node() -> TapTestNode { fn create_tap_node() -> TapTestNode {
TestNode::new( TestNode::new(
&Config::default(), &Config { port: NEXT_PORT.with(|p| p.fetch_add(1, Ordering::Relaxed)) as u16, ..Config::default() },
MockDevice::new(), MockDevice::new(),
SwitchTable::new(1800, 10), SwitchTable::new(1800, 10),
true, true, vec![], Crypto::None, None true, true, vec![], Crypto::None, None
@ -37,7 +42,7 @@ fn create_tap_node() -> TapTestNode {
fn create_tun_node(addresses: Vec<Range>) -> TunTestNode { fn create_tun_node(addresses: Vec<Range>) -> TunTestNode {
TestNode::new( TestNode::new(
&Config::default(), &Config { port: NEXT_PORT.with(|p| p.fetch_add(1, Ordering::Relaxed)) as u16, ..Config::default() },
MockDevice::new(), MockDevice::new(),
RoutingTable::new(), RoutingTable::new(),
false, false, addresses, Crypto::None, None false, false, addresses, Crypto::None, None

View File

@ -5,7 +5,7 @@
use super::*; use super::*;
#[test] #[test]
fn ethernet_send() { fn ethernet_delivers() {
let mut node1 = create_tap_node(); let mut node1 = create_tap_node();
let node1_addr = addr!("1.2.3.4:5678"); let node1_addr = addr!("1.2.3.4:5678");
let mut node2 = create_tap_node(); let mut node2 = create_tap_node();
@ -27,7 +27,7 @@ fn ethernet_send() {
} }
#[test] #[test]
fn learning_switch() { fn switch_learns() {
let mut node1 = create_tap_node(); let mut node1 = create_tap_node();
let node1_addr = addr!("1.2.3.4:5678"); let node1_addr = addr!("1.2.3.4:5678");
let mut node2 = create_tap_node(); let mut node2 = create_tap_node();
@ -42,6 +42,8 @@ fn learning_switch() {
let payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5]; let payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
// Nothing learnt so far, node1 broadcasts
node1.device().put_inbound(payload.clone()); node1.device().put_inbound(payload.clone());
simulate!(node1 => node1_addr, node2 => node2_addr, node3 => node3_addr); simulate!(node1 => node1_addr, node2 => node2_addr, node3 => node3_addr);
@ -51,6 +53,8 @@ fn learning_switch() {
let payload = vec![1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 5, 4, 3, 2, 1]; let payload = vec![1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 5, 4, 3, 2, 1];
// Node 2 learned the address by receiving it, does not broadcast
node2.device().put_inbound(payload.clone()); node2.device().put_inbound(payload.clone());
simulate!(node1 => node1_addr, node2 => node2_addr, node3 => node3_addr); simulate!(node1 => node1_addr, node2 => node2_addr, node3 => node3_addr);
@ -59,4 +63,24 @@ fn learning_switch() {
assert_clean!(node3); assert_clean!(node3);
assert_clean!(node1, node2, node3); assert_clean!(node1, node2, node3);
}
#[test]
fn switch_honours_vlans() {
//TODO
}
#[test]
fn switch_forgets() {
//TODO
}
#[test]
fn router_delivers() {
//TODO
}
#[test]
fn router_drops_unknown_dest() {
//TODO
} }

View File

@ -90,5 +90,46 @@ fn cross_connect() {
assert_connected!(node3, node2); assert_connected!(node3, node2);
// transient connections 2nd degree // transient connections 2nd degree
assert_connected!(node1, node4); assert_connected!(node2, node4);
} }
#[test]
fn connect_via_beacons() {
//TODO
}
#[test]
fn reconnect_after_timeout() {
//TODO
}
#[test]
fn lost_init1() {
//TODO
}
#[test]
fn wrong_magic() {
//TODO
}
#[test]
fn peer_exchange() {
//TODO
}
#[test]
fn lost_peer_exchange() {
//TODO
}
#[test]
fn remove_dead_peers() {
//TODO
}
#[test]
fn update_primary_address() {
//TODO
}

View File

@ -129,6 +129,7 @@ pub fn resolve<Addr: ToSocketAddrs+fmt::Debug>(addr: Addr) -> Result<Vec<SocketA
Ok(addrs) Ok(addrs)
} }
#[allow(unused_macros)]
macro_rules! addr { macro_rules! addr {
($addr: expr) => { ($addr: expr) => {
{ {