tenjin_sdn/openflow/ofp13/message.rs
1//! OpenFlow 1.3 Message Types
2//!
3//! This module defines the message types used in OpenFlow 1.3 protocol communication.
4//! OpenFlow 1.3 introduces several new message types and features compared to 1.0,
5//! including support for multiple tables, groups, meters, and enhanced statistics.
6
7use std::mem::transmute;
8
9/// Represents all possible OpenFlow 1.3 message types
10///
11/// Each variant corresponds to a specific message type in the OpenFlow 1.3 protocol.
12/// The values match the official OpenFlow 1.3 specification message type codes.
13#[repr(u8)]
14#[derive(Clone)]
15pub enum Msg {
16 /// Initial handshake message
17 Hello = 0,
18 /// Error notification message
19 Error = 1,
20 /// Echo request for connection testing
21 EchoRequest = 2,
22 /// Echo reply for connection testing
23 EchoReply = 3,
24 /// Experimenter-specific message
25 Experimenter = 4,
26 /// Request switch features
27 FeaturesRequest = 5,
28 /// Switch features reply
29 FeaturesReply = 6,
30 /// Request switch configuration
31 ConfigRequest = 7,
32 /// Switch configuration reply
33 ConfigReply = 8,
34 /// Set switch configuration
35 SetConfig = 9,
36 /// Packet received by switch
37 PacketIn = 10,
38 /// Flow removed notification
39 FlowRemove = 11,
40 /// Port status change notification
41 PortStatus = 12,
42 /// Packet to be sent by switch
43 PacketOut = 13,
44 /// Flow table modification
45 FlowMod = 14,
46 /// Group table modification
47 GroupMod = 15,
48 /// Port configuration modification
49 PortMod = 16,
50 /// Table configuration modification
51 TableMod = 17,
52 /// Multipart message request
53 MultipartRequest = 18,
54 /// Multipart message reply
55 MultipartReply = 19,
56 /// Request to ensure all previous messages are processed
57 BarrierRequest = 20,
58 /// Barrier reply confirmation
59 BarrierReply = 21,
60 /// Get configuration request
61 GetConfigRequest = 22,
62 /// Get configuration reply
63 GetConfigReply = 23,
64 /// Controller role request
65 RoleRequest = 24,
66 /// Controller role reply
67 RoleReply = 25,
68 /// Get asynchronous message configuration request
69 GetAsyncRequest = 26,
70 /// Get asynchronous message configuration reply
71 GetAsyncReply = 27,
72 /// Set asynchronous message configuration
73 SetAsync = 28,
74 /// Meter table modification
75 MeterMod = 29,
76 /// Unknown or unsupported message type
77 NotFound = 0xff,
78}
79
80impl Msg {
81 /// Converts the message type to its corresponding integer value
82 pub fn to_int(&self) -> u8 {
83 self.clone().into()
84 }
85
86 /// Creates a message type from an integer value
87 ///
88 /// # Arguments
89 /// * `msg_code` - The integer code representing the message type
90 ///
91 /// # Returns
92 /// The corresponding Msg enum variant, or NotFound if the code is invalid
93 pub fn from(msg_code: u8) -> Self {
94 if msg_code > 21 {
95 return Self::NotFound;
96 }
97 unsafe { transmute::<u8, Msg>(msg_code) }
98 }
99}
100
101/// Implementation of From trait to convert Msg to u8
102impl From<Msg> for u8 {
103 fn from(value: Msg) -> Self {
104 value as u8
105 }
106}