7
7
// See: https://nlnet.nl/NGI0
8
8
//
9
9
10
+ use holo_utils:: DatabaseError ;
10
11
use holo_utils:: ip:: AddressFamily ;
11
12
use holo_yang:: ToYang ;
12
13
use tracing:: { error, warn, warn_span} ;
13
14
14
15
use crate :: collections:: { AdjacencyId , InterfaceId , LspEntryId } ;
15
16
use crate :: network:: MulticastAddr ;
17
+ use crate :: packet:: consts:: PduType ;
16
18
use crate :: packet:: error:: DecodeError ;
19
+ use crate :: packet:: tlv:: ExtendedSeqNum ;
17
20
use crate :: packet:: { LevelNumber , SystemId } ;
18
21
use crate :: spf;
19
22
@@ -26,9 +29,8 @@ pub enum Error {
26
29
InterfaceIdNotFound ( InterfaceId ) ,
27
30
AdjacencyIdNotFound ( AdjacencyId ) ,
28
31
LspEntryIdNotFound ( LspEntryId ) ,
29
- // Packet input
30
- PduDecodeError ( String , [ u8 ; 6 ] , DecodeError ) ,
31
- AdjacencyReject ( String , [ u8 ; 6 ] , AdjacencyRejectError ) ,
32
+ // PDU input
33
+ PduInputError ( String , [ u8 ; 6 ] , PduInputError ) ,
32
34
// Segment Routing
33
35
SrCapNotFound ( LevelNumber , SystemId ) ,
34
36
SrCapUnsupportedAf ( LevelNumber , SystemId , AddressFamily ) ,
@@ -38,6 +40,7 @@ pub enum Error {
38
40
SpfDelayUnexpectedEvent ( LevelNumber , spf:: fsm:: State , spf:: fsm:: Event ) ,
39
41
InterfaceStartError ( String , Box < Error > ) ,
40
42
InstanceStartError ( Box < Error > ) ,
43
+ BootCountNvmUpdate ( DatabaseError ) ,
41
44
}
42
45
43
46
// IS-IS I/O errors.
@@ -51,6 +54,13 @@ pub enum IoError {
51
54
SendError ( std:: io:: Error ) ,
52
55
}
53
56
57
+ #[ derive( Debug ) ]
58
+ pub enum PduInputError {
59
+ DecodeError ( DecodeError ) ,
60
+ AdjacencyReject ( AdjacencyRejectError ) ,
61
+ ExtendedSeqNumError ( ExtendedSeqNumError ) ,
62
+ }
63
+
54
64
#[ derive( Debug ) ]
55
65
pub enum AdjacencyRejectError {
56
66
InvalidHelloType ,
@@ -62,6 +72,12 @@ pub enum AdjacencyRejectError {
62
72
NoCommonMt ,
63
73
}
64
74
75
+ #[ derive( Debug ) ]
76
+ pub enum ExtendedSeqNumError {
77
+ MissingSeqNum ( PduType ) ,
78
+ InvalidSeqNum ( PduType , ExtendedSeqNum ) ,
79
+ }
80
+
65
81
// ===== impl Error =====
66
82
67
83
impl Error {
@@ -79,14 +95,7 @@ impl Error {
79
95
Error :: LspEntryIdNotFound ( lse_id) => {
80
96
warn ! ( ?lse_id, "{}" , self ) ;
81
97
}
82
- Error :: PduDecodeError ( ifname, source, error) => {
83
- warn_span ! ( "interface" , name = %ifname, ?source) . in_scope (
84
- || {
85
- warn ! ( %error, "{}" , self ) ;
86
- } ,
87
- )
88
- }
89
- Error :: AdjacencyReject ( ifname, source, error) => {
98
+ Error :: PduInputError ( ifname, source, error) => {
90
99
warn_span ! ( "interface" , name = %ifname, ?source) . in_scope (
91
100
|| {
92
101
error. log ( ) ;
@@ -114,6 +123,9 @@ impl Error {
114
123
Error :: InstanceStartError ( error) => {
115
124
error ! ( error = %with_source( error) , "{}" , self ) ;
116
125
}
126
+ Error :: BootCountNvmUpdate ( error) => {
127
+ error ! ( %error, "{}" , self ) ;
128
+ }
117
129
}
118
130
}
119
131
}
@@ -131,10 +143,9 @@ impl std::fmt::Display for Error {
131
143
Error :: LspEntryIdNotFound ( ..) => {
132
144
write ! ( f, "LSP entry ID not found" )
133
145
}
134
- Error :: PduDecodeError ( ..) => {
146
+ Error :: PduInputError ( ..) => {
135
147
write ! ( f, "failed to decode packet" )
136
148
}
137
- Error :: AdjacencyReject ( _, _, error) => error. fmt ( f) ,
138
149
Error :: CircuitIdAllocationFailed => {
139
150
write ! ( f, "failed to allocate Circuit ID" )
140
151
}
@@ -159,6 +170,12 @@ impl std::fmt::Display for Error {
159
170
Error :: InstanceStartError ( ..) => {
160
171
write ! ( f, "failed to start instance" )
161
172
}
173
+ Error :: BootCountNvmUpdate ( ..) => {
174
+ write ! (
175
+ f,
176
+ "failed to record updated boot count in non-volatile storage"
177
+ )
178
+ }
162
179
}
163
180
}
164
181
}
@@ -243,10 +260,40 @@ impl std::error::Error for IoError {
243
260
}
244
261
}
245
262
263
+ // ===== impl PduInputError =====
264
+
265
+ impl PduInputError {
266
+ fn log ( & self ) {
267
+ match self {
268
+ PduInputError :: DecodeError ( error) => {
269
+ warn ! ( "{}" , error) ;
270
+ }
271
+ PduInputError :: AdjacencyReject ( error) => {
272
+ error. log ( ) ;
273
+ }
274
+ PduInputError :: ExtendedSeqNumError ( error) => {
275
+ error. log ( ) ;
276
+ }
277
+ }
278
+ }
279
+ }
280
+
281
+ impl From < AdjacencyRejectError > for PduInputError {
282
+ fn from ( error : AdjacencyRejectError ) -> PduInputError {
283
+ PduInputError :: AdjacencyReject ( error)
284
+ }
285
+ }
286
+
287
+ impl From < ExtendedSeqNumError > for PduInputError {
288
+ fn from ( error : ExtendedSeqNumError ) -> PduInputError {
289
+ PduInputError :: ExtendedSeqNumError ( error)
290
+ }
291
+ }
292
+
246
293
// ===== impl AdjacencyRejectError =====
247
294
248
295
impl AdjacencyRejectError {
249
- pub ( crate ) fn log ( & self ) {
296
+ fn log ( & self ) {
250
297
match self {
251
298
AdjacencyRejectError :: MaxAreaAddrsMismatch ( max_area_addrs) => {
252
299
warn ! ( %max_area_addrs, "{}" , self ) ;
@@ -288,6 +335,36 @@ impl std::fmt::Display for AdjacencyRejectError {
288
335
289
336
impl std:: error:: Error for AdjacencyRejectError { }
290
337
338
+ // ===== impl ExtendedSeqNumError =====
339
+
340
+ impl ExtendedSeqNumError {
341
+ fn log ( & self ) {
342
+ match self {
343
+ ExtendedSeqNumError :: MissingSeqNum ( pdu_type) => {
344
+ warn ! ( ?pdu_type, "{}" , self ) ;
345
+ }
346
+ ExtendedSeqNumError :: InvalidSeqNum ( pdu_type, ext_seqnum) => {
347
+ warn ! ( ?pdu_type, ?ext_seqnum, "{}" , self ) ;
348
+ }
349
+ }
350
+ }
351
+ }
352
+
353
+ impl std:: fmt:: Display for ExtendedSeqNumError {
354
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
355
+ match self {
356
+ ExtendedSeqNumError :: MissingSeqNum ( ..) => {
357
+ write ! ( f, "missing extended sequence number" )
358
+ }
359
+ ExtendedSeqNumError :: InvalidSeqNum ( ..) => {
360
+ write ! ( f, "invalid extended sequence number" )
361
+ }
362
+ }
363
+ }
364
+ }
365
+
366
+ impl std:: error:: Error for ExtendedSeqNumError { }
367
+
291
368
// ===== helper functions =====
292
369
293
370
fn with_source < E : std:: error:: Error > ( error : E ) -> String {
0 commit comments