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
1291acdc
Commit
1291acdc
authored
Jul 24, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packet_out
parent
8bb532bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
32 deletions
+29
-32
actions.rs
src/openflow/ofp13/events/actions.rs
+4
-9
packet_out.rs
src/openflow/ofp13/events/packet_out.rs
+25
-23
No files found.
src/openflow/ofp13/events/actions.rs
View file @
1291acdc
...
@@ -161,12 +161,11 @@ impl SetField {
...
@@ -161,12 +161,11 @@ impl SetField {
}
}
}
}
pub
type
Buffer
=
u16
;
pub
type
Buffer
=
u16
;
#[derive(Clone)]
#[derive(Clone)]
#[repr(u8)]
#[repr(u8)]
pub
enum
Action
{
pub
enum
Action
{
Oputput
(
PseudoPort
,
Option
<
Buffer
>
),
Oputput
(
PseudoPort
),
CopyTtlOut
,
// Copy TTL "outwards" -- from next-to-outermost to outermost
CopyTtlOut
,
// Copy TTL "outwards" -- from next-to-outermost to outermost
CopyTtlIn
,
// Copy TTL "inwards" -- from outermost to next-to-outermost
CopyTtlIn
,
// Copy TTL "inwards" -- from outermost to next-to-outermost
SetMplsTtl
(
u8
),
// MPLS TTL
SetMplsTtl
(
u8
),
// MPLS TTL
...
@@ -191,7 +190,7 @@ pub enum Action {
...
@@ -191,7 +190,7 @@ pub enum Action {
impl
Action
{
impl
Action
{
pub
fn
action_type
(
&
self
)
->
ActionType
{
pub
fn
action_type
(
&
self
)
->
ActionType
{
match
&
self
{
match
&
self
{
Action
::
Oputput
(
_
,
_
)
=>
ActionType
::
Output
,
Action
::
Oputput
(
_
)
=>
ActionType
::
Output
,
Action
::
CopyTtlOut
=>
ActionType
::
CopyTtlOut
,
Action
::
CopyTtlOut
=>
ActionType
::
CopyTtlOut
,
Action
::
CopyTtlIn
=>
ActionType
::
CopyTtlIn
,
Action
::
CopyTtlIn
=>
ActionType
::
CopyTtlIn
,
Action
::
SetMplsTtl
(
_
)
=>
ActionType
::
SetMplsTtl
,
Action
::
SetMplsTtl
(
_
)
=>
ActionType
::
SetMplsTtl
,
...
@@ -212,15 +211,11 @@ impl Action {
...
@@ -212,15 +211,11 @@ impl Action {
}
}
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
match
&
self
{
match
&
self
{
Action
::
Oputput
(
port
,
buffer
)
=>
{
Action
::
Oputput
(
port
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
16
);
// len
bytes
.write_u16
::
<
BigEndian
>
(
16
);
// len
port
.marshal
(
bytes
);
port
.marshal
(
bytes
);
if
let
Some
(
buf_id
)
=
buffer
{
bytes
.write_u16
::
<
BigEndian
>
(
ControllerMaxLen
::
NoBuffer
.into
());
bytes
.write_u16
::
<
BigEndian
>
(
*
buf_id
);
}
else
{
bytes
.write_u16
::
<
BigEndian
>
(
ControllerMaxLen
::
NoBuffer
.into
());
}
// padding 48bit
// padding 48bit
bytes
.write_u32
::
<
BigEndian
>
(
0
);
bytes
.write_u32
::
<
BigEndian
>
(
0
);
bytes
.write_u16
::
<
BigEndian
>
(
0
);
bytes
.write_u16
::
<
BigEndian
>
(
0
);
...
...
src/openflow/ofp13/events/packet_out.rs
View file @
1291acdc
use
std
::{
use
crate
::
openflow
::
ofp13
::
PseudoPort
;
io
::{
BufRead
,
Cursor
,
Error
,
Read
},
use
crate
::
openflow
::
ofp13
::{
ofp_port
::
OfpPort
,
MessageMarshal
,
Msg
};
mem
::
size_of
,
use
byteorder
::{
BigEndian
,
WriteBytesExt
};
};
use
crate
::
openflow
::
ofp10
::
PseudoPort
;
use
super
::{
Action
,
Payload
};
use
crate
::
openflow
::
ofp10
::{
ofp_port
::
OfpPort
,
MessageMarshal
,
Msg
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
super
::{
actions
::
SizeCheck
,
Action
,
Payload
};
pub
struct
PacketOutEvent
{
pub
struct
PacketOutEvent
{
pub
payload
:
Payload
,
// buffer_id is in Payload
pub
in_port
:
Option
<
u
16
>
,
pub
in_port
:
Option
<
u
32
>
,
pub
actions
:
Vec
<
Action
>
,
pub
actions
:
Vec
<
Action
>
,
pub
payload
:
Payload
,
}
}
impl
MessageMarshal
for
PacketOutEvent
{
impl
MessageMarshal
for
PacketOutEvent
{
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
// buffer id
let
_
=
bytes
.write_i32
::
<
BigEndian
>
(
match
self
.payload
{
let
_
=
bytes
.write_i32
::
<
BigEndian
>
(
match
self
.payload
{
Payload
::
Buffered
(
n
,
_
)
=>
n
as
i32
,
Payload
::
Buffered
(
n
,
_
)
=>
n
as
i32
,
Payload
::
NoBuffered
(
_
)
=>
-
1
,
Payload
::
NoBuffered
(
_
)
=>
-
1
,
});
});
// in_port
match
self
.in_port
{
match
self
.in_port
{
Some
(
id
)
=>
{
Some
(
id
)
=>
{
PseudoPort
::
PhysicalPort
(
id
)
.marshal
(
bytes
);
PseudoPort
::
PhysicalPort
(
id
)
.marshal
(
bytes
);
}
}
None
=>
{
None
=>
{
let
_
=
bytes
.write_u
16
::
<
BigEndian
>
(
OfpPort
::
None
as
u16
);
let
_
=
bytes
.write_u
32
::
<
BigEndian
>
(
OfpPort
::
Any
as
u32
);
}
}
}
}
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
self
.actions
.size_of_sequence
()
as
u16
);
let
mut
action_byte
:
Vec
<
u8
>
=
Vec
::
new
(
);
for
act
in
self
.actions
.
move_controller_last
()
{
for
act
in
self
.actions
.
iter
()
{
act
.marshal
(
bytes
);
act
.marshal
(
&
mut
action_byte
);
}
}
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
action_byte
.len
()
as
u16
);
// padding 48 bit
bytes
.write_u32
::
<
BigEndian
>
(
0
);
bytes
.write_u16
::
<
BigEndian
>
(
0
);
bytes
.append
(
&
mut
action_byte
);
self
.payload
.marshal
(
bytes
);
self
.payload
.marshal
(
bytes
);
}
}
...
@@ -45,28 +49,26 @@ impl MessageMarshal for PacketOutEvent {
...
@@ -45,28 +49,26 @@ impl MessageMarshal for PacketOutEvent {
}
}
fn
size_of
(
&
self
)
->
usize
{
fn
size_of
(
&
self
)
->
usize
{
size_of
::
<
(
u32
,
u16
,
u16
)
>
()
+
self
.actions
.size_of_sequence
()
+
self
.payload
.length
()
24
}
}
}
}
impl
PacketOutEvent
{
impl
PacketOutEvent
{
pub
fn
new
(
in_port
:
Option
<
u
16
>
,
payload
:
Payload
,
actions
:
Vec
<
Action
>
)
->
Self
{
pub
fn
new
(
in_port
:
Option
<
u
32
>
,
payload
:
Payload
,
actions
:
Vec
<
Action
>
)
->
Self
{
Self
{
Self
{
in_port
,
in_port
,
payload
,
payload
,
actions
,
actions
,
}
}
}
}
/* TODO
pub fn parse(buf: &Vec<u8>) -> Result<Self, Error> {
pub fn parse(buf: &Vec<u8>) -> Result<Self, Error> {
let mut bytes = Cursor::new(buf);
let mut bytes = Cursor::new(buf);
let
buf_id
=
match
bytes
let buf_id = match bytes.read_i32::<BigEndian>()? {
.read_i32
::
<
BigEndian
>
()
.expect
(
"cannot parse buf id in packetout"
)
{
-1 => None,
-1 => None,
n => Some(n),
n => Some(n),
};
};
let
in_port
=
bytes
.read_u
16
::
<
BigEndian
>
()
?
;
let in_port = bytes.read_u
32
::<BigEndian>()?;
let action_len = bytes.read_u16::<BigEndian>()?;
let action_len = bytes.read_u16::<BigEndian>()?;
let mut actions_buf = vec![0; action_len as usize];
let mut actions_buf = vec![0; action_len as usize];
let _ = bytes.read_exact(&mut actions_buf);
let _ = bytes.read_exact(&mut actions_buf);
...
@@ -86,5 +88,5 @@ impl PacketOutEvent {
...
@@ -86,5 +88,5 @@ impl PacketOutEvent {
},
},
actions,
actions,
})
})
}
}
*/
}
}
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