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
32a24045
Commit
32a24045
authored
Jun 13, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
define value to Msg and impl
parent
8a49beb1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
32 deletions
+51
-32
controller_frame.rs
src/openflow/controller_frame.rs
+6
-5
message.rs
src/openflow/ofp10/message.rs
+41
-7
ofp_v1_0.rs
src/openflow/ofp10/ofp_v1_0.rs
+3
-19
event_trait.rs
src/openflow/traiter/event_trait.rs
+1
-1
No files found.
src/openflow/controller_frame.rs
View file @
32a24045
use
crate
::
openflow
::
ofp10
::{
use
crate
::
openflow
::
ofp10
::{
ErrorEvent
,
Msg
,
PacketInEvent
};
ErrorEvent
,
Msg
,
PacketInEvent
,
};
use
std
::{
use
std
::{
io
::{
Read
,
Write
},
io
::{
Read
,
Write
},
net
::
TcpStream
,
net
::
TcpStream
,
};
};
use
super
::{
tcp_listener
::
tcp_listener_handler
,
traiter
::{
MessageMarshal
,
OfpMsgEvent
}};
use
super
::{
tcp_listener
::
tcp_listener_handler
,
traiter
::{
MessageMarshal
,
OfpMsgEvent
},
};
pub
trait
ControllerFrame
<
OME
:
OfpMsgEvent
>
{
pub
trait
ControllerFrame
<
OME
:
OfpMsgEvent
>
{
fn
get_ofp
(
&
self
)
->
&
impl
OfpMsgEvent
;
fn
get_ofp
(
&
self
)
->
&
impl
OfpMsgEvent
;
...
@@ -30,7 +31,7 @@ pub trait ControllerFrame<OME: OfpMsgEvent> {
...
@@ -30,7 +31,7 @@ pub trait ControllerFrame<OME: OfpMsgEvent> {
let
(
message
,
pkt_size
,
xid
)
=
self
.handle_header
(
buf
);
let
(
message
,
pkt_size
,
xid
)
=
self
.handle_header
(
buf
);
let
mut
payload
=
vec!
[
0u8
;
pkt_size
];
let
mut
payload
=
vec!
[
0u8
;
pkt_size
];
let
_
=
stream
.read
(
&
mut
payload
);
let
_
=
stream
.read
(
&
mut
payload
);
let
message
=
self
.get_ofp
()
.msg_parse
(
message
as
u
16
);
let
message
=
self
.get_ofp
()
.msg_parse
(
message
as
u
8
);
match
message
{
match
message
{
Msg
::
Hello
=>
self
.send_msg
(
self
.get_ofp
()
.fetures_req
(),
xid
,
stream
),
Msg
::
Hello
=>
self
.send_msg
(
self
.get_ofp
()
.fetures_req
(),
xid
,
stream
),
Msg
::
Error
=>
{
Msg
::
Error
=>
{
...
...
src/openflow/ofp10/message.rs
View file @
32a24045
#
[
repr
(
u8
)]
pub
enum
Msg
{
pub
enum
Msg
{
Hello
,
Hello
=
0
,
Error
,
Error
=
1
,
FeaturesReq
,
FeaturesReq
=
5
,
PacketIn
,
PacketIn
=
10
,
PacketOut
,
PacketOut
=
13
,
FlowMod
,
FlowMod
=
14
,
NotFound
,
NotFound
=
0xff
,
}
}
impl
Msg
{
pub
fn
to_int
(
&
self
)
->
u8
{
self
.clone
()
as
u8
}
pub
fn
parse
(
msg_code
:
u8
)
->
Self
{
type
ConvTyp
=
u8
;
match
msg_code
{
m
if
m
==
(
Self
::
Hello
as
ConvTyp
)
=>
Self
::
Hello
,
m
if
m
==
(
Self
::
Error
as
ConvTyp
)
=>
Self
::
Error
,
m
if
m
==
(
Self
::
FeaturesReq
as
ConvTyp
)
=>
Self
::
FeaturesReq
,
m
if
m
==
(
Self
::
PacketIn
as
ConvTyp
)
=>
Self
::
PacketIn
,
m
if
m
==
(
Self
::
PacketOut
as
ConvTyp
)
=>
Self
::
PacketOut
,
m
if
m
==
(
Self
::
FlowMod
as
ConvTyp
)
=>
Self
::
FlowMod
,
_
=>
Self
::
NotFound
,
}
}
}
impl
Clone
for
Msg
{
fn
clone
(
&
self
)
->
Self
{
match
self
{
Self
::
Hello
=>
Self
::
Hello
,
Self
::
Error
=>
Self
::
Error
,
Self
::
FeaturesReq
=>
Self
::
FeaturesReq
,
Self
::
PacketIn
=>
Self
::
PacketIn
,
Self
::
PacketOut
=>
Self
::
PacketOut
,
Self
::
FlowMod
=>
Self
::
FlowMod
,
Self
::
NotFound
=>
Self
::
NotFound
,
}
}
}
src/openflow/ofp10/ofp_v1_0.rs
View file @
32a24045
...
@@ -46,27 +46,11 @@ impl OfpMsgEvent for Openflow10 {
...
@@ -46,27 +46,11 @@ impl OfpMsgEvent for Openflow10 {
OfpHeader
::
new
(
OfpHeader10
::
new
(
message
,
length
as
usize
,
xid
as
usize
))
OfpHeader
::
new
(
OfpHeader10
::
new
(
message
,
length
as
usize
,
xid
as
usize
))
}
}
fn
msg_parse
(
&
self
,
msg
:
u16
)
->
Msg
{
fn
msg_parse
(
&
self
,
msg
:
u8
)
->
Msg
{
match
msg
{
Msg
::
parse
(
msg
)
0
=>
Msg
::
Hello
,
1
=>
Msg
::
Error
,
5
=>
Msg
::
FeaturesReq
,
10
=>
Msg
::
PacketIn
,
13
=>
Msg
::
PacketOut
,
14
=>
Msg
::
FlowMod
,
_
=>
Msg
::
NotFound
,
}
}
}
fn
msg_usize
(
&
self
,
msg
:
Msg
)
->
usize
{
fn
msg_usize
(
&
self
,
msg
:
Msg
)
->
usize
{
match
msg
{
msg
.to_int
()
as
usize
Msg
::
Hello
=>
0
,
Msg
::
Error
=>
1
,
Msg
::
FeaturesReq
=>
5
,
Msg
::
PacketIn
=>
10
,
Msg
::
PacketOut
=>
13
,
Msg
::
FlowMod
=>
14
,
_
=>
1024
,
}
}
}
}
}
src/openflow/traiter/event_trait.rs
View file @
32a24045
...
@@ -28,7 +28,7 @@ pub trait OfpMsgEvent {
...
@@ -28,7 +28,7 @@ pub trait OfpMsgEvent {
fn
header_size
(
&
self
)
->
usize
;
fn
header_size
(
&
self
)
->
usize
;
fn
msg_usize
(
&
self
,
msg
:
Msg
)
->
usize
;
fn
msg_usize
(
&
self
,
msg
:
Msg
)
->
usize
;
fn
msg_parse
(
&
self
,
msg
:
u
16
)
->
Msg
;
fn
msg_parse
(
&
self
,
msg
:
u
8
)
->
Msg
;
fn
hello_event
(
&
self
)
->
HelloEvent
;
fn
hello_event
(
&
self
)
->
HelloEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReqEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReqEvent
;
fn
packet_out
(
fn
packet_out
(
...
...
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