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

move trait to outside ofp10

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