Commit 08809962 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

in controller, use openflow10 instead of impl

parent 6d8bb627
......@@ -2,24 +2,36 @@
#![allow(unused_variables)]
use std::{collections::HashMap, net::TcpStream};
use crate::{etherparser::ether_type::EtherType, openflow::{controller_frame::ControllerFrame, ofp10::{self, events::{flow_mod::MatchFields, Action}, traiter::OfpMsgEvent, FlowModEvent, PacketInEvent}}};
use crate::{
etherparser::ether_type::EtherType,
openflow::{
controller_frame::ControllerFrame,
ofp10::{
self,
events::{flow_mod::MatchFields, Action},
ofp_v1_0::Openflow10,
traiter::OfpMsgEvent,
FlowModEvent, PacketInEvent,
},
},
};
/**
* Here is Controller you can modify and write the process or more you need.
* In production please remove allow unused.
*/
pub struct Controller<OME: OfpMsgEvent> {
ofp: OME,
pub struct Controller {
ofp: Openflow10,
mac_to_port: HashMap<u64, u16>,
}
impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
impl ControllerFrame<Openflow10> for Controller {
fn get_ofp(&self) -> &impl OfpMsgEvent {
&self.ofp
}
fn new(ofp: OME) -> Self {
fn new() -> Self {
Self {
ofp,
ofp: Openflow10::new(),
mac_to_port: HashMap::new(),
}
}
......@@ -63,7 +75,7 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
}
}
impl<OME: OfpMsgEvent> Controller<OME> {
impl Controller {
fn add_flow(
&self,
xid: u32,
......
use tenjin::{
openflow::{controller_frame::ControllerFrame, ofp10::ofp_v1_0::Openflow10},
Controller,
};
use tenjin::{openflow::controller_frame::ControllerFrame, Controller};
extern crate byteorder;
fn main() -> Result<(), std::io::Error> {
// Controller::listener("127.0.0.1:6633", Openflow10::new());
// tcp_listener_handler(Controller::new(Openflow10), "127.0.0.1:6633");
Controller::listener("127.0.0.1:6633", Openflow10::new());
Controller::listener("127.0.0.1:6633");
Ok(())
}
use crate::openflow::ofp10::{
traiter::{MessageMarshal, OfpMsgEvent}, ErrorEvent, Msg, PacketInEvent
traiter::{MessageMarshal, OfpMsgEvent},
ErrorEvent, Msg, PacketInEvent,
};
use std::{
io::{Read, Write},
......@@ -11,10 +12,10 @@ use super::tcp_listener::tcp_listener_handler;
pub trait ControllerFrame<OME: OfpMsgEvent> {
fn get_ofp(&self) -> &impl OfpMsgEvent;
fn packet_in_handler(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream);
fn new(ofp: OME) -> Self;
fn new() -> Self;
fn listener(address: &str, ofp: OME) {
tcp_listener_handler::<OME>(address, ofp.version() as u8);
fn listener(address: &str) {
tcp_listener_handler::<OME>(address);
}
fn handle_header(&mut self, buf: &mut Vec<u8>) -> (u8, usize, u32) {
......@@ -34,10 +35,10 @@ pub trait ControllerFrame<OME: OfpMsgEvent> {
match message {
Msg::Hello => self.send_msg(self.get_ofp().fetures_req(), xid, stream),
Msg::Error => {
let error =ErrorEvent::parse(&payload);
let error = ErrorEvent::parse(&payload);
println!("Error {:?}", error.error_type);
()
},
}
Msg::FeaturesReq => (),
Msg::PacketIn => {
self.packet_in_handler(xid, PacketInEvent::parse(&payload), stream);
......
/**
* this macro use for create Controller with version inside thread.
* Tt is used at 'tcp_listener/tcp_listener_handler.rs'
*/
#[macro_export]
macro_rules! ofp_from_version {
($ofp_version: expr) => {
match $ofp_version {
1 => Openflow10::new(),
_ => panic!("This version is not support")
}
};
}
\ No newline at end of file
pub mod controller_frame;
pub mod ofp10;
pub mod tcp_listener;
pub mod macro_selector;
\ No newline at end of file
use crate::{ofp_from_version, Controller};
use crate::Controller;
use std::sync::{Arc, Mutex};
use std::{io::Read, net::TcpListener, thread};
use super::controller_frame::ControllerFrame;
use super::ofp10::ofp_v1_0::Openflow10;
use crate::openflow::ofp10::{traiter::OfpMsgEvent, HelloEvent};
pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str, ofp_version: u8) {
let controller = Arc::new(Mutex::from(Controller::new(ofp_from_version!(ofp_version))));
pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str) {
let controller = Arc::new(Mutex::from(Controller::new()));
let listener = TcpListener::bind(address).unwrap();
for stream in listener.incoming() {
match stream {
......
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