Skip to content

Commit cb4bd97

Browse files
author
rstade
committed
version 1.0.0 (branch e2d2-rs-v1), packet.rs replaced by pdu.rs
1 parent e9ed376 commit cb4bd97

49 files changed

Lines changed: 923 additions & 1826 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ members=["framework",
1414
"test/tcp_payload",
1515
"test/sctp-test",
1616
"test/config-test",
17-
"test/reset-parse",
1817
"test/tcp_reconstruction",
1918
"test/acl-fw",]
2019
[profile.release]

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## Remarks to Branch e2d2-rs-v1
2+
3+
This branch is a major change to the original NetBricks code. The code of packet.rs was replaced by pdu.rs. Pdu stands for "protocol data unit". Objective was to allow for a more arbitrary protocol stacking and header parsing. In the original code the protocol stacks must follow a tree topology, which is fixed at compile time through type parameters (e.g. PreviousHeader). The Pdu struct has no longer type parameters but includes a stack of Rust enumeration values (enum Header) which can abstract any arbitrary sequence of protocol encapsulations. The protocol sequence is determined at run time by the pdu parser and not limited at compile time, except through the capabilities of the parser.
4+
5+
As a positive side effect the code becomes more comprehensive as a lot of type parameters can be removed. This makes also the code easier to understand. Also we found no negative impact on the performance.
6+
7+
After parsing we specialize the parsed generic Header type to a specific Rust struct type, e.g. a struct IpHeader. Therefore we still utilize the full type checking capabilities of Rust at compile time and we lose nothing compared to the original code.
8+
9+
10+
## The original NetBricks ReadMe:
11+
12+
13+
114
[NetBricks](http://netbricks.io/) is a Rust based framework for NFV development. Please refer to the
215
[paper](https://people.eecs.berkeley.edu/~apanda/assets/papers/osdi16.pdf) for information
316
about the architecture and design. Currently NetBricks requires a relatively modern Linux version.

examples.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export examples=(
1111
test/tcp_check
1212
test/sctp-test
1313
test/config-test
14-
test/reset-parse
1514
test/tcp_reconstruction
1615
test/acl-fw
1716
test/packet_generation

framework/src/headers/ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl EndOffset for IpHeader {
6666
}
6767

6868
#[inline]
69-
fn is_header(&self) -> HeaderKind {
69+
fn header_kind(&self) -> HeaderKind {
7070
HeaderKind::Ip
7171
}
7272
}

framework/src/headers/mac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl EndOffset for MacHeader {
5353
}
5454

5555
#[inline]
56-
fn is_header(&self) -> HeaderKind {
56+
fn header_kind(&self) -> HeaderKind {
5757
HeaderKind::Mac
5858
}
5959
}

framework/src/headers/mod.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub trait EndOffset: Send {
3838

3939
fn check_correct(&self, prev: &Self::PreviousHeader) -> bool;
4040

41-
fn is_header(&self) -> HeaderKind;
41+
fn header_kind(&self) -> HeaderKind;
4242
}
4343

44-
#[derive(Debug, PartialEq, Clone)]
44+
#[derive(Debug, PartialEq, Clone, Copy)]
4545
pub enum Header {
4646
Null,
4747
Mac(*mut MacHeader),
@@ -51,6 +51,17 @@ pub enum Header {
5151
}
5252

5353
impl Header {
54+
55+
pub fn new<T:EndOffset>(ptr: *mut T) -> Header {
56+
match unsafe { (*ptr).header_kind() } {
57+
HeaderKind::Null => Header::Null,
58+
HeaderKind::Mac => Header::Mac(ptr as *mut MacHeader),
59+
HeaderKind::Ip => Header::Ip(ptr as *mut IpHeader),
60+
HeaderKind::Tcp => Header::Tcp(ptr as *mut TcpHeader),
61+
HeaderKind::Udp => Header::Udp(ptr as *mut UdpHeader),
62+
}
63+
}
64+
5465
pub fn as_mac(&self) -> Option<&mut MacHeader> {
5566
match &self {
5667
Header::Mac(p) => Some(unsafe { &mut **p }),
@@ -113,11 +124,11 @@ impl Header {
113124
impl fmt::Display for Header {
114125
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
115126
match &self {
116-
Header::Null => write!(f, "{:?}", &self),
117-
Header::Mac(_) => write!(f, "{:?}", &self.as_mac().unwrap()),
118-
Header::Ip(_) => write!(f, "{:?}", &self.as_ip().unwrap()),
119-
Header::Tcp(_) => write!(f, "{:?}", &self.as_tcp().unwrap()),
120-
Header::Udp(_) => write!(f, "{:?}", &self.as_udp().unwrap()),
127+
Header::Null => write!(f, "{:?}", self),
128+
Header::Mac(_) => write!(f, "{:?}", self.as_mac().unwrap()),
129+
Header::Ip(_) => write!(f, "{ }", self.as_ip().unwrap()),
130+
Header::Tcp(_) => write!(f, "{ }", self.as_tcp().unwrap()),
131+
Header::Udp(_) => write!(f, "{:?}", self.as_udp().unwrap()),
121132
}
122133
}
123134
}

framework/src/headers/null_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl EndOffset for NullHeader {
3535
}
3636

3737
#[inline]
38-
fn is_header(&self) -> HeaderKind {
38+
fn header_kind(&self) -> HeaderKind {
3939
HeaderKind::Null
4040
}
4141
}

framework/src/headers/tcp.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl EndOffset for TcpHeader {
8787
}
8888

8989
#[inline]
90-
fn is_header(&self) -> HeaderKind {
90+
fn header_kind(&self) -> HeaderKind {
9191
HeaderKind::Tcp
9292
}
9393
}
@@ -350,23 +350,27 @@ impl TcpHeader {
350350
// END FLAGS
351351

352352
/// Receive window.
353+
#[inline]
353354
pub fn window_size(&self) -> u16 {
354355
u16::from_be(self.window)
355356
}
356357

358+
#[inline]
357359
pub fn set_window_size(&mut self, wnd: u16) {
358360
self.window = u16::to_be(wnd);
359361
}
360362

361363
/// Checksum
364+
#[inline]
362365
pub fn checksum(&self) -> u16 {
363366
u16::from_be(self.csum)
364367
}
365368

366369
// TODO: Validate checksum and update checksum
367370

371+
#[inline]
368372
pub fn set_checksum(&mut self, csum: u16) {
369-
self.csum = u16::to_be(csum)
373+
self.csum = u16::to_be(csum);
370374
}
371375

372376
pub fn update_checksum_incremental(&mut self, old_word: u16, new_word: u16) {

framework/src/headers/udp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl EndOffset for UdpHeader {
5050
}
5151

5252
#[inline]
53-
fn is_header(&self) -> HeaderKind {
53+
fn header_kind(&self) -> HeaderKind {
5454
HeaderKind::Udp
5555
}
5656
}

framework/src/interface/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
pub use self::packet::*;
21
pub use self::pdu::*;
32
pub use self::port::*;
43
pub mod dpdk;
5-
mod packet;
64
mod pdu;
75
mod port;
86
use common::errors;

0 commit comments

Comments
 (0)