Skip to main content

rovs_openflow/
lib.rs

1// OpenFlow implementation is work-in-progress
2#![allow(clippy::must_use_candidate)]
3#![allow(clippy::return_self_not_must_use)]
4#![allow(clippy::doc_markdown)]
5#![allow(clippy::missing_errors_doc)]
6#![allow(clippy::struct_excessive_bools)]
7#![allow(clippy::cast_possible_truncation)]
8#![allow(clippy::unused_async)]
9#![allow(clippy::bool_to_int_with_if)]
10#![allow(clippy::cast_lossless)]
11
12//! `OpenFlow` protocol implementation for OVS.
13//!
14//! Provides:
15//! - `OpenFlow` message encoding/decoding
16//! - Match field builder
17//! - Action types
18//! - Flow modification
19//! - Virtual connection (`VConn`) abstraction
20
21mod action;
22mod error;
23mod flow;
24mod flow_monitor;
25mod instruction;
26mod match_fields;
27mod message;
28mod multipart;
29pub mod ndp;
30pub mod oxm;
31mod packet_in;
32mod packet_out;
33mod vconn;
34
35pub use action::{nxm, Action, ActionList, LearnSpec, NatConfig, NxLearn, OutputPort, CT_COMMIT};
36pub use error::{Error, OfError, OfErrorType};
37pub use flow::{Flow, FlowCommand, FlowFlags, FlowStats};
38pub use flow_monitor::{monitor_flags, FlowMonitorRequest, FlowUpdate, FlowUpdateEvent, FlowUpdateFull};
39pub use instruction::{Instruction, InstructionList};
40pub use match_fields::Match;
41pub use message::{Header, Message, MessageType};
42pub use multipart::{FlowStatsEntry, FlowStatsRequest, MultipartType};
43pub use packet_in::{PacketIn, PacketInReason, OFP_NO_BUFFER};
44pub use packet_out::{PacketOut, OFPP_CONTROLLER, OFPP_ANY};
45pub use vconn::VConn;
46
47pub type Result<T> = std::result::Result<T, Error>;
48
49/// OpenFlow protocol versions.
50#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
51#[repr(u8)]
52pub enum Version {
53    /// OpenFlow 1.0
54    Of10 = 0x01,
55    /// OpenFlow 1.1
56    Of11 = 0x02,
57    /// OpenFlow 1.2
58    Of12 = 0x03,
59    /// OpenFlow 1.3
60    Of13 = 0x04,
61    /// OpenFlow 1.4
62    Of14 = 0x05,
63    /// OpenFlow 1.5
64    Of15 = 0x06,
65}
66
67impl Version {
68    /// Get the wire format version number.
69    pub fn wire_version(self) -> u8 {
70        self as u8
71    }
72}
73
74impl TryFrom<u8> for Version {
75    type Error = Error;
76
77    fn try_from(v: u8) -> Result<Self> {
78        match v {
79            0x01 => Ok(Self::Of10),
80            0x02 => Ok(Self::Of11),
81            0x03 => Ok(Self::Of12),
82            0x04 => Ok(Self::Of13),
83            0x05 => Ok(Self::Of14),
84            0x06 => Ok(Self::Of15),
85            _ => Err(Error::UnsupportedVersion(v)),
86        }
87    }
88}