Commit 8bb532bc authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

packet_in and change match_fields return error

parent af398df7
use std::{ use std::{
error::Error, io::{BufRead, Cursor, Error},
io::{BufRead, Cursor},
mem::transmute, mem::transmute,
net::{Ipv4Addr, Ipv6Addr}, net::{Ipv4Addr, Ipv6Addr},
}; };
...@@ -275,7 +274,7 @@ impl MatchFields { ...@@ -275,7 +274,7 @@ impl MatchFields {
ofp_match.marshal(bytes); ofp_match.marshal(bytes);
} }
pub fn parse(bytes: &mut Cursor<Vec<u8>>) -> Result<MatchFields, Box<dyn Error>> { pub fn parse(bytes: &mut Cursor<Vec<u8>>) -> Result<MatchFields, Error> {
let mut matcher = MatchFields::match_all(); let mut matcher = MatchFields::match_all();
let typ = bytes.read_u16::<BigEndian>()?; let typ = bytes.read_u16::<BigEndian>()?;
......
use crate::etherparser::ethernet::EthernetFrame; use crate::etherparser::ethernet::EthernetFrame;
use super::Payload; use super::{MatchFields, Payload};
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
use std::io::{BufRead, Cursor, Error}; use std::io::{BufRead, Cursor, Error};
...@@ -30,11 +30,7 @@ pub struct PacketInEvent { ...@@ -30,11 +30,7 @@ pub struct PacketInEvent {
pub reason: PacketInReason, pub reason: PacketInReason,
pub table_id: u8, pub table_id: u8,
pub cookie: u64, pub cookie: u64,
/** pub matchs: MatchFields,
* TODO
* Ofp Match
*/
pub in_port: u16,
pub payload: Payload, pub payload: Payload,
} }
...@@ -51,9 +47,12 @@ impl PacketInEvent { ...@@ -51,9 +47,12 @@ impl PacketInEvent {
n => Some(n as u32), n => Some(n as u32),
}; };
let total_len = bytes.read_u16::<BigEndian>()?; let total_len = bytes.read_u16::<BigEndian>()?;
let in_port = bytes.read_u16::<BigEndian>()?;
let reason = PacketInReason::new(bytes.read_u8()?); let reason = PacketInReason::new(bytes.read_u8()?);
let table_id = bytes.read_u8()?; let table_id = bytes.read_u8()?;
let cookie = bytes.read_u64::<BigEndian>()?;
let matchs = MatchFields::parse(&mut bytes)?;
// padding
bytes.consume(2);
let packet = bytes.fill_buf()?.to_vec(); let packet = bytes.fill_buf()?.to_vec();
let payload = match buf_id { let payload = match buf_id {
Some(n) => Payload::Buffered(n as u32, packet), Some(n) => Payload::Buffered(n as u32, packet),
...@@ -62,9 +61,10 @@ impl PacketInEvent { ...@@ -62,9 +61,10 @@ impl PacketInEvent {
Ok(PacketInEvent { Ok(PacketInEvent {
buf_id, buf_id,
total_len, total_len,
in_port,
reason, reason,
table_id, table_id,
cookie,
matchs,
payload, payload,
}) })
} }
......
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