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::{
MessageMarshal, Msg, OfpMsgEvent, PseudoPort,
};
use super::{FlowModCommand, MatchFields};
use super::{FlowModCommand, FlowModFlags, MatchFields};
pub enum Timeout {
Permanent,
......@@ -37,10 +37,9 @@ pub struct FlowModEvent {
cookie: u64,
idle_timeout: Timeout,
hard_timeout: Timeout,
notify_when_removed: bool,
flags: FlowModFlags,
buffer_id: Option<u32>,
out_port: Option<PseudoPort>,
check_overlap: bool,
}
impl FlowModEvent {
......@@ -58,10 +57,9 @@ impl FlowModEvent {
cookie: 0,
idle_timeout: Timeout::Permanent,
hard_timeout: Timeout::Permanent,
notify_when_removed: false,
flags: FlowModFlags::all_false(),
buffer_id,
out_port: None,
check_overlap: false,
}
}
......@@ -85,7 +83,7 @@ impl FlowModEvent {
priority,
idle_timeout,
hard_timeout,
notify_when_removed: flags & 1 != 0,
flags: FlowModFlags::parse(flags),
buffer_id: {
match buffer_id {
-1 => None,
......@@ -93,7 +91,6 @@ impl FlowModEvent {
}
},
out_port,
check_overlap: flags & 2 != 0,
}
}
}
......@@ -123,10 +120,7 @@ impl MessageMarshal for FlowModEvent {
None => bytes.write_u16::<BigEndian>(OfpPort::None as u16).unwrap(),
Some(p) => p.marshal(bytes),
}
let _ = bytes.write_u16::<BigEndian>(
(if self.check_overlap { 1 << 1 } else { 0 })
| (if self.notify_when_removed { 1 << 0 } else { 0 }),
);
self.flags.marshal(bytes);
for act in self.actions.move_controller_last() {
match act {
Action::Oputput(PseudoPort::Table) => {
......
......@@ -4,7 +4,8 @@ pub use flow_mod_handler::FlowModEvent;
pub mod command;
pub use command::FlowModCommand;
pub mod match_fields;
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