From 591e22234cfd13303c63e9380465e52e8975082e Mon Sep 17 00:00:00 2001 From: Nawasan Wisitsingkhon Date: Tue, 4 Jun 2024 16:03:58 +0700 Subject: [PATCH] fix parse wrong packetInReason code --- src/controller.rs | 3 +++ src/openflow/ofp10/events/packet_in.rs | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index be85243..8af149b 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -39,6 +39,7 @@ impl ControllerFrame 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); @@ -62,9 +63,11 @@ impl ControllerFrame 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); } } diff --git a/src/openflow/ofp10/events/packet_in.rs b/src/openflow/ofp10/events/packet_in.rs index c1fd89e..271b455 100644 --- a/src/openflow/ofp10/events/packet_in.rs +++ b/src/openflow/ofp10/events/packet_in.rs @@ -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 { @@ -33,11 +46,7 @@ impl PacketInEvent { }; let total_len = bytes.read_u16::().unwrap(); let in_port = bytes.read_u16::().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 {