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
943ae31f
Commit
943ae31f
authored
May 06, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use multi thread in tcp connect
parent
fbf4d695
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
24 deletions
+46
-24
main.rs
src/main.rs
+1
-2
controller.rs
src/openflow/controller.rs
+2
-2
macro_selector.rs
src/openflow/messages/macro_selector.rs
+13
-0
mod.rs
src/openflow/messages/mod.rs
+2
-0
ofp_v1_0.rs
src/openflow/messages/ofp_v1_0.rs
+3
-0
traiter.rs
src/openflow/messages/traiter.rs
+5
-3
tcp_listener.rs
src/tcp_listener.rs
+20
-17
No files found.
src/main.rs
View file @
943ae31f
...
@@ -4,7 +4,6 @@ use tenjin::openflow::Controller;
...
@@ -4,7 +4,6 @@ use tenjin::openflow::Controller;
extern
crate
byteorder
;
extern
crate
byteorder
;
fn
main
()
->
Result
<
(),
std
::
io
::
Error
>
{
fn
main
()
->
Result
<
(),
std
::
io
::
Error
>
{
let
mut
controller
=
Controller
::
new
(
Openflow10
::
new
());
Controller
::
listener
(
"127.0.0.1:6633"
,
Openflow10
::
new
());
controller
.listener
(
"127.0.0.1:6633"
);
Ok
(())
Ok
(())
}
}
src/openflow/controller.rs
View file @
943ae31f
...
@@ -33,8 +33,8 @@ impl<OME: OfpMsgEvent> Controller<OME> {
...
@@ -33,8 +33,8 @@ impl<OME: OfpMsgEvent> Controller<OME> {
}
}
}
}
pub
fn
listener
(
&
mut
self
,
address
:
&
str
)
{
pub
fn
listener
(
address
:
&
str
,
ofp
:
OME
)
{
tcp_listener_handler
(
self
,
address
);
tcp_listener_handler
(
ofp
.version
()
as
u8
,
address
);
}
}
pub
fn
request_handler
(
&
mut
self
,
buf
:
&
mut
Vec
<
u8
>
,
stream
:
&
mut
TcpStream
)
{
pub
fn
request_handler
(
&
mut
self
,
buf
:
&
mut
Vec
<
u8
>
,
stream
:
&
mut
TcpStream
)
{
...
...
src/openflow/messages/macro_selector.rs
0 → 100644
View file @
943ae31f
/**
* 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"
)
}
};
}
src/openflow/messages/mod.rs
View file @
943ae31f
...
@@ -7,3 +7,5 @@ pub use traiter::OfpMsgEvent;
...
@@ -7,3 +7,5 @@ pub use traiter::OfpMsgEvent;
pub
mod
ofp_v1_0
;
pub
mod
ofp_v1_0
;
pub
use
ofp_v1_0
::
Openflow10
;
pub
use
ofp_v1_0
::
Openflow10
;
pub
mod
macro_selector
;
src/openflow/messages/ofp_v1_0.rs
View file @
943ae31f
...
@@ -15,6 +15,9 @@ impl Openflow10 {
...
@@ -15,6 +15,9 @@ impl Openflow10 {
}
}
impl
OfpMsgEvent
for
Openflow10
{
impl
OfpMsgEvent
for
Openflow10
{
fn
header_size
(
&
self
)
->
usize
{
8
}
fn
hello_event
(
&
self
)
->
HelloEvent
{
fn
hello_event
(
&
self
)
->
HelloEvent
{
HelloEvent
::
new
()
HelloEvent
::
new
()
}
}
...
...
src/openflow/messages/traiter.rs
View file @
943ae31f
...
@@ -21,9 +21,11 @@ pub trait MessageMarshal {
...
@@ -21,9 +21,11 @@ pub trait MessageMarshal {
*/
*/
pub
trait
OfpMsgEvent
{
pub
trait
OfpMsgEvent
{
fn
header
(
&
self
,
message
:
u8
,
length
:
u16
,
xid
:
u32
)
->
OfpHeader
;
fn
header
(
&
self
,
message
:
u8
,
length
:
u16
,
xid
:
u32
)
->
OfpHeader
;
fn
hello_event
(
&
self
)
->
HelloEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReq
;
fn
version
(
&
self
)
->
usize
;
fn
version
(
&
self
)
->
usize
;
fn
msg_parse
(
&
self
,
msg
:
u16
)
->
OfpMsg
;
fn
header_size
(
&
self
)
->
usize
;
fn
msg_usize
(
&
self
,
msg
:
OfpMsg
)
->
usize
;
fn
msg_usize
(
&
self
,
msg
:
OfpMsg
)
->
usize
;
fn
msg_parse
(
&
self
,
msg
:
u16
)
->
OfpMsg
;
fn
hello_event
(
&
self
)
->
HelloEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReq
;
}
}
src/tcp_listener.rs
View file @
943ae31f
use
std
::{
io
::
Read
,
net
::
TcpListener
};
use
crate
::
ofp_from_version
;
use
crate
::
openflow
::{
messages
::
Openflow10
,
traiter
::
OfpMsgEvent
,
Controller
};
use
std
::{
io
::
Read
,
net
::
TcpListener
,
thread
};
use
crate
::
openflow
::{
traiter
::
OfpMsgEvent
,
Controller
};
pub
fn
tcp_listener_handler
(
ofp_version
:
u8
,
address
:
&
str
)
{
pub
fn
tcp_listener_handler
<
OME
:
OfpMsgEvent
>
(
controller
:
&
mut
Controller
<
OME
>
,
address
:
&
str
)
{
let
listener
=
TcpListener
::
bind
(
address
)
.unwrap
();
let
listener
=
TcpListener
::
bind
(
address
)
.unwrap
();
/*
* buffer with 8 length that only support openflow 1.0
* I will make it support others version soon.
*/
let
mut
buffer
=
vec!
[
0u8
;
8
];
for
stream
in
listener
.incoming
()
{
for
stream
in
listener
.incoming
()
{
match
stream
{
match
stream
{
Ok
(
mut
stream
)
=>
{
Ok
(
mut
stream
)
=>
{
controller
.hello
(
&
mut
stream
);
thread
::
spawn
(
move
||
{
loop
{
/*
match
stream
.read
(
&
mut
buffer
)
{
* when spawn new thread.
Ok
(
v
)
if
v
>
0
=>
{
* The Controller will be create.
controller
.request_handler
(
&
mut
buffer
,
&
mut
stream
);
*/
let
mut
controller
=
Controller
::
new
(
ofp_from_version!
(
ofp_version
));
controller
.hello
(
&
mut
stream
);
let
mut
buffer
=
vec!
[
0u8
;
controller
.ofp
.header_size
()];
loop
{
match
stream
.read
(
&
mut
buffer
)
{
Ok
(
v
)
if
v
>
0
=>
{
controller
.request_handler
(
&
mut
buffer
,
&
mut
stream
);
}
Ok
(
_
)
|
Err
(
_
)
=>
break
,
}
}
Ok
(
_
)
|
Err
(
_
)
=>
panic!
(
"Connection failed!"
),
}
}
}
}
);
}
}
Err
(
_
)
=>
todo!
(
),
Err
(
_
)
=>
panic!
(
"Connection failed!"
),
}
}
}
}
}
}
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