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
55d2aee1
Commit
55d2aee1
authored
Apr 17, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix warning code
parent
15388f3c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
23 deletions
+19
-23
ipv4.rs
src/etherparser/packet/ipv4.rs
+12
-9
main.rs
src/main.rs
+3
-4
controller.rs
src/openflow/controller.rs
+1
-7
message.rs
src/openflow/message.rs
+3
-3
No files found.
src/etherparser/packet/ipv4.rs
View file @
55d2aee1
...
@@ -2,10 +2,17 @@ use super::{tcp::TCP, udp::UDP, ICMP};
...
@@ -2,10 +2,17 @@ use super::{tcp::TCP, udp::UDP, ICMP};
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
use
std
::
io
::{
BufRead
,
Cursor
,
Read
};
use
std
::
io
::{
BufRead
,
Cursor
,
Read
};
struct
Flags
{
pub
struct
Flags
{
dont_flagment
:
bool
,
pub
dont_flagment
:
bool
,
more_fragments
:
bool
,
pub
more_fragments
:
bool
,
}
}
pub
enum
IpProtocol
{
ICMP
=
0x01
,
TCP
=
0x06
,
UDP
=
0x11
,
}
pub
struct
IP
{
pub
struct
IP
{
pub
version
:
u8
,
pub
version
:
u8
,
pub
ihl
:
u8
,
pub
ihl
:
u8
,
...
@@ -20,12 +27,7 @@ pub struct IP {
...
@@ -20,12 +27,7 @@ pub struct IP {
pub
src
:
u32
,
pub
src
:
u32
,
pub
des
:
u32
,
pub
des
:
u32
,
pub
options
:
Vec
<
u8
>
,
pub
options
:
Vec
<
u8
>
,
}
pub
ptcol
:
EtherData
,
pub
enum
IpProtocol
{
ICMP
=
0x01
,
TCP
=
0x06
,
UDP
=
0x11
,
}
}
impl
IP
{
impl
IP
{
...
@@ -96,6 +98,7 @@ impl IP {
...
@@ -96,6 +98,7 @@ impl IP {
src
,
src
,
des
,
des
,
options
,
options
,
ptcol
,
})
})
}
}
}
}
...
...
src/main.rs
View file @
55d2aee1
use
std
::
io
::
Read
;
use
std
::
io
::
Read
;
use
std
::
net
::
TcpListener
;
use
std
::
net
::
TcpListener
;
use
tenjin
::
etherparser
::
ethernet
::
EthernetFrame
;
use
tenjin
::
openflow
::
events
::
packet_in
::
PacketInEvent
;
use
tenjin
::
openflow
::
events
::
packet_in
::
PacketInEvent
;
use
tenjin
::
openflow
::{
Controller
,
Msg
,
OfpHeader
};
use
tenjin
::
openflow
::{
Controller
,
Msg
,
OfpHeader
};
...
@@ -32,7 +31,7 @@ fn main() -> Result<(), std::io::Error> {
...
@@ -32,7 +31,7 @@ fn main() -> Result<(), std::io::Error> {
let
length_payload
=
packet
.size
();
let
length_payload
=
packet
.size
();
let
mut
payload
=
vec!
[
0u8
;
length_payload
];
let
mut
payload
=
vec!
[
0u8
;
length_payload
];
stream
.read
(
&
mut
payload
)
?
;
stream
.read
(
&
mut
payload
)
?
;
let
message
=
Msg
::
parse
(
packet
.message
,
&
payload
);
let
message
=
Msg
::
parse
(
packet
.message
);
match
message
{
match
message
{
// 0 is Hello message
// 0 is Hello message
...
@@ -41,8 +40,8 @@ fn main() -> Result<(), std::io::Error> {
...
@@ -41,8 +40,8 @@ fn main() -> Result<(), std::io::Error> {
controller
.feture_req
(
packet
.xid
,
&
mut
stream
);
controller
.feture_req
(
packet
.xid
,
&
mut
stream
);
println!
(
"Hello event"
);
println!
(
"Hello event"
);
}
}
Msg
::
PacketIn
(
b
)
=>
{
Msg
::
PacketIn
=>
{
controller
.packet
I
n
(
controller
.packet
_i
n
(
packet
.xid
,
packet
.xid
,
PacketInEvent
::
parse
(
&
payload
),
PacketInEvent
::
parse
(
&
payload
),
&
mut
stream
,
&
mut
stream
,
...
...
src/openflow/controller.rs
View file @
55d2aee1
use
std
::{
collections
::
HashMap
,
io
::
Write
,
mem
::
size_of
,
net
::
TcpStream
};
use
std
::{
collections
::
HashMap
,
io
::
Write
,
mem
::
size_of
,
net
::
TcpStream
};
use
byteorder
::{
BigEndian
,
WriteBytesExt
};
use
crate
::
etherparser
::
ethernet
::
EthernetFrame
;
use
super
::{
events
::
packet_in
::
PacketInEvent
,
OfpHeader
};
use
super
::{
events
::
packet_in
::
PacketInEvent
,
OfpHeader
};
pub
struct
Controller
{
pub
struct
Controller
{
...
@@ -33,11 +29,9 @@ impl Controller {
...
@@ -33,11 +29,9 @@ impl Controller {
stream
.write_all
(
&
bytes
)
.unwrap
();
stream
.write_all
(
&
bytes
)
.unwrap
();
}
}
pub
fn
packet
I
n
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
pub
fn
packet
_i
n
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
let
ether
=
packetin
.payload
;
let
ether
=
packetin
.payload
;
self
.mac_to_port
.insert
(
ether
.mac_src
,
packetin
.port
);
self
.mac_to_port
.insert
(
ether
.mac_src
,
packetin
.port
);
}
}
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
)
{
...
...
src/openflow/message.rs
View file @
55d2aee1
pub
enum
Msg
{
pub
enum
Msg
{
Hello
,
Hello
,
PacketIn
(
Vec
<
u8
>
)
,
PacketIn
,
NotFound
,
NotFound
,
}
}
impl
Msg
{
impl
Msg
{
pub
fn
parse
(
message_code
:
u8
,
payload
:
&
Vec
<
u8
>
)
->
Self
{
pub
fn
parse
(
message_code
:
u8
)
->
Self
{
match
message_code
{
match
message_code
{
0
=>
Msg
::
Hello
,
0
=>
Msg
::
Hello
,
8
=>
Msg
::
PacketIn
(
payload
.clone
())
,
8
=>
Msg
::
PacketIn
,
_
=>
Msg
::
NotFound
,
_
=>
Msg
::
NotFound
,
}
}
}
}
...
...
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