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
228d23b2
Commit
228d23b2
authored
Jun 16, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethernet frame: remove unwarp
parent
82e98223
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
20 deletions
+21
-20
controller.rs
src/controller.rs
+4
-1
ethernet.rs
src/etherparser/ethernet.rs
+15
-17
packet_in.rs
src/openflow/ofp10/events/packet_in.rs
+2
-2
No files found.
src/controller.rs
View file @
228d23b2
...
...
@@ -31,7 +31,10 @@ impl ControllerFrame10 for Controller {
*/
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
println!
(
"reason {:?}"
,
packetin
.reason
);
let
pkt
=
packetin
.ether_parse
();
let
pkt
=
match
packetin
.ether_parse
()
{
Ok
(
pkt
)
=>
pkt
,
Err
(
_
)
=>
return
,
};
self
.mac_to_port
.insert
(
pkt
.mac_src
,
packetin
.in_port
);
let
mac_dst
=
pkt
.mac_dst
;
...
...
src/etherparser/ethernet.rs
View file @
228d23b2
use
crate
::
etherparser
::
ether_type
::
EtherType
;
use
std
::
io
::{
BufRead
,
Cursor
};
use
std
::
io
::{
BufRead
,
Cursor
,
Error
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
...
...
@@ -19,21 +19,21 @@ pub struct EthernetFrame {
}
impl
EthernetFrame
{
pub
fn
parse
(
payload
:
&
Vec
<
u8
>
)
->
EthernetFrame
{
pub
fn
parse
(
payload
:
&
Vec
<
u8
>
)
->
Result
<
EthernetFrame
,
Error
>
{
let
mut
bytes
=
Cursor
::
new
(
payload
.to_vec
());
let
mut
mac_dst
=
[
0u8
;
6
];
let
mut
mac_src
=
[
0u8
;
6
];
for
i
in
0
..
6
{
mac_dst
[
i
]
=
bytes
.read_u8
()
.unwrap
()
;
mac_dst
[
i
]
=
bytes
.read_u8
()
?
;
}
for
i
in
0
..
6
{
mac_src
[
i
]
=
bytes
.read_u8
()
.unwrap
()
;
mac_src
[
i
]
=
bytes
.read_u8
()
?
;
}
// check 802.1q tag tpid
let
typ
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
()
;
let
typ
=
bytes
.read_u16
::
<
BigEndian
>
()
?
;
let
(
vlan_pcp
,
vlan_dei
,
vlan_vid
,
typ
)
=
match
typ
{
tp
if
tp
==
EtherType
::
VLAN
as
u16
=>
{
let
tci
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
()
;
let
tci
=
bytes
.read_u16
::
<
BigEndian
>
()
?
;
let
pcp
=
tci
>>
13
;
let
dei
=
(
tci
&
0x1000
)
>
0
;
let
vid
=
tci
&
0xfff
;
...
...
@@ -44,23 +44,21 @@ impl EthernetFrame {
let
network
=
match
typ
{
tp
if
tp
==
EtherType
::
IP
as
u16
=>
{
let
ip
=
IP
::
parse
(
&
mut
bytes
);
if
ip
.is_some
()
{
Network
::
IP
(
ip
.unwrap
())
}
else
{
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
.unwrap
()
.to_vec
())
match
ip
{
Some
(
ip
)
=>
Network
::
IP
(
ip
),
None
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
}
}
tp
if
tp
==
(
EtherType
::
ARP
as
u16
)
=>
{
let
arp
=
ARP
::
parse
(
&
mut
bytes
);
if
arp
.is_some
()
{
Network
::
ARP
(
arp
.unwrap
())
}
else
{
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
.unwrap
()
.to_vec
())
match
arp
{
Some
(
arp
)
=>
Network
::
ARP
(
arp
),
None
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
}
}
_
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
.unwrap
()
.to_vec
()),
_
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
};
EthernetFrame
{
Ok
(
EthernetFrame
{
ether_type
:
EtherType
::
parse
(
typ
),
mac_dst
:
mac_to_bytes
(
mac_dst
),
mac_src
:
mac_to_bytes
(
mac_src
),
...
...
@@ -68,7 +66,7 @@ impl EthernetFrame {
vlan_dei
,
vlan_vid
,
network
,
}
}
)
}
}
...
...
src/openflow/ofp10/events/packet_in.rs
View file @
228d23b2
...
...
@@ -2,7 +2,7 @@ use crate::etherparser::ethernet::EthernetFrame;
use
super
::
Payload
;
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
use
std
::
io
::{
BufRead
,
Cursor
};
use
std
::
io
::{
BufRead
,
Cursor
,
Error
};
#[derive(Debug)]
pub
enum
PacketInReason
{
...
...
@@ -33,7 +33,7 @@ pub struct PacketInEvent {
}
impl
PacketInEvent
{
pub
fn
ether_parse
(
&
self
)
->
EthernetFrame
{
pub
fn
ether_parse
(
&
self
)
->
Result
<
EthernetFrame
,
Error
>
{
match
&
self
.payload
{
Payload
::
Buffered
(
_
,
p
)
|
Payload
::
NoBuffered
(
p
)
=>
EthernetFrame
::
parse
(
&
p
),
}
...
...
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