Commit 117ebae2 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

packet_in: change payload -> dont auto parse to ethernet frame and create method to parse payload

parent 8e30497f
......@@ -29,8 +29,9 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
* Start here for handle packetIn message.
*/
fn packet_in_handler(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream) {
let mac_dst = packetin.payload.mac_des;
let mac_src = packetin.payload.mac_src;
let pkt = packetin.ether_parse();
let mac_dst = pkt.mac_des;
let mac_src = pkt.mac_src;
let out_port = self.mac_to_port.get(&mac_dst);
match out_port {
Some(p) => {
......@@ -49,7 +50,7 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
let actions = vec![FlowAction::Oputput(PseudoPort::PhysicalPort(src_port))];
self.add_flow(xid, dst_src_match, actions, stream);
// let pkt_out =
// let pkt_out =
}
None => todo!(),
}
......
pub mod packet_in;
pub use packet_in::{PacketInEvent, PacketInReason};
pub mod packet_out;
pub mod flow_mod;
pub use flow_mod::{FlowAction, FlowModEvent};
......@@ -8,4 +10,7 @@ pub mod hello;
pub use hello::HelloEvent;
pub mod features_req;
pub use features_req::FeaturesReq;
\ No newline at end of file
pub use features_req::FeaturesReq;
pub mod payload;
pub use payload::Payload;
\ No newline at end of file
use std::io::{BufRead, Cursor};
use crate::etherparser::ethernet::EthernetFrame;
use super::Payload;
use byteorder::{BigEndian, ReadBytesExt};
use crate::etherparser::ethernet::EthernetFrame;
use std::io::{BufRead, Cursor};
pub enum PacketInReason {
NoMatch,
......@@ -16,10 +16,15 @@ pub struct PacketInEvent {
pub port: u16,
pub reason: PacketInReason,
pub table_id: u8,
pub payload: EthernetFrame,
pub payload: Payload,
}
impl PacketInEvent {
pub fn ether_parse(&self) -> EthernetFrame {
match &self.payload {
Payload::Buffered(_, p) | Payload::NoBuffered(p) => EthernetFrame::parse(&p),
}
}
pub fn parse(payload: &Vec<u8>) -> PacketInEvent {
let mut bytes = Cursor::new(payload.to_vec());
let buf_id = match bytes.read_i32::<BigEndian>().unwrap() {
......@@ -35,7 +40,10 @@ impl PacketInEvent {
};
let table_id = bytes.read_u8().unwrap();
let packet = bytes.fill_buf().unwrap().to_vec();
let payload = EthernetFrame::parse(&packet);
let payload = match buf_id {
Some(n) => Payload::Buffered(n as u32, packet),
None => Payload::NoBuffered(packet),
};
PacketInEvent {
buf_id,
total_len,
......
use super::Payload;
pub struct PacketOutEvent {
pub payload: Payload
}
\ No newline at end of file
pub enum Payload {
Buffered(u32, Vec<u8>),
NoBuffered(Vec<u8>),
}
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