Skip to content

Commit de21dc2

Browse files
committed
ospfv3: Add encode/decode tests for Hello LLS data block
DbDesc messages are not tested as RFC 5613 does not specify LLS data to embed in such messages. Signed-off-by: Nicolas Rybowski <[email protected]>
1 parent 2b894a9 commit de21dc2

File tree

1 file changed

+295
-0
lines changed

1 file changed

+295
-0
lines changed

holo-ospf/tests/packet/ospfv3.rs

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use const_addrs::{ip, ip4, net};
1313
use holo_ospf::ospfv3::packet::lsa::*;
1414
use holo_ospf::ospfv3::packet::*;
1515
use holo_ospf::packet::auth::{AuthDecodeCtx, AuthEncodeCtx, AuthMethod};
16+
use holo_ospf::packet::lls::ExtendedOptionsFlags;
1617
use holo_ospf::packet::lsa::{Lsa, LsaKey};
1718
use holo_ospf::packet::tlv::*;
1819
use holo_ospf::packet::{DbDescFlags, Packet, PacketType};
@@ -119,6 +120,43 @@ static HELLO1: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
119120
)
120121
});
121122

123+
static HELLO1_LLS: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
124+
Lazy::new(|| {
125+
(
126+
vec![
127+
0x03, 0x01, 0x00, 0x28, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
128+
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
129+
0x01, 0x00, 0x02, 0x13, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00,
130+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02,
131+
0xf3, 0x86, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00,
132+
0x00, 0x03,
133+
],
134+
None,
135+
Packet::Hello(Hello {
136+
hdr: PacketHdr {
137+
pkt_type: PacketType::Hello,
138+
router_id: ip4!("1.1.1.1"),
139+
area_id: ip4!("0.0.0.1"),
140+
instance_id: 0,
141+
auth_seqno: None,
142+
},
143+
iface_id: 4,
144+
priority: 1,
145+
options: Options::R | Options::E | Options::V6 | Options::L,
146+
hello_interval: 3,
147+
dead_interval: 36,
148+
dr: None,
149+
bdr: None,
150+
neighbors: [ip4!("2.2.2.2")].into(),
151+
lls: Some(holo_ospf::packet::lls::LlsHelloData {
152+
eof: Some(
153+
ExtendedOptionsFlags::LR | ExtendedOptionsFlags::RS,
154+
),
155+
}),
156+
}),
157+
)
158+
});
159+
122160
static HELLO1_HMAC_SHA1: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
123161
Lazy::new(|| {
124162
(
@@ -157,6 +195,53 @@ static HELLO1_HMAC_SHA1: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
157195
)
158196
});
159197

198+
static HELLO1_HMAC_SHA1_LLS: Lazy<(
199+
Vec<u8>,
200+
Option<(Key, u64)>,
201+
Packet<Ospfv3>,
202+
)> = Lazy::new(|| {
203+
(
204+
vec![
205+
0x03, 0x01, 0x00, 0x28, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
206+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
207+
0x06, 0x13, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
208+
0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x03,
209+
0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
210+
0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x32, 0x45,
211+
0xd0, 0x14, 0xfe, 0xef, 0xc6, 0xce, 0x7d, 0xbe, 0x66, 0x4e, 0xc3,
212+
0x92, 0x0c, 0xc9, 0x2f, 0x6d, 0x42, 0x1f, 0x38, 0xb2, 0xd2, 0x3c,
213+
],
214+
Some((
215+
Key::new(1, CryptoAlgo::HmacSha1, "HOLO".as_bytes().to_vec()),
216+
843436052,
217+
)),
218+
Packet::Hello(Hello {
219+
hdr: PacketHdr {
220+
pkt_type: PacketType::Hello,
221+
router_id: ip4!("1.1.1.1"),
222+
area_id: ip4!("0.0.0.1"),
223+
instance_id: 0,
224+
auth_seqno: Some(843436052),
225+
},
226+
iface_id: 4,
227+
priority: 1,
228+
options: Options::R
229+
| Options::E
230+
| Options::V6
231+
| Options::AT
232+
| Options::L,
233+
hello_interval: 3,
234+
dead_interval: 36,
235+
dr: None,
236+
bdr: None,
237+
neighbors: [ip4!("2.2.2.2")].into(),
238+
lls: Some(holo_ospf::packet::lls::LlsHelloData {
239+
eof: Some(ExtendedOptionsFlags::LR | ExtendedOptionsFlags::RS),
240+
}),
241+
}),
242+
)
243+
});
244+
160245
static HELLO1_HMAC_SHA256: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
161246
Lazy::new(|| {
162247
(
@@ -196,6 +281,55 @@ static HELLO1_HMAC_SHA256: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
196281
)
197282
});
198283

284+
static HELLO1_HMAC_SHA256_LLS: Lazy<(
285+
Vec<u8>,
286+
Option<(Key, u64)>,
287+
Packet<Ospfv3>,
288+
)> = Lazy::new(|| {
289+
(
290+
vec![
291+
0x03, 0x01, 0x00, 0x28, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
292+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
293+
0x06, 0x13, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
294+
0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x03,
295+
0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
296+
0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x32, 0x45,
297+
0xd0, 0x14, 0xdf, 0x4b, 0x87, 0x87, 0xea, 0x1f, 0xaf, 0x92, 0xe9,
298+
0xcc, 0x0d, 0x1f, 0xbc, 0x70, 0xf7, 0xbc, 0x58, 0xa7, 0x1e, 0x37,
299+
0xc1, 0x4e, 0x6e, 0x8a, 0x22, 0xe3, 0xd1, 0xc7, 0x2d, 0xed, 0xef,
300+
0x67,
301+
],
302+
Some((
303+
Key::new(1, CryptoAlgo::HmacSha256, "HOLO".as_bytes().to_vec()),
304+
843436052,
305+
)),
306+
Packet::Hello(Hello {
307+
hdr: PacketHdr {
308+
pkt_type: PacketType::Hello,
309+
router_id: ip4!("1.1.1.1"),
310+
area_id: ip4!("0.0.0.1"),
311+
instance_id: 0,
312+
auth_seqno: Some(843436052),
313+
},
314+
iface_id: 4,
315+
priority: 1,
316+
options: Options::R
317+
| Options::E
318+
| Options::V6
319+
| Options::AT
320+
| Options::L,
321+
hello_interval: 3,
322+
dead_interval: 36,
323+
dr: None,
324+
bdr: None,
325+
neighbors: [ip4!("2.2.2.2")].into(),
326+
lls: Some(holo_ospf::packet::lls::LlsHelloData {
327+
eof: Some(ExtendedOptionsFlags::LR | ExtendedOptionsFlags::RS),
328+
}),
329+
}),
330+
)
331+
});
332+
199333
static HELLO1_HMAC_SHA384: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
200334
Lazy::new(|| {
201335
(
@@ -237,6 +371,56 @@ static HELLO1_HMAC_SHA384: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
237371
)
238372
});
239373

374+
static HELLO1_HMAC_SHA384_LLS: Lazy<(
375+
Vec<u8>,
376+
Option<(Key, u64)>,
377+
Packet<Ospfv3>,
378+
)> = Lazy::new(|| {
379+
(
380+
vec![
381+
0x03, 0x01, 0x00, 0x28, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
382+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
383+
0x06, 0x13, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
384+
0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x03,
385+
0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
386+
0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x32, 0x45,
387+
0xd0, 0x14, 0xb2, 0xe6, 0x9b, 0x9e, 0x54, 0xd0, 0xad, 0xb9, 0x59,
388+
0xad, 0x9c, 0x35, 0x1c, 0x08, 0x96, 0xda, 0x72, 0x77, 0x30, 0x4b,
389+
0x15, 0x88, 0xcc, 0x18, 0xf0, 0xc4, 0x02, 0xa9, 0x67, 0x65, 0x82,
390+
0x87, 0x68, 0xf5, 0xc0, 0x72, 0x10, 0x2b, 0xa0, 0x4c, 0x1e, 0x44,
391+
0x8f, 0xa1, 0xbe, 0x69, 0xac, 0x6e,
392+
],
393+
Some((
394+
Key::new(1, CryptoAlgo::HmacSha384, "HOLO".as_bytes().to_vec()),
395+
843436052,
396+
)),
397+
Packet::Hello(Hello {
398+
hdr: PacketHdr {
399+
pkt_type: PacketType::Hello,
400+
router_id: ip4!("1.1.1.1"),
401+
area_id: ip4!("0.0.0.1"),
402+
instance_id: 0,
403+
auth_seqno: Some(843436052),
404+
},
405+
iface_id: 4,
406+
priority: 1,
407+
options: Options::R
408+
| Options::E
409+
| Options::V6
410+
| Options::AT
411+
| Options::L,
412+
hello_interval: 3,
413+
dead_interval: 36,
414+
dr: None,
415+
bdr: None,
416+
neighbors: [ip4!("2.2.2.2")].into(),
417+
lls: Some(holo_ospf::packet::lls::LlsHelloData {
418+
eof: Some(ExtendedOptionsFlags::LR | ExtendedOptionsFlags::RS),
419+
}),
420+
}),
421+
)
422+
});
423+
240424
static HELLO1_HMAC_SHA512: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
241425
Lazy::new(|| {
242426
(
@@ -279,6 +463,57 @@ static HELLO1_HMAC_SHA512: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
279463
)
280464
});
281465

466+
static HELLO1_HMAC_SHA512_LLS: Lazy<(
467+
Vec<u8>,
468+
Option<(Key, u64)>,
469+
Packet<Ospfv3>,
470+
)> = Lazy::new(|| {
471+
(
472+
vec![
473+
0x03, 0x01, 0x00, 0x28, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
474+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
475+
0x06, 0x13, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
476+
0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x03,
477+
0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
478+
0x50, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x32, 0x45,
479+
0xd0, 0x14, 0x43, 0x1e, 0x7b, 0xcd, 0x00, 0x46, 0xe5, 0x6c, 0xb6,
480+
0x46, 0x63, 0x87, 0x02, 0xeb, 0x5b, 0x10, 0xe0, 0xd0, 0x7e, 0x96,
481+
0x20, 0xdb, 0x34, 0x7e, 0x12, 0xd8, 0x8c, 0xf0, 0xaa, 0xfd, 0xd9,
482+
0x32, 0xcc, 0x2f, 0x85, 0xef, 0x5f, 0x63, 0xcd, 0x5f, 0x0b, 0x10,
483+
0xa8, 0x0a, 0xf7, 0x7a, 0x27, 0x7f, 0x3c, 0xc9, 0x4b, 0xc4, 0xc0,
484+
0xf8, 0x92, 0xa5, 0x43, 0xf0, 0xac, 0x73, 0xe1, 0xf5, 0xfe, 0x7a,
485+
],
486+
Some((
487+
Key::new(1, CryptoAlgo::HmacSha512, "HOLO".as_bytes().to_vec()),
488+
843436052,
489+
)),
490+
Packet::Hello(Hello {
491+
hdr: PacketHdr {
492+
pkt_type: PacketType::Hello,
493+
router_id: ip4!("1.1.1.1"),
494+
area_id: ip4!("0.0.0.1"),
495+
instance_id: 0,
496+
auth_seqno: Some(843436052),
497+
},
498+
iface_id: 4,
499+
priority: 1,
500+
options: Options::R
501+
| Options::E
502+
| Options::V6
503+
| Options::AT
504+
| Options::L,
505+
hello_interval: 3,
506+
dead_interval: 36,
507+
dr: None,
508+
bdr: None,
509+
neighbors: [ip4!("2.2.2.2")].into(),
510+
lls: Some(holo_ospf::packet::lls::LlsHelloData {
511+
eof: Some(ExtendedOptionsFlags::LR | ExtendedOptionsFlags::RS),
512+
}),
513+
}),
514+
)
515+
});
516+
282517
static DBDESCR1: Lazy<(Vec<u8>, Option<(Key, u64)>, Packet<Ospfv3>)> =
283518
Lazy::new(|| {
284519
(
@@ -998,6 +1233,18 @@ fn test_decode_hello1() {
9981233
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
9991234
}
10001235

1236+
#[test]
1237+
fn test_encode_hello1_lls() {
1238+
let (ref bytes, ref auth, ref hello) = *HELLO1_LLS;
1239+
test_encode_packet(bytes, auth, hello);
1240+
}
1241+
1242+
#[test]
1243+
fn test_decode_hello1_lls() {
1244+
let (ref bytes, ref auth, ref hello) = *HELLO1_LLS;
1245+
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
1246+
}
1247+
10011248
#[test]
10021249
fn test_encode_hello_hmac_sha1() {
10031250
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA1;
@@ -1010,6 +1257,18 @@ fn test_decode_hello_hmac_sha1() {
10101257
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
10111258
}
10121259

1260+
#[test]
1261+
fn test_encode_hello_hmac_sha1_lls() {
1262+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA1_LLS;
1263+
test_encode_packet(bytes, auth, hello);
1264+
}
1265+
1266+
#[test]
1267+
fn test_decode_hello_hmac_sha1_lls() {
1268+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA1_LLS;
1269+
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
1270+
}
1271+
10131272
#[test]
10141273
fn test_encode_hello_hmac_sha256() {
10151274
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA256;
@@ -1022,6 +1281,18 @@ fn test_decode_hello_hmac_sha256() {
10221281
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
10231282
}
10241283

1284+
#[test]
1285+
fn test_encode_hello_hmac_sha256_lls() {
1286+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA256_LLS;
1287+
test_encode_packet(bytes, auth, hello);
1288+
}
1289+
1290+
#[test]
1291+
fn test_decode_hello_hmac_sha256_lls() {
1292+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA256_LLS;
1293+
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
1294+
}
1295+
10251296
#[test]
10261297
fn test_encode_hello_hmac_sha384() {
10271298
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA384;
@@ -1034,6 +1305,18 @@ fn test_decode_hello_hmac_sha384() {
10341305
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
10351306
}
10361307

1308+
#[test]
1309+
fn test_encode_hello_hmac_sha384_lls() {
1310+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA384_LLS;
1311+
test_encode_packet(bytes, auth, hello);
1312+
}
1313+
1314+
#[test]
1315+
fn test_decode_hello_hmac_sha384_lls() {
1316+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA384_LLS;
1317+
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
1318+
}
1319+
10371320
#[test]
10381321
fn test_encode_hello_hmac_sha512() {
10391322
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA512;
@@ -1046,6 +1329,18 @@ fn test_decode_hello_hmac_sha512() {
10461329
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
10471330
}
10481331

1332+
#[test]
1333+
fn test_encode_hello_hmac_sha512_lls() {
1334+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA512_LLS;
1335+
test_encode_packet(bytes, auth, hello);
1336+
}
1337+
1338+
#[test]
1339+
fn test_decode_hello_hmac_sha512_lls() {
1340+
let (ref bytes, ref auth, ref hello) = *HELLO1_HMAC_SHA512_LLS;
1341+
test_decode_packet(bytes, auth, hello, AddressFamily::Ipv6);
1342+
}
1343+
10491344
#[test]
10501345
fn test_encode_dbdescr1() {
10511346
let (ref bytes, ref auth, ref dbdescr) = *DBDESCR1;

0 commit comments

Comments
 (0)