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
5e3ca5f4
Commit
5e3ca5f4
authored
May 12, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: packetOut event and payload
parent
117ebae2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
20 deletions
+106
-20
flow_actions.rs
src/openflow/events/flow_mod/flow_actions.rs
+25
-0
flow_mod_handler.rs
src/openflow/events/flow_mod/flow_mod_handler.rs
+2
-16
mod.rs
src/openflow/events/flow_mod/mod.rs
+1
-2
mod.rs
src/openflow/events/mod.rs
+1
-0
packet_out.rs
src/openflow/events/packet_out.rs
+65
-2
payload.rs
src/openflow/events/payload.rs
+12
-0
No files found.
src/openflow/events/flow_mod/flow_actions.rs
View file @
5e3ca5f4
...
...
@@ -202,6 +202,31 @@ impl FlowAction {
}
}
pub
trait
SizeCheck
{
fn
size_of_sequence
(
&
self
)
->
usize
;
fn
move_controller_last
(
&
self
)
->
Vec
<
FlowAction
>
;
}
impl
SizeCheck
for
Vec
<
FlowAction
>
{
fn
size_of_sequence
(
&
self
)
->
usize
{
self
.iter
()
.fold
(
0
,
|
acc
,
x
|
x
.length
()
+
acc
)
}
fn
move_controller_last
(
&
self
)
->
Vec
<
FlowAction
>
{
let
mut
not_ctrl
:
Vec
<
FlowAction
>
=
Vec
::
new
();
let
mut
is_ctrl
:
Vec
<
FlowAction
>
=
Vec
::
new
();
for
act
in
self
{
match
act
{
FlowAction
::
Oputput
(
PseudoPort
::
Controller
(
_
))
=>
{
is_ctrl
.push
(
act
.clone
());
}
_
=>
not_ctrl
.push
(
act
.clone
()),
}
}
not_ctrl
.append
(
&
mut
is_ctrl
);
not_ctrl
}
}
impl
Clone
for
FlowAction
{
fn
clone
(
&
self
)
->
Self
{
...
...
src/openflow/events/flow_mod/flow_mod_handler.rs
View file @
5e3ca5f4
...
...
@@ -7,7 +7,7 @@ use crate::openflow::{
OfpPort
,
PseudoPort
,
};
use
super
::{
FlowAction
,
FlowModCommand
,
MatchFields
};
use
super
::{
FlowAction
,
FlowModCommand
,
MatchFields
,
SizeCheck
};
pub
enum
Timeout
{
Permanent
,
...
...
@@ -58,20 +58,6 @@ impl FlowModEvent {
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
();
for
act
in
&
self
.actions
{
match
act
{
FlowAction
::
Oputput
(
PseudoPort
::
Controller
(
_
))
=>
{
is_ctrl
.push
(
act
.clone
());
}
_
=>
not_ctrl
.push
(
act
.clone
()),
}
}
not_ctrl
.append
(
&
mut
is_ctrl
);
not_ctrl
}
pub
fn
parse
(
buf
:
&
[
u8
])
->
FlowModEvent
{
let
mut
bytes
=
Cursor
::
new
(
buf
.to_vec
());
...
...
@@ -135,7 +121,7 @@ impl MessageMarshal for FlowModEvent {
(
if
self
.check_overlap
{
1
<<
1
}
else
{
0
})
|
(
if
self
.notify_when_removed
{
1
<<
0
}
else
{
0
}),
);
for
act
in
self
.
get
_controller_last
()
{
for
act
in
self
.
actions
.move
_controller_last
()
{
match
act
{
FlowAction
::
Oputput
(
PseudoPort
::
Table
)
=>
{
panic!
(
"Openflow table not allowed"
)
...
...
src/openflow/events/flow_mod/mod.rs
View file @
5e3ca5f4
...
...
@@ -5,11 +5,10 @@ pub mod command;
pub
use
command
::
FlowModCommand
;
pub
mod
flow_actions
;
pub
use
flow_actions
::
FlowAction
;
pub
use
flow_actions
::
{
FlowAction
,
SizeCheck
}
;
pub
mod
flow_actions_type
;
pub
use
flow_actions_type
::
FlowActionType
;
pub
mod
match_fields
;
pub
use
match_fields
::{
Mask
,
MatchFields
};
src/openflow/events/mod.rs
View file @
5e3ca5f4
...
...
@@ -2,6 +2,7 @@ pub mod packet_in;
pub
use
packet_in
::{
PacketInEvent
,
PacketInReason
};
pub
mod
packet_out
;
pub
use
packet_out
::
PacketOutEvent
;
pub
mod
flow_mod
;
pub
use
flow_mod
::{
FlowAction
,
FlowModEvent
};
...
...
src/openflow/events/packet_out.rs
View file @
5e3ca5f4
use
super
::
Payload
;
use
std
::
io
::{
BufRead
,
Cursor
,
Read
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
crate
::
openflow
::{
OfpPort
,
PseudoPort
};
use
super
::{
flow_mod
::
SizeCheck
,
FlowAction
,
Payload
};
pub
struct
PacketOutEvent
{
pub
payload
:
Payload
pub
payload
:
Payload
,
pub
port_id
:
Option
<
u16
>
,
pub
actions
:
Vec
<
FlowAction
>
,
}
impl
PacketOutEvent
{
pub
fn
parse
(
buf
:
&
Vec
<
u8
>
)
->
Self
{
let
mut
bytes
=
Cursor
::
new
(
buf
);
let
buf_id
=
match
bytes
.read_i32
::
<
BigEndian
>
()
.expect
(
"cannot parse buf id in packetout"
)
{
-
1
=>
None
,
n
=>
Some
(
n
),
};
let
in_port
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
();
let
action_len
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
();
let
mut
actions_buf
=
vec!
[
0
;
action_len
as
usize
];
let
_
=
bytes
.read_exact
(
&
mut
actions_buf
);
let
mut
action_bytes
=
Cursor
::
new
(
actions_buf
);
let
actions
=
FlowAction
::
parse_sequence
(
&
mut
action_bytes
);
Self
{
payload
:
match
buf_id
{
None
=>
Payload
::
NoBuffered
(
bytes
.fill_buf
()
.unwrap
()
.to_vec
()),
Some
(
n
)
=>
{
Payload
::
Buffered
(
n
as
u32
,
bytes
.fill_buf
()
.unwrap
()
.to_ascii_lowercase
())
}
},
port_id
:
{
if
in_port
==
OfpPort
::
None
as
u16
{
None
}
else
{
Some
(
in_port
)
}
},
actions
,
}
}
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
let
_
=
bytes
.write_i32
::
<
BigEndian
>
(
match
self
.payload
{
Payload
::
Buffered
(
n
,
_
)
=>
n
as
i32
,
Payload
::
NoBuffered
(
_
)
=>
-
1
,
});
match
self
.port_id
{
Some
(
id
)
=>
{
PseudoPort
::
PhysicalPort
(
id
)
.marshal
(
bytes
);
}
None
=>
{
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
OfpPort
::
None
as
u16
);
}
}
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
self
.actions
.size_of_sequence
()
as
u16
);
for
act
in
self
.actions
.move_controller_last
()
{
act
.marshal
(
bytes
);
}
self
.payload
.marshal
(
bytes
);
}
}
src/openflow/events/payload.rs
View file @
5e3ca5f4
use
std
::
io
::
Write
;
pub
enum
Payload
{
Buffered
(
u32
,
Vec
<
u8
>
),
NoBuffered
(
Vec
<
u8
>
),
}
impl
Payload
{
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
match
self
{
Payload
::
Buffered
(
_
,
buf
)
|
Payload
::
NoBuffered
(
buf
)
=>
{
let
_
=
bytes
.write_all
(
&
buf
);
}
}
}
}
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