Skip to content

Commit 242dbc3

Browse files
committed
feat(log): add compressed packet log
Resolves: #81
1 parent be32cdf commit 242dbc3

10 files changed

Lines changed: 724 additions & 30 deletions

File tree

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,56 @@ cargo run --example channel-xdp --release --features="camellia" # AF_XDP version
2828
cargo install flamegraph
2929
cargo flamegraph --root --example channel
3030
```
31+
32+
### Packet Log Spec
33+
34+
```text
35+
0 1 2 3
36+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
37+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38+
| LH.length | LH.ty.| GPH.length |GPH.ac.|GPH.ty.|
39+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40+
| GP.timestamp |
41+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42+
| GP.length | PRH.length |PRH.ty.|
43+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44+
| PRT (custom) |
45+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46+
```
47+
48+
Generated with [protocol](https://github.com/luismartingarcia/protocol), where:
49+
50+
* `LH` is short for log entry header
51+
* `GPH` is short for general packet entry header
52+
* `GP` is short for general packet entry (the body part)
53+
* `PRH` is short for protocol entry header
54+
* `PRT` is short for protocol entry (the body part)
55+
* `ty.` is short for type
56+
* `ac.` is short for action
57+
58+
```shell
59+
protocol "LH.length:12,LH.ty.:4,GPH.length:8,GPH.ac.:4,GPH.ty.:4,GP.timestamp:32,GP.length:16,PRH.length:12,PRH.ty.:4,PRT (custom):32"
60+
```
61+
62+
We currently provide TCP log spec (a variant of the protocol entry body part, i.e. `PRT (custom)`):
63+
64+
```text
65+
0 1 2 3
66+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
67+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68+
| tcp.flow_id |
69+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70+
| tcp.seq |
71+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72+
| tcp.ack |
73+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74+
| ip.id | ip.frag_offset |
75+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76+
| ip.checksum | tcp.flags | padding |
77+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78+
79+
```
80+
81+
```shell
82+
protocol "tcp.flow_id:32,tcp.seq:32,tcp.ack:32,ip.id:16,ip.frag_offset:16,ip.checksum:16,tcp.flags:8,padding:8"
83+
```

config.example.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
#
4040

4141

42+
# ----- General Section -----
43+
# This section determines how to build the rattan itself in general.
44+
[general]
45+
46+
# Configure the path to store compressed packet log.
47+
# This logging feature will only be enabled when the `packet_log` field is specified.
48+
# The meta data of flows will be stored in the file of name `packet_log`.flows
49+
# packet_log = "./example.log"
50+
51+
# ----- General Section End -----
52+
53+
4254
# ----- Environment Section -----
4355
# This section determines how to build the environment.
4456
[env]

rattan-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ tracing = { workspace = true }
3939
tempfile = "3.10.1"
4040
uuid = { version = "1.10.0", features = ["v4"] }
4141
serde_with = "3.9.0"
42+
bitfield = "0.16.1"
4243

4344
[dev-dependencies]
4445
anyhow = "1.0.69"

rattan-core/src/config/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::{collections::HashMap, path::PathBuf};
22

33
use crate::{devices::Packet, env::StdNetEnvConfig};
44

@@ -35,6 +35,8 @@ pub struct RattanConfig<P: Packet> {
3535
pub links: HashMap<String, String>,
3636
#[cfg_attr(feature = "serde", serde(default))]
3737
pub resource: RattanResourceConfig,
38+
#[cfg_attr(feature = "serde", serde(default))]
39+
pub general: RattanGeneralConfig,
3840
}
3941

4042
impl<P: Packet> Default for RattanConfig<P> {
@@ -46,6 +48,7 @@ impl<P: Packet> Default for RattanConfig<P> {
4648
devices: HashMap::new(),
4749
links: HashMap::new(),
4850
resource: RattanResourceConfig::new(),
51+
general: RattanGeneralConfig::new(),
4952
}
5053
}
5154
}
@@ -70,6 +73,24 @@ impl RattanResourceConfig {
7073
}
7174
}
7275

76+
#[cfg_attr(
77+
feature = "serde",
78+
serde_with::skip_serializing_none,
79+
derive(Serialize, Deserialize),
80+
serde(bound = "")
81+
)]
82+
#[derive(Clone, Debug, Default)]
83+
pub struct RattanGeneralConfig {
84+
#[cfg_attr(feature = "serde", serde(default))]
85+
pub packet_log: Option<PathBuf>,
86+
}
87+
88+
impl RattanGeneralConfig {
89+
pub fn new() -> Self {
90+
Default::default()
91+
}
92+
}
93+
7394
#[cfg_attr(
7495
feature = "serde",
7596
derive(Serialize, Deserialize),

0 commit comments

Comments
 (0)