Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
Tenjin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
Tenjin
Commits
08809962
Commit
08809962
authored
Jun 02, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
in controller, use openflow10 instead of impl
parent
6d8bb627
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
43 deletions
+31
-43
controller.rs
src/controller.rs
+19
-7
main.rs
src/main.rs
+2
-7
controller_frame.rs
src/openflow/controller_frame.rs
+7
-6
macro_selector.rs
src/openflow/macro_selector.rs
+0
-14
mod.rs
src/openflow/mod.rs
+0
-5
tcp_listener.rs
src/openflow/tcp_listener.rs
+3
-4
No files found.
src/controller.rs
View file @
08809962
...
...
@@ -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
:
O
ME
,
pub
struct
Controller
{
ofp
:
O
penflow10
,
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
,
...
...
src/main.rs
View file @
08809962
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
(())
}
src/openflow/controller_frame.rs
View file @
08809962
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
);
...
...
src/openflow/macro_selector.rs
deleted
100644 → 0
View file @
6d8bb627
/**
* 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
src/openflow/mod.rs
View file @
08809962
pub
mod
controller_frame
;
pub
mod
ofp10
;
pub
mod
tcp_listener
;
pub
mod
macro_selector
;
\ No newline at end of file
src/openflow/tcp_listener.rs
View file @
08809962
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment