Skip to content

Commit

Permalink
remove ip4 and ip6 alias
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkirishcoder committed Jan 8, 2022
1 parent bfeb7a9 commit d478ea2
Show file tree
Hide file tree
Showing 36 changed files with 255 additions and 263 deletions.
30 changes: 15 additions & 15 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::Ip4;
use capsule::packets::ip::v6::{Ip6, SegmentRouting};
use capsule::packets::ip::v4::Ipv4;
use capsule::packets::ip::v6::{Ipv6, SegmentRouting};
use capsule::packets::udp::Udp4;
use capsule::packets::{Mbuf, Packet};
use capsule::testils::criterion::BencherExt;
Expand All @@ -32,11 +32,11 @@ use std::net::Ipv6Addr;

const BATCH_SIZE: usize = 500;

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

fn single_peek_udp(ip4: Ip4) -> Ip4 {
fn single_peek_udp(ip4: Ipv4) -> Ipv4 {
ip4.peek::<Udp4>().unwrap();
ip4
}
Expand Down Expand Up @@ -66,13 +66,13 @@ fn single_peek_vs_parse(c: &mut Criterion) {

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

fn multi_peek_udp(mbuf: Mbuf) -> Mbuf {
let ethernet = mbuf.peek::<Ethernet>().unwrap();
let ip4 = ethernet.peek::<Ip4>().unwrap();
let ip4 = ethernet.peek::<Ipv4>().unwrap();
ip4.peek::<Udp4>().unwrap();
mbuf
}
Expand All @@ -94,8 +94,8 @@ fn multi_peek_vs_parse(c: &mut Criterion) {
group.finish()
}

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

#[capsule::bench(mempool_capacity = 511)]
Expand Down Expand Up @@ -135,10 +135,10 @@ fn single_parse_sr_segments_sizes(c: &mut Criterion) {
group.finish()
}

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

#[capsule::bench(mempool_capacity = 511)]
Expand Down Expand Up @@ -177,7 +177,7 @@ fn reset(c: &mut Criterion) {

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

Expand All @@ -189,7 +189,7 @@ fn multi_push(c: &mut Criterion) {
});
}

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

Expand All @@ -204,7 +204,7 @@ fn single_push(c: &mut Criterion) {
});
}

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

Expand All @@ -230,7 +230,7 @@ fn multi_remove(c: &mut Criterion) {
});
}

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

Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v4/echo_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct EchoReplyBody {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v4::Ip4;
use crate::packets::ip::v4::Ipv4;
use crate::packets::Mbuf;

#[test]
Expand All @@ -234,8 +234,8 @@ mod tests {
fn push_and_set_echo_reply() {
let packet = Mbuf::new().unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let mut echo = ip4.push::<EchoReply<Ip4>>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();
let mut echo = ip4.push::<EchoReply<Ipv4>>().unwrap();

assert_eq!(4, echo.header_len());
assert_eq!(EchoReplyBody::size_of(), echo.payload_len());
Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v4/echo_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ struct EchoRequestBody {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v4::Ip4;
use crate::packets::ip::v4::Ipv4;
use crate::packets::Mbuf;

#[test]
Expand All @@ -235,8 +235,8 @@ mod tests {
fn push_and_set_echo_request() {
let packet = Mbuf::new().unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let mut echo = ip4.push::<EchoRequest<Ip4>>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();
let mut echo = ip4.push::<EchoRequest<Ipv4>>().unwrap();

assert_eq!(4, echo.header_len());
assert_eq!(EchoRequestBody::size_of(), echo.payload_len());
Expand Down
28 changes: 14 additions & 14 deletions core/src/packets/icmp/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ pub trait Icmpv4Packet {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v4::Ip4;
use crate::packets::ip::v4::Ipv4;
use crate::packets::Mbuf;
use crate::testils::byte_arrays::{ICMPV4_PACKET, IPV4_UDP_PACKET};

Expand All @@ -462,16 +462,16 @@ mod tests {
fn parse_icmpv4_packet() {
let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap();
let ethernet = packet.parse::<Ethernet>().unwrap();
let ip4 = ethernet.parse::<Ip4>().unwrap();
let icmp4 = ip4.parse::<Icmpv4<Ip4>>().unwrap();
let ip4 = ethernet.parse::<Ipv4>().unwrap();
let icmp4 = ip4.parse::<Icmpv4<Ipv4>>().unwrap();

// parses the generic header
assert_eq!(Icmpv4Types::EchoRequest, icmp4.msg_type());
assert_eq!(0, icmp4.code());
assert_eq!(0x2a5c, icmp4.checksum());

// downcasts to specific message
let echo = icmp4.downcast::<EchoRequest<Ip4>>().unwrap();
let echo = icmp4.downcast::<EchoRequest<Ipv4>>().unwrap();
assert_eq!(Icmpv4Types::EchoRequest, echo.msg_type());
assert_eq!(0, echo.code());
assert_eq!(0x2a5c, echo.checksum());
Expand All @@ -480,34 +480,34 @@ mod tests {

// also can one-step parse
let ip4 = echo.deparse();
assert!(ip4.parse::<EchoRequest<Ip4>>().is_ok());
assert!(ip4.parse::<EchoRequest<Ipv4>>().is_ok());
}

#[capsule::test]
fn parse_wrong_icmpv4_type() {
let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap();
let ethernet = packet.parse::<Ethernet>().unwrap();
let ip4 = ethernet.parse::<Ip4>().unwrap();
let icmp4 = ip4.parse::<Icmpv4<Ip4>>().unwrap();
let ip4 = ethernet.parse::<Ipv4>().unwrap();
let icmp4 = ip4.parse::<Icmpv4<Ipv4>>().unwrap();

assert!(icmp4.downcast::<EchoReply<Ip4>>().is_err());
assert!(icmp4.downcast::<EchoReply<Ipv4>>().is_err());
}

#[capsule::test]
fn parse_non_icmpv4_packet() {
let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap();
let ethernet = packet.parse::<Ethernet>().unwrap();
let ip4 = ethernet.parse::<Ip4>().unwrap();
let ip4 = ethernet.parse::<Ipv4>().unwrap();

assert!(ip4.parse::<Icmpv4<Ip4>>().is_err());
assert!(ip4.parse::<Icmpv4<Ipv4>>().is_err());
}

#[capsule::test]
fn compute_checksum() {
let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap();
let ethernet = packet.parse::<Ethernet>().unwrap();
let ip4 = ethernet.parse::<Ip4>().unwrap();
let mut icmp4 = ip4.parse::<Icmpv4<Ip4>>().unwrap();
let ip4 = ethernet.parse::<Ipv4>().unwrap();
let mut icmp4 = ip4.parse::<Icmpv4<Ipv4>>().unwrap();

let expected = icmp4.checksum();
// no payload change but force a checksum recompute anyway
Expand All @@ -519,8 +519,8 @@ mod tests {
fn push_icmpv4_header_without_body() {
let packet = Mbuf::new().unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();

assert!(ip4.push::<Icmpv4<Ip4>>().is_err());
assert!(ip4.push::<Icmpv4<Ipv4>>().is_err());
}
}
14 changes: 7 additions & 7 deletions core/src/packets/icmp/v4/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Default for RedirectBody {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v4::Ip4;
use crate::packets::ip::v4::Ipv4;
use crate::packets::Mbuf;
use crate::testils::byte_arrays::IPV4_TCP_PACKET;

Expand All @@ -232,10 +232,10 @@ mod tests {
fn push_and_set_redirect() {
let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap();
let ethernet = packet.parse::<Ethernet>().unwrap();
let ip4 = ethernet.parse::<Ip4>().unwrap();
let ip4 = ethernet.parse::<Ipv4>().unwrap();
let tcp_len = ip4.payload_len();

let mut redirect = ip4.push::<Redirect<Ip4>>().unwrap();
let mut redirect = ip4.push::<Redirect<Ipv4>>().unwrap();

assert_eq!(4, redirect.header_len());
assert_eq!(RedirectBody::size_of() + tcp_len, redirect.payload_len());
Expand All @@ -259,8 +259,8 @@ mod tests {
// starts with buffer larger than min MTU of 68 bytes.
let packet = Mbuf::from_bytes(&[42; 100]).unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let mut redirect = ip4.push::<Redirect<Ip4>>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();
let mut redirect = ip4.push::<Redirect<Ipv4>>().unwrap();
assert!(redirect.data_len() > IPV4_MIN_MTU);

redirect.reconcile_all();
Expand All @@ -272,8 +272,8 @@ mod tests {
// starts with buffer smaller than min MTU of 68 bytes.
let packet = Mbuf::from_bytes(&[42; 50]).unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let mut redirect = ip4.push::<Redirect<Ip4>>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();
let mut redirect = ip4.push::<Redirect<Ipv4>>().unwrap();
assert!(redirect.data_len() < IPV4_MIN_MTU);

redirect.reconcile_all();
Expand Down
14 changes: 7 additions & 7 deletions core/src/packets/icmp/v4/time_exceeded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct TimeExceededBody {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v4::Ip4;
use crate::packets::ip::v4::Ipv4;
use crate::packets::Mbuf;
use crate::testils::byte_arrays::IPV4_TCP_PACKET;

Expand All @@ -196,10 +196,10 @@ mod tests {
fn push_and_set_time_exceeded() {
let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap();
let ethernet = packet.parse::<Ethernet>().unwrap();
let ip4 = ethernet.parse::<Ip4>().unwrap();
let ip4 = ethernet.parse::<Ipv4>().unwrap();
let tcp_len = ip4.payload_len();

let mut exceeded = ip4.push::<TimeExceeded<Ip4>>().unwrap();
let mut exceeded = ip4.push::<TimeExceeded<Ipv4>>().unwrap();

assert_eq!(4, exceeded.header_len());
assert_eq!(
Expand All @@ -222,8 +222,8 @@ mod tests {
// starts with a buffer with a message body larger than min MTU.
let packet = Mbuf::from_bytes(&[42; 100]).unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let mut exceeded = ip4.push::<TimeExceeded<Ip4>>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();
let mut exceeded = ip4.push::<TimeExceeded<Ipv4>>().unwrap();
assert!(exceeded.data_len() > IPV4_MIN_MTU);

exceeded.reconcile_all();
Expand All @@ -235,8 +235,8 @@ mod tests {
// starts with a buffer with a message body smaller than min MTU.
let packet = Mbuf::from_bytes(&[42; 50]).unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip4 = ethernet.push::<Ip4>().unwrap();
let mut exceeded = ip4.push::<TimeExceeded<Ip4>>().unwrap();
let ip4 = ethernet.push::<Ipv4>().unwrap();
let mut exceeded = ip4.push::<TimeExceeded<Ipv4>>().unwrap();
assert!(exceeded.data_len() < IPV4_MIN_MTU);

exceeded.reconcile_all();
Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v6/echo_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ struct EchoReplyBody {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v6::Ip6;
use crate::packets::ip::v6::Ipv6;
use crate::packets::Mbuf;

#[test]
Expand All @@ -230,8 +230,8 @@ mod tests {
fn push_and_set_echo_reply() {
let packet = Mbuf::new().unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip6 = ethernet.push::<Ip6>().unwrap();
let mut echo = ip6.push::<EchoReply<Ip6>>().unwrap();
let ip6 = ethernet.push::<Ipv6>().unwrap();
let mut echo = ip6.push::<EchoReply<Ipv6>>().unwrap();

assert_eq!(4, echo.header_len());
assert_eq!(EchoReplyBody::size_of(), echo.payload_len());
Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v6/echo_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct EchoRequestBody {
mod tests {
use super::*;
use crate::packets::ethernet::Ethernet;
use crate::packets::ip::v6::Ip6;
use crate::packets::ip::v6::Ipv6;
use crate::packets::Mbuf;

#[test]
Expand All @@ -231,8 +231,8 @@ mod tests {
fn push_and_set_echo_request() {
let packet = Mbuf::new().unwrap();
let ethernet = packet.push::<Ethernet>().unwrap();
let ip6 = ethernet.push::<Ip6>().unwrap();
let mut echo = ip6.push::<EchoRequest<Ip6>>().unwrap();
let ip6 = ethernet.push::<Ipv6>().unwrap();
let mut echo = ip6.push::<EchoRequest<Ipv6>>().unwrap();

assert_eq!(4, echo.header_len());
assert_eq!(EchoRequestBody::size_of(), echo.payload_len());
Expand Down
Loading

0 comments on commit d478ea2

Please sign in to comment.