Commit 937468b3 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

change folder name of message to ofp_manager

parent f34edd49
...@@ -5,25 +5,25 @@ use std::{ ...@@ -5,25 +5,25 @@ use std::{
use super::{ use super::{
events::PacketInEvent, events::PacketInEvent,
messages::{ ofp_manager::{
traiter::{MessageMarshal, OfpMsgEvent}, traiter::{MessageMarshal, OfpMsgEvent},
OfpMsg, OfpMsg,
}, },
tcp_listener_handler, OfpHeader, tcp_listener_handler,
}; };
pub trait ControllerFrame<OME: OfpMsgEvent> { pub trait ControllerFrame<OME: OfpMsgEvent> {
fn get_ofp(&self) -> &impl OfpMsgEvent; fn get_ofp(&self) -> &impl OfpMsgEvent;
fn packet_in_handler(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream); fn packet_in_handler(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream);
fn new(ofp: OME) -> Self; fn new(ofp: OME) -> Self;
fn listener(address: &str, ofp: OME) { fn listener(address: &str, ofp: OME) {
tcp_listener_handler::<OME>(address, ofp.version() as u8); tcp_listener_handler::<OME>(address, ofp.version() as u8);
} }
fn request_handler(&mut self, buf: &mut Vec<u8>, stream: &mut TcpStream) { fn request_handler(&mut self, buf: &mut Vec<u8>, stream: &mut TcpStream) {
let ofp = self.get_ofp(); let ofp = self.get_ofp();
let ofp_header = OfpHeader::parse(&buf); let ofp_header = ofp.header_parse(&buf);
let mut payload = vec![0u8; ofp_header.pkt_size()]; let mut payload = vec![0u8; ofp_header.pkt_size()];
let _ = stream.read(&mut payload); let _ = stream.read(&mut payload);
let message = ofp.msg_parse(ofp_header.message as u16); let message = ofp.msg_parse(ofp_header.message as u16);
...@@ -50,4 +50,3 @@ pub trait ControllerFrame<OME: OfpMsgEvent> { ...@@ -50,4 +50,3 @@ pub trait ControllerFrame<OME: OfpMsgEvent> {
let _ = stream.write_all(&header_bytes); let _ = stream.write_all(&header_bytes);
} }
} }
use crate::openflow::messages::{MessageMarshal, OfpMsg, OfpMsgEvent}; use crate::openflow::ofp_manager::{MessageMarshal, OfpMsg, OfpMsgEvent};
pub struct FeaturesReq {} pub struct FeaturesReq {}
......
...@@ -3,7 +3,7 @@ use std::io::Cursor; ...@@ -3,7 +3,7 @@ use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use crate::openflow::{ use crate::openflow::{
messages::{MessageMarshal, OfpMsg, OfpMsgEvent}, ofp_manager::{MessageMarshal, OfpMsg, OfpMsgEvent},
OfpPort, PseudoPort, OfpPort, PseudoPort,
}; };
......
use crate::openflow::messages::{MessageMarshal, OfpMsg}; use crate::openflow::ofp_manager::{MessageMarshal, OfpMsg};
use crate::openflow::traiter::OfpMsgEvent; use crate::openflow::traiter::OfpMsgEvent;
pub struct HelloEvent {} pub struct HelloEvent {}
......
...@@ -8,8 +8,8 @@ pub mod events; ...@@ -8,8 +8,8 @@ pub mod events;
pub mod ofp_port; pub mod ofp_port;
pub use ofp_port::{OfpPort, PseudoPort}; pub use ofp_port::{OfpPort, PseudoPort};
pub mod messages; pub mod ofp_manager;
pub use messages::{ofp_v1_0, traiter}; pub use ofp_manager::{ofp_v1_0, traiter};
pub mod tcp_listener; pub mod tcp_listener;
pub use tcp_listener::tcp_listener_handler; pub use tcp_listener::tcp_listener_handler;
\ No newline at end of file
...@@ -15,6 +15,9 @@ impl Openflow10 { ...@@ -15,6 +15,9 @@ impl Openflow10 {
} }
impl OfpMsgEvent for Openflow10 { impl OfpMsgEvent for Openflow10 {
fn header_parse(&self, bytes:&Vec<u8>) -> OfpHeader {
OfpHeader::parse(bytes)
}
fn header_size(&self) -> usize { fn header_size(&self) -> usize {
8 8
} }
......
...@@ -24,6 +24,7 @@ pub trait OfpMsgEvent { ...@@ -24,6 +24,7 @@ pub trait OfpMsgEvent {
fn version(&self) -> usize; fn version(&self) -> usize;
fn ofp_version() -> usize; fn ofp_version() -> usize;
fn header_size(&self) -> usize; fn header_size(&self) -> usize;
fn header_parse(&self, bytes:&Vec<u8>) -> OfpHeader;
fn msg_usize(&self, msg: OfpMsg) -> usize; fn msg_usize(&self, msg: OfpMsg) -> usize;
fn msg_parse(&self, msg: u16) -> OfpMsg; fn msg_parse(&self, msg: u16) -> OfpMsg;
......
use crate::openflow::{messages::Openflow10, traiter::OfpMsgEvent}; use crate::openflow::{ofp_manager::Openflow10, traiter::OfpMsgEvent};
use crate::{ofp_from_version, Controller}; use crate::{ofp_from_version, Controller};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::{io::Read, net::TcpListener, thread}; use std::{io::Read, net::TcpListener, thread};
......
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