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
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
100 additions
and
40 deletions
+100
-40
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
+7
-2
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
::
io
::
Read
;
use
std
::
net
::
TcpListener
;
use
std
::
net
::
TcpListener
;
use
tenjin
::
openflow
::
events
::
packet_in
::
PacketInEvent
;
use
tenjin
::
openflow
::
events
::
packet_in
::
PacketInEvent
;
use
tenjin
::
openflow
::
message
::
Openflow10
;
use
tenjin
::
openflow
::
messages
::{
OfpMsg
,
Openflow10
};
use
tenjin
::
openflow
::{
Controller
,
OfpHeader
,
OfpMsg
};
use
tenjin
::
openflow
::
traiter
::
OfpMsgEvent
;
use
tenjin
::
openflow
::{
Controller
,
OfpHeader
};
extern
crate
byteorder
;
extern
crate
byteorder
;
...
@@ -32,7 +33,7 @@ fn main() -> Result<(), std::io::Error> {
...
@@ -32,7 +33,7 @@ fn main() -> Result<(), std::io::Error> {
let
length_payload
=
packet
.size
();
let
length_payload
=
packet
.size
();
let
mut
payload
=
vec!
[
0u8
;
length_payload
];
let
mut
payload
=
vec!
[
0u8
;
length_payload
];
stream
.read
(
&
mut
payload
)
?
;
stream
.read
(
&
mut
payload
)
?
;
let
message
=
OfpMsg
::
parse
(
packet
.message
);
let
message
=
controller
.ofp
.msg_parse
(
packet
.message
as
u16
);
match
message
{
match
message
{
// 0 is Hello message
// 0 is Hello message
...
...
src/openflow/controller.rs
View file @
f8cf0109
use
std
::{
collections
::
HashMap
,
io
::
Write
,
net
::
TcpStream
};
use
std
::{
collections
::
HashMap
,
io
::
Write
,
net
::
TcpStream
};
use
super
::{
use
super
::{
events
::
PacketInEvent
,
message
::
OfpMsgEvent
,
trait_marshal
::
MessageMarshal
,
OfpHeader
,
events
::
PacketInEvent
,
messages
::
traiter
::{
MessageMarshal
,
OfpMsgEvent
},
};
};
pub
struct
Controller
<
OME
:
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
>
,
mac_to_port
:
HashMap
<
u64
,
u16
>
,
}
}
...
@@ -22,12 +27,9 @@ impl<OME: OfpMsgEvent> Controller<OME> {
...
@@ -22,12 +27,9 @@ impl<OME: OfpMsgEvent> Controller<OME> {
let
mut
header_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
let
mut
header_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
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
=
self
.ofp
.version
()
as
u8
,
self
.ofp
msg
.msg_code
()
as
u8
,
.header
(
msg
.msg_usize
(
&
self
.ofp
)
as
u8
,
body_bytes
.len
()
as
u16
,
xid
);
body_bytes
.len
()
as
u16
,
xid
,
);
ofpheader
.marshal
(
&
mut
header_bytes
);
ofpheader
.marshal
(
&
mut
header_bytes
);
header_bytes
.append
(
&
mut
body_bytes
);
header_bytes
.append
(
&
mut
body_bytes
);
let
_
=
stream
.write_all
(
&
header_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
{}
pub
struct
FeaturesReq
{}
...
@@ -11,11 +11,15 @@ impl FeaturesReq {
...
@@ -11,11 +11,15 @@ impl FeaturesReq {
impl
MessageMarshal
for
FeaturesReq
{
impl
MessageMarshal
for
FeaturesReq
{
fn
marshal
(
&
self
,
_
:
&
mut
Vec
<
u8
>
)
{}
fn
marshal
(
&
self
,
_
:
&
mut
Vec
<
u8
>
)
{}
fn
msg_code
(
&
self
)
->
crate
::
openflow
::
OfpMsg
{
fn
msg_code
(
&
self
)
->
OfpMsg
{
crate
::
openflow
::
OfpMsg
::
FeaturesReq
OfpMsg
::
FeaturesReq
}
}
fn
size_of
(
&
self
)
->
usize
{
fn
size_of
(
&
self
)
->
usize
{
0
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;
...
@@ -2,7 +2,10 @@ use std::io::Cursor;
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
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
};
use
super
::{
FlowAction
,
FlowModCommand
,
MatchFields
};
...
@@ -89,6 +92,9 @@ impl FlowModEvent {
...
@@ -89,6 +92,9 @@ impl FlowModEvent {
}
}
impl
MessageMarshal
for
FlowModEvent
{
impl
MessageMarshal
for
FlowModEvent
{
fn
msg_usize
<
OFP
:
OfpMsgEvent
>
(
&
self
,
ofp
:
&
OFP
)
->
usize
{
ofp
.msg_usize
(
OfpMsg
::
FlowMod
)
}
fn
size_of
(
&
self
)
->
usize
{
fn
size_of
(
&
self
)
->
usize
{
24
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
{}
pub
struct
HelloEvent
{}
...
@@ -11,11 +12,15 @@ impl HelloEvent {
...
@@ -11,11 +12,15 @@ impl HelloEvent {
impl
MessageMarshal
for
HelloEvent
{
impl
MessageMarshal
for
HelloEvent
{
fn
marshal
(
&
self
,
_
:
&
mut
Vec
<
u8
>
)
{}
fn
marshal
(
&
self
,
_
:
&
mut
Vec
<
u8
>
)
{}
fn
msg_code
(
&
self
)
->
crate
::
openflow
::
OfpMsg
{
fn
msg_code
(
&
self
)
->
OfpMsg
{
OfpMsg
::
Hello
OfpMsg
::
Hello
}
}
fn
size_of
(
&
self
)
->
usize
{
fn
size_of
(
&
self
)
->
usize
{
0
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
{
use
super
::
traiter
::
OfpMsgEvent
;
fn
hello_event
(
&
self
)
->
HelloEvent
;
use
super
::
OfpMsg
;
fn
fetures_req
(
&
self
)
->
FeaturesReq
;
fn
version
(
&
self
)
->
usize
;
}
pub
enum
OfpMsg
{
Hello
=
0
,
FeaturesReq
=
5
,
PacketIn
=
8
,
FlowMod
=
14
,
NotFound
=
-
1
,
}
pub
struct
Openflow10
{}
pub
struct
Openflow10
{}
...
@@ -34,14 +26,33 @@ impl OfpMsgEvent for Openflow10 {
...
@@ -34,14 +26,33 @@ impl OfpMsgEvent for Openflow10 {
fn
version
(
&
self
)
->
usize
{
fn
version
(
&
self
)
->
usize
{
1
1
}
}
}
impl
OfpMsg
{
fn
header
(
&
self
,
message
:
u8
,
length
:
u16
,
xid
:
u32
)
->
OfpHeader
{
pub
fn
parse
(
message_code
:
u8
)
->
Self
{
OfpHeader
{
match
message_code
{
version
:
1
,
message
,
length
,
xid
,
}
}
fn
msg_parse
(
&
self
,
msg
:
u16
)
->
OfpMsg
{
match
msg
{
0
=>
OfpMsg
::
Hello
,
0
=>
OfpMsg
::
Hello
,
5
=>
OfpMsg
::
FeaturesReq
,
8
=>
OfpMsg
::
PacketIn
,
8
=>
OfpMsg
::
PacketIn
,
14
=>
OfpMsg
::
FlowMod
,
_
=>
OfpMsg
::
NotFound
,
_
=>
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
;
use
super
::
OfpMsg
;
/**
/**
...
@@ -7,5 +12,18 @@ use super::OfpMsg;
...
@@ -7,5 +12,18 @@ use super::OfpMsg;
pub
trait
MessageMarshal
{
pub
trait
MessageMarshal
{
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
);
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
);
fn
msg_code
(
&
self
)
->
OfpMsg
;
fn
msg_code
(
&
self
)
->
OfpMsg
;
fn
msg_usize
<
OFP
:
OfpMsgEvent
>
(
&
self
,
ofp
:
&
OFP
)
->
usize
;
fn
size_of
(
&
self
)
->
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
mod
header
;
pub
use
header
::
OfpHeader
;
pub
use
header
::
OfpHeader
;
pub
mod
message
;
pub
use
message
::
OfpMsg
;
pub
mod
controller
;
pub
mod
controller
;
pub
use
controller
::
Controller
;
pub
use
controller
::
Controller
;
...
@@ -12,4 +9,5 @@ pub mod events;
...
@@ -12,4 +9,5 @@ pub mod events;
pub
mod
ofp_port
;
pub
mod
ofp_port
;
pub
use
ofp_port
::{
OfpPort
,
PseudoPort
};
pub
use
ofp_port
::{
OfpPort
,
PseudoPort
};
pub
mod
trait_marshal
;
pub
mod
messages
;
\ No newline at end of file
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