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
d7bd9dad
Commit
d7bd9dad
authored
Jul 24, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add controller v1.0 and change test
parent
3ac60692
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
9 deletions
+107
-9
ctrl10.rs
src/example/ctrl10.rs
+96
-0
ctrl13.rs
src/example/ctrl13.rs
+0
-0
mod.rs
src/example/mod.rs
+6
-3
headers.rs
tests/headers.rs
+5
-6
No files found.
src/example/ctrl10.rs
0 → 100644
View file @
d7bd9dad
#
!
[
allow
(
unused
)]
#
!
[
allow
(
unused_variables
)]
use
std
::{
collections
::
HashMap
,
net
::
TcpStream
};
use
crate
::{
etherparser
::
ether_type
::
EtherType
,
openflow
::
ofp10
::{
self
,
events
::{
flow_mod
::
MatchFields
,
Action
},
ofp_manager
::
Openflow10
,
ControllerFrame10
,
FlowModEvent
,
OfpMsgEvent
,
PacketInEvent
,
},
};
/**
* Here is Controller you can modify and write the process or more you need.
* In production please remove allow unused.
*/
pub
struct
Controller10
{
mac_to_port
:
HashMap
<
u64
,
u16
>
,
}
impl
ControllerFrame10
for
Controller10
{
fn
new
()
->
Self
{
Self
{
mac_to_port
:
HashMap
::
new
(),
}
}
/**
* Start here for handle packetIn message.
*/
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
let
pkt
=
match
packetin
.ether_parse
()
{
Ok
(
pkt
)
=>
pkt
,
Err
(
_
)
=>
return
,
};
println!
(
"packet in {} {} {}"
,
pkt
.mac_src_string
(),
pkt
.mac_dst_string
(),
packetin
.in_port
);
self
.mac_to_port
.insert
(
pkt
.mac_src
,
packetin
.in_port
);
let
mac_dst
=
pkt
.mac_dst
;
let
mac_src
=
pkt
.mac_src
;
if
let
EtherType
::
LLDP
=
pkt
.ether_type
{
return
;
}
let
out_port
=
match
self
.mac_to_port
.get
(
&
mac_dst
)
{
Some
(
p
)
=>
ofp10
::
PseudoPort
::
PhysicalPort
(
*
p
),
None
=>
ofp10
::
PseudoPort
::
Flood
,
};
let
actions
=
vec!
[
Action
::
Oputput
(
out_port
.clone
())];
if
let
ofp10
::
PseudoPort
::
PhysicalPort
(
_
)
=
out_port
{
let
mut
match_fields
=
MatchFields
::
match_all
();
match_fields
.in_port
=
Some
(
packetin
.in_port
);
match_fields
.mac_dest
=
Some
(
mac_dst
);
match_fields
.mac_src
=
Some
(
mac_src
);
if
let
Some
(
buf_id
)
=
packetin
.buf_id
{
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
Some
(
buf_id
as
u32
),
stream
);
return
;
}
else
{
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
None
,
stream
);
}
}
let
packet_out
=
self
.ofp
()
.packet_out
(
Some
(
packetin
.in_port
),
packetin
.payload
,
actions
);
self
.send_msg
(
packet_out
,
xid
,
stream
);
}
}
impl
Controller10
{
fn
add_flow
(
&
self
,
xid
:
u32
,
priority
:
u16
,
flow
:
MatchFields
,
actions
:
&
Vec
<
Action
>
,
buffer_id
:
Option
<
u32
>
,
stream
:
&
mut
TcpStream
,
)
{
self
.send_msg
(
FlowModEvent
::
add_flow
(
10
,
flow
,
actions
.clone
(),
buffer_id
),
xid
,
stream
,
)
}
}
\ No newline at end of file
src/example/c
ontroller
13.rs
→
src/example/c
trl
13.rs
View file @
d7bd9dad
File moved
src/example/mod.rs
View file @
d7bd9dad
pub
mod
controller13
;
pub
mod
ctrl13
;
pub
use
controller13
::
Controller13
;
pub
use
ctrl13
::
Controller13
;
\ No newline at end of file
pub
mod
ctrl10
;
pub
use
ctrl10
::
Controller10
;
\ No newline at end of file
tests/headers.rs
View file @
d7bd9dad
#
[
cfg
(
test
)]
#
[
cfg
(
test
)]
mod
tests
{
mod
tests
{
use
tenjin
::{
use
tenjin
::
example
::
Controller10
;
openflow
::
ofp13
::{
ControllerFrame13
,
Msg
,
OfpMsgEvent
,
OpenflowHeader
},
use
tenjin
::
openflow
::
ofp10
::
ControllerFrame10
;
Controller
,
use
tenjin
::
openflow
::
ofp10
::{
Msg
,
OfpMsgEvent
,
OpenflowHeader
};
};
#[test]
#[test]
fn
test_header_v1_0_parser
()
{
fn
test_header_v1_0_parser
()
{
let
ofp_header_bytes
:
Vec
<
u8
>
=
vec!
[
1
,
0
,
0
,
8
,
0
,
0
,
0
,
1
];
let
ofp_header_bytes
:
Vec
<
u8
>
=
vec!
[
1
,
0
,
0
,
8
,
0
,
0
,
0
,
1
];
let
controller
=
Controller
::
new
();
let
controller
=
Controller
10
::
new
();
let
ofp
=
controller
.ofp
();
let
ofp
=
controller
.ofp
();
let
header
=
match
ofp
.header_parse
(
&
ofp_header_bytes
)
{
let
header
=
match
ofp
.header_parse
(
&
ofp_header_bytes
)
{
Ok
(
v
)
=>
v
,
Ok
(
v
)
=>
v
,
...
@@ -25,7 +24,7 @@ mod tests {
...
@@ -25,7 +24,7 @@ mod tests {
fn
test_header_v1_0_marshal
()
{
fn
test_header_v1_0_marshal
()
{
let
ofp_header_bytes
:
Vec
<
u8
>
=
vec!
[
1
,
0
,
0
,
8
,
0
,
0
,
0
,
0
];
let
ofp_header_bytes
:
Vec
<
u8
>
=
vec!
[
1
,
0
,
0
,
8
,
0
,
0
,
0
,
0
];
let
controller
=
Controller
::
new
();
let
controller
=
Controller
10
::
new
();
let
ofp
=
controller
.ofp
();
let
ofp
=
controller
.ofp
();
let
ofp_header
=
ofp
.header
(
ofp
.msg_usize
(
Msg
::
Hello
)
as
u8
,
0
,
0
);
let
ofp_header
=
ofp
.header
(
ofp
.msg_usize
(
Msg
::
Hello
)
as
u8
,
0
,
0
);
let
mut
bytes
:
Vec
<
u8
>
=
Vec
::
new
();
let
mut
bytes
:
Vec
<
u8
>
=
Vec
::
new
();
...
...
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