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
ed177dfa
Commit
ed177dfa
authored
Jun 03, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tcp_listener: move controller variable into thread -> for multi switch
parent
962c16ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
+9
-11
tcp_listener.rs
src/openflow/tcp_listener.rs
+9
-11
No files found.
src/openflow/tcp_listener.rs
View file @
ed177dfa
use
crate
::
Controller
;
use
crate
::
Controller
;
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::{
io
::
Read
,
net
::
TcpListener
,
thread
};
use
std
::{
io
::
Read
,
net
::
TcpListener
,
thread
};
use
super
::
controller_frame
::
ControllerFrame
;
use
super
::
controller_frame
::
ControllerFrame
;
use
crate
::
openflow
::
ofp10
::{
traiter
::
OfpMsgEvent
,
HelloEvent
};
use
crate
::
openflow
::
ofp10
::{
traiter
::
OfpMsgEvent
,
HelloEvent
};
pub
fn
tcp_listener_handler
<
OME
:
OfpMsgEvent
>
(
address
:
&
str
)
{
pub
fn
tcp_listener_handler
<
OME
:
OfpMsgEvent
>
(
address
:
&
str
)
{
let
controller
=
Arc
::
new
(
Mutex
::
from
(
Controller
::
new
()));
let
listener
=
TcpListener
::
bind
(
address
)
.unwrap
();
let
listener
=
TcpListener
::
bind
(
address
)
.unwrap
();
for
stream
in
listener
.incoming
()
{
for
stream
in
listener
.incoming
()
{
match
stream
{
match
stream
{
Ok
(
mut
stream
)
=>
{
Ok
(
mut
stream
)
=>
{
let
controller_clone
=
controller
.clone
();
if
let
Ok
(
addr
)
=
stream
.local_addr
()
{
println!
(
"server has connection from {}"
,
addr
);
}
thread
::
spawn
(
move
||
{
thread
::
spawn
(
move
||
{
let
mut
ctrl
=
match
controller_clone
.lock
()
{
let
mut
ctrl
=
Controller
::
new
();
Ok
(
guard
)
=>
guard
,
Err
(
poinsoned
)
=>
{
let
guard
=
poinsoned
.into_inner
();
guard
}
};
ctrl
.send_msg
(
HelloEvent
::
new
(),
0
,
&
mut
stream
);
ctrl
.send_msg
(
HelloEvent
::
new
(),
0
,
&
mut
stream
);
let
ofp_size
=
ctrl
.get_ofp
()
.header_size
();
let
ofp_size
=
ctrl
.get_ofp
()
.header_size
();
// let ofp = controller.lock().unwrap().get_ofp();
// let ofp = controller.lock().unwrap().get_ofp();
...
@@ -29,7 +24,10 @@ pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str) {
...
@@ -29,7 +24,10 @@ pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str) {
Ok
(
v
)
if
v
>
0
=>
{
Ok
(
v
)
if
v
>
0
=>
{
ctrl
.request_handler
(
&
mut
buffer
,
&
mut
stream
);
ctrl
.request_handler
(
&
mut
buffer
,
&
mut
stream
);
}
}
Ok
(
_
)
|
Err
(
_
)
=>
break
,
Ok
(
_
)
|
Err
(
_
)
=>
{
println!
(
"cannot read packet"
);
break
;
}
}
}
}
}
});
});
...
...
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