Skip to content

Commit

Permalink
fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkirishcoder committed Jan 8, 2022
1 parent fda00b8 commit bfeb7a9
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 166 deletions.
124 changes: 62 additions & 62 deletions bench/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use anyhow::Result;
use capsule::fieldmap;
use capsule::packets::ethernet::Ethernet;
use capsule::packets::ip::v4::Ipv4;
use capsule::packets::ip::v6::{Ipv6, SegmentRouting};
use capsule::packets::ip::v4::Ip4;
use capsule::packets::ip::v6::{Ip6, SegmentRouting};
use capsule::packets::udp::Udp4;
use capsule::packets::{Mbuf, Packet};
use capsule::testils::criterion::BencherExt;
Expand All @@ -32,30 +32,30 @@ use std::net::Ipv6Addr;

const BATCH_SIZE: usize = 500;

fn single_parse_udp(ipv4: Ipv4) -> Udp4 {
ipv4.parse::<Udp4>().unwrap()
fn single_parse_udp(ip4: Ip4) -> Udp4 {
ip4.parse::<Udp4>().unwrap()
}

fn single_peek_udp(ipv4: Ipv4) -> Ipv4 {
ipv4.peek::<Udp4>().unwrap();
ipv4
fn single_peek_udp(ip4: Ip4) -> Ip4 {
ip4.peek::<Udp4>().unwrap();
ip4
}

#[capsule::bench(mempool_capacity = 511)]
fn single_peek_vs_parse(c: &mut Criterion) {
let mut group = c.benchmark_group("packets::single_peek_vs_parse_on_udp");

group.bench_function("packets::single_parse_udp", |b| {
let s = v4_udp().prop_map(|v| {
let packet = v.into_v4_udp();
let s = udp4().prop_map(|v| {
let packet = v.into_udp4();
packet.deparse()
});
b.iter_proptest_batched(s, single_parse_udp, BATCH_SIZE)
});

group.bench_function("packets::single_peek_udp", |b| {
let s = v4_udp().prop_map(|v| {
let packet = v.into_v4_udp();
let s = udp4().prop_map(|v| {
let packet = v.into_udp4();
packet.deparse()
});
b.iter_proptest_batched(s, single_peek_udp, BATCH_SIZE)
Expand All @@ -66,14 +66,14 @@ fn single_peek_vs_parse(c: &mut Criterion) {

fn multi_parse_udp(mbuf: Mbuf) -> Udp4 {
let ethernet = mbuf.parse::<Ethernet>().unwrap();
let ipv4 = ethernet.parse::<Ipv4>().unwrap();
ipv4.parse::<Udp4>().unwrap()
let ip4 = ethernet.parse::<Ip4>().unwrap();
ip4.parse::<Udp4>().unwrap()
}

fn multi_peek_udp(mbuf: Mbuf) -> Mbuf {
let ethernet = mbuf.peek::<Ethernet>().unwrap();
let ipv4 = ethernet.peek::<Ipv4>().unwrap();
ipv4.peek::<Udp4>().unwrap();
let ip4 = ethernet.peek::<Ip4>().unwrap();
ip4.peek::<Udp4>().unwrap();
mbuf
}

Expand All @@ -82,70 +82,70 @@ fn multi_peek_vs_parse(c: &mut Criterion) {
let mut group = c.benchmark_group("packets::multi_peek_vs_parse_on_udp_packets");

group.bench_function("packets::multi_parse_udp", |b| {
let s = v4_udp();
let s = udp4();
b.iter_proptest_batched(s, multi_parse_udp, BATCH_SIZE)
});

group.bench_function("packets::multi_peek_udp", |b| {
let s = v4_udp();
let s = udp4();
b.iter_proptest_batched(s, multi_peek_udp, BATCH_SIZE)
});

group.finish()
}

fn single_parse_srh(ipv6: Ipv6) -> SegmentRouting<Ipv6> {
ipv6.parse::<SegmentRouting<Ipv6>>().unwrap()
fn single_parse_sr(ip6: Ip6) -> SegmentRouting<Ip6> {
ip6.parse::<SegmentRouting<Ip6>>().unwrap()
}

#[capsule::bench(mempool_capacity = 511)]
fn single_parse_srh_segments_sizes(c: &mut Criterion) {
let mut group = c.benchmark_group("packets::parsing_on_SRH_across_segment_sizes");
fn single_parse_sr_segments_sizes(c: &mut Criterion) {
let mut group = c.benchmark_group("packets::parsing_on_sr_across_segment_sizes");

let mut rvg = Rvg::new();

group.bench_function("packets::single_parse_srh::size=1", |b| {
group.bench_function("packets::single_parse_sr::size=1", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 1);
let s = sr_tcp_with(fieldmap! {field::sr_segments => segments})
.prop_map(|v| v.into_sr().deparse());
b.iter_proptest_batched(s, single_parse_srh, BATCH_SIZE)
b.iter_proptest_batched(s, single_parse_sr, BATCH_SIZE)
});

group.bench_function("packets::single_parse_srh::size=2", |b| {
group.bench_function("packets::single_parse_sr::size=2", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 2);
let s = sr_tcp_with(fieldmap! {field::sr_segments => segments})
.prop_map(|v| v.into_sr().deparse());
b.iter_proptest_batched(s, single_parse_srh, BATCH_SIZE)
b.iter_proptest_batched(s, single_parse_sr, BATCH_SIZE)
});

group.bench_function("packets::single_parse_srh::size=4", |b| {
group.bench_function("packets::single_parse_sr::size=4", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 4);
let s = sr_tcp_with(fieldmap! {field::sr_segments => segments})
.prop_map(|v| v.into_sr().deparse());
b.iter_proptest_batched(s, single_parse_srh, BATCH_SIZE)
b.iter_proptest_batched(s, single_parse_sr, BATCH_SIZE)
});

group.bench_function("packets::single_parse_srh::size=8", |b| {
group.bench_function("packets::single_parse_sr::size=8", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 8);
let s = sr_tcp_with(fieldmap! {field::sr_segments => segments})
.prop_map(|v| v.into_sr().deparse());
b.iter_proptest_batched(s, single_parse_srh, BATCH_SIZE)
b.iter_proptest_batched(s, single_parse_sr, BATCH_SIZE)
});

group.finish()
}

fn multi_parse_srh(mbuf: Mbuf) -> SegmentRouting<Ipv6> {
fn multi_parse_sr(mbuf: Mbuf) -> SegmentRouting<Ip6> {
let ethernet = mbuf.parse::<Ethernet>().unwrap();
let ipv6 = ethernet.parse::<Ipv6>().unwrap();
ipv6.parse::<SegmentRouting<Ipv6>>().unwrap()
let ip6 = ethernet.parse::<Ip6>().unwrap();
ip6.parse::<SegmentRouting<Ip6>>().unwrap()
}

#[capsule::bench(mempool_capacity = 511)]
fn multi_parse_upto_variable_srh(c: &mut Criterion) {
c.bench_function("packets::multi_parse_srh", |b| {
fn multi_parse_upto_variable_sr(c: &mut Criterion) {
c.bench_function("packets::multi_parse_sr", |b| {
let s = sr_tcp();
b.iter_proptest_batched(s, multi_parse_srh, BATCH_SIZE)
b.iter_proptest_batched(s, multi_parse_sr, BATCH_SIZE)
});
}

Expand All @@ -158,7 +158,7 @@ fn deparse_udp(udp: Udp4) -> Mbuf {
#[capsule::bench(mempool_capacity = 511)]
fn deparse(c: &mut Criterion) {
c.bench_function("packets::deparse_udp", |b| {
let s = v4_udp().prop_map(|v| v.into_v4_udp());
let s = udp4().prop_map(|v| v.into_udp4());
b.iter_proptest_batched(s, deparse_udp, BATCH_SIZE)
});
}
Expand All @@ -170,15 +170,15 @@ fn reset_udp(udp: Udp4) -> Mbuf {
#[capsule::bench(mempool_capacity = 511)]
fn reset(c: &mut Criterion) {
c.bench_function("packets::reset_udp", |b| {
let s = v4_udp().prop_map(|v| v.into_v4_udp());
let s = udp4().prop_map(|v| v.into_udp4());
b.iter_proptest_batched(s, reset_udp, BATCH_SIZE)
});
}

fn multi_push_udp(mbuf: Mbuf) -> Udp4 {
let ethernet = mbuf.push::<Ethernet>().unwrap();
let ipv4 = ethernet.push::<Ipv4>().unwrap();
ipv4.push::<Udp4>().unwrap()
let ip4 = ethernet.push::<Ip4>().unwrap();
ip4.push::<Udp4>().unwrap()
}

#[capsule::bench(mempool_capacity = 511)]
Expand All @@ -189,79 +189,79 @@ fn multi_push(c: &mut Criterion) {
});
}

fn single_push_udp(ipv4: Ipv4) -> Udp4 {
ipv4.push::<Udp4>().unwrap()
fn single_push_udp(ip4: Ip4) -> Udp4 {
ip4.push::<Udp4>().unwrap()
}

#[capsule::bench(mempool_capacity = 511)]
fn single_push(c: &mut Criterion) {
c.bench_function("packets::single_push_udp", |b| {
let s = v4_udp().prop_map(|v| {
let udp = v.into_v4_udp();
let s = udp4().prop_map(|v| {
let udp = v.into_udp4();
udp.remove().unwrap()
});
b.iter_proptest_batched(s, single_push_udp, BATCH_SIZE)
});
}

fn single_remove_udp(udp: Udp4) -> Ipv4 {
fn single_remove_udp(udp: Udp4) -> Ip4 {
udp.remove().unwrap()
}

#[capsule::bench(mempool_capacity = 511)]
fn single_remove(c: &mut Criterion) {
c.bench_function("packets::single_remove_from_udp", |b| {
let s = v4_udp().prop_map(|v| v.into_v4_udp());
let s = udp4().prop_map(|v| v.into_udp4());
b.iter_proptest_batched(s, single_remove_udp, BATCH_SIZE)
});
}

fn multi_remove_udp(udp: Udp4) -> Mbuf {
let ipv4 = udp.remove().unwrap();
let ethernet = ipv4.remove().unwrap();
let ip4 = udp.remove().unwrap();
let ethernet = ip4.remove().unwrap();
ethernet.remove().unwrap()
}

#[capsule::bench(mempool_capacity = 511)]
fn multi_remove(c: &mut Criterion) {
c.bench_function("packets::multi_remove_from_udp", |b| {
let s = v4_udp().prop_map(|v| v.into_v4_udp());
let s = udp4().prop_map(|v| v.into_udp4());
b.iter_proptest_batched(s, multi_remove_udp, BATCH_SIZE)
});
}

fn set_srh_segments(mut args: (SegmentRouting<Ipv6>, Vec<Ipv6Addr>)) -> Result<()> {
fn set_sr_segments(mut args: (SegmentRouting<Ip6>, Vec<Ipv6Addr>)) -> Result<()> {
args.0.set_segments(&args.1)
}

#[capsule::bench(mempool_capacity = 511)]
fn set_srh_segments_sizes(c: &mut Criterion) {
let mut group = c.benchmark_group("packets::setting_segments_on_SRH_across_segment_sizes");
fn set_sr_segments_sizes(c: &mut Criterion) {
let mut group = c.benchmark_group("packets::setting_segments_on_sr_across_segment_sizes");

let mut rvg = Rvg::new();

group.bench_function("packets::set_srh_segments::size=1", |b| {
group.bench_function("packets::set_sr_segments::size=1", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 1);
let s = (sr_tcp().prop_map(|v| v.into_sr()), Just(segments));
b.iter_proptest_batched(s, set_srh_segments, BATCH_SIZE)
b.iter_proptest_batched(s, set_sr_segments, BATCH_SIZE)
});

group.bench_function("packets::set_srh_segments::size=2", |b| {
group.bench_function("packets::set_sr_segments::size=2", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 2);
let s = (sr_tcp().prop_map(|v| v.into_sr()), Just(segments));
b.iter_proptest_batched(s, set_srh_segments, BATCH_SIZE)
b.iter_proptest_batched(s, set_sr_segments, BATCH_SIZE)
});

group.bench_function("packets::set_srh_segments::size=4", |b| {
group.bench_function("packets::set_sr_segments::size=4", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 4);
let s = (sr_tcp().prop_map(|v| v.into_sr()), Just(segments));
b.iter_proptest_batched(s, set_srh_segments, BATCH_SIZE)
b.iter_proptest_batched(s, set_sr_segments, BATCH_SIZE)
});

group.bench_function("packets::set_srh_segments::size=8", |b| {
group.bench_function("packets::set_sr_segments::size=8", |b| {
let segments = rvg.generate_vec(&any::<Ipv6Addr>(), 8);
let s = (sr_tcp().prop_map(|v| v.into_sr()), Just(segments));
b.iter_proptest_batched(s, set_srh_segments, BATCH_SIZE)
b.iter_proptest_batched(s, set_sr_segments, BATCH_SIZE)
});

group.finish()
Expand All @@ -276,9 +276,9 @@ criterion_group! {
config=bench_config();
targets=single_peek_vs_parse,
multi_peek_vs_parse,
single_parse_srh_segments_sizes,
multi_parse_upto_variable_srh,
set_srh_segments_sizes,
single_parse_sr_segments_sizes,
multi_parse_upto_variable_sr,
set_sr_segments_sizes,
deparse,
single_push,
multi_push,
Expand Down
Loading

0 comments on commit bfeb7a9

Please sign in to comment.