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
914467e0
Commit
914467e0
authored
Jun 16, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
print log
parent
45c2db0f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
controller.rs
src/controller.rs
+7
-3
ethernet.rs
src/etherparser/ethernet.rs
+16
-0
No files found.
src/controller.rs
View file @
914467e0
...
@@ -30,11 +30,17 @@ impl ControllerFrame10 for Controller {
...
@@ -30,11 +30,17 @@ impl ControllerFrame10 for Controller {
* Start here for handle packetIn message.
* Start here for handle packetIn message.
*/
*/
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
fn
packet_in_handler
(
&
mut
self
,
xid
:
u32
,
packetin
:
PacketInEvent
,
stream
:
&
mut
TcpStream
)
{
println!
(
"reason {:?}"
,
packetin
.reason
);
let
pkt
=
match
packetin
.ether_parse
()
{
let
pkt
=
match
packetin
.ether_parse
()
{
Ok
(
pkt
)
=>
pkt
,
Ok
(
pkt
)
=>
pkt
,
Err
(
_
)
=>
return
,
Err
(
_
)
=>
return
,
};
};
println!
(
"packet in {} {} {}"
,
pkt
.mac_src_string
(),
pkt
.mac_dst_string
(),
packetin
.in_port
);
self
.mac_to_port
.insert
(
pkt
.mac_src
,
packetin
.in_port
);
self
.mac_to_port
.insert
(
pkt
.mac_src
,
packetin
.in_port
);
let
mac_dst
=
pkt
.mac_dst
;
let
mac_dst
=
pkt
.mac_dst
;
...
@@ -57,11 +63,9 @@ impl ControllerFrame10 for Controller {
...
@@ -57,11 +63,9 @@ impl ControllerFrame10 for Controller {
match_fields
.mac_dest
=
Some
(
mac_dst
);
match_fields
.mac_dest
=
Some
(
mac_dst
);
match_fields
.mac_src
=
Some
(
mac_src
);
match_fields
.mac_src
=
Some
(
mac_src
);
if
let
Some
(
buf_id
)
=
packetin
.buf_id
{
if
let
Some
(
buf_id
)
=
packetin
.buf_id
{
println!
(
"found buf id"
);
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
Some
(
buf_id
as
u32
),
stream
);
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
Some
(
buf_id
as
u32
),
stream
);
return
;
return
;
}
else
{
}
else
{
println!
(
"not found buf id"
);
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
None
,
stream
);
self
.add_flow
(
xid
,
1
,
match_fields
,
&
actions
,
None
,
stream
);
}
}
}
}
...
...
src/etherparser/ethernet.rs
View file @
914467e0
...
@@ -19,6 +19,22 @@ pub struct EthernetFrame {
...
@@ -19,6 +19,22 @@ pub struct EthernetFrame {
}
}
impl
EthernetFrame
{
impl
EthernetFrame
{
pub
fn
mac_dst_string
(
&
self
)
->
String
{
Self
::
mac_str
(
self
.mac_dst
)
}
pub
fn
mac_src_string
(
&
self
)
->
String
{
Self
::
mac_str
(
self
.mac_src
)
}
pub
fn
mac_str
(
mac
:
u64
)
->
String
{
let
mut
mac_string
=
String
::
new
();
let
mut
mac
=
mac
;
for
_
in
0
..
8
{
mac_string
=
format!
(
"{}:{}"
,
mac
as
u8
,
mac_string
);
mac
=
mac
>>
8
;
}
mac_string
.pop
();
mac_string
}
pub
fn
parse
(
payload
:
&
Vec
<
u8
>
)
->
Result
<
EthernetFrame
,
Error
>
{
pub
fn
parse
(
payload
:
&
Vec
<
u8
>
)
->
Result
<
EthernetFrame
,
Error
>
{
let
mut
bytes
=
Cursor
::
new
(
payload
.to_vec
());
let
mut
bytes
=
Cursor
::
new
(
payload
.to_vec
());
let
mut
mac_dst
=
[
0u8
;
6
];
let
mut
mac_dst
=
[
0u8
;
6
];
...
...
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