Commit ecaef6a6 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

write all messages and change method to convet u8 to Msg

parent 0c981725
...@@ -39,13 +39,13 @@ pub trait ControllerFrame10 { ...@@ -39,13 +39,13 @@ pub trait ControllerFrame10 {
println!("Error {:?}", error.error_type); println!("Error {:?}", error.error_type);
() ()
} }
Msg::FeaturesReq => (), Msg::FeaturesRequest => (),
Msg::PacketIn => { Msg::PacketIn => {
self.packet_in_handler(xid, PacketInEvent::parse(&payload), stream); self.packet_in_handler(xid, PacketInEvent::parse(&payload), stream);
} }
Msg::PacketOut => (), Msg::PacketOut => (),
Msg::FlowMod => (), Msg::FlowMod => (),
Msg::NotFound => (), _ => (),
} }
} }
......
...@@ -12,7 +12,7 @@ impl MessageMarshal for FeaturesReqEvent { ...@@ -12,7 +12,7 @@ impl MessageMarshal for FeaturesReqEvent {
fn marshal(&self, _: &mut Vec<u8>) {} fn marshal(&self, _: &mut Vec<u8>) {}
fn msg_code(&self) -> Msg { fn msg_code(&self) -> Msg {
Msg::FeaturesReq Msg::FeaturesRequest
} }
fn size_of(&self) -> usize { fn size_of(&self) -> usize {
...@@ -20,6 +20,6 @@ impl MessageMarshal for FeaturesReqEvent { ...@@ -20,6 +20,6 @@ impl MessageMarshal for FeaturesReqEvent {
} }
fn msg_usize<OFP: OfpMsgEvent>(&self, ofp: &OFP) -> usize { fn msg_usize<OFP: OfpMsgEvent>(&self, ofp: &OFP) -> usize {
ofp.msg_usize(Msg::FeaturesReq) ofp.msg_usize(Msg::FeaturesRequest)
} }
} }
use std::mem::transmute;
#[derive(Clone)] #[derive(Clone)]
pub enum Msg { pub enum Msg {
Hello = 0, Hello = 0,
Error = 1, Error = 1,
FeaturesReq = 5, EchoRequest = 2,
EchoReply = 3,
Vendor = 4,
FeaturesRequest = 5,
FeaturesReply = 6,
ConfigRequest = 7,
ConfigReply = 8,
SetConfig = 9,
PacketIn = 10, PacketIn = 10,
FlowRemove = 11,
PortStatus = 12,
PacketOut = 13, PacketOut = 13,
FlowMod = 14, FlowMod = 14,
PortMod = 15,
StatsRequest = 16,
StateReply = 17,
BarrierRequest = 18,
BarrierReply = 19,
QueueGetConfigRequest = 20,
QueueGetConfigReply = 21,
NotFound = 0xff, NotFound = 0xff,
} }
...@@ -13,16 +31,10 @@ impl Msg { ...@@ -13,16 +31,10 @@ impl Msg {
pub fn to_int(&self) -> u8 { pub fn to_int(&self) -> u8 {
self.clone() as u8 self.clone() as u8
} }
pub fn parse(msg_code: u8) -> Self { pub fn from(msg_code: u8) -> Self {
type ConvTyp = u8; if msg_code > 21 {
match msg_code { return Self::NotFound;
m if m == (Self::Hello as ConvTyp) => Self::Hello,
m if m == (Self::Error as ConvTyp) => Self::Error,
m if m == (Self::FeaturesReq as ConvTyp) => Self::FeaturesReq,
m if m == (Self::PacketIn as ConvTyp) => Self::PacketIn,
m if m == (Self::PacketOut as ConvTyp) => Self::PacketOut,
m if m == (Self::FlowMod as ConvTyp) => Self::FlowMod,
_ => Self::NotFound,
} }
unsafe { transmute::<u8, Msg>(msg_code) }
} }
} }
...@@ -46,7 +46,7 @@ impl OfpMsgEvent for Openflow10 { ...@@ -46,7 +46,7 @@ impl OfpMsgEvent for Openflow10 {
} }
fn msg_parse(&self, msg: u8) -> Msg { fn msg_parse(&self, msg: u8) -> Msg {
Msg::parse(msg) Msg::from(msg)
} }
fn msg_usize(&self, msg: Msg) -> usize { fn msg_usize(&self, msg: Msg) -> usize {
......
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