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
3ac60692
Commit
3ac60692
authored
Jul 24, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve controller13, match_fields to public
parent
1291acdc
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
38 deletions
+61
-38
controller13.rs
src/example/controller13.rs
+36
-15
mod.rs
src/example/mod.rs
+3
-0
lib.rs
src/lib.rs
+2
-3
main.rs
src/main.rs
+3
-3
command.rs
src/openflow/ofp13/events/flow_mod/command.rs
+1
-1
match_fields.rs
src/openflow/ofp13/events/flow_mod/match_fields.rs
+13
-13
ofp_manager.rs
src/openflow/ofp13/ofp_manager.rs
+2
-2
event_trait.rs
src/openflow/ofp13/traiter/event_trait.rs
+1
-1
No files found.
src/
controller
.rs
→
src/
example/controller13
.rs
View file @
3ac60692
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
use
std
::{
collections
::
HashMap
,
net
::
TcpStream
};
use
std
::{
collections
::
HashMap
,
net
::
TcpStream
};
use
crate
::{
use
crate
::{
etherparser
::
ether_type
::
EtherType
,
etherparser
::
{
ether_type
::
EtherType
,
MacAddr
}
,
openflow
::
ofp13
::{
openflow
::
ofp13
::{
self
,
self
,
events
::{
flow_mod
::
MatchFields
,
Action
},
events
::{
flow_mod
::
MatchFields
,
Action
},
...
@@ -16,12 +16,12 @@ use crate::{
...
@@ -16,12 +16,12 @@ use crate::{
* In production please remove allow unused.
* In production please remove allow unused.
*/
*/
#[derive(Clone)]
#[derive(Clone)]
pub
struct
Controller
{
pub
struct
Controller
13
{
mac_to_port
:
HashMap
<
u64
,
u
16
>
,
mac_to_port
:
HashMap
<
u64
,
u
32
>
,
}
}
impl
ControllerFrame13
for
Controller
{
impl
ControllerFrame13
for
Controller
13
{
fn
new
()
->
Self
{
fn
new
()
->
Self
{
Self
{
Self
{
mac_to_port
:
HashMap
::
new
(),
mac_to_port
:
HashMap
::
new
(),
...
@@ -35,14 +35,18 @@ impl ControllerFrame13 for Controller {
...
@@ -35,14 +35,18 @@ impl ControllerFrame13 for Controller {
Ok
(
pkt
)
=>
pkt
,
Ok
(
pkt
)
=>
pkt
,
Err
(
_
)
=>
return
,
Err
(
_
)
=>
return
,
};
};
let
in_port
=
match
packetin
.matchs.in_port
{
Some
(
p
)
=>
p
,
None
=>
return
,
};
println!
(
println!
(
"packet in {} {} {}"
,
"packet in {} {} {}"
,
pkt
.mac_src_string
(),
pkt
.mac_src_string
(),
pkt
.mac_dst_string
(),
pkt
.mac_dst_string
(),
packetin
.
in_port
in_port
);
);
self
.mac_to_port
.insert
(
pkt
.mac_src
,
packetin
.
in_port
);
self
.mac_to_port
.insert
(
pkt
.mac_src
,
in_port
);
let
mac_dst
=
pkt
.mac_dst
;
let
mac_dst
=
pkt
.mac_dst
;
let
mac_src
=
pkt
.mac_src
;
let
mac_src
=
pkt
.mac_src
;
...
@@ -60,35 +64,52 @@ impl ControllerFrame13 for Controller {
...
@@ -60,35 +64,52 @@ impl ControllerFrame13 for Controller {
if
let
ofp13
::
PseudoPort
::
PhysicalPort
(
_
)
=
out_port
{
if
let
ofp13
::
PseudoPort
::
PhysicalPort
(
_
)
=
out_port
{
let
mut
match_fields
=
MatchFields
::
match_all
();
let
mut
match_fields
=
MatchFields
::
match_all
();
match_fields
.in_port
=
Some
(
packetin
.
in_port
);
match_fields
.in_port
=
Some
(
in_port
);
match_fields
.
mac_dest
=
Some
(
mac_dst
);
match_fields
.
eth_dst
=
Some
(
MacAddr
::
from
(
mac_dst
)
);
match_fields
.
mac_src
=
Some
(
mac_src
);
match_fields
.
eth_src
=
Some
(
MacAddr
::
from
(
mac_src
)
);
if
let
Some
(
buf_id
)
=
packetin
.buf_id
{
if
let
Some
(
buf_id
)
=
packetin
.buf_id
{
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
Some
(
buf_id
as
u32
),
stream
);
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
packetin
.table_id
,
Some
(
buf_id
as
u32
),
stream
,
);
return
;
return
;
}
else
{
}
else
{
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
None
,
stream
);
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
packetin
.table_id
,
None
,
stream
,
);
}
}
}
}
let
packet_out
=
self
let
packet_out
=
self
.ofp
()
.ofp
()
.packet_out
(
Some
(
packetin
.
in_port
),
packetin
.payload
,
actions
);
.packet_out
(
Some
(
in_port
),
packetin
.payload
,
actions
);
self
.send_msg
(
packet_out
,
xid
,
stream
);
self
.send_msg
(
packet_out
,
xid
,
stream
);
}
}
}
}
impl
Controller
{
impl
Controller
13
{
fn
add_flow
(
fn
add_flow
(
&
self
,
&
self
,
xid
:
u32
,
xid
:
u32
,
priority
:
u16
,
priority
:
u16
,
flow
:
MatchFields
,
flow
:
MatchFields
,
actions
:
&
Vec
<
Action
>
,
actions
:
&
Vec
<
Action
>
,
table_id
:
u8
,
buffer_id
:
Option
<
u32
>
,
buffer_id
:
Option
<
u32
>
,
stream
:
&
mut
TcpStream
,
stream
:
&
mut
TcpStream
,
)
{
)
{
self
.send_msg
(
self
.send_msg
(
FlowModEvent
::
add_flow
(
10
,
flow
,
actions
.clone
(),
buffer_id
),
FlowModEvent
::
add_flow
(
10
,
flow
,
actions
.clone
(),
table_id
,
buffer_id
),
xid
,
xid
,
stream
,
stream
,
)
)
...
...
src/example/mod.rs
0 → 100644
View file @
3ac60692
pub
mod
controller13
;
pub
use
controller13
::
Controller13
;
\ No newline at end of file
src/lib.rs
View file @
3ac60692
...
@@ -2,5 +2,4 @@ pub mod openflow;
...
@@ -2,5 +2,4 @@ pub mod openflow;
pub
mod
etherparser
;
pub
mod
etherparser
;
pub
mod
controller
;
pub
mod
example
;
pub
use
controller
::
Controller
;
\ No newline at end of file
\ No newline at end of file
src/main.rs
View file @
3ac60692
use
tenjin
::
{
openflow
::
ofp13
::
ControllerFrame13
,
Controller
}
;
use
tenjin
::
example
;
use
tenjin
::
openflow
::
ofp13
::
ControllerFrame13
;
extern
crate
byteorder
;
extern
crate
byteorder
;
fn
main
()
->
Result
<
(),
std
::
io
::
Error
>
{
fn
main
()
->
Result
<
(),
std
::
io
::
Error
>
{
let
controller
=
Controller
::
new
();
let
controller
=
example
::
Controller13
::
new
();
controller
.listener
(
"127.0.0.1:6633"
);
controller
.listener
(
"127.0.0.1:6633"
);
Ok
(())
Ok
(())
}
}
src/openflow/ofp13/events/flow_mod/command.rs
View file @
3ac60692
...
@@ -5,7 +5,7 @@ pub enum FlowModCommand {
...
@@ -5,7 +5,7 @@ pub enum FlowModCommand {
ModifyStrict
=
2
,
ModifyStrict
=
2
,
Delete
=
3
,
Delete
=
3
,
DeleteStrict
=
4
,
DeleteStrict
=
4
,
Unparsable
=
0xff
ff
,
Unparsable
=
0xff
,
}
}
impl
FlowModCommand
{
impl
FlowModCommand
{
...
...
src/openflow/ofp13/events/flow_mod/match_fields.rs
View file @
3ac60692
...
@@ -179,19 +179,19 @@ impl From<OxmMatchFields> for u8 {
...
@@ -179,19 +179,19 @@ impl From<OxmMatchFields> for u8 {
// Required match fields.
// Required match fields.
pub
struct
MatchFields
{
pub
struct
MatchFields
{
in_port
:
Option
<
u32
>
,
// Ingress port. This may be a physical or switch-defined logical port.
pub
in_port
:
Option
<
u32
>
,
// Ingress port. This may be a physical or switch-defined logical port.
eth_dst
:
Option
<
MacAddr
>
,
// Ethernet source address. Can use arbitrary bitmask
pub
eth_dst
:
Option
<
MacAddr
>
,
// Ethernet source address. Can use arbitrary bitmask
eth_src
:
Option
<
MacAddr
>
,
// Ethernet destination address. Can use arbitrary bitmask
pub
eth_src
:
Option
<
MacAddr
>
,
// Ethernet destination address. Can use arbitrary bitmask
eth_typ
:
Option
<
u16
>
,
// Ethernet type of the OpenFlow packet payload, after VLAN tags.
pub
eth_typ
:
Option
<
u16
>
,
// Ethernet type of the OpenFlow packet payload, after VLAN tags.
ip_proto
:
Option
<
u8
>
,
// IPv4 or IPv6 protocol number
pub
ip_proto
:
Option
<
u8
>
,
// IPv4 or IPv6 protocol number
ipv4_src
:
Option
<
Ipv4Addr
>
,
// IPv4 source address. Can use subnet mask or arbitrary bitmask
pub
ipv4_src
:
Option
<
Ipv4Addr
>
,
// IPv4 source address. Can use subnet mask or arbitrary bitmask
ipv4_dst
:
Option
<
Ipv4Addr
>
,
// IPv4 destination address. Can use subnet mask or arbitrary bitmask
pub
ipv4_dst
:
Option
<
Ipv4Addr
>
,
// IPv4 destination address. Can use subnet mask or arbitrary bitmask
ipv6_src
:
Option
<
Ipv6Addr
>
,
// IPv6 source address. Can use subnet mask or arbitrary bitmask
pub
ipv6_src
:
Option
<
Ipv6Addr
>
,
// IPv6 source address. Can use subnet mask or arbitrary bitmask
ipv6_dst
:
Option
<
Ipv6Addr
>
,
// IPv6 destination address. Can use subnet mask or arbitrary bitmask
pub
ipv6_dst
:
Option
<
Ipv6Addr
>
,
// IPv6 destination address. Can use subnet mask or arbitrary bitmask
tcp_src
:
Option
<
u16
>
,
// TCP source port
pub
tcp_src
:
Option
<
u16
>
,
// TCP source port
tcp_dst
:
Option
<
u16
>
,
// TCP destination port
pub
tcp_dst
:
Option
<
u16
>
,
// TCP destination port
udp_src
:
Option
<
u16
>
,
// UDP source port
pub
udp_src
:
Option
<
u16
>
,
// UDP source port
udp_dst
:
Option
<
u16
>
,
// UDP destination port
pub
udp_dst
:
Option
<
u16
>
,
// UDP destination port
}
}
impl
MatchFields
{
impl
MatchFields
{
...
...
src/openflow/ofp13/ofp_manager.rs
View file @
3ac60692
...
@@ -13,7 +13,7 @@ impl Openflow13 {
...
@@ -13,7 +13,7 @@ impl Openflow13 {
}
}
impl
OfpMsgEvent
for
Openflow13
{
impl
OfpMsgEvent
for
Openflow13
{
fn
header_parse
(
&
self
,
bytes
:
&
Vec
<
u8
>
)
->
Result
<
OfpHeader
,
std
::
io
::
Error
>
{
fn
header_parse
(
&
self
,
bytes
:
&
Vec
<
u8
>
)
->
Result
<
OfpHeader
,
std
::
io
::
Error
>
{
OfpHeader
::
parse
(
bytes
)
OfpHeader
::
parse
(
bytes
)
}
}
fn
header_size
(
&
self
)
->
usize
{
fn
header_size
(
&
self
)
->
usize
{
...
@@ -28,7 +28,7 @@ impl OfpMsgEvent for Openflow13 {
...
@@ -28,7 +28,7 @@ impl OfpMsgEvent for Openflow13 {
}
}
fn
packet_out
(
fn
packet_out
(
&
self
,
&
self
,
port_id
:
Option
<
u
16
>
,
port_id
:
Option
<
u
32
>
,
payload
:
Payload
,
payload
:
Payload
,
actions
:
Vec
<
Action
>
,
actions
:
Vec
<
Action
>
,
)
->
PacketOutEvent
{
)
->
PacketOutEvent
{
...
...
src/openflow/ofp13/traiter/event_trait.rs
View file @
3ac60692
...
@@ -33,7 +33,7 @@ pub trait OfpMsgEvent {
...
@@ -33,7 +33,7 @@ pub trait OfpMsgEvent {
fn
fetures_req
(
&
self
)
->
FeaturesReqEvent
;
fn
fetures_req
(
&
self
)
->
FeaturesReqEvent
;
fn
packet_out
(
fn
packet_out
(
&
self
,
&
self
,
port_id
:
Option
<
u
16
>
,
port_id
:
Option
<
u
32
>
,
payload
:
Payload
,
payload
:
Payload
,
actions
:
Vec
<
Action
>
,
actions
:
Vec
<
Action
>
,
)
->
PacketOutEvent
;
)
->
PacketOutEvent
;
...
...
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