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
466cd82f
Commit
466cd82f
authored
Jun 21, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve tcp_listener of ofp10
parent
239a28c0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
7 deletions
+19
-7
controller.rs
src/controller.rs
+1
-0
main.rs
src/main.rs
+2
-1
controller_frame.rs
src/openflow/ofp10/controller_frame.rs
+11
-3
tcp_listener.rs
src/openflow/ofp10/tcp_listener.rs
+5
-2
tcp_listener.rs
src/openflow/ofp13/tcp_listener.rs
+0
-1
No files found.
src/controller.rs
View file @
466cd82f
...
...
@@ -16,6 +16,7 @@ use crate::{
* In production please remove allow unused.
*/
#[derive(Clone)]
pub
struct
Controller
{
mac_to_port
:
HashMap
<
u64
,
u16
>
,
}
...
...
src/main.rs
View file @
466cd82f
...
...
@@ -3,6 +3,7 @@ use tenjin::{openflow::ofp10::ControllerFrame10, Controller};
extern
crate
byteorder
;
fn
main
()
->
Result
<
(),
std
::
io
::
Error
>
{
Controller
::
listener
(
"127.0.0.1:6653"
);
let
controller
=
Controller
::
new
();
controller
.listener
(
"127.0.0.1:6633"
);
Ok
(())
}
src/openflow/ofp10/controller_frame.rs
View file @
466cd82f
...
...
@@ -9,16 +9,24 @@ use super::{
tcp_listener_handler
,
MessageMarshal
,
OfpMsgEvent
,
Openflow10
,
OpenflowHeader
,
};
pub
trait
ControllerFrame10
{
pub
trait
ControllerFrame10
where
Self
:
'static
,
{
fn
ofp
(
&
self
)
->
ofp10
::
Openflow10
{
Openflow10
::
new
()
}
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
);
fn
new
()
->
Self
;
fn
listener
(
address
:
&
str
)
{
fn
listener
(
&
self
,
address
:
&
str
)
where
Self
:
Sized
,
Self
:
Send
,
Self
:
Clone
,
{
println!
(
"server run at {}"
,
address
);
let
_
=
tcp_listener_handler
(
address
);
let
_
=
tcp_listener_handler
(
address
,
self
.clone
()
);
}
fn
handle_header
(
&
mut
self
,
buf
:
&
mut
Vec
<
u8
>
)
->
Option
<
(
u8
,
usize
,
u32
)
>
{
...
...
src/openflow/ofp10/tcp_listener.rs
View file @
466cd82f
...
...
@@ -5,7 +5,10 @@ use crate::openflow::ofp10::HelloEvent;
use
super
::{
ControllerFrame10
,
OfpMsgEvent
};
pub
fn
tcp_listener_handler
(
address
:
&
str
)
->
Result
<
(),
std
::
io
::
Error
>
{
pub
fn
tcp_listener_handler
(
address
:
&
str
,
controller
:
impl
ControllerFrame10
+
Send
+
'static
+
Clone
,
)
->
Result
<
(),
std
::
io
::
Error
>
{
let
listener
=
TcpListener
::
bind
(
address
)
?
;
for
stream
in
listener
.incoming
()
{
match
stream
{
...
...
@@ -14,8 +17,8 @@ pub fn tcp_listener_handler(address: &str) -> Result<(), std::io::Error> {
println!
(
"server has connection from {}"
,
addr
);
}
let
mut
ctrl
=
controller
.clone
();
thread
::
spawn
(
move
||
{
let
mut
ctrl
=
Controller
::
new
();
ctrl
.send_msg
(
HelloEvent
::
new
(),
0
,
&
mut
stream
);
let
ofp_size
=
ctrl
.ofp
()
.header_size
();
let
mut
buffer
=
vec!
[
0u8
;
ofp_size
];
...
...
src/openflow/ofp13/tcp_listener.rs
View file @
466cd82f
...
...
@@ -9,7 +9,6 @@ pub fn tcp_listener_handler(
controller
:
impl
ControllerFrame13
+
Send
+
'static
+
Clone
,
)
->
Result
<
(),
std
::
io
::
Error
>
{
let
listener
=
TcpListener
::
bind
(
address
)
?
;
// let controller = Arc::new(Mutex::new(controller));
for
stream
in
listener
.incoming
()
{
match
stream
{
Ok
(
mut
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