Commit c5a87ff1 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

add features_reply event

parent 46111381
...@@ -55,6 +55,7 @@ where ...@@ -55,6 +55,7 @@ where
Msg::EchoRequest => { Msg::EchoRequest => {
self.echo_request_handler(xid, EchoRequestEvent::new(payload), stream) self.echo_request_handler(xid, EchoRequestEvent::new(payload), stream)
} }
Msg::FeaturesReply => {}
Msg::PacketIn => match PacketInEvent::parse(&payload) { Msg::PacketIn => match PacketInEvent::parse(&payload) {
Ok(pkt_in) => self.packet_in_handler(xid, pkt_in, stream), Ok(pkt_in) => self.packet_in_handler(xid, pkt_in, stream),
Err(_) => (), Err(_) => (),
...@@ -87,4 +88,5 @@ where ...@@ -87,4 +88,5 @@ where
fn echo_request_handler(&self, xid: u32, echo: EchoRequestEvent, stream: &mut TcpStream) { fn echo_request_handler(&self, xid: u32, echo: EchoRequestEvent, stream: &mut TcpStream) {
self.send_msg(EchoReplyEvent::new(echo.payload), xid, stream); self.send_msg(EchoReplyEvent::new(echo.payload), xid, stream);
} }
fn switch_features_handler(&self) {}
} }
use std::io::{Cursor, Error};
use byteorder::{BigEndian, ReadBytesExt};
pub struct FeaturesReplyEvent {
pub datapath_id: u64,
pub n_buffers: u32,
pub n_tables: u8,
pub auxiliary: u8,
// pad 16 bit
pub capabilities: Capabilities,
pub reserved: u32,
}
impl FeaturesReplyEvent {
pub fn parse(bytes: &mut Vec<u8>) -> Result<Self, Error> {
let mut bytes = Cursor::new(bytes);
let datapath_id = bytes.read_u64::<BigEndian>()?;
let n_buffers = bytes.read_u32::<BigEndian>()?;
let n_tables = bytes.read_u8()?;
let auxiliary = bytes.read_u8()?;
let capabilities: Capabilities = bytes.read_u32::<BigEndian>()?.into();
let reserved = bytes.read_u32::<BigEndian>()?;
Ok(Self {
datapath_id,
n_buffers,
n_tables,
auxiliary,
capabilities,
reserved,
})
}
}
pub struct Capabilities {
pub flow_stats: bool,
pub table_stats: bool,
pub port_stats: bool,
pub group_stats: bool,
pub ip_reasm: bool,
pub queue_stats: bool,
pub port_blocked: bool,
}
impl From<u32> for Capabilities {
fn from(value: u32) -> Self {
Self {
flow_stats: value & 1 == 1,
table_stats: value >> 1 & 1 == 1,
port_stats: value >> 2 & 1 == 1,
group_stats: value >> 3 & 1 == 1,
ip_reasm: value >> 5 & 1 == 1,
queue_stats: value >> 6 & 1 == 1,
port_blocked: value >> 8 & 1 == 1,
}
}
}
impl From<Capabilities> for u32 {
fn from(value: Capabilities) -> Self {
(value.flow_stats as u32)
| ((value.table_stats as u32) << 1)
| (value.port_stats as u32) << 2
| (value.group_stats as u32) << 3
| (value.ip_reasm as u32) << 5
| (value.queue_stats as u32) << 6
| (value.port_blocked as u32) << 8
}
}
...@@ -19,6 +19,9 @@ pub use hello::HelloEvent; ...@@ -19,6 +19,9 @@ pub use hello::HelloEvent;
pub mod features_req; pub mod features_req;
pub use features_req::FeaturesReqEvent; pub use features_req::FeaturesReqEvent;
pub mod features_reply;
pub use features_reply::FeaturesReplyEvent;
pub mod payload; pub mod payload;
pub use payload::Payload; pub use payload::Payload;
......
...@@ -6,8 +6,8 @@ pub use ofp_port::PseudoPort; ...@@ -6,8 +6,8 @@ pub use ofp_port::PseudoPort;
pub mod events; pub mod events;
pub use events::{ pub use events::{
Action, EchoReplyEvent, EchoRequestEvent, ErrorEvent, FlowModEvent, HelloEvent, MatchFields, Action, EchoReplyEvent, EchoRequestEvent, ErrorEvent, FeaturesReplyEvent, FlowModEvent,
PacketInEvent, PacketOutEvent, HelloEvent, MatchFields, PacketInEvent, PacketOutEvent,
}; };
pub mod ofp_header; pub mod ofp_header;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment