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
ecb47c2e
Commit
ecb47c2e
authored
Apr 17, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add event of message -> packetIn
parent
3baedfb4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
6 deletions
+63
-6
main.rs
src/main.rs
+2
-1
controller.rs
src/openflow/controller.rs
+9
-5
mod.rs
src/openflow/events/mod.rs
+1
-0
packet_in.rs
src/openflow/events/packet_in.rs
+48
-0
mod.rs
src/openflow/mod.rs
+3
-0
No files found.
src/main.rs
View file @
ecb47c2e
use
tenjin
::
etherparser
::
ethernet
::
EthernetFrame
;
use
tenjin
::
openflow
::{
Controller
,
Msg
,
OfpHeader
};
use
tenjin
::
openflow
::{
Controller
,
Msg
,
OfpHeader
};
use
std
::
io
::
Read
;
use
std
::
io
::
Read
;
use
std
::
net
::
TcpListener
;
use
std
::
net
::
TcpListener
;
...
@@ -40,7 +41,7 @@ fn main() -> Result<(), std::io::Error> {
...
@@ -40,7 +41,7 @@ fn main() -> Result<(), std::io::Error> {
println!
(
"Hello event"
);
println!
(
"Hello event"
);
}
}
Msg
::
PacketIn
(
b
)
=>
{
Msg
::
PacketIn
(
b
)
=>
{
controller
.packetIn
(
packet
.xid
,
&
payload
,
&
mut
stream
);
controller
.packetIn
(
packet
.xid
,
EthernetFrame
::
parse
(
&
payload
)
,
&
mut
stream
);
println!
(
"PacketIn event"
);
println!
(
"PacketIn event"
);
}
}
_
=>
{
_
=>
{
...
...
src/openflow/controller.rs
View file @
ecb47c2e
use
std
::{
io
::
Write
,
mem
::
size_of
,
net
::
TcpStream
};
use
std
::{
collections
::
HashMap
,
io
::
Write
,
mem
::
size_of
,
net
::
TcpStream
};
use
byteorder
::{
BigEndian
,
WriteBytesExt
};
use
byteorder
::{
BigEndian
,
WriteBytesExt
};
use
crate
::
etherparser
::
ethernet
::
EthernetFrame
;
use
super
::
OfpHeader
;
use
super
::
OfpHeader
;
pub
struct
Controller
{
pub
struct
Controller
{
version
:
u8
,
version
:
u8
,
mac_to_port
:
HashMap
<
u64
,
u16
>
,
}
}
impl
Controller
{
impl
Controller
{
pub
const
OFP_1_0
:
u8
=
1
;
pub
const
OFP_1_0
:
u8
=
1
;
pub
fn
new
(
version
:
u8
)
->
Self
{
pub
fn
new
(
version
:
u8
)
->
Self
{
Self
{
version
}
Self
{
version
,
mac_to_port
:
HashMap
::
new
(),
}
}
}
pub
fn
hello
(
&
self
,
stream
:
&
mut
TcpStream
)
{
pub
fn
hello
(
&
self
,
stream
:
&
mut
TcpStream
)
{
let
header
=
OfpHeader
::
new
(
self
.version
,
0
,
size_of
::
<
OfpHeader
>
()
as
u16
,
0
);
let
header
=
OfpHeader
::
new
(
self
.version
,
0
,
size_of
::
<
OfpHeader
>
()
as
u16
,
0
);
...
@@ -27,9 +33,7 @@ impl Controller {
...
@@ -27,9 +33,7 @@ impl Controller {
stream
.write_all
(
&
bytes
)
.unwrap
();
stream
.write_all
(
&
bytes
)
.unwrap
();
}
}
pub
fn
packetIn
(
&
self
,
xid
:
u32
,
payload
:
&
Vec
<
u8
>
,
stream
:
&
mut
TcpStream
)
{
pub
fn
packetIn
(
&
self
,
xid
:
u32
,
payload
:
EthernetFrame
,
stream
:
&
mut
TcpStream
)
{}
// pass
}
pub
fn
send
(
&
self
,
xid
:
u32
,
message
:
u8
,
payload
:
&
Vec
<
u8
>
,
stream
:
&
mut
TcpStream
)
{
pub
fn
send
(
&
self
,
xid
:
u32
,
message
:
u8
,
payload
:
&
Vec
<
u8
>
,
stream
:
&
mut
TcpStream
)
{
let
length
=
size_of
::
<
OfpHeader
>
()
+
payload
.len
();
let
length
=
size_of
::
<
OfpHeader
>
()
+
payload
.len
();
...
...
src/openflow/events/mod.rs
0 → 100644
View file @
ecb47c2e
pub
mod
packet_in
;
src/openflow/events/packet_in.rs
0 → 100644
View file @
ecb47c2e
use
std
::
io
::{
BufRead
,
Cursor
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
use
crate
::
etherparser
::
ethernet
::
EthernetFrame
;
pub
enum
PacketInReason
{
NoMatch
,
Action
,
Unknown
,
}
pub
struct
PacketInEvent
{
pub
buf_id
:
Option
<
i32
>
,
pub
total_len
:
u16
,
pub
port
:
u16
,
pub
reason
:
PacketInReason
,
pub
table_id
:
u8
,
pub
payload
:
EthernetFrame
,
}
impl
PacketInEvent
{
pub
fn
parse
(
payload
:
&
Vec
<
u8
>
)
->
PacketInEvent
{
let
mut
bytes
=
Cursor
::
new
(
payload
.to_vec
());
let
buf_id
=
match
bytes
.read_i32
::
<
BigEndian
>
()
.unwrap
()
{
-
1
=>
None
,
n
=>
Some
(
n
),
};
let
total_len
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
();
let
port
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
();
let
reason
=
match
bytes
.read_u8
()
.unwrap
()
{
1
=>
PacketInReason
::
NoMatch
,
2
=>
PacketInReason
::
Action
,
_
=>
PacketInReason
::
Unknown
,
};
let
table_id
=
bytes
.read_u8
()
.unwrap
();
let
packet
=
bytes
.fill_buf
()
.unwrap
()
.to_vec
();
let
payload
=
EthernetFrame
::
parse
(
&
packet
);
PacketInEvent
{
buf_id
,
total_len
,
port
,
reason
,
table_id
,
payload
,
}
}
}
src/openflow/mod.rs
View file @
ecb47c2e
...
@@ -6,3 +6,5 @@ pub use message::Msg;
...
@@ -6,3 +6,5 @@ pub use message::Msg;
pub
mod
controller
;
pub
mod
controller
;
pub
use
controller
::
Controller
;
pub
use
controller
::
Controller
;
pub
mod
events
;
\ 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