-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle unaligned fields > than 1 byte in setters
- Loading branch information
1 parent
526a5bd
commit ec28986
Showing
4 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
header ethernet_h { | ||
bit<48> dst; | ||
bit<48> src; | ||
bit<16> ether_type; | ||
} | ||
|
||
header vlan_h { | ||
bit<3> pcp; | ||
bit<1> dei; | ||
bit<12> vid; | ||
bit<16> ether_type; | ||
} | ||
|
||
header sidecar_h { | ||
bit<8> sc_code; | ||
bit<8> sc_pad; | ||
bit<16> sc_ingress; | ||
bit<16> sc_egress; | ||
bit<16> sc_ether_type; | ||
bit<128> sc_payload; | ||
} | ||
|
||
header ipv4_h { | ||
bit<4> version; | ||
bit<4> ihl; | ||
bit<8> diffserv; | ||
bit<16> total_len; | ||
bit<16> identification; | ||
bit<3> flags; | ||
bit<13> frag_offset; | ||
bit<8> ttl; | ||
bit<8> protocol; | ||
bit<16> hdr_checksum; | ||
bit<32> src; | ||
bit<32> dst; | ||
} | ||
|
||
struct headers_t { | ||
ethernet_h ethernet; | ||
vlan_h vlan; | ||
sidecar_h sidecar; | ||
ipv4_h ipv4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
p4_macro::use_p4!("test/src/p4/vlan_header.p4"); | ||
|
||
#[test] | ||
fn test_vlan_parse() -> anyhow::Result<()> { | ||
let mut data = [0u8; 256]; | ||
data[0] = 0x0; | ||
data[1] = 0x47; | ||
let mut pkt = vlan_h::new(); | ||
pkt.set(&data).unwrap(); | ||
let vid: u16 = pkt.vid.to_owned().load_le(); | ||
assert_eq!(vid, 0x47); | ||
|
||
let mut data = [0u8; 256]; | ||
data[0] = 0x77; | ||
data[1] = 0x47; | ||
let mut pkt = vlan_h::new(); | ||
pkt.set(&data).unwrap(); | ||
let vid: u16 = pkt.vid.to_owned().load_le(); | ||
assert_eq!(vid, 0x747); | ||
|
||
Ok(()) | ||
} |