Commit a048d1ba authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

flowmod: change to add flags

parent 53c50a2e
use byteorder::{BigEndian, WriteBytesExt};
pub struct FlowModFlags {
pub send_flow_rem: bool,
pub check_overlap: bool,
pub emerg: bool,
}
impl FlowModFlags {
pub fn new(send_flow_rem: bool, check_overlap: bool, emerg: bool) -> Self {
Self {
send_flow_rem,
check_overlap,
emerg,
}
}
pub fn all_false() -> Self {
Self {
check_overlap: false,
emerg: false,
send_flow_rem: false,
}
}
pub fn parse(byte: u16) -> Self {
let send_flow_rem = byte >> 0 & 1 != 0;
let check_overlap = byte >> 1 & 1 != 0;
let emerg = byte >> 2 & 1 != 0;
Self {
send_flow_rem,
check_overlap,
emerg,
}
}
pub fn marshal(&self, bytes: &mut Vec<u8>) {
let mut value = 0u16;
if self.send_flow_rem {
value |= 1 << 0;
}
if self.check_overlap {
value |= 1 << 1;
}
if self.emerg {
value |= 1 << 2;
}
let _ = bytes.write_u16::<BigEndian>(value);
}
}
...@@ -8,7 +8,7 @@ use crate::openflow::ofp10::{ ...@@ -8,7 +8,7 @@ use crate::openflow::ofp10::{
MessageMarshal, Msg, OfpMsgEvent, PseudoPort, MessageMarshal, Msg, OfpMsgEvent, PseudoPort,
}; };
use super::{FlowModCommand, MatchFields}; use super::{FlowModCommand, FlowModFlags, MatchFields};
pub enum Timeout { pub enum Timeout {
Permanent, Permanent,
...@@ -37,10 +37,9 @@ pub struct FlowModEvent { ...@@ -37,10 +37,9 @@ pub struct FlowModEvent {
cookie: u64, cookie: u64,
idle_timeout: Timeout, idle_timeout: Timeout,
hard_timeout: Timeout, hard_timeout: Timeout,
notify_when_removed: bool, flags: FlowModFlags,
buffer_id: Option<u32>, buffer_id: Option<u32>,
out_port: Option<PseudoPort>, out_port: Option<PseudoPort>,
check_overlap: bool,
} }
impl FlowModEvent { impl FlowModEvent {
...@@ -58,10 +57,9 @@ impl FlowModEvent { ...@@ -58,10 +57,9 @@ impl FlowModEvent {
cookie: 0, cookie: 0,
idle_timeout: Timeout::Permanent, idle_timeout: Timeout::Permanent,
hard_timeout: Timeout::Permanent, hard_timeout: Timeout::Permanent,
notify_when_removed: false, flags: FlowModFlags::all_false(),
buffer_id, buffer_id,
out_port: None, out_port: None,
check_overlap: false,
} }
} }
...@@ -85,7 +83,7 @@ impl FlowModEvent { ...@@ -85,7 +83,7 @@ impl FlowModEvent {
priority, priority,
idle_timeout, idle_timeout,
hard_timeout, hard_timeout,
notify_when_removed: flags & 1 != 0, flags: FlowModFlags::parse(flags),
buffer_id: { buffer_id: {
match buffer_id { match buffer_id {
-1 => None, -1 => None,
...@@ -93,7 +91,6 @@ impl FlowModEvent { ...@@ -93,7 +91,6 @@ impl FlowModEvent {
} }
}, },
out_port, out_port,
check_overlap: flags & 2 != 0,
} }
} }
} }
...@@ -123,10 +120,7 @@ impl MessageMarshal for FlowModEvent { ...@@ -123,10 +120,7 @@ impl MessageMarshal for FlowModEvent {
None => bytes.write_u16::<BigEndian>(OfpPort::None as u16).unwrap(), None => bytes.write_u16::<BigEndian>(OfpPort::None as u16).unwrap(),
Some(p) => p.marshal(bytes), Some(p) => p.marshal(bytes),
} }
let _ = bytes.write_u16::<BigEndian>( self.flags.marshal(bytes);
(if self.check_overlap { 1 << 1 } else { 0 })
| (if self.notify_when_removed { 1 << 0 } else { 0 }),
);
for act in self.actions.move_controller_last() { for act in self.actions.move_controller_last() {
match act { match act {
Action::Oputput(PseudoPort::Table) => { Action::Oputput(PseudoPort::Table) => {
......
...@@ -4,7 +4,8 @@ pub use flow_mod_handler::FlowModEvent; ...@@ -4,7 +4,8 @@ pub use flow_mod_handler::FlowModEvent;
pub mod command; pub mod command;
pub use command::FlowModCommand; pub use command::FlowModCommand;
pub mod match_fields; pub mod match_fields;
pub use match_fields::{Mask, MatchFields}; pub use match_fields::{Mask, MatchFields};
pub mod flow_mod_flags;
pub use flow_mod_flags::FlowModFlags;
\ No newline at end of file
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