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
f8cf0109
Commit
f8cf0109
authored
May 05, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor and plan for others message
parent
2a1ef305
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
101 additions
and
41 deletions
+101
-41
main.rs
src/main.rs
+4
-3
controller.rs
src/openflow/controller.rs
+10
-8
features_req.rs
src/openflow/events/features_req.rs
+7
-3
flow_mod_handler.rs
src/openflow/events/flow_mod/flow_mod_handler.rs
+7
-1
hello.rs
src/openflow/events/hello.rs
+8
-3
mod.rs
src/openflow/messages/mod.rs
+9
-0
ofp_message.rs
src/openflow/messages/ofp_message.rs
+7
-0
ofp_v1_0.rs
src/openflow/messages/ofp_v1_0.rs
+29
-18
traiter.rs
src/openflow/messages/traiter.rs
+18
-0
mod.rs
src/openflow/mod.rs
+2
-5
No files found.
src/main.rs
View file @
f8cf0109
use
std
::
io
::
Read
;
use
std
::
net
::
TcpListener
;
use
tenjin
::
openflow
::
events
::
packet_in
::
PacketInEvent
;
use
tenjin
::
openflow
::
message
::
Openflow10
;
use
tenjin
::
openflow
::{
Controller
,
OfpHeader
,
OfpMsg
};
use
tenjin
::
openflow
::
messages
::{
OfpMsg
,
Openflow10
};
use
tenjin
::
openflow
::
traiter
::
OfpMsgEvent
;
use
tenjin
::
openflow
::{
Controller
,
OfpHeader
};
extern
crate
byteorder
;
...
...
@@ -32,7 +33,7 @@ fn main() -> Result<(), std::io::Error> {
let
length_payload
=
packet
.size
();
let
mut
payload
=
vec!
[
0u8
;
length_payload
];
stream
.read
(
&
mut
payload
)
?
;
let
message
=
OfpMsg
::
parse
(
packet
.message
);
let
message
=
controller
.ofp
.msg_parse
(
packet
.message
as
u16
);
match
message
{
// 0 is Hello message
...
...
src/openflow/controller.rs
View file @
f8cf0109
use
std
::{
collections
::
HashMap
,
io
::
Write
,
net
::
TcpStream
};
use
super
::{
events
::
PacketInEvent
,
message
::
OfpMsgEvent
,
trait_marshal
::
MessageMarshal
,
OfpHeader
,
events
::
PacketInEvent
,
messages
::
traiter
::{
MessageMarshal
,
OfpMsgEvent
},
};
pub
struct
Controller
<
OME
:
OfpMsgEvent
>
{
ofp
:
OME
,
/*
* pub is temporary, remove soon;
* for test in main func
*/
pub
ofp
:
OME
,
mac_to_port
:
HashMap
<
u64
,
u16
>
,
}
...
...
@@ -22,12 +27,9 @@ impl<OME: OfpMsgEvent> Controller<OME> {
let
mut
header_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
let
mut
body_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
msg
.marshal
(
&
mut
body_bytes
);
let
ofpheader
=
OfpHeader
::
new
(
self
.ofp
.version
()
as
u8
,
msg
.msg_code
()
as
u8
,
body_bytes
.len
()
as
u16
,
xid
,
);
let
ofpheader
=
self
.ofp
.header
(
msg
.msg_usize
(
&
self
.ofp
)
as
u8
,
body_bytes
.len
()
as
u16
,
xid
);
ofpheader
.marshal
(
&
mut
header_bytes
);
header_bytes
.append
(
&
mut
body_bytes
);
let
_
=
stream
.write_all
(
&
header_bytes
);
...
...
src/openflow/events/features_req.rs
View file @
f8cf0109
use
crate
::
openflow
::
trait_marshal
::
MessageMarshal
;
use
crate
::
openflow
::
messages
::{
MessageMarshal
,
OfpMsg
,
OfpMsgEvent
}
;
pub
struct
FeaturesReq
{}
...
...
@@ -11,11 +11,15 @@ impl FeaturesReq {
impl
MessageMarshal
for
FeaturesReq
{
fn
marshal
(
&
self
,
_
:
&
mut
Vec
<
u8
>
)
{}
fn
msg_code
(
&
self
)
->
crate
::
openflow
::
OfpMsg
{
crate
::
openflow
::
OfpMsg
::
FeaturesReq
fn
msg_code
(
&
self
)
->
OfpMsg
{
OfpMsg
::
FeaturesReq
}
fn
size_of
(
&
self
)
->
usize
{
0
}
fn
msg_usize
<
OFP
:
OfpMsgEvent
>
(
&
self
,
ofp
:
&
OFP
)
->
usize
{
ofp
.msg_usize
(
OfpMsg
::
FeaturesReq
)
}
}
src/openflow/events/flow_mod/flow_mod_handler.rs
View file @
f8cf0109
...
...
@@ -2,7 +2,10 @@ use std::io::Cursor;
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
crate
::
openflow
::{
trait_marshal
::
MessageMarshal
,
OfpMsg
,
OfpPort
,
PseudoPort
};
use
crate
::
openflow
::{
messages
::{
MessageMarshal
,
OfpMsg
,
OfpMsgEvent
},
OfpPort
,
PseudoPort
,
};
use
super
::{
FlowAction
,
FlowModCommand
,
MatchFields
};
...
...
@@ -89,6 +92,9 @@ impl FlowModEvent {
}
impl
MessageMarshal
for
FlowModEvent
{
fn
msg_usize
<
OFP
:
OfpMsgEvent
>
(
&
self
,
ofp
:
&
OFP
)
->
usize
{
ofp
.msg_usize
(
OfpMsg
::
FlowMod
)
}
fn
size_of
(
&
self
)
->
usize
{
24
}
...
...
src/openflow/events/hello.rs
View file @
f8cf0109
use
crate
::
openflow
::{
trait_marshal
::
MessageMarshal
,
OfpMsg
};
use
crate
::
openflow
::
messages
::{
MessageMarshal
,
OfpMsg
};
use
crate
::
openflow
::
traiter
::
OfpMsgEvent
;
pub
struct
HelloEvent
{}
impl
HelloEvent
{
pub
fn
new
()
->
Self
{
pub
fn
new
()
->
Self
{
HelloEvent
{}
}
}
...
...
@@ -11,11 +12,15 @@ impl HelloEvent {
impl
MessageMarshal
for
HelloEvent
{
fn
marshal
(
&
self
,
_
:
&
mut
Vec
<
u8
>
)
{}
fn
msg_code
(
&
self
)
->
crate
::
openflow
::
OfpMsg
{
fn
msg_code
(
&
self
)
->
OfpMsg
{
OfpMsg
::
Hello
}
fn
size_of
(
&
self
)
->
usize
{
0
}
fn
msg_usize
<
OFP
:
OfpMsgEvent
>
(
&
self
,
ofp
:
&
OFP
)
->
usize
{
ofp
.msg_usize
(
OfpMsg
::
Hello
)
}
}
src/openflow/messages/mod.rs
0 → 100644
View file @
f8cf0109
pub
mod
ofp_message
;
pub
use
ofp_message
::
OfpMsg
;
pub
mod
traiter
;
pub
use
traiter
::
MessageMarshal
;
pub
use
traiter
::
OfpMsgEvent
;
pub
mod
ofp_v1_0
;
pub
use
ofp_v1_0
::
Openflow10
;
src/openflow/messages/ofp_message.rs
0 → 100644
View file @
f8cf0109
pub
enum
OfpMsg
{
Hello
=
0
,
FeaturesReq
=
5
,
PacketIn
=
8
,
FlowMod
=
14
,
NotFound
=
-
1
,
}
src/openflow/message.rs
→
src/openflow/message
s/ofp_v1_0
.rs
View file @
f8cf0109
use
super
::
events
::{
FeaturesReq
,
HelloEvent
};
use
crate
::
openflow
::{
events
::{
FeaturesReq
,
HelloEvent
},
OfpHeader
,
};
pub
trait
OfpMsgEvent
{
fn
hello_event
(
&
self
)
->
HelloEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReq
;
fn
version
(
&
self
)
->
usize
;
}
pub
enum
OfpMsg
{
Hello
=
0
,
FeaturesReq
=
5
,
PacketIn
=
8
,
FlowMod
=
14
,
NotFound
=
-
1
,
}
use
super
::
traiter
::
OfpMsgEvent
;
use
super
::
OfpMsg
;
pub
struct
Openflow10
{}
...
...
@@ -34,14 +26,33 @@ impl OfpMsgEvent for Openflow10 {
fn
version
(
&
self
)
->
usize
{
1
}
}
impl
OfpMsg
{
pub
fn
parse
(
message_code
:
u8
)
->
Self
{
match
message_code
{
fn
header
(
&
self
,
message
:
u8
,
length
:
u16
,
xid
:
u32
)
->
OfpHeader
{
OfpHeader
{
version
:
1
,
message
,
length
,
xid
,
}
}
fn
msg_parse
(
&
self
,
msg
:
u16
)
->
OfpMsg
{
match
msg
{
0
=>
OfpMsg
::
Hello
,
5
=>
OfpMsg
::
FeaturesReq
,
8
=>
OfpMsg
::
PacketIn
,
14
=>
OfpMsg
::
FlowMod
,
_
=>
OfpMsg
::
NotFound
,
}
}
fn
msg_usize
(
&
self
,
msg
:
OfpMsg
)
->
usize
{
match
msg
{
OfpMsg
::
Hello
=>
0
,
OfpMsg
::
FeaturesReq
=>
5
,
OfpMsg
::
PacketIn
=>
8
,
OfpMsg
::
FlowMod
=>
14
,
_
=>
1024
,
}
}
}
src/openflow/
trait_marshal
.rs
→
src/openflow/
messages/traiter
.rs
View file @
f8cf0109
use
crate
::
openflow
::{
events
::{
FeaturesReq
,
HelloEvent
},
OfpHeader
,
};
use
super
::
OfpMsg
;
/**
...
...
@@ -7,5 +12,18 @@ use super::OfpMsg;
pub
trait
MessageMarshal
{
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
);
fn
msg_code
(
&
self
)
->
OfpMsg
;
fn
msg_usize
<
OFP
:
OfpMsgEvent
>
(
&
self
,
ofp
:
&
OFP
)
->
usize
;
fn
size_of
(
&
self
)
->
usize
;
}
/**
* for works with controller to create OfpMsgEvent
*/
pub
trait
OfpMsgEvent
{
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
msg_parse
(
&
self
,
msg
:
u16
)
->
OfpMsg
;
fn
msg_usize
(
&
self
,
msg
:
OfpMsg
)
->
usize
;
}
src/openflow/mod.rs
View file @
f8cf0109
pub
mod
header
;
pub
use
header
::
OfpHeader
;
pub
mod
message
;
pub
use
message
::
OfpMsg
;
pub
mod
controller
;
pub
use
controller
::
Controller
;
...
...
@@ -12,4 +9,5 @@ pub mod events;
pub
mod
ofp_port
;
pub
use
ofp_port
::{
OfpPort
,
PseudoPort
};
pub
mod
trait_marshal
;
\ No newline at end of file
pub
mod
messages
;
pub
use
messages
::{
ofp_v1_0
,
traiter
};
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