Commit 914467e0 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

print log

parent 45c2db0f
...@@ -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);
} }
} }
......
...@@ -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];
......
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