@@ -8,7 +8,7 @@ use crate::{event_section, event_type, Formatter};
8
8
9
9
///The OVS Event
10
10
#[ event_section( SectionId :: Ovs ) ]
11
- #[ derive( Default , PartialEq ) ]
11
+ #[ derive( PartialEq ) ]
12
12
pub struct OvsEvent {
13
13
/// Event data
14
14
#[ serde( flatten) ]
@@ -23,7 +23,7 @@ impl EventFmt for OvsEvent {
23
23
24
24
#[ event_type]
25
25
#[ serde( tag = "event_type" ) ]
26
- #[ derive( Default , PartialEq ) ]
26
+ #[ derive( PartialEq ) ]
27
27
pub enum OvsEventType {
28
28
/// Upcall event. It indicates the begining of an upcall. An upcall can have multiple enqueue
29
29
/// events.
@@ -51,10 +51,6 @@ pub enum OvsEventType {
51
51
/// Action execution event. It indicates the datapath has executed an action on a packet.
52
52
#[ serde( rename = "action_execute" ) ]
53
53
Action ( ActionEvent ) ,
54
-
55
- #[ serde( rename = "undefined" ) ]
56
- #[ default]
57
- Undefined ,
58
54
}
59
55
60
56
impl EventFmt for OvsEventType {
@@ -67,7 +63,6 @@ impl EventFmt for OvsEventType {
67
63
RecvUpcall ( e) => e,
68
64
Operation ( e) => e,
69
65
Action ( e) => e,
70
- Undefined => return write ! ( f, "?" ) ,
71
66
} ;
72
67
73
68
disp. event_fmt ( f, format)
@@ -266,7 +261,7 @@ impl EventFmt for RecvUpcallEvent {
266
261
pub struct ActionEvent {
267
262
/// Action to be executed.
268
263
#[ serde( flatten) ]
269
- pub action : OvsAction ,
264
+ pub action : Option < OvsAction > ,
270
265
/// Recirculation id.
271
266
pub recirc_id : u32 ,
272
267
/// Queue id used for tracking. None if not tracking or if the output event did not come from
@@ -284,19 +279,18 @@ impl EventFmt for ActionEvent {
284
279
write ! ( f, "exec" ) ?;
285
280
286
281
match & self . action {
287
- OvsAction :: Unspecified => write ! ( f, " (unspecified)" ) ?,
288
- OvsAction :: Output ( a) => write ! ( f, " oport {}" , a. port) ?,
289
- OvsAction :: Userspace => write ! ( f, " userspace" ) ?,
290
- OvsAction :: Set => write ! ( f, " tunnel_set" ) ?,
291
- OvsAction :: PushVlan => write ! ( f, " push_vlan" ) ?,
292
- OvsAction :: PopVlan => write ! ( f, " pop_vlan" ) ?,
293
- OvsAction :: Sample => write ! ( f, " sample" ) ?,
294
- OvsAction :: Recirc ( a) => write ! ( f, " recirc {:#x}" , a. id) ?,
295
- OvsAction :: Hash => write ! ( f, " hash" ) ?,
296
- OvsAction :: PushMpls => write ! ( f, " push_mpls" ) ?,
297
- OvsAction :: PopMpls => write ! ( f, " pop_mpls" ) ?,
298
- OvsAction :: SetMasked => write ! ( f, " set_masked" ) ?,
299
- OvsAction :: Ct ( ct) => {
282
+ Some ( OvsAction :: Output ( a) ) => write ! ( f, " oport {}" , a. port) ?,
283
+ Some ( OvsAction :: Userspace ( _) ) => write ! ( f, " userspace" ) ?,
284
+ Some ( OvsAction :: Set ( _) ) => write ! ( f, " tunnel_set" ) ?,
285
+ Some ( OvsAction :: PushVlan ( _) ) => write ! ( f, " push_vlan" ) ?,
286
+ Some ( OvsAction :: PopVlan ( _) ) => write ! ( f, " pop_vlan" ) ?,
287
+ Some ( OvsAction :: Sample ( _) ) => write ! ( f, " sample" ) ?,
288
+ Some ( OvsAction :: Recirc ( a) ) => write ! ( f, " recirc {:#x}" , a. id) ?,
289
+ Some ( OvsAction :: Hash ( _) ) => write ! ( f, " hash" ) ?,
290
+ Some ( OvsAction :: PushMpls ( _) ) => write ! ( f, " push_mpls" ) ?,
291
+ Some ( OvsAction :: PopMpls ( _) ) => write ! ( f, " pop_mpls" ) ?,
292
+ Some ( OvsAction :: SetMasked ( _) ) => write ! ( f, " set_masked" ) ?,
293
+ Some ( OvsAction :: Ct ( ct) ) => {
300
294
write ! ( f, " ct zone {}" , ct. zone_id) ?;
301
295
302
296
if let Some ( nat) = & ct. nat {
@@ -358,17 +352,18 @@ impl EventFmt for ActionEvent {
358
352
write ! ( f, " {}" , flags. join( "," ) ) ?;
359
353
}
360
354
}
361
- OvsAction :: Trunc => write ! ( f, " trunc" ) ?,
362
- OvsAction :: PushEth => write ! ( f, " push_eth" ) ?,
363
- OvsAction :: PopEth => write ! ( f, " pop_eth" ) ?,
364
- OvsAction :: CtClear => write ! ( f, " ct_clear" ) ?,
365
- OvsAction :: PushNsh => write ! ( f, " push_nsh" ) ?,
366
- OvsAction :: PopNsh => write ! ( f, " pop_nsh" ) ?,
367
- OvsAction :: Meter => write ! ( f, " meter" ) ?,
368
- OvsAction :: Clone => write ! ( f, " clone" ) ?,
369
- OvsAction :: CheckPktLen => write ! ( f, " check_pkt_len" ) ?,
370
- OvsAction :: AddMpls => write ! ( f, " add_mpls" ) ?,
371
- OvsAction :: DecTtl => write ! ( f, " dec_ttl" ) ?,
355
+ Some ( OvsAction :: Trunc ( _) ) => write ! ( f, " trunc" ) ?,
356
+ Some ( OvsAction :: PushEth ( _) ) => write ! ( f, " push_eth" ) ?,
357
+ Some ( OvsAction :: PopEth ( _) ) => write ! ( f, " pop_eth" ) ?,
358
+ Some ( OvsAction :: CtClear ( _) ) => write ! ( f, " ct_clear" ) ?,
359
+ Some ( OvsAction :: PushNsh ( _) ) => write ! ( f, " push_nsh" ) ?,
360
+ Some ( OvsAction :: PopNsh ( _) ) => write ! ( f, " pop_nsh" ) ?,
361
+ Some ( OvsAction :: Meter ( _) ) => write ! ( f, " meter" ) ?,
362
+ Some ( OvsAction :: Clone ( _) ) => write ! ( f, " clone" ) ?,
363
+ Some ( OvsAction :: CheckPktLen ( _) ) => write ! ( f, " check_pkt_len" ) ?,
364
+ Some ( OvsAction :: AddMpls ( _) ) => write ! ( f, " add_mpls" ) ?,
365
+ Some ( OvsAction :: DecTtl ( _) ) => write ! ( f, " dec_ttl" ) ?,
366
+ None => write ! ( f, " unspec" ) ?,
372
367
}
373
368
374
369
if let Some ( p) = self . queue_id {
@@ -379,59 +374,62 @@ impl EventFmt for ActionEvent {
379
374
}
380
375
}
381
376
377
+ // Adding unit values in an otherwise complex is not supported by pyo3.
378
+ // FIXME: Remove when arguments from all actions are implemented.
379
+ #[ event_type]
380
+ #[ derive( PartialEq ) ]
381
+ pub struct OvsDummyAction ;
382
+
382
383
#[ event_type]
383
384
#[ serde( tag = "action" ) ]
384
- #[ derive( Default , PartialEq ) ]
385
+ #[ derive( PartialEq ) ]
385
386
pub enum OvsAction {
386
- #[ serde( rename = "unspecified" ) ]
387
- #[ default]
388
- Unspecified ,
389
387
#[ serde( rename = "output" ) ]
390
388
Output ( OvsActionOutput ) ,
391
389
#[ serde( rename = "userspace" ) ]
392
- Userspace ,
390
+ Userspace ( OvsDummyAction ) ,
393
391
#[ serde( rename = "set" ) ]
394
- Set ,
392
+ Set ( OvsDummyAction ) ,
395
393
#[ serde( rename = "push_vlan" ) ]
396
- PushVlan ,
394
+ PushVlan ( OvsDummyAction ) ,
397
395
#[ serde( rename = "pop_vlan" ) ]
398
- PopVlan ,
396
+ PopVlan ( OvsDummyAction ) ,
399
397
#[ serde( rename = "sample" ) ]
400
- Sample ,
398
+ Sample ( OvsDummyAction ) ,
401
399
#[ serde( rename = "recirc" ) ]
402
400
Recirc ( OvsActionRecirc ) ,
403
401
#[ serde( rename = "hash" ) ]
404
- Hash ,
402
+ Hash ( OvsDummyAction ) ,
405
403
#[ serde( rename = "push_mpls" ) ]
406
- PushMpls ,
404
+ PushMpls ( OvsDummyAction ) ,
407
405
#[ serde( rename = "pop_mpls" ) ]
408
- PopMpls ,
406
+ PopMpls ( OvsDummyAction ) ,
409
407
#[ serde( rename = "set_masked" ) ]
410
- SetMasked ,
408
+ SetMasked ( OvsDummyAction ) ,
411
409
#[ serde( rename = "ct" ) ]
412
410
Ct ( OvsActionCt ) ,
413
411
#[ serde( rename = "trunc" ) ]
414
- Trunc ,
412
+ Trunc ( OvsDummyAction ) ,
415
413
#[ serde( rename = "push_eth" ) ]
416
- PushEth ,
414
+ PushEth ( OvsDummyAction ) ,
417
415
#[ serde( rename = "pop_eth" ) ]
418
- PopEth ,
416
+ PopEth ( OvsDummyAction ) ,
419
417
#[ serde( rename = "ct_clear" ) ]
420
- CtClear ,
418
+ CtClear ( OvsDummyAction ) ,
421
419
#[ serde( rename = "push_nsh" ) ]
422
- PushNsh ,
420
+ PushNsh ( OvsDummyAction ) ,
423
421
#[ serde( rename = "pop_nsh" ) ]
424
- PopNsh ,
422
+ PopNsh ( OvsDummyAction ) ,
425
423
#[ serde( rename = "meter" ) ]
426
- Meter ,
424
+ Meter ( OvsDummyAction ) ,
427
425
#[ serde( rename = "clone" ) ]
428
- Clone ,
426
+ Clone ( OvsDummyAction ) ,
429
427
#[ serde( rename = "check_pkt_len" ) ]
430
- CheckPktLen ,
428
+ CheckPktLen ( OvsDummyAction ) ,
431
429
#[ serde( rename = "add_mpls" ) ]
432
- AddMpls ,
430
+ AddMpls ( OvsDummyAction ) ,
433
431
#[ serde( rename = "dec_ttl" ) ]
434
- DecTtl ,
432
+ DecTtl ( OvsDummyAction ) ,
435
433
}
436
434
437
435
/// OVS output action data.
@@ -555,7 +553,7 @@ mod tests {
555
553
r#"{"action":"output","event_type":"action_execute","port":2,"queue_id":1361394472,"recirc_id":0}"# ,
556
554
OvsEvent {
557
555
event : OvsEventType :: Action ( ActionEvent {
558
- action : OvsAction :: Output ( OvsActionOutput { port : 2 } ) ,
556
+ action : Some ( OvsAction :: Output ( OvsActionOutput { port : 2 } ) ) ,
559
557
recirc_id : 0 ,
560
558
queue_id : Some ( 1361394472 ) ,
561
559
} ) ,
@@ -615,7 +613,7 @@ mod tests {
615
613
r#"{"action":"ct","event_type":"action_execute","flags":485,"nat":{"dir":"dst","max_addr":"10.244.1.30","max_port":36900,"min_addr":"10.244.1.3","min_port":36895},"recirc_id":34,"zone_id":20}"# ,
616
614
OvsEvent {
617
615
event : OvsEventType :: Action ( ActionEvent {
618
- action : OvsAction :: Ct ( OvsActionCt {
616
+ action : Some ( OvsAction :: Ct ( OvsActionCt {
619
617
zone_id : 20 ,
620
618
flags : 485 ,
621
619
nat : Some ( OvsActionCtNat {
@@ -625,7 +623,7 @@ mod tests {
625
623
min_port : Some ( 36895 ) ,
626
624
max_port : Some ( 36900 ) ,
627
625
} ) ,
628
- } ) ,
626
+ } ) ) ,
629
627
recirc_id : 34 ,
630
628
queue_id : None ,
631
629
} ) ,
0 commit comments