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