-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and plan for others message
- Loading branch information
1 parent
2a1ef30
commit f8cf010
Showing
12 changed files
with
141 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
use crate::openflow::{trait_marshal::MessageMarshal, OfpMsg}; | ||
use crate::openflow::messages::{MessageMarshal, OfpMsg}; | ||
use crate::openflow::traiter::OfpMsgEvent; | ||
|
||
pub struct HelloEvent {} | ||
|
||
impl HelloEvent { | ||
pub fn new() -> Self { | ||
pub fn new() -> Self { | ||
HelloEvent {} | ||
} | ||
} | ||
|
||
impl MessageMarshal for HelloEvent { | ||
fn marshal(&self, _: &mut Vec<u8>) {} | ||
|
||
fn msg_code(&self) -> crate::openflow::OfpMsg { | ||
fn msg_code(&self) -> OfpMsg { | ||
OfpMsg::Hello | ||
} | ||
|
||
fn size_of(&self) -> usize { | ||
0 | ||
} | ||
|
||
fn msg_usize<OFP: OfpMsgEvent>(&self, ofp: &OFP) -> usize { | ||
ofp.msg_usize(OfpMsg::Hello) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod ofp_message; | ||
pub use ofp_message::OfpMsg; | ||
|
||
pub mod traiter; | ||
pub use traiter::MessageMarshal; | ||
pub use traiter::OfpMsgEvent; | ||
|
||
pub mod ofp_v1_0; | ||
pub use ofp_v1_0::Openflow10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub enum OfpMsg { | ||
Hello = 0, | ||
FeaturesReq = 5, | ||
PacketIn = 8, | ||
FlowMod = 14, | ||
NotFound = -1, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::openflow::{ | ||
events::{FeaturesReq, HelloEvent}, | ||
OfpHeader, | ||
}; | ||
|
||
use super::traiter::OfpMsgEvent; | ||
use super::OfpMsg; | ||
|
||
pub struct Openflow10 {} | ||
|
||
impl Openflow10 { | ||
pub fn new() -> Self { | ||
Openflow10 {} | ||
} | ||
} | ||
|
||
impl OfpMsgEvent for Openflow10 { | ||
fn hello_event(&self) -> HelloEvent { | ||
HelloEvent::new() | ||
} | ||
|
||
fn fetures_req(&self) -> FeaturesReq { | ||
FeaturesReq::new() | ||
} | ||
|
||
fn version(&self) -> usize { | ||
1 | ||
} | ||
|
||
fn header(&self, message: u8, length: u16, xid: u32) -> OfpHeader { | ||
OfpHeader { | ||
version: 1, | ||
message, | ||
length, | ||
xid, | ||
} | ||
} | ||
|
||
fn msg_parse(&self, msg: u16) -> OfpMsg { | ||
match msg { | ||
0 => OfpMsg::Hello, | ||
5 => OfpMsg::FeaturesReq, | ||
8 => OfpMsg::PacketIn, | ||
14 => OfpMsg::FlowMod, | ||
_ => OfpMsg::NotFound, | ||
} | ||
} | ||
|
||
fn msg_usize(&self, msg: OfpMsg) -> usize { | ||
match msg { | ||
OfpMsg::Hello => 0, | ||
OfpMsg::FeaturesReq => 5, | ||
OfpMsg::PacketIn => 8, | ||
OfpMsg::FlowMod => 14, | ||
_ => 1024, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::openflow::{ | ||
events::{FeaturesReq, HelloEvent}, | ||
OfpHeader, | ||
}; | ||
|
||
use super::OfpMsg; | ||
|
||
/** | ||
* the trait for parse value to bytes. | ||
* for use with Controller's send_msg. | ||
*/ | ||
pub trait MessageMarshal { | ||
fn marshal(&self, bytes: &mut Vec<u8>); | ||
fn msg_code(&self) -> OfpMsg; | ||
fn msg_usize<OFP: OfpMsgEvent>(&self, ofp: &OFP) -> usize; | ||
fn size_of(&self) -> usize; | ||
} | ||
|
||
/** | ||
* for works with controller to create OfpMsgEvent | ||
*/ | ||
pub trait OfpMsgEvent { | ||
fn header(&self, message: u8, length: u16, xid: u32) -> OfpHeader; | ||
fn hello_event(&self) -> HelloEvent; | ||
fn fetures_req(&self) -> FeaturesReq; | ||
fn version(&self) -> usize; | ||
fn msg_parse(&self, msg: u16) -> OfpMsg; | ||
fn msg_usize(&self, msg: OfpMsg) -> usize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.