Commit 8a49beb1 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

move trait to outside ofp10

parent 14945b63
...@@ -10,9 +10,9 @@ use crate::{ ...@@ -10,9 +10,9 @@ use crate::{
self, self,
events::{flow_mod::MatchFields, Action}, events::{flow_mod::MatchFields, Action},
ofp_v1_0::Openflow10, ofp_v1_0::Openflow10,
traiter::OfpMsgEvent,
FlowModEvent, PacketInEvent, FlowModEvent, PacketInEvent,
}, },
traiter::OfpMsgEvent,
}, },
}; };
/** /**
......
use crate::openflow::ofp10::{ use crate::openflow::ofp10::{
traiter::{MessageMarshal, OfpMsgEvent},
ErrorEvent, Msg, PacketInEvent, ErrorEvent, Msg, PacketInEvent,
}; };
use std::{ use std::{
...@@ -7,7 +6,7 @@ use std::{ ...@@ -7,7 +6,7 @@ use std::{
net::TcpStream, net::TcpStream,
}; };
use super::tcp_listener::tcp_listener_handler; use super::{tcp_listener::tcp_listener_handler, traiter::{MessageMarshal, OfpMsgEvent}};
pub trait ControllerFrame<OME: OfpMsgEvent> { pub trait ControllerFrame<OME: OfpMsgEvent> {
fn get_ofp(&self) -> &impl OfpMsgEvent; fn get_ofp(&self) -> &impl OfpMsgEvent;
......
pub mod controller_frame; pub mod controller_frame;
pub mod ofp10; pub mod ofp10;
pub mod tcp_listener; pub mod tcp_listener;
pub mod traiter;
\ No newline at end of file
use std::{io::{BufRead, Cursor}, mem::size_of}; use std::{
io::{BufRead, Cursor},
use crate::openflow::ofp10::{traiter::MessageMarshal, Msg}; mem::size_of,
use byteorder::{BigEndian, ReadBytesExt}; };
use super::error_type::ErrorType; use super::error_type::ErrorType;
use crate::openflow::{
ofp10::Msg,
traiter::{MessageMarshal, OfpMsgEvent},
};
use byteorder::{BigEndian, ReadBytesExt};
pub struct ErrorEvent { pub struct ErrorEvent {
pub error_type: ErrorType, pub error_type: ErrorType,
...@@ -34,11 +39,11 @@ impl MessageMarshal for ErrorEvent { ...@@ -34,11 +39,11 @@ impl MessageMarshal for ErrorEvent {
Msg::Error Msg::Error
} }
fn msg_usize<OFP: crate::openflow::ofp10::traiter::OfpMsgEvent>(&self, ofp: &OFP) -> usize { fn msg_usize<OFP: OfpMsgEvent>(&self, ofp: &OFP) -> usize {
ofp.msg_usize(Msg::Error) ofp.msg_usize(Msg::Error)
} }
fn size_of(&self) -> usize { fn size_of(&self) -> usize {
size_of::<(u16,u16)>() + self.payload.len() size_of::<(u16, u16)>() + self.payload.len()
} }
} }
use crate::openflow::ofp10::{traiter::{MessageMarshal, OfpMsgEvent}, Msg}; use crate::openflow::{
ofp10::Msg,
traiter::{MessageMarshal, OfpMsgEvent},
};
pub struct FeaturesReqEvent {} pub struct FeaturesReqEvent {}
......
...@@ -2,11 +2,17 @@ use std::io::Cursor; ...@@ -2,11 +2,17 @@ use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use crate::openflow::ofp10::{events::{actions::SizeCheck, Action}, ofp_port::OfpPort, traiter::{MessageMarshal, OfpMsgEvent}, Msg, PseudoPort}; use crate::openflow::{
ofp10::{
events::{actions::SizeCheck, Action},
ofp_port::OfpPort,
Msg, PseudoPort,
},
traiter::{MessageMarshal, OfpMsgEvent},
};
use super::{FlowModCommand, MatchFields}; use super::{FlowModCommand, MatchFields};
pub enum Timeout { pub enum Timeout {
Permanent, Permanent,
ExpireAfter(u16), ExpireAfter(u16),
......
use crate::openflow::ofp10::{traiter::{MessageMarshal, OfpMsgEvent}, Msg}; use crate::openflow::{
ofp10::Msg,
traiter::{MessageMarshal, OfpMsgEvent},
};
pub struct HelloEvent {} pub struct HelloEvent {}
......
...@@ -4,9 +4,9 @@ use std::{ ...@@ -4,9 +4,9 @@ use std::{
}; };
use crate::openflow::ofp10::{ofp_port::OfpPort, Msg}; use crate::openflow::ofp10::{ofp_port::OfpPort, Msg};
use crate::openflow::ofp10::{ use crate::openflow::{
ofp10::PseudoPort,
traiter::{MessageMarshal, OfpMsgEvent}, traiter::{MessageMarshal, OfpMsgEvent},
PseudoPort,
}; };
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
......
...@@ -9,4 +9,3 @@ pub use events::{ErrorEvent, FlowModEvent, HelloEvent, PacketInEvent, PacketOutE ...@@ -9,4 +9,3 @@ pub use events::{ErrorEvent, FlowModEvent, HelloEvent, PacketInEvent, PacketOutE
pub mod ofp_header; pub mod ofp_header;
pub mod ofp_v1_0; pub mod ofp_v1_0;
pub mod traiter;
pub mod header_traiter;
pub use header_traiter::OpenflowHeader;
pub mod ofp_header; pub mod ofp_header;
pub use ofp_header::OfpHeader; pub use ofp_header::OfpHeader;
......
use super::OpenflowHeader; use crate::openflow::traiter::header_trait::OpenflowHeader;
pub struct OfpHeader<OFH: OpenflowHeader> { pub struct OfpHeader<OFH: OpenflowHeader> {
ofp_header: OFH, ofp_header: OFH,
......
use super::OpenflowHeader;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::{io::Cursor, mem::size_of}; use std::{io::Cursor, mem::size_of};
use crate::openflow::traiter::header_trait::OpenflowHeader;
pub struct OfpHeader10 { pub struct OfpHeader10 {
pub version: u8, pub version: u8,
pub message: u8, pub message: u8,
......
use super::{ use super::{
events::{Action, FeaturesReqEvent, Payload}, events::{Action, FeaturesReqEvent, Payload},
ofp_header::{OfpHeader, OfpHeader10, OpenflowHeader}, ofp_header::{OfpHeader, OfpHeader10},
traiter::OfpMsgEvent,
HelloEvent, Msg, PacketOutEvent, HelloEvent, Msg, PacketOutEvent,
}; };
use crate::openflow::traiter::{event_trait::OfpMsgEvent, header_trait::OpenflowHeader};
pub struct Openflow10 {} pub struct Openflow10 {}
......
use crate::Controller; use crate::Controller;
use std::{io::Read, net::TcpListener, thread}; use std::{io::Read, net::TcpListener, thread};
use super::controller_frame::ControllerFrame; use super::{controller_frame::ControllerFrame, traiter::OfpMsgEvent};
use crate::openflow::ofp10::{traiter::OfpMsgEvent, HelloEvent}; use crate::openflow::ofp10::HelloEvent;
pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str) { pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str) {
let listener = TcpListener::bind(address).unwrap(); let listener = TcpListener::bind(address).unwrap();
......
use crate::openflow::{ use crate::openflow::ofp10::{
ofp10::events::{FeaturesReqEvent, Action, HelloEvent, PacketOutEvent, Payload}, events::{Action, FeaturesReqEvent, HelloEvent, PacketOutEvent, Payload},
ofp_header::OfpHeader,
Msg,
}; };
use super::{ofp_header::{OfpHeader, OpenflowHeader}, Msg}; use super::header_trait::OpenflowHeader;
/** /**
* the trait for parse value to bytes. * the trait for parse value to bytes.
......
pub mod header_trait;
pub use header_trait::OpenflowHeader;
pub mod event_trait;
pub use event_trait::{MessageMarshal, OfpMsgEvent};
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use tenjin::{ use tenjin::{
openflow::{controller_frame::ControllerFrame, ofp10::traiter::OfpMsgEvent, ofp10::Msg}, openflow::{controller_frame::ControllerFrame, ofp10::Msg, traiter::OfpMsgEvent},
Controller, Controller,
}; };
......
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