Commit a7725227 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

add OfpMsgEvent to packet_out and at packet_out to ofp v1.0

parent 78cf45a2
......@@ -41,6 +41,7 @@ pub trait ControllerFrame<OME: OfpMsgEvent> {
OfpMsg::PacketIn => {
self.packet_in_handler(xid, PacketInEvent::parse(&payload), stream);
}
OfpMsg::PacketOut => (),
OfpMsg::FlowMod => todo!(),
OfpMsg::NotFound => todo!(),
}
......
use std::io::{BufRead, Cursor, Read};
use std::{
io::{BufRead, Cursor, Read},
mem::size_of,
};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use crate::openflow::{OfpPort, PseudoPort};
use crate::openflow::{
ofp_manager::{MessageMarshal, OfpMsg, OfpMsgEvent},
OfpPort, PseudoPort,
};
use super::{flow_mod::SizeCheck, FlowAction, Payload};
......@@ -12,6 +18,40 @@ pub struct PacketOutEvent {
pub actions: Vec<FlowAction>,
}
impl MessageMarshal for PacketOutEvent {
fn marshal(&self, bytes: &mut Vec<u8>) {
let _ = bytes.write_i32::<BigEndian>(match self.payload {
Payload::Buffered(n, _) => n as i32,
Payload::NoBuffered(_) => -1,
});
match self.port_id {
Some(id) => {
PseudoPort::PhysicalPort(id).marshal(bytes);
}
None => {
let _ = bytes.write_u16::<BigEndian>(OfpPort::None as u16);
}
}
let _ = bytes.write_u16::<BigEndian>(self.actions.size_of_sequence() as u16);
for act in self.actions.move_controller_last() {
act.marshal(bytes);
}
self.payload.marshal(bytes);
}
fn msg_code(&self) -> OfpMsg {
OfpMsg::PacketOut
}
fn msg_usize<OFP: OfpMsgEvent>(&self, ofp: &OFP) -> usize {
ofp.msg_usize(OfpMsg::PacketOut)
}
fn size_of(&self) -> usize {
size_of::<(u32, u16, u16)>() + self.actions.size_of_sequence() + self.payload.length()
}
}
impl PacketOutEvent {
pub fn new(port_id: Option<u16>, payload: Payload, actions: Vec<FlowAction>) -> Self {
Self {
......@@ -52,24 +92,4 @@ impl PacketOutEvent {
actions,
}
}
pub fn marshal(&self, bytes: &mut Vec<u8>) {
let _ = bytes.write_i32::<BigEndian>(match self.payload {
Payload::Buffered(n, _) => n as i32,
Payload::NoBuffered(_) => -1,
});
match self.port_id {
Some(id) => {
PseudoPort::PhysicalPort(id).marshal(bytes);
}
None => {
let _ = bytes.write_u16::<BigEndian>(OfpPort::None as u16);
}
}
let _ = bytes.write_u16::<BigEndian>(self.actions.size_of_sequence() as u16);
for act in self.actions.move_controller_last() {
act.marshal(bytes);
}
self.payload.marshal(bytes);
}
}
......@@ -6,6 +6,11 @@ pub enum Payload {
}
impl Payload {
pub fn length(&self) -> usize {
match self {
Payload::Buffered(_, p) | Payload::NoBuffered(p) => p.len(),
}
}
pub fn marshal(&self, bytes: &mut Vec<u8>) {
match self {
Payload::Buffered(_, buf) | Payload::NoBuffered(buf) => {
......
......@@ -2,6 +2,7 @@ pub enum OfpMsg {
Hello,
FeaturesReq,
PacketIn,
PacketOut,
FlowMod,
NotFound
}
......@@ -53,6 +53,7 @@ impl OfpMsgEvent for Openflow10 {
0 => OfpMsg::Hello,
5 => OfpMsg::FeaturesReq,
8 => OfpMsg::PacketIn,
13 => OfpMsg::PacketOut,
14 => OfpMsg::FlowMod,
_ => OfpMsg::NotFound,
}
......@@ -63,6 +64,7 @@ impl OfpMsgEvent for Openflow10 {
OfpMsg::Hello => 0,
OfpMsg::FeaturesReq => 5,
OfpMsg::PacketIn => 8,
OfpMsg::PacketOut => 13,
OfpMsg::FlowMod => 14,
_ => 1024,
}
......
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