Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve integration tests, fix bugs in rita #34

Merged
merged 40 commits into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c3fdb7d
implement Debug for num256
jtremback Jan 25, 2018
31473ab
add to gitignore
jtremback Jan 25, 2018
c934e20
remove more useless logs
jtremback Jan 25, 2018
3d496d0
clean up logs
jtremback Jan 25, 2018
6c00bc7
refactor to more of a actor model
jtremback Jan 26, 2018
d86e1a1
WIP cleanup, fix bugs
jtremback Jan 27, 2018
5e81251
merge changes from patch
kingoflolz Jan 27, 2018
8be20f7
fix bug with crediting instead of debiting neighbour
kingoflolz Jan 27, 2018
17c231a
add bridge interface to nodes 1 and 3 in integration test
kingoflolz Jan 27, 2018
578a39d
add python script to create network topologies
kingoflolz Jan 28, 2018
12da134
fleshing out rita.py, almost feature complete
kingoflolz Jan 29, 2018
cbd8e6c
add neighbour hello retry feature
kingoflolz Jan 29, 2018
c10394c
integration-tests: start using sudo internally (#28)
drozdziak1 Jan 30, 2018
ef57811
make rita.sh use the new python script
jtremback Jan 31, 2018
84957b7
Make debt keeper tests pass
jtremback Jan 31, 2018
505b46e
fix test for payment controller
jtremback Jan 31, 2018
007f2cc
add first test to python framework (reachability)
kingoflolz Jan 31, 2018
4772f3b
Add scaffolding for traffic accounting tests
kingoflolz Jan 31, 2018
57e3dc5
Change where deps are pulled for network lab to my fork
kingoflolz Jan 31, 2018
40b57e6
traffic gen improvements
kingoflolz Feb 1, 2018
7fc8b69
Fix babel pricing quirk
kingoflolz Feb 1, 2018
8ff0441
Refactor debtkeeper to enable easier addition of per node data
kingoflolz Feb 1, 2018
e1fc00f
add fudge factor to debt calculations
kingoflolz Feb 1, 2018
1123cb4
refix babel price quirk
kingoflolz Feb 1, 2018
2537261
Refactor payment controller for more consistent API
kingoflolz Feb 2, 2018
ad0190f
Merge branch 'fix-rita-billing' into improve-integration-tests
kingoflolz Feb 2, 2018
923957c
Send updates to bounty hunter occasionally
kingoflolz Feb 2, 2018
3db79d3
Add traffic test
kingoflolz Feb 2, 2018
a80f7f7
Fix traffic accounting bugs and increase robustness of rita
kingoflolz Feb 3, 2018
55e7ae0
Add traffic integration tests
kingoflolz Feb 3, 2018
4a0cff9
Add more From impls to Int256
kingoflolz Feb 5, 2018
aeef816
Make traffic counters atomic
kingoflolz Feb 5, 2018
c81be23
Fix bugs in debt keeper and traffic watcher, make watching atomic
kingoflolz Feb 5, 2018
afff14d
updated integration test script
kingoflolz Feb 5, 2018
524307b
implement debt buffering
kingoflolz Feb 7, 2018
9f1e0aa
update test cases
kingoflolz Feb 7, 2018
32ded9d
add suspension integration test
kingoflolz Feb 7, 2018
2e3b074
make travis run integration tests
kingoflolz Feb 7, 2018
d112c72
make build more robust
kingoflolz Feb 7, 2018
15d178b
fix nits
kingoflolz Feb 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.DS_Store
*.bak
/target/
target-mac
**/*.rs.bk
.idea
integration_test/test.db
integration-tests/test.db
bounty_hunter/test.db
test.db-journal
*.log
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
language: rust
cache: cargo
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y ebtables libsqlite3-dev iperf3 python3-pip bridge-utils
- sudo pip3 install termcolor
- which diesel || cargo install diesel_cli --no-default-features --features sqlite
env:
- TYPE=build
- TYPE=test RUST_TEST_THREADS=1
- TEST_COMMAND="cargo build --verbose --all"
- TEST_COMMAND="cargo test --verbose --all" RUST_TEST_THREADS=1
- TEST_COMMAND="./integration-tests/rita.sh"
rust:
- stable
- beta
- nightly
script:
- cargo $TYPE --verbose --all
- (eval "$TEST_COMMAND")
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ use super::{KernelInterface, Error};

use std::net::{IpAddr};

use eui48::MacAddress;

impl KernelInterface {
pub fn delete_destination_counter_linux(
&mut self,
des_neighbor: MacAddress,
destination: IpAddr,
) -> Result<(), Error> {
self.delete_ebtables_rule(&[
"-D",
"OUTPUT",
"-d",
&format!("{}", des_neighbor.to_hex_string()),
"-p",
"IPV6",
"--ip6-dst",
&format!("{}", destination),
"-j",
"CONTINUE",
"ACCEPT",
])
}

}
44 changes: 17 additions & 27 deletions althea_kernel_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ impl KernelInterface {
/// Implemented with `ebtables` on linux.
pub fn start_destination_counter(
&mut self,
des_neighbor: MacAddress,
destination: IpAddr,
) -> Result<(), Error> {
if cfg!(target_os = "linux") {
return self.start_destination_counter_linux(destination);
return self.start_destination_counter_linux(des_neighbor, destination);
}

Err(Error::RuntimeError(
Expand All @@ -102,18 +103,18 @@ impl KernelInterface {
/// Implemented with `ebtables` on linux.
pub fn delete_destination_counter(
&mut self,
des_neighbor: MacAddress,
destination: IpAddr,
) -> Result<(), Error> {
if cfg!(target_os = "linux") {
return self.delete_destination_counter_linux(destination);
return self.delete_destination_counter_linux(des_neighbor, destination);
}

Err(Error::RuntimeError(
String::from("not implemented for this platform"),
))
}


/// This starts a counter of the bytes used by a particular "flow", a
/// Neighbor/Destination pair. If the flow already exists, it resets the counter.
/// Implemented with `ebtables` on linux.
Expand Down Expand Up @@ -151,9 +152,9 @@ impl KernelInterface {
/// Returns a vector of traffic coming from a specific hardware address and going
/// to a specific IP. Note that this will only track flows that have already been
/// registered. Implemented with `ebtables` on Linux.
pub fn read_flow_counters(&mut self) -> Result<Vec<(MacAddress, IpAddr, u64)>, Error> {
pub fn read_flow_counters(&mut self, zero: bool) -> Result<Vec<(MacAddress, IpAddr, u64)>, Error> {
if cfg!(target_os = "linux") {
return self.read_flow_counters_linux();
return self.read_flow_counters_linux(zero);
}

Err(Error::RuntimeError(
Expand All @@ -164,9 +165,9 @@ impl KernelInterface {
/// Returns a vector of going to a specific IP address.
/// Note that this will only track flows that have already been
/// registered. Implemented with `ebtables` on Linux.
pub fn read_destination_counters(&mut self) -> Result<Vec<(IpAddr, u64)>, Error> {
pub fn read_destination_counters(&mut self, zero: bool) -> Result<Vec<(MacAddress, IpAddr, u64)>, Error> {
if cfg!(target_os = "linux") {
return self.read_destination_counters_linux();
return self.read_destination_counters_linux(zero);
}

Err(Error::RuntimeError(
Expand Down Expand Up @@ -302,7 +303,7 @@ Bridge chain: INPUT, entries: 3, policy: ACCEPT
}),
};

let traffic = ki.read_flow_counters_linux().unwrap();
let traffic = ki.read_flow_counters_linux(false).unwrap();

assert_eq!(format!("{}", traffic[0].0), "00-00-00-aa-00-02");
assert_eq!(format!("{}", traffic[0].1), "2001::1");
Expand Down Expand Up @@ -412,18 +413,6 @@ Bridge chain: INPUT, entries: 3, policy: ACCEPT
#[test]
fn test_start_flow_counter_linux() {
let mut counter = 0;
let delete_rule = &[
"-D",
"INPUT",
"-s",
"00:00:00:aa:00:02",
"-p",
"IPV6",
"--ip6-dst",
"2001::3",
"-j",
"CONTINUE",
];
let add_rule = &[
"-A",
"INPUT",
Expand All @@ -443,14 +432,15 @@ Bridge chain: INPUT, entries: 3, policy: ACCEPT
counter = counter + 1;
println!("COUNTER {}", counter);
match counter {
1 => {
assert_eq!(args, delete_rule);
Ok(Output {
stdout: b"Sorry, rule does not exist.".to_vec(),
1 => { Ok(Output {
stdout:
b"Bridge table: filter

Bridge chain: INPUT, entries: 3, policy: ACCEPT
"
.to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
status: ExitStatus::from_raw(0)})}
2 => {
assert_eq!(args, add_rule);
Ok(Output {
Expand Down
20 changes: 14 additions & 6 deletions althea_kernel_interface/src/read_destination_counters_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ use super::{KernelInterface, Error};
use std::net::{IpAddr};
use std::str::FromStr;

use eui48::MacAddress;
use regex::Regex;

impl KernelInterface {
pub fn read_destination_counters_linux(&mut self) -> Result<Vec<(IpAddr, u64)>, Error> {
let output = self.run_command("ebtables", &["-L", "OUTPUT", "--Lc", "--Lmac2"])?;
pub fn read_destination_counters_linux(&mut self, zero: bool) -> Result<Vec<(MacAddress, IpAddr, u64)>, Error> {
let output = if zero {
self.run_command("ebtables", &["-L", "-Z", "OUTPUT", "--Lc", "--Lmac2"])?
} else {
self.run_command("ebtables", &["-L", "OUTPUT", "--Lc", "--Lmac2"])?
};
let mut vec = Vec::new();
let re = Regex::new(r"-p IPv6 --ip6-dst (.*)/.* bcnt = (.*)").unwrap();
let re = Regex::new(r"-p IPv6 -d (.*) --ip6-dst (.*)/.* bcnt = (.*)").unwrap();
for caps in re.captures_iter(&String::from_utf8(output.stdout)?) {
vec.push((
IpAddr::from_str(&caps[1])?,
caps[2].parse::<u64>()?,
MacAddress::parse_str(&caps[1]).unwrap_or_else(|e| {
panic!("{:?}, original string {:?}", e, caps);
}), // Ugly and inconsiderate, remove ASAP
IpAddr::from_str(&caps[2])?,
caps[3].parse::<u64>()?,
));
}
trace!("Read destination couters {:?}", &vec);
trace!("Read destination counters {:?}", &vec);
Ok(vec)
}

Expand Down
8 changes: 6 additions & 2 deletions althea_kernel_interface/src/read_flow_counters_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ use eui48::MacAddress;
use regex::Regex;

impl KernelInterface {
pub fn read_flow_counters_linux(&mut self) -> Result<Vec<(MacAddress, IpAddr, u64)>, Error> {
let output = self.run_command("ebtables", &["-L", "INPUT", "--Lc", "--Lmac2"])?;
pub fn read_flow_counters_linux(&mut self, zero: bool) -> Result<Vec<(MacAddress, IpAddr, u64)>, Error> {
let output = if zero {
self.run_command("ebtables", &["-L", "-Z", "INPUT", "--Lc", "--Lmac2"])?
} else {
self.run_command("ebtables", &["-L", "INPUT", "--Lc", "--Lmac2"])?
};
let mut vec = Vec::new();
let re = Regex::new(r"-s (.*) --ip6-dst (.*)/.* bcnt = (.*)").unwrap();
for caps in re.captures_iter(&String::from_utf8(output.stdout)?) {
Expand Down
47 changes: 32 additions & 15 deletions althea_kernel_interface/src/start_destination_counter_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,39 @@ use super::{Error, KernelInterface};

use std::net::{IpAddr};

use eui48::MacAddress;

impl KernelInterface {
pub fn start_destination_counter_linux(&mut self, destination: IpAddr) -> Result<(), Error> {
self.delete_destination_counter_linux(destination)?;
self.run_command(
"ebtables",
&[
"-A",
"OUTPUT",
"-p",
"IPV6",
"--ip6-dst",
&format!("{}", destination),
"-j",
"CONTINUE",
],
)?;
pub fn start_destination_counter_linux(
&mut self,
des_neighbor: MacAddress,
destination: IpAddr,
) -> Result<(), Error> {
let ctr = self.read_destination_counters(false)?;
let mut exists = false;
for (mac, ip, _) in ctr {
if (mac == des_neighbor) && (ip == destination) {
exists = true;
}
}
trace!("rule exists: {:?}", exists);
if !exists {
self.run_command(
"ebtables",
&[
"-A",
"OUTPUT",
"-d",
&format!("{}", des_neighbor.to_hex_string()),
"-p",
"IPV6",
"--ip6-dst",
&format!("{}", destination),
"-j",
"ACCEPT",
],
)?;
}
Ok(())
}
}
41 changes: 25 additions & 16 deletions althea_kernel_interface/src/start_flow_counter_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ impl KernelInterface {
source_neighbor: MacAddress,
destination: IpAddr,
) -> Result<(), Error> {
self.delete_flow_counter_linux(source_neighbor, destination)?;
self.run_command(
"ebtables",
&[
"-A",
"INPUT",
"-s",
&format!("{}", source_neighbor.to_hex_string()),
"-p",
"IPV6",
"--ip6-dst",
&format!("{}", destination),
"-j",
"CONTINUE",
],
)?;
let ctr = self.read_flow_counters(false)?;
let mut exists = false;
for (mac, ip, _) in ctr {
if (mac == source_neighbor) && (ip == destination) {
exists = true;
}
}
trace!("rule exists: {:?}", exists);
if !exists {
self.run_command(
"ebtables",
&[
"-A",
"INPUT",
"-s",
&format!("{}", source_neighbor.to_hex_string()),
"-p",
"IPV6",
"--ip6-dst",
&format!("{}", destination),
"-j",
"CONTINUE",
],
)?;
}
Ok(())
}
}
8 changes: 4 additions & 4 deletions babel_monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct Route {
}

#[derive(Debug)]
pub struct Neighbour {
pub struct Neighbor {
pub id: String,
pub iface: String,
pub reach: u16,
Expand Down Expand Up @@ -138,12 +138,12 @@ impl<T: Read + Write> InnerBabel<T> {
}


pub fn parse_neighs(&mut self) -> Result<VecDeque<Neighbour>, Error> {
let mut vector: VecDeque<Neighbour> = VecDeque::with_capacity(5);
pub fn parse_neighs(&mut self) -> Result<VecDeque<Neighbor>, Error> {
let mut vector: VecDeque<Neighbor> = VecDeque::with_capacity(5);
self.write("dump\n")?;
for entry in self.read()?.split("\n") {
if entry.contains("add neighbour") {
vector.push_back(Neighbour {
vector.push_back(Neighbor {
id: find_babel_val("neighbour", entry)?,
iface: find_babel_val("if", entry)?,
reach: u16::from_str_radix(&find_babel_val("reach", entry)?, 16)?,
Expand Down
Binary file removed bounty_hunter/test.db
Binary file not shown.
3 changes: 1 addition & 2 deletions integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.log
*.pid
/deps/
.cache
.vagrant
/babeld/
/deps/
Loading