Commit 591e2223 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

fix parse wrong packetInReason code

parent c48821ad
...@@ -39,6 +39,7 @@ impl ControllerFrame<Openflow10> for Controller { ...@@ -39,6 +39,7 @@ impl ControllerFrame<Openflow10> 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 = packetin.ether_parse(); let pkt = packetin.ether_parse();
self.mac_to_port.insert(pkt.mac_src, packetin.in_port); self.mac_to_port.insert(pkt.mac_src, packetin.in_port);
...@@ -62,9 +63,11 @@ impl ControllerFrame<Openflow10> for Controller { ...@@ -62,9 +63,11 @@ impl ControllerFrame<Openflow10> 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);
} }
} }
......
...@@ -4,10 +4,23 @@ use super::Payload; ...@@ -4,10 +4,23 @@ use super::Payload;
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
use std::io::{BufRead, Cursor}; use std::io::{BufRead, Cursor};
#[derive(Debug)]
pub enum PacketInReason { pub enum PacketInReason {
NoMatch, NoMatch,
Action, 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 { pub struct PacketInEvent {
...@@ -33,11 +46,7 @@ impl PacketInEvent { ...@@ -33,11 +46,7 @@ impl PacketInEvent {
}; };
let total_len = bytes.read_u16::<BigEndian>().unwrap(); let total_len = bytes.read_u16::<BigEndian>().unwrap();
let in_port = bytes.read_u16::<BigEndian>().unwrap(); let in_port = bytes.read_u16::<BigEndian>().unwrap();
let reason = match bytes.read_u8().unwrap() { let reason = PacketInReason::new(bytes.read_u8().unwrap());
1 => PacketInReason::NoMatch,
2 => PacketInReason::Action,
_ => PacketInReason::Unknown,
};
let table_id = bytes.read_u8().unwrap(); let table_id = bytes.read_u8().unwrap();
let packet = bytes.fill_buf().unwrap().to_vec(); let packet = bytes.fill_buf().unwrap().to_vec();
let payload = match buf_id { let payload = match buf_id {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment