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
2e236afa
Commit
2e236afa
authored
May 11, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
setup and send flow_mod
parent
61401812
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
2 deletions
+72
-2
controller.rs
src/controller.rs
+41
-2
flow_mod_handler.rs
src/openflow/events/flow_mod/flow_mod_handler.rs
+15
-0
match_fields.rs
src/openflow/events/flow_mod/match_fields.rs
+16
-0
No files found.
src/controller.rs
View file @
2e236afa
#
!
[
allow
(
unused
)]
#
!
[
allow
(
unused_variables
)]
use
crate
::
openflow
::
events
::
flow_mod
::{
FlowModCommand
,
MatchFields
};
/**
* Here is Controller you can modify and write the process or more you need.
* In production please remove allow unused.
*/
use
crate
::
openflow
::
events
::
PacketInEvent
;
use
crate
::
openflow
::
events
::{
FlowAction
,
FlowModEvent
,
PacketInEvent
};
use
crate
::
openflow
::
PseudoPort
;
use
crate
::
openflow
::{
controller_frame
::
ControllerFrame
,
traiter
::
OfpMsgEvent
};
use
std
::{
collections
::
HashMap
,
net
::
TcpStream
};
...
...
@@ -26,5 +28,42 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
/**
* Start here for handle packetIn message.
*/
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{}
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
let
mac_dst
=
packetin
.payload.mac_des
;
let
mac_src
=
packetin
.payload.mac_src
;
let
out_port
=
self
.mac_to_port
.get
(
&
mac_dst
);
match
out_port
{
Some
(
p
)
=>
{
let
src_port
=
packetin
.port
;
let
mut
src_dst_match
=
MatchFields
::
match_all
();
src_dst_match
.mac_dest
=
Some
(
mac_dst
);
src_dst_match
.mac_src
=
Some
(
mac_src
);
let
mut
dst_src_match
=
MatchFields
::
match_all
();
dst_src_match
.mac_dest
=
Some
(
mac_src
);
dst_src_match
.mac_src
=
Some
(
mac_dst
);
let
actions
=
vec!
[
FlowAction
::
Oputput
(
PseudoPort
::
PhysicalPort
(
*
p
))];
self
.add_flow
(
xid
,
src_dst_match
,
actions
,
stream
);
let
actions
=
vec!
[
FlowAction
::
Oputput
(
PseudoPort
::
PhysicalPort
(
src_port
))];
self
.add_flow
(
xid
,
dst_src_match
,
actions
,
stream
);
// let pkt_out =
}
None
=>
todo!
(),
}
}
}
impl
<
OME
:
OfpMsgEvent
>
Controller
<
OME
>
{
fn
add_flow
(
&
self
,
xid
:
u32
,
flow
:
MatchFields
,
actions
:
Vec
<
FlowAction
>
,
stream
:
&
mut
TcpStream
,
)
{
self
.send_msg
(
FlowModEvent
::
add_flow
(
10
,
flow
,
actions
),
xid
,
stream
)
}
}
src/openflow/events/flow_mod/flow_mod_handler.rs
View file @
2e236afa
...
...
@@ -43,6 +43,21 @@ pub struct FlowModEvent {
}
impl
FlowModEvent
{
pub
fn
add_flow
(
priority
:
u16
,
match_fileds
:
MatchFields
,
actions
:
Vec
<
FlowAction
>
)
->
Self
{
Self
{
command
:
FlowModCommand
::
Add
,
match_fields
:
match_fileds
,
priority
,
actions
,
cookie
:
0
,
idle_timeout
:
Timeout
::
Permanent
,
hard_timeout
:
Timeout
::
Permanent
,
notify_when_removed
:
false
,
apply_to_packet
:
None
,
out_port
:
None
,
check_overlap
:
false
,
}
}
pub
fn
get_controller_last
(
&
self
)
->
Vec
<
FlowAction
>
{
let
mut
not_ctrl
:
Vec
<
FlowAction
>
=
Vec
::
new
();
let
mut
is_ctrl
:
Vec
<
FlowAction
>
=
Vec
::
new
();
...
...
src/openflow/events/flow_mod/match_fields.rs
View file @
2e236afa
...
...
@@ -75,6 +75,22 @@ pub struct MatchFields {
}
impl
MatchFields
{
pub
fn
match_all
()
->
Self
{
Self
{
ethernet_type
:
None
,
in_port
:
None
,
ip_dest
:
None
,
ip_src
:
None
,
mac_dest
:
None
,
mac_src
:
None
,
protocol
:
None
,
tos
:
None
,
transport_dest
:
None
,
transport_src
:
None
,
vlan_pcp
:
None
,
vlan_vid
:
None
,
}
}
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
let
mut
match_f
=
0u32
;
match_f
=
set_bit
(
match_f
,
0
,
self
.in_port
.is_some
());
...
...
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