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
0b80948b
Commit
0b80948b
authored
May 05, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: create message in controller, make it simple to use
parent
282cba84
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
controller.rs
src/openflow/controller.rs
+9
-11
message.rs
src/openflow/message.rs
+22
-0
No files found.
src/openflow/controller.rs
View file @
0b80948b
use
std
::{
collections
::
HashMap
,
io
::
Write
,
net
::
TcpStream
};
use
std
::{
collections
::
HashMap
,
io
::
Write
,
net
::
TcpStream
};
use
super
::{
use
super
::{
events
::{
FeaturesReq
,
HelloEvent
,
PacketInEvent
},
events
::
PacketInEvent
,
message
::
OfpMsgEvent
,
trait_marshal
::
MessageMarshal
,
OfpHeader
,
trait_marshal
::
MessageMarshal
,
OfpHeader
,
};
};
pub
struct
Controller
{
pub
struct
Controller
<
OME
:
OfpMsgEvent
>
{
version
:
u8
,
ofp
:
OME
,
mac_to_port
:
HashMap
<
u64
,
u16
>
,
mac_to_port
:
HashMap
<
u64
,
u16
>
,
}
}
impl
Controller
{
impl
<
OME
:
OfpMsgEvent
>
Controller
<
OME
>
{
pub
const
OFP_1_0
:
u8
=
1
;
pub
const
OFP_1_0
:
u8
=
1
;
pub
fn
new
(
version
:
u8
)
->
Self
{
pub
fn
new
(
ofp
:
OME
)
->
Self
{
Self
{
Self
{
version
,
ofp
,
mac_to_port
:
HashMap
::
new
(),
mac_to_port
:
HashMap
::
new
(),
}
}
}
}
...
@@ -25,7 +23,7 @@ impl Controller {
...
@@ -25,7 +23,7 @@ impl Controller {
let
mut
body_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
let
mut
body_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
msg
.marshal
(
&
mut
body_bytes
);
msg
.marshal
(
&
mut
body_bytes
);
let
ofpheader
=
OfpHeader
::
new
(
let
ofpheader
=
OfpHeader
::
new
(
self
.
version
,
self
.
ofp
.version
()
as
u8
,
msg
.msg_code
()
as
u8
,
msg
.msg_code
()
as
u8
,
body_bytes
.len
()
as
u16
,
body_bytes
.len
()
as
u16
,
xid
,
xid
,
...
@@ -39,12 +37,12 @@ impl Controller {
...
@@ -39,12 +37,12 @@ impl Controller {
* example of sending message
* example of sending message
*/
*/
pub
fn
hello
(
&
self
,
stream
:
&
mut
TcpStream
)
{
pub
fn
hello
(
&
self
,
stream
:
&
mut
TcpStream
)
{
let
hello_msg
=
HelloEvent
::
new
();
let
hello_msg
=
self
.ofp
.hello_event
();
self
.send_msg
(
hello_msg
,
0
,
stream
);
self
.send_msg
(
hello_msg
,
0
,
stream
);
}
}
pub
fn
fetures_req
(
&
self
,
xid
:
u32
,
stream
:
&
mut
TcpStream
)
{
pub
fn
fetures_req
(
&
self
,
xid
:
u32
,
stream
:
&
mut
TcpStream
)
{
let
fetreq_msg
=
FeaturesReq
::
new
();
let
fetreq_msg
=
self
.ofp
.fetures_req
();
self
.send_msg
(
fetreq_msg
,
xid
,
stream
);
self
.send_msg
(
fetreq_msg
,
xid
,
stream
);
}
}
...
...
src/openflow/message.rs
View file @
0b80948b
use
super
::
events
::{
FeaturesReq
,
HelloEvent
};
pub
trait
OfpMsgEvent
{
fn
hello_event
(
&
self
)
->
HelloEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReq
;
fn
version
(
&
self
)
->
usize
;
}
pub
enum
OfpMsg
{
pub
enum
OfpMsg
{
Hello
=
0
,
Hello
=
0
,
FeaturesReq
=
5
,
FeaturesReq
=
5
,
...
@@ -6,6 +14,20 @@ pub enum OfpMsg {
...
@@ -6,6 +14,20 @@ pub enum OfpMsg {
NotFound
=
-
1
,
NotFound
=
-
1
,
}
}
impl
OfpMsgEvent
for
OfpMsg
{
fn
hello_event
(
&
self
)
->
HelloEvent
{
HelloEvent
::
new
()
}
fn
fetures_req
(
&
self
)
->
FeaturesReq
{
FeaturesReq
::
new
()
}
fn
version
(
&
self
)
->
usize
{
1
}
}
impl
OfpMsg
{
impl
OfpMsg
{
pub
fn
parse
(
message_code
:
u8
)
->
Self
{
pub
fn
parse
(
message_code
:
u8
)
->
Self
{
match
message_code
{
match
message_code
{
...
...
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