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
Hide 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};
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
use
std
::
io
::{
BufRead
,
Cursor
,
Read
};
struct
Flags
{
dont_flagment
:
bool
,
more_fragments
:
bool
,
pub
struct
Flags
{
pub
dont_flagment
:
bool
,
pub
more_fragments
:
bool
,
}
pub
enum
IpProtocol
{
ICMP
=
0x01
,
TCP
=
0x06
,
UDP
=
0x11
,
}
pub
struct
IP
{
pub
version
:
u8
,
pub
ihl
:
u8
,
...
...
@@ -20,12 +27,7 @@ pub struct IP {
pub
src
:
u32
,
pub
des
:
u32
,
pub
options
:
Vec
<
u8
>
,
}
pub
enum
IpProtocol
{
ICMP
=
0x01
,
TCP
=
0x06
,
UDP
=
0x11
,
pub
ptcol
:
EtherData
,
}
impl
IP
{
...
...
@@ -96,6 +98,7 @@ impl IP {
src
,
des
,
options
,
ptcol
,
})
}
}
...
...
src/main.rs
View file @
55d2aee1
use
std
::
io
::
Read
;
use
std
::
net
::
TcpListener
;
use
tenjin
::
etherparser
::
ethernet
::
EthernetFrame
;
use
tenjin
::
openflow
::
events
::
packet_in
::
PacketInEvent
;
use
tenjin
::
openflow
::{
Controller
,
Msg
,
OfpHeader
};
...
...
@@ -32,7 +31,7 @@ fn main() -> Result<(), std::io::Error> {
let
length_payload
=
packet
.size
();
let
mut
payload
=
vec!
[
0u8
;
length_payload
];
stream
.read
(
&
mut
payload
)
?
;
let
message
=
Msg
::
parse
(
packet
.message
,
&
payload
);
let
message
=
Msg
::
parse
(
packet
.message
);
match
message
{
// 0 is Hello message
...
...
@@ -41,8 +40,8 @@ fn main() -> Result<(), std::io::Error> {
controller
.feture_req
(
packet
.xid
,
&
mut
stream
);
println!
(
"Hello event"
);
}
Msg
::
PacketIn
(
b
)
=>
{
controller
.packet
I
n
(
Msg
::
PacketIn
=>
{
controller
.packet
_i
n
(
packet
.xid
,
PacketInEvent
::
parse
(
&
payload
),
&
mut
stream
,
...
...
src/openflow/controller.rs
View file @
55d2aee1
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
};
pub
struct
Controller
{
...
...
@@ -33,11 +29,9 @@ impl Controller {
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
;
self
.mac_to_port
.insert
(
ether
.mac_src
,
packetin
.port
);
}
pub
fn
send
(
&
self
,
xid
:
u32
,
message
:
u8
,
payload
:
&
Vec
<
u8
>
,
stream
:
&
mut
TcpStream
)
{
...
...
src/openflow/message.rs
View file @
55d2aee1
pub
enum
Msg
{
Hello
,
PacketIn
(
Vec
<
u8
>
)
,
PacketIn
,
NotFound
,
}
impl
Msg
{
pub
fn
parse
(
message_code
:
u8
,
payload
:
&
Vec
<
u8
>
)
->
Self
{
pub
fn
parse
(
message_code
:
u8
)
->
Self
{
match
message_code
{
0
=>
Msg
::
Hello
,
8
=>
Msg
::
PacketIn
(
payload
.clone
())
,
8
=>
Msg
::
PacketIn
,
_
=>
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