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
6c677f99
Commit
6c677f99
authored
Jul 01, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add action oxm and others
parent
36bf05c2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
427 additions
and
110 deletions
+427
-110
mac_address.rs
src/etherparser/net/mac_address.rs
+1
-0
actions.rs
src/openflow/ofp13/events/actions.rs
+380
-106
instructions.rs
src/openflow/ofp13/events/flow_mod/instructions.rs
+40
-0
match_fields.rs
src/openflow/ofp13/events/flow_mod/match_fields.rs
+2
-2
mod.rs
src/openflow/ofp13/events/flow_mod/mod.rs
+4
-2
No files found.
src/etherparser/net/mac_address.rs
View file @
6c677f99
use
byteorder
::
WriteBytesExt
;
use
byteorder
::
WriteBytesExt
;
#[derive(Clone)]
pub
struct
MacAddr
{
pub
struct
MacAddr
{
mac
:
[
u8
;
6
],
mac
:
[
u8
;
6
],
}
}
...
...
src/openflow/ofp13/events/actions.rs
View file @
6c677f99
use
crate
::{
etherparser
::{
tools
::
bits
::{
bytes_to_mac
,
mac_to_bytes
},
MacAddr
,
},
openflow
::
ofp13
::{
ofp_port
::
OfpPort
,
PseudoPort
},
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
std
::{
use
std
::{
io
::{
BufRead
,
Cursor
,
Error
},
io
::{
BufRead
,
Cursor
,
Error
},
mem
::
size_of
,
mem
::
size_of
,
net
::{
Ipv4Addr
,
Ipv6Addr
},
};
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
super
::
flow_mod
::
match_fields
::{
OxmHeader
,
OxmMatchFields
};
use
crate
::{
struct
ActionHeader
{
etherparser
::
tools
::
bits
::{
bytes_to_mac
,
mac_to_bytes
},
typ
:
ActionType
,
openflow
::
ofp13
::
PseudoPort
,
// len: u16,
};
// pad: [u8; 4],
}
pub
enum
ActionType
{
impl
ActionHeader
{
Output
=
0
,
pub
fn
new
(
typ
:
ActionType
)
->
Self
{
SetVlanId
=
1
,
Self
{
typ
}
SetVlanPCP
=
2
,
}
StripVlan
=
3
,
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
SetSrcMac
=
4
,
bytes
.write_u16
::
<
BigEndian
>
(
self
.typ
.clone
()
.into
());
SetDstMac
=
5
,
bytes
.write_u16
::
<
BigEndian
>
(
8
);
SetIPv4Src
=
6
,
bytes
.write_u32
::
<
BigEndian
>
(
0
);
SetIPv4Des
=
7
,
}
SetTos
=
8
,
SetTpSrc
=
9
,
SetTpDst
=
10
,
Enqueue
=
11
,
}
}
#[derive(Clone)]
#[derive(Clone)]
pub
enum
Action
{
#[repr(u16)]
Oputput
(
PseudoPort
),
enum
ActionType
{
SetDlVlan
(
Option
<
u16
>
),
Output
=
0
,
// Output to switch port.
SetDlVlanPcp
(
u8
),
CopyTtlOut
=
11
,
// Copy TTL "outwards" -- from next-to-outermost to outermost
SetDlSrc
(
u64
),
CopyTtlIn
=
12
,
// Copy TTL "inwards" -- from outermost to next-to-outermost
SetDlDest
(
u64
),
SetMplsTtl
=
15
,
// MPLS TTL
SetIpSrc
(
u32
),
SetIpDes
(
u32
),
DecMplsTtl
=
16
,
// Decrement MPLS TTL
SetTos
(
u8
),
PushVlan
=
17
,
// Push a new VLAN tag
SetTpSrc
(
u16
),
PopVlan
=
18
,
// Pop the outer VLAN tag
SetTpDest
(
u16
),
PushMpls
=
19
,
// Push a new MPLS tag
Enqueue
(
PseudoPort
,
u32
),
PopMpls
=
20
,
// Pop the outer MPLS tag
Unparsable
,
SetQueue
=
21
,
// Set queue id when outputting to a port
Group
=
22
,
// Apply group.
SetNwTtl
=
23
,
// IP TTL.
DecNwTtl
=
24
,
// Decrement IP TTL.
SetField
=
25
,
// Set a header field using OXM TLV format.
PushPbb
=
26
,
// Push a new PBB service tag (I-TAG)
PopPbb
=
27
,
// Pop the outer PBB service tag (I-TAG)
Experimenter
=
0xffff
,
}
}
impl
Action
{
impl
ActionType
{
pub
fn
to_action_code
(
&
self
)
->
ActionType
{
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
match
self
{
bytes
.write_u16
::
<
BigEndian
>
(
self
.clone
()
.into
());
Action
::
Oputput
(
_
)
=>
ActionType
::
Output
,
}
Action
::
SetDlVlan
(
_
)
=>
ActionType
::
SetVlanId
,
}
Action
::
SetDlVlanPcp
(
_
)
=>
ActionType
::
SetVlanPCP
,
Action
::
SetDlSrc
(
_
)
=>
ActionType
::
SetSrcMac
,
impl
From
<
ActionType
>
for
u16
{
Action
::
SetDlDest
(
_
)
=>
ActionType
::
SetDstMac
,
fn
from
(
value
:
ActionType
)
->
Self
{
Action
::
SetIpSrc
(
_
)
=>
ActionType
::
SetIPv4Src
,
value
as
u16
Action
::
SetIpDes
(
_
)
=>
ActionType
::
SetIPv4Des
,
}
Action
::
SetTos
(
_
)
=>
ActionType
::
SetTos
,
}
Action
::
SetTpSrc
(
_
)
=>
ActionType
::
SetTpSrc
,
Action
::
SetTpDest
(
_
)
=>
ActionType
::
SetTpDst
,
#[derive(Clone)]
Action
::
Enqueue
(
_
,
_
)
=>
ActionType
::
Enqueue
,
#[repr(u16)]
Action
::
Unparsable
=>
panic!
(
"Unparse Action to ActionType"
),
enum
ControllerMaxLen
{
Custom
(
u16
),
Max
=
0xffe5
,
NoBuffer
=
0xffff
,
}
impl
From
<
ControllerMaxLen
>
for
u16
{
fn
from
(
value
:
ControllerMaxLen
)
->
Self
{
match
value
{
ControllerMaxLen
::
Custom
(
v
)
=>
v
,
ControllerMaxLen
::
Max
=>
u16
::
from
(
ControllerMaxLen
::
Max
),
ControllerMaxLen
::
NoBuffer
=>
u16
::
from
(
ControllerMaxLen
::
NoBuffer
),
}
}
}
struct
ActionOutput
{
typ
:
ActionType
,
// u16
port
:
PseudoPort
,
// u32
max_len
:
ControllerMaxLen
,
}
impl
ActionOutput
{
pub
const
LEN
:
usize
=
16
;
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
self
.typ
.marshal
(
bytes
);
self
.port
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
self
.max_len
.clone
()
.into
());
// write padding 48 bytes [32 + 16]
bytes
.write_u32
::
<
BigEndian
>
(
0
);
bytes
.write_u16
::
<
BigEndian
>
(
0
);
}
pub
fn
new
(
port
:
PseudoPort
,
max_len
:
ControllerMaxLen
)
->
Self
{
Self
{
typ
:
ActionType
::
Output
,
port
,
max_len
,
}
}
}
}
pub
fn
length
(
&
self
)
->
usize
{
}
let
header
=
size_of
::
<
(
u16
,
u16
)
>
();
let
body
=
match
self
{
struct
ActionGroup
{
Action
::
Oputput
(
_
)
=>
size_of
::
<
(
u16
,
u16
)
>
(),
typ
:
ActionType
,
Action
::
SetDlVlan
(
_
)
=>
size_of
::
<
(
u16
,
u16
)
>
(),
len
:
u16
,
Action
::
SetDlVlanPcp
(
_
)
=>
size_of
::
<
(
u8
,
[
u8
;
3
])
>
(),
group_id
:
u32
,
Action
::
SetDlSrc
(
_
)
=>
size_of
::
<
([
u8
;
6
],
[
u8
;
6
])
>
(),
}
Action
::
SetDlDest
(
_
)
=>
size_of
::
<
([
u8
;
6
],
[
u8
;
6
])
>
(),
Action
::
SetIpSrc
(
_
)
=>
size_of
::
<
u32
>
(),
impl
ActionGroup
{
Action
::
SetIpDes
(
_
)
=>
size_of
::
<
u32
>
(),
pub
const
LEN
:
usize
=
8
;
Action
::
SetTos
(
_
)
=>
size_of
::
<
(
u8
,
[
u8
;
3
])
>
(),
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
Action
::
SetTpSrc
(
_
)
=>
size_of
::
<
(
u16
,
u16
)
>
(),
self
.typ
.marshal
(
bytes
);
Action
::
SetTpDest
(
_
)
=>
size_of
::
<
(
u16
,
u16
)
>
(),
bytes
.write_u16
::
<
BigEndian
>
(
self
.len
);
Action
::
Enqueue
(
_
,
_
)
=>
size_of
::
<
(
u16
,
[
u8
;
6
],
u32
)
>
(),
bytes
.write_u32
::
<
BigEndian
>
(
self
.group_id
);
Action
::
Unparsable
=>
0
,
}
};
pub
fn
new
(
group_id
:
u32
)
->
Self
{
header
+
body
Self
{
typ
:
ActionType
::
Group
,
len
:
Self
::
LEN
as
u16
,
group_id
,
}
}
}
}
struct
ActionSetQueue
{
typ
:
ActionType
,
len
:
u16
,
queue_id
:
u32
,
}
impl
ActionSetQueue
{
pub
const
LEN
:
usize
=
8
;
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
self
.to_action_code
()
as
u16
);
self
.typ
.marshal
(
bytes
);
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
self
.length
()
as
u16
);
bytes
.write_u16
::
<
BigEndian
>
(
self
.len
);
match
self
{
bytes
.write_u32
::
<
BigEndian
>
(
self
.queue_id
);
Action
::
Oputput
(
pseudo
)
=>
{
}
pseudo
.marshal
(
bytes
);
pub
fn
new
(
queue_id
:
u32
)
->
Self
{
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
match
pseudo
{
Self
{
PseudoPort
::
Controller
(
w
)
=>
*
w
as
u16
,
typ
:
ActionType
::
SetQueue
,
_
=>
0
,
len
:
Self
::
LEN
as
u16
,
});
queue_id
,
}
}
Action
::
SetDlVlan
(
None
)
=>
{
}
let
_
=
bytes
.write_u32
::
<
BigEndian
>
(
0xffff
);
}
}
Action
::
SetDlVlan
(
Some
(
vid
))
=>
{
struct
ActionMplsTtl
{
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
*
vid
);
typ
:
ActionType
,
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
0
);
len
:
u16
,
}
mpls_ttl
:
u8
,
Action
::
SetDlVlanPcp
(
pcp
)
=>
{
pad
:
[
u8
;
3
],
let
_
=
bytes
.write_u8
(
*
pcp
);
}
for
_
in
0
..
3
{
let
_
=
bytes
.write_u8
(
0
);
impl
ActionMplsTtl
{
}
pub
const
LEN
:
usize
=
8
;
}
struct
ActionNwTtl
{
typ
:
ActionType
,
// OFPAT_SET_NW_TTL
len
:
u16
,
// Length is 8.
nw_ttl
:
u8
,
// IP TTL
pad
:
[
u8
;
3
],
}
impl
ActionNwTtl
{
pub
const
LEN
:
usize
=
8
;
}
struct
ActionPush
{
typ
:
ActionType
,
len
:
u16
,
ethertype
:
u16
,
pad
:
[
u8
;
2
],
}
impl
ActionPush
{
pub
const
LEN
:
usize
=
8
;
}
struct
ActionPopMpls
{
typ
:
ActionType
,
len
:
u16
,
ethertype
:
u16
,
pad
:
[
u8
;
2
],
}
impl
ActionPopMpls
{
pub
const
LEN
:
usize
=
8
;
}
#[derive(Clone)]
pub
enum
SetField
{
InPort
(
PseudoPort
),
// Ingress port. This may be a physical or switch-defined logical port.
EthDst
(
MacAddr
),
// Ethernet source address. Can use arbitrary bitmask
EthSrc
(
MacAddr
),
// Ethernet destination address. Can use arbitrary bitmask
EthTyp
(
u16
),
// Ethernet type of the OpenFlow packet payload, after VLAN tags.
IpProto
(
u8
),
// IPv4 or IPv6 protocol number
Ipv4Src
(
Ipv4Addr
),
// IPv4 source address. Can use subnet mask or arbitrary bitmask
Ipv4Dst
(
Ipv4Addr
),
// IPv4 destination address. Can use subnet mask or arbitrary bitmask
Ipv6Src
(
Ipv6Addr
),
// IPv6 source address. Can use subnet mask or arbitrary bitmask
Ipv6Dst
(
Ipv6Addr
),
// IPv6 destination address. Can use subnet mask or arbitrary bitmask
TcpSrc
(
u16
),
// TCP source port
TcpDst
(
u16
),
// TCP destination port
UdpSrc
(
u16
),
// UDP source port
UdpDst
(
u16
),
// UDP destination port
}
impl
SetField
{
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
match
&
self
{
SetField
::
InPort
(
port
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
ActsetOutput
,
4
)
.marshal
(
bytes
);
port
.marshal
(
bytes
);
}
}
Action
::
SetDlSrc
(
mac
)
|
Action
::
SetDlDest
(
mac
)
=>
{
SetField
::
EthDst
(
mac
)
=>
{
let
mac
=
bytes_to_mac
(
*
mac
);
OxmHeader
::
new
(
OxmMatchFields
::
MacDest
,
6
)
.marshal
(
bytes
);
for
m
in
mac
{
mac
.marshal
(
bytes
);
let
_
=
bytes
.write_u8
(
m
);
}
}
SetField
::
EthSrc
(
mac
)
=>
{
for
_
in
0
..
6
{
OxmHeader
::
new
(
OxmMatchFields
::
MacSrc
,
6
);
let
_
=
bytes
.write_u8
(
0
);
mac
.marshal
(
bytes
);
}
}
SetField
::
EthTyp
(
eth
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
EthernetType
,
2
)
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
*
eth
);
}
SetField
::
IpProto
(
proto
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
Protocol
,
1
)
.marshal
(
bytes
);
bytes
.write_u8
(
*
proto
);
}
SetField
::
Ipv4Src
(
ipv4
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
IpSrc
,
4
)
.marshal
(
bytes
);
bytes
.write_u32
::
<
BigEndian
>
(
ipv4
.clone
()
.into
());
}
}
Action
::
SetIpSrc
(
address
)
|
Action
::
SetIpDes
(
address
)
=>
{
SetField
::
Ipv4Dst
(
ipv4
)
=>
{
let
_
=
bytes
.write_u32
::
<
BigEndian
>
(
*
address
);
OxmHeader
::
new
(
OxmMatchFields
::
IpDst
,
4
)
.marshal
(
bytes
);
bytes
.write_u32
::
<
BigEndian
>
(
ipv4
.clone
()
.into
());
}
}
Action
::
SetTos
(
n
)
=>
{
SetField
::
Ipv6Src
(
ipv6
)
=>
{
let
_
=
bytes
.write_u8
(
*
n
);
OxmHeader
::
new
(
OxmMatchFields
::
Ipv6Src
,
16
)
.marshal
(
bytes
);
bytes
.write_u128
::
<
BigEndian
>
(
ipv6
.clone
()
.into
());
}
}
Action
::
SetTpSrc
(
pt
)
|
Action
::
SetTpDest
(
pt
)
=>
{
SetField
::
Ipv6Dst
(
ipv6
)
=>
{
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
*
pt
);
OxmHeader
::
new
(
OxmMatchFields
::
Ipv6Dst
,
16
)
.marshal
(
bytes
);
let
_
=
bytes
.write_u16
::
<
BigEndian
>
(
0
);
bytes
.write_u128
::
<
BigEndian
>
(
ipv6
.clone
()
.into
()
);
}
}
Action
::
Enqueue
(
pp
,
qid
)
=>
{
SetField
::
TcpSrc
(
tcp
)
=>
{
pp
.marshal
(
bytes
);
OxmHeader
::
new
(
OxmMatchFields
::
TcpSrc
,
2
)
.marshal
(
bytes
);
for
_
in
0
..
6
{
bytes
.write_u16
::
<
BigEndian
>
(
*
tcp
);
let
_
=
bytes
.write_u8
(
0
);
}
SetField
::
TcpDst
(
tcp
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
TcpDst
,
2
)
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
*
tcp
);
}
SetField
::
UdpSrc
(
udp
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
UdpSrc
,
2
)
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
*
udp
);
}
SetField
::
UdpDst
(
udp
)
=>
{
OxmHeader
::
new
(
OxmMatchFields
::
UdpDst
,
2
)
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
*
udp
);
}
}
}
}
struct
ActionExperimenterHeader
{
typ
:
ActionType
,
len
:
u16
,
experimenter
:
u32
,
}
pub
type
Buffer
=
u16
;
#[derive(Clone)]
#[repr(u8)]
enum
Action
{
Oputput
(
PseudoPort
,
Option
<
Buffer
>
),
CopyTtlOut
,
// Copy TTL "outwards" -- from next-to-outermost to outermost
CopyTtlIn
,
// Copy TTL "inwards" -- from outermost to next-to-outermost
SetMplsTtl
(
u8
),
// MPLS TTL
DecMplsTtl
,
// Decrement MPLS TTL
PushVlan
(
u16
),
PushMpls
(
u16
),
PushPbb
(
u16
),
PopVlan
(
u16
),
PopMpls
(
u16
),
PopPbb
(
u16
),
SetQueue
(
u32
),
// Set queue id when outputting to a port
Group
(
u32
),
// Apply group.
SetNwTtl
(
u8
),
// IP TTL.
DecNwTtl
=
24
,
// Decrement IP TTL.
SetField
(
SetField
),
// Set a header field using OXM TLV format.
Experimenter
(
u32
),
}
impl
Action
{
pub
fn
action_type
(
&
self
)
->
ActionType
{
match
&
self
{
Action
::
Oputput
(
_
,
_
)
=>
ActionType
::
Output
,
Action
::
CopyTtlOut
=>
ActionType
::
CopyTtlOut
,
Action
::
CopyTtlIn
=>
ActionType
::
CopyTtlIn
,
Action
::
SetMplsTtl
(
_
)
=>
ActionType
::
SetMplsTtl
,
Action
::
DecMplsTtl
=>
ActionType
::
DecMplsTtl
,
Action
::
PushVlan
(
_
)
=>
ActionType
::
PushVlan
,
Action
::
PushMpls
(
_
)
=>
ActionType
::
PushMpls
,
Action
::
PushPbb
(
_
)
=>
ActionType
::
PushPbb
,
Action
::
PopVlan
(
_
)
=>
ActionType
::
PopVlan
,
Action
::
PopMpls
(
_
)
=>
ActionType
::
PopMpls
,
Action
::
PopPbb
(
_
)
=>
ActionType
::
PopPbb
,
Action
::
SetQueue
(
_
)
=>
ActionType
::
SetQueue
,
Action
::
Group
(
_
)
=>
ActionType
::
Group
,
Action
::
SetNwTtl
(
_
)
=>
ActionType
::
SetNwTtl
,
Action
::
DecNwTtl
=>
ActionType
::
DecNwTtl
,
Action
::
SetField
(
_
)
=>
ActionType
::
SetField
,
Action
::
Experimenter
(
_
)
=>
ActionType
::
Experimenter
,
}
}
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
match
&
self
{
Action
::
Oputput
(
port
,
buffer
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
16
);
// len
port
.marshal
(
bytes
);
if
let
Some
(
buf_id
)
=
buffer
{
bytes
.write_u16
::
<
BigEndian
>
(
*
buf_id
);
}
else
{
bytes
.write_u16
::
<
BigEndian
>
(
ControllerMaxLen
::
NoBuffer
.into
());
}
}
let
_
=
bytes
.write_u32
::
<
BigEndian
>
(
*
qid
);
// padding 48bit
bytes
.write_u32
::
<
BigEndian
>
(
0
);
bytes
.write_u16
::
<
BigEndian
>
(
0
);
}
Action
::
SetMplsTtl
(
mpls_ttl
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u8
(
*
mpls_ttl
);
// padding 24bit
bytes
.write_u16
::
<
BigEndian
>
(
0
);
bytes
.write_u8
(
0
);
}
Action
::
PushVlan
(
ethertype
)
|
Action
::
PushMpls
(
ethertype
)
|
Action
::
PushPbb
(
ethertype
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u16
::
<
BigEndian
>
(
*
ethertype
);
// padding 16 bit
bytes
.write_u16
::
<
BigEndian
>
(
0
);
}
Action
::
PopVlan
(
ethertype
)
|
Action
::
PopMpls
(
ethertype
)
|
Action
::
PopPbb
(
ethertype
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u16
::
<
BigEndian
>
(
*
ethertype
);
bytes
.write_u16
::
<
BigEndian
>
(
0
);
}
Action
::
SetQueue
(
queue_id
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u32
::
<
BigEndian
>
(
*
queue_id
);
}
Action
::
Group
(
group_id
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u32
::
<
BigEndian
>
(
*
group_id
);
}
Action
::
SetNwTtl
(
nw_ttl
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u8
(
*
nw_ttl
);
// padding 24bit
bytes
.write_u16
::
<
BigEndian
>
(
0
);
bytes
.write_u8
(
0
);
}
Action
::
SetField
(
omx_field
)
=>
{
let
mut
field_bytes
:
Vec
<
u8
>
=
Vec
::
new
();
omx_field
.marshal
(
&
mut
field_bytes
);
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
4
+
field_bytes
.len
()
as
u16
);
bytes
.append
(
&
mut
field_bytes
);
}
Action
::
Experimenter
(
exper_id
)
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
bytes
.write_u32
::
<
BigEndian
>
(
*
exper_id
);
}
Action
::
DecMplsTtl
|
Action
::
DecNwTtl
|
Action
::
CopyTtlOut
|
Action
::
CopyTtlIn
=>
{
self
.action_type
()
.marshal
(
bytes
);
bytes
.write_u16
::
<
BigEndian
>
(
8
);
// padding 32 bit
bytes
.write_u32
::
<
BigEndian
>
(
0
);
}
}
Action
::
Unparsable
=>
(),
}
}
}
}
pub
fn
parse_sequence
(
bytes
:
&
mut
Cursor
<
Vec
<
u8
>>
)
->
Vec
<
Action
>
{
pub
fn
parse_sequence
(
bytes
:
&
mut
Cursor
<
Vec
<
u8
>>
)
->
Vec
<
Action
>
{
...
...
src/openflow/ofp13/events/flow_mod/instructions.rs
0 → 100644
View file @
6c677f99
use
crate
::
openflow
::
ofp13
::
Action
;
#[repr(u16)]
pub
enum
InstructType
{
GotoTable
=
1
,
WriteMetadata
=
2
,
WriteActions
=
3
,
ApplyActions
=
4
,
ClearActions
=
5
,
Meter
=
6
,
Experimenter
=
0xffff
,
}
impl
From
<
InstructType
>
for
u16
{
fn
from
(
value
:
InstructType
)
->
Self
{
value
as
u16
}
}
pub
struct
GotoTable
{
typ
:
InstructType
,
len
:
u16
,
table_id
:
u8
,
pad
:
[
u8
;
3
],
}
pub
struct
WriteMetadata
{
typ
:
InstructType
,
len
:
u16
,
pad
:
[
u8
;
4
],
metadata
:
u64
,
meta_mask
:
u64
,
}
pub
struct
InstructActions
{
typ
:
InstructType
,
len
:
u16
,
pad
:
[
u8
;
4
],
action_header
:
Vec
<
Action
>
,
}
src/openflow/ofp13/events/flow_mod/match_fields.rs
View file @
6c677f99
...
@@ -76,7 +76,7 @@ pub struct OxmHeader {
...
@@ -76,7 +76,7 @@ pub struct OxmHeader {
}
}
impl
OxmHeader
{
impl
OxmHeader
{
fn
new
(
field
:
OxmMatchFields
,
size
:
u8
)
->
Self
{
pub
fn
new
(
field
:
OxmMatchFields
,
size
:
u8
)
->
Self
{
Self
{
Self
{
class
:
OxmClass
::
OpenflowBasic
,
class
:
OxmClass
::
OpenflowBasic
,
field
,
field
,
...
@@ -85,7 +85,7 @@ impl OxmHeader {
...
@@ -85,7 +85,7 @@ impl OxmHeader {
experimenter
:
None
,
experimenter
:
None
,
}
}
}
}
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
pub
fn
marshal
(
&
self
,
bytes
:
&
mut
Vec
<
u8
>
)
{
bytes
.write_u16
::
<
BigEndian
>
(
self
.class
.clone
()
.into
());
bytes
.write_u16
::
<
BigEndian
>
(
self
.class
.clone
()
.into
());
let
field
:
u8
=
self
.field
.clone
()
.into
();
let
field
:
u8
=
self
.field
.clone
()
.into
();
bytes
.write_u8
(
field
<<
1
|
if
self
.hasmask
{
1
}
else
{
0
});
bytes
.write_u8
(
field
<<
1
|
if
self
.hasmask
{
1
}
else
{
0
});
...
...
src/openflow/ofp13/events/flow_mod/mod.rs
View file @
6c677f99
...
@@ -8,4 +8,6 @@ pub mod match_fields;
...
@@ -8,4 +8,6 @@ pub mod match_fields;
pub
use
match_fields
::{
Mask
,
MatchFields
};
pub
use
match_fields
::{
Mask
,
MatchFields
};
pub
mod
flow_mod_flags
;
pub
mod
flow_mod_flags
;
pub
use
flow_mod_flags
::
FlowModFlags
;
pub
use
flow_mod_flags
::
FlowModFlags
;
\ No newline at end of file
pub
mod
instructions
;
\ No newline at end of file
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