Commit 19be69bc authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

rewrite packet_in_handler and change packet_in buf to option u32

parent 98928545
...@@ -40,40 +40,29 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> { ...@@ -40,40 +40,29 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
return; return;
} }
let out_port = self.mac_to_port.get(&mac_dst); let out_port = match self.mac_to_port.get(&mac_dst) {
match out_port { Some(p) => PseudoPort::PhysicalPort(*p),
Some(p) => { None => PseudoPort::Flood,
let src_port = packetin.port; };
let mut src_dst_match = MatchFields::match_all();
src_dst_match.mac_dest = Some(mac_dst);
src_dst_match.mac_src = Some(mac_src);
let mut dst_src_match = MatchFields::match_all(); let actions = vec![FlowAction::Oputput(out_port.clone())];
dst_src_match.mac_dest = Some(mac_src);
dst_src_match.mac_src = Some(mac_dst);
let actions = vec![FlowAction::Oputput(PseudoPort::PhysicalPort(*p))]; if let PseudoPort::PhysicalPort(_) = out_port {
self.add_flow(0, src_dst_match, actions, stream); let mut match_fields = MatchFields::match_all();
match_fields.in_port = Some(packetin.port);
let actions = vec![FlowAction::Oputput(PseudoPort::PhysicalPort(src_port))]; match_fields.mac_dest = Some(mac_dst);
self.add_flow(0, dst_src_match, actions, stream); match_fields.mac_src = Some(mac_src);
if let Some(buf_id) = packetin.buf_id {
let packet_out = self.ofp.packet_out( self.add_flow(xid, 1, match_fields, &actions, Some(buf_id as u32), stream);
None, return;
packetin.payload, } else {
vec![FlowAction::Oputput(PseudoPort::PhysicalPort(*p))], self.add_flow(xid, 1, match_fields, &actions, None, stream);
);
self.send_msg(packet_out, xid, stream);
}
None => {
let packet_out = self.ofp.packet_out(
None,
packetin.payload,
vec![FlowAction::Oputput(PseudoPort::AllPorts)],
);
self.send_msg(packet_out, xid, stream);
} }
} }
let packet_out = self
.ofp
.packet_out(Some(packetin.port), packetin.payload, actions);
self.send_msg(packet_out, xid, stream);
} }
} }
...@@ -81,10 +70,16 @@ impl<OME: OfpMsgEvent> Controller<OME> { ...@@ -81,10 +70,16 @@ impl<OME: OfpMsgEvent> Controller<OME> {
fn add_flow( fn add_flow(
&self, &self,
xid: u32, xid: u32,
priority: u16,
flow: MatchFields, flow: MatchFields,
actions: Vec<FlowAction>, actions: &Vec<FlowAction>,
buffer_id: Option<u32>,
stream: &mut TcpStream, stream: &mut TcpStream,
) { ) {
self.send_msg(FlowModEvent::add_flow(10, flow, actions, None), xid, stream) self.send_msg(
FlowModEvent::add_flow(10, flow, actions.clone(), buffer_id),
xid,
stream,
)
} }
} }
...@@ -11,7 +11,7 @@ pub enum PacketInReason { ...@@ -11,7 +11,7 @@ pub enum PacketInReason {
} }
pub struct PacketInEvent { pub struct PacketInEvent {
pub buf_id: Option<i32>, pub buf_id: Option<u32>,
pub total_len: u16, pub total_len: u16,
pub port: u16, pub port: u16,
pub reason: PacketInReason, pub reason: PacketInReason,
...@@ -29,7 +29,7 @@ impl PacketInEvent { ...@@ -29,7 +29,7 @@ impl PacketInEvent {
let mut bytes = Cursor::new(payload.to_vec()); let mut bytes = Cursor::new(payload.to_vec());
let buf_id = match bytes.read_i32::<BigEndian>().unwrap() { let buf_id = match bytes.read_i32::<BigEndian>().unwrap() {
-1 => None, -1 => None,
n => Some(n), n => Some(n as u32),
}; };
let total_len = bytes.read_u16::<BigEndian>().unwrap(); let total_len = bytes.read_u16::<BigEndian>().unwrap();
let port = bytes.read_u16::<BigEndian>().unwrap(); let port = bytes.read_u16::<BigEndian>().unwrap();
......
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