Skip to main content

tenjin_sdn/openflow/ofp13/events/flow_mod/
command.rs

1//! OpenFlow v1.3 Flow Modification Commands
2//!
3//! This module defines the different commands that can be used to modify
4//! flow entries in the OpenFlow switch's flow tables.
5
6/// Commands for modifying flow entries in the OpenFlow switch
7#[repr(u8)]
8pub enum FlowModCommand {
9    /// Add a new flow entry
10    Add = 0,
11    /// Modify all matching flow entries
12    Modify = 1,
13    /// Modify flow entries with exactly matching fields
14    ModifyStrict = 2,
15    /// Delete all matching flow entries
16    Delete = 3,
17    /// Delete flow entries with exactly matching fields
18    DeleteStrict = 4,
19    /// Command could not be parsed
20    Unparsable = 0xff,
21}
22
23impl FlowModCommand {
24    /// Converts the command to its numeric representation
25    ///
26    /// # Returns
27    /// * `usize` - The numeric value of the command
28    pub fn to_number(&self) -> usize {
29        match self {
30            FlowModCommand::Add => Self::Add as usize,
31            FlowModCommand::Modify => Self::Modify as usize,
32            FlowModCommand::ModifyStrict => Self::ModifyStrict as usize,
33            FlowModCommand::Delete => Self::Delete as usize,
34            FlowModCommand::DeleteStrict => Self::DeleteStrict as usize,
35            FlowModCommand::Unparsable => Self::Unparsable as usize,
36        }
37    }
38
39    /// Parses a command from its numeric representation
40    ///
41    /// # Arguments
42    /// * `byte` - The numeric value to parse
43    ///
44    /// # Returns
45    /// * `FlowModCommand` - The parsed command or Unparsable if invalid
46    pub fn parse(byte: u16) -> Self {
47        match byte {
48            0 => Self::Add,
49            1 => Self::Modify,
50            2 => Self::ModifyStrict,
51            3 => Self::Delete,
52            4 => Self::DeleteStrict,
53            _ => Self::Unparsable,
54        }
55    }
56}