Skip to content

Commit

Permalink
Impl mod destination_unreachable
Browse files Browse the repository at this point in the history
Co-authored-by: Adenylatcyclase <[email protected]>
  • Loading branch information
2 people authored and plumenator committed Feb 27, 2021
1 parent b92b02f commit 47b3faa
Show file tree
Hide file tree
Showing 73 changed files with 1,812 additions and 477 deletions.
112 changes: 51 additions & 61 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ jobs:
rust-toolchain: [stable, beta, nightly]
# Allow failures on nightly, it's just informative
include:
- rust: stable
- rust-toolchain: stable
can-fail: false
- rust: beta
- rust-toolchain: beta
can-fail: false
- rust: nightly
- rust-toolchain: nightly
can-fail: true

container:
Expand Down Expand Up @@ -196,51 +196,50 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

# issue on tarpaulin: https://github.com/xd009642/tarpaulin/issues/461
# coverage:
# runs-on: ubuntu-18.04

# container:
# image: getcapsule/sandbox
# options: --privileged

# steps:
# - name: install curl
# run: apt-get update && apt-get install -y curl

# - uses: actions/checkout@v2

# - uses: actions-rs/toolchain@v1
# with:
# toolchain: nightly
# override: true

# - name: install-tarpaulin
# uses: actions-rs/cargo@v1
# with:
# command: install
# args: --force cargo-tarpaulin

# - name: run-tarpaulin
# uses: actions-rs/cargo@v1
# with:
# command: tarpaulin
# args: '-p capsule -l --count --exclude-files examples/* ffi/* macros/* --out Xml -Zpackage-features --features full'

# - uses: codecov/codecov-action@v1
# with:
# file: ./cobertura.xml

# - name: slack-it
# uses: homoluctus/[email protected]
# if: failure() || cancelled()
# with:
# type: ${{ job.status }}
# job_name: '*${{ github.workflow }}* @ coverage'
# url: ${{ secrets.SLACK_WEBHOOK }}
# commit: true
# token: ${{ secrets.GITHUB_TOKEN }}
# continue-on-error: true
coverage:
runs-on: ubuntu-18.04

container:
image: getcapsule/sandbox
options: --privileged

steps:
- name: install curl
run: apt-get update && apt-get install -y curl

- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: install-tarpaulin
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-tarpaulin

- name: run-tarpaulin
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: "-p capsule -l --count --exclude-files examples/* ffi/* macros/* --out Xml -Zpackage-features --features full"

- uses: codecov/codecov-action@v1
with:
file: ./cobertura.xml

- name: slack-it
uses: homoluctus/[email protected]
if: failure() || cancelled()
with:
type: ${{ job.status }}
job_name: "*${{ github.workflow }}* @ coverage"
url: ${{ secrets.SLACK_WEBHOOK }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

format:
runs-on: ubuntu-18.04
Expand Down Expand Up @@ -293,10 +292,6 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

## TODO 01/23/21: Return to this, as it's getting an Exit 1,
## but I can't get leak errors locally on our VM (exit 0) or my local
## system 76 (bare). So, only shows up on GH (no problem in past runs).
## I've tested on recent rust nightly and 19.11.6 (and 19.11.1)
sanitize:
runs-on: ubuntu-18.04

Expand All @@ -321,7 +316,6 @@ jobs:
/bin/bash -c "rustup install nightly && rustup default nightly \
&& rustup component add rust-src \
&& cargo run --target x86_64-unknown-linux-gnu -Zbuild-std -- -f ping4d.toml"
continue-on-error: true
- name: slack-it
uses: homoluctus/[email protected]
Expand Down Expand Up @@ -360,8 +354,7 @@ jobs:

slack-pr:
if: github.event_name == 'pull_request'
# TODO: re-add coverage
needs: [audit, bench-pr, check, format, lint, sanitize, test]
needs: [audit, bench-pr, check, coverage, format, lint, sanitize, test]
runs-on: ubuntu-18.04
steps:
- name: slack-it
Expand All @@ -377,8 +370,7 @@ jobs:

slack:
if: github.event_name == 'push'
# TODO: re-add coverage
needs: [audit, bench, check, format, lint, sanitize, test]
needs: [audit, bench, check, coverage, format, lint, sanitize, test]
runs-on: ubuntu-18.04
steps:
- name: slack-it
Expand All @@ -394,8 +386,7 @@ jobs:

discord-pr:
if: github.event_name == 'pull_request'
# TODO: re-add coverage
needs: [audit, bench-pr, check, format, lint, sanitize, test]
needs: [audit, bench-pr, check, coverage, format, lint, sanitize, test]
runs-on: ubuntu-18.04
steps:
- name: discord-it
Expand All @@ -408,8 +399,7 @@ jobs:

discord:
if: github.event_name == 'push'
# TODO: re-add coverage
needs: [audit, bench, check, format, lint, sanitize, test]
needs: [audit, bench, check, coverage, format, lint, sanitize, test]
runs-on: ubuntu-18.04
steps:
- name: discord-it
Expand Down
2 changes: 1 addition & 1 deletion bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Benchmarks for Capsule.
"""

[dev-dependencies]
anyhow = "1.0"
capsule = { version = "0.1", path = "../core", features = ["testils"] }
criterion = "0.3"
failure = "0.1"
proptest = "0.10"

[[bench]]
Expand Down
6 changes: 3 additions & 3 deletions bench/combinators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

use anyhow::Result;
use capsule::batch::{Batch, Either};
use capsule::packets::ip::v4::Ipv4;
use capsule::packets::{Ethernet, Packet};
use capsule::testils::criterion::BencherExt;
use capsule::testils::proptest::*;
use capsule::{compose, Mbuf};
use criterion::{criterion_group, criterion_main, Criterion};
use failure::Fallible;
use proptest::prelude::*;
use proptest::strategy;

Expand Down Expand Up @@ -86,7 +86,7 @@ fn map(batch: impl Batch<Item = Mbuf>) -> impl Batch<Item = Ethernet> {
batch.map(|p| p.parse::<Ethernet>())
}

fn no_batch_map(mbuf: Mbuf) -> Fallible<Ethernet> {
fn no_batch_map(mbuf: Mbuf) -> Result<Ethernet> {
mbuf.parse::<Ethernet>()
}

Expand Down Expand Up @@ -189,7 +189,7 @@ fn replace(batch: impl Batch<Item = Mbuf>) -> impl Batch<Item = Mbuf> {
batch.replace(|_p| Mbuf::new())
}

fn no_batch_replace(_mbuf: Mbuf) -> Fallible<Mbuf> {
fn no_batch_replace(_mbuf: Mbuf) -> Result<Mbuf> {
Mbuf::new()
}

Expand Down
8 changes: 4 additions & 4 deletions bench/mbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

use anyhow::Result;
use capsule::Mbuf;
use criterion::{criterion_group, criterion_main, Criterion};
use failure::Fallible;

const BATCH_SIZE: usize = 100;

fn alloc() -> Fallible<Vec<Mbuf>> {
fn alloc() -> Result<Vec<Mbuf>> {
(0..BATCH_SIZE)
.map(|_| Mbuf::new())
.collect::<Fallible<Vec<Mbuf>>>()
.collect::<Result<Vec<Mbuf>>>()
}

fn alloc_bulk() -> Fallible<Vec<Mbuf>> {
fn alloc_bulk() -> Result<Vec<Mbuf>> {
Mbuf::alloc_bulk(BATCH_SIZE)
}

Expand Down
4 changes: 2 additions & 2 deletions bench/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

use anyhow::Result;
use capsule::packets::ip::v4::Ipv4;
use capsule::packets::ip::v6::{Ipv6, SegmentRouting};
use capsule::packets::{Ethernet, Packet, Udp4};
Expand All @@ -24,7 +25,6 @@ use capsule::testils::proptest::*;
use capsule::testils::{PacketExt, Rvg};
use capsule::{fieldmap, Mbuf};
use criterion::{criterion_group, criterion_main, Criterion};
use failure::Fallible;
use proptest::prelude::*;
use std::net::Ipv6Addr;

Expand Down Expand Up @@ -228,7 +228,7 @@ fn multi_remove(c: &mut Criterion) {
});
}

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

Expand Down
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ path = "src/lib.rs"
doctest = false

[dependencies]
anyhow = "1.0"
capsule-ffi = { version = "0.1.4", path = "../ffi" }
capsule-macros = { version = "0.1.4", path = "../macros" }
clap = "2.33"
criterion = { version = "0.3", optional = true }
failure = "0.1"
futures-preview = "=0.3.0-alpha.19"
libc = "0.2"
metrics-core = { version = "0.5", optional = true }
Expand All @@ -33,6 +33,7 @@ once_cell = "1.2"
proptest = { version = "0.10", optional = true }
regex = "1"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"
tokio = "=0.2.0-alpha.6"
tokio-executor = { version = "=0.2.0-alpha.6", features = ["current-thread", "threadpool"] }
tokio-net = { version = "=0.2.0-alpha.6", features = ["signal"] }
Expand Down
8 changes: 4 additions & 4 deletions core/src/batch/filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use super::{Batch, Disposition};
use crate::packets::Packet;
use crate::Mbuf;
use failure::Fallible;
use anyhow::Result;

/// The result of a [`filter_map`].
///
Expand All @@ -41,15 +41,15 @@ pub enum Either<T> {
#[allow(missing_debug_implementations)]
pub struct FilterMap<B: Batch, T: Packet, F>
where
F: FnMut(B::Item) -> Fallible<Either<T>>,
F: FnMut(B::Item) -> Result<Either<T>>,
{
batch: B,
f: F,
}

impl<B: Batch, T: Packet, F> FilterMap<B, T, F>
where
F: FnMut(B::Item) -> Fallible<Either<T>>,
F: FnMut(B::Item) -> Result<Either<T>>,
{
/// Creates a new `FilterMap` batch.
#[inline]
Expand All @@ -60,7 +60,7 @@ where

impl<B: Batch, T: Packet, F> Batch for FilterMap<B, T, F>
where
F: FnMut(B::Item) -> Fallible<Either<T>>,
F: FnMut(B::Item) -> Result<Either<T>>,
{
type Item = T;

Expand Down
8 changes: 4 additions & 4 deletions core/src/batch/for_each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
*/

use super::{Batch, Disposition};
use failure::Fallible;
use anyhow::Result;

/// A batch that calls a closure on packets in the underlying batch.
#[allow(missing_debug_implementations)]
pub struct ForEach<B: Batch, F>
where
F: FnMut(&B::Item) -> Fallible<()>,
F: FnMut(&B::Item) -> Result<()>,
{
batch: B,
f: F,
}

impl<B: Batch, F> ForEach<B, F>
where
F: FnMut(&B::Item) -> Fallible<()>,
F: FnMut(&B::Item) -> Result<()>,
{
/// Creates a new `ForEach` batch.
#[inline]
Expand All @@ -42,7 +42,7 @@ where

impl<B: Batch, F> Batch for ForEach<B, F>
where
F: FnMut(&B::Item) -> Fallible<()>,
F: FnMut(&B::Item) -> Result<()>,
{
type Item = B::Item;

Expand Down
8 changes: 4 additions & 4 deletions core/src/batch/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::{Batch, Disposition};
use crate::packets::Packet;
use failure::Fallible;
use anyhow::Result;

/// A batch that maps the packets of the underlying batch.
///
Expand All @@ -27,15 +27,15 @@ use failure::Fallible;
#[allow(missing_debug_implementations)]
pub struct Map<B: Batch, T: Packet, F>
where
F: FnMut(B::Item) -> Fallible<T>,
F: FnMut(B::Item) -> Result<T>,
{
batch: B,
f: F,
}

impl<B: Batch, T: Packet, F> Map<B, T, F>
where
F: FnMut(B::Item) -> Fallible<T>,
F: FnMut(B::Item) -> Result<T>,
{
/// Creates a new `Map` batch.
#[inline]
Expand All @@ -46,7 +46,7 @@ where

impl<B: Batch, T: Packet, F> Batch for Map<B, T, F>
where
F: FnMut(B::Item) -> Fallible<T>,
F: FnMut(B::Item) -> Result<T>,
{
type Item = T;

Expand Down
Loading

0 comments on commit 47b3faa

Please sign in to comment.