Skip to content

Commit

Permalink
fix parse wrong packetInReason code
Browse files Browse the repository at this point in the history
  • Loading branch information
Arikato111 committed Jun 4, 2024
1 parent c48821a commit 591e222
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl ControllerFrame<Openflow10> for Controller {
* Start here for handle packetIn message.
*/
fn packet_in_handler(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream) {
println!("reason {:?}", packetin.reason);
let pkt = packetin.ether_parse();
self.mac_to_port.insert(pkt.mac_src, packetin.in_port);

Expand All @@ -62,9 +63,11 @@ impl ControllerFrame<Openflow10> for Controller {
match_fields.mac_dest = Some(mac_dst);
match_fields.mac_src = Some(mac_src);
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);
return;
} else {
println!("not found buf id");
self.add_flow(xid, 1, match_fields, &actions, None, stream);
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/openflow/ofp10/events/packet_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ use super::Payload;
use byteorder::{BigEndian, ReadBytesExt};
use std::io::{BufRead, Cursor};

#[derive(Debug)]
pub enum PacketInReason {
NoMatch,
Action,
Unknown,
InvalidTTL,
Unknown(u8),
}

impl PacketInReason {
fn new(code: u8) -> Self {
match code {
0 => PacketInReason::NoMatch,
1 => PacketInReason::Action,
2 => PacketInReason::InvalidTTL,
t => PacketInReason::Unknown(t),
}
}
}

pub struct PacketInEvent {
Expand All @@ -33,11 +46,7 @@ impl PacketInEvent {
};
let total_len = bytes.read_u16::<BigEndian>().unwrap();
let in_port = bytes.read_u16::<BigEndian>().unwrap();
let reason = match bytes.read_u8().unwrap() {
1 => PacketInReason::NoMatch,
2 => PacketInReason::Action,
_ => PacketInReason::Unknown,
};
let reason = PacketInReason::new(bytes.read_u8().unwrap());
let table_id = bytes.read_u8().unwrap();
let packet = bytes.fill_buf().unwrap().to_vec();
let payload = match buf_id {
Expand Down

0 comments on commit 591e222

Please sign in to comment.