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

packet_in and change match_fields return error

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