Commit 42ffef9b authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

change port

parent 303d46be
......@@ -149,7 +149,7 @@ impl Action {
let _ = bytes.read_u16::<BigEndian>()?;
match action_code {
t if t == (ActionType::Output as u16) => {
let port_code = bytes.read_u16::<BigEndian>()?;
let port_code = bytes.read_u32::<BigEndian>()?;
let len = bytes.read_u16::<BigEndian>()?;
Ok(Action::Oputput(PseudoPort::new(
port_code,
......@@ -212,7 +212,7 @@ impl Action {
Ok(Action::SetTpDest(pt))
}
t if t == (ActionType::Enqueue as u16) => {
let pt = bytes.read_u16::<BigEndian>()?;
let pt = bytes.read_u32::<BigEndian>()?;
bytes.consume(6);
let qid = bytes.read_u32::<BigEndian>()?;
Ok(Action::Enqueue(PseudoPort::new(pt, Some(0)), qid))
......
......@@ -72,7 +72,7 @@ impl FlowModEvent {
let hard_timeout = Timeout::parse(bytes.read_u16::<BigEndian>()?);
let priority = bytes.read_u16::<BigEndian>()?;
let buffer_id = bytes.read_i32::<BigEndian>()?;
let out_port = PseudoPort::parse(bytes.read_u16::<BigEndian>()?);
let out_port = PseudoPort::parse(bytes.read_u32::<BigEndian>()?);
let flags = bytes.read_u16::<BigEndian>()?;
let actions = Action::parse_sequence(&mut bytes);
Ok(FlowModEvent {
......@@ -119,7 +119,7 @@ impl MessageMarshal for FlowModEvent {
match self.out_port.as_ref() {
Some(p) => p.marshal(bytes),
None => {
let _ = bytes.write_u16::<BigEndian>(OfpPort::None as u16);
let _ = bytes.write_u32::<BigEndian>(OfpPort::Any as u32);
}
}
self.flags.marshal(bytes);
......
......@@ -3,8 +3,8 @@ use std::{
mem::size_of,
};
use crate::openflow::ofp13::PseudoPort;
use crate::openflow::ofp13::{ofp_port::OfpPort, MessageMarshal, Msg};
use crate::openflow::ofp10::PseudoPort;
use crate::openflow::ofp10::{ofp_port::OfpPort, MessageMarshal, Msg};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use super::{actions::SizeCheck, Action, Payload};
......
use byteorder::{BigEndian, WriteBytesExt};
#[repr(u32)]
pub enum OfpPort {
Max = 0xff00,
InPort = 0xfff8,
Table = 0xfff9,
Normal = 0xfffa,
Flood = 0xfffb,
All = 0xfffc,
Controller = 0xfffd,
Local = 0xfffe,
None = 0xffff,
Max = 0xffffff00,
InPort = 0xfffffff8,
Table = 0xfffffff9,
Normal = 0xfffffffa,
Flood = 0xfffffffb,
All = 0xfffffffc,
Controller = 0xfffffffd,
Local = 0xfffffffe,
Any = 0xffffffff,
}
#[derive(Clone)]
pub enum PseudoPort {
PhysicalPort(u16),
PhysicalPort(u32),
InPort,
Table,
Normal,
......@@ -26,27 +27,23 @@ pub enum PseudoPort {
}
impl PseudoPort {
pub fn parse(byte: u16) -> Option<PseudoPort> {
if (OfpPort::None as u16) == byte {
None
} else {
pub fn parse(byte: u32) -> Option<PseudoPort> {
Some(PseudoPort::new(byte, Some(0)))
}
}
pub fn new(port: u16, len: Option<u64>) -> PseudoPort {
pub fn new(port: u32, len: Option<u64>) -> PseudoPort {
match port {
p if p == (OfpPort::InPort as u16) => PseudoPort::InPort,
p if p == (OfpPort::Table as u16) => PseudoPort::Table,
p if p == (OfpPort::Normal as u16) => PseudoPort::Normal,
p if p == (OfpPort::Flood as u16) => PseudoPort::Flood,
p if p == (OfpPort::All as u16) => PseudoPort::AllPorts,
p if p == (OfpPort::Controller as u16) => match len {
p if p == (OfpPort::InPort as u32) => PseudoPort::InPort,
p if p == (OfpPort::Table as u32) => PseudoPort::Table,
p if p == (OfpPort::Normal as u32) => PseudoPort::Normal,
p if p == (OfpPort::Flood as u32) => PseudoPort::Flood,
p if p == (OfpPort::All as u32) => PseudoPort::AllPorts,
p if p == (OfpPort::Controller as u32) => match len {
Some(len) => PseudoPort::Controller(len),
None => PseudoPort::Unsupport,
},
p if p == (OfpPort::Local as u16) => PseudoPort::InPort,
p if p == (OfpPort::Local as u32) => PseudoPort::InPort,
_ => {
if port <= (OfpPort::Max as u16) {
if port <= (OfpPort::Max as u32) {
PseudoPort::PhysicalPort(port)
} else {
PseudoPort::Unsupport
......@@ -57,16 +54,16 @@ impl PseudoPort {
pub fn marshal(&self, bytes: &mut Vec<u8>) {
let port = match *self {
PseudoPort::PhysicalPort(p) => p,
PseudoPort::InPort => OfpPort::InPort as u16,
PseudoPort::Table => OfpPort::Table as u16,
PseudoPort::Normal => OfpPort::Normal as u16,
PseudoPort::Flood => OfpPort::Flood as u16,
PseudoPort::AllPorts => OfpPort::All as u16,
PseudoPort::Controller(_) => OfpPort::Controller as u16,
PseudoPort::Local => OfpPort::Local as u16,
PseudoPort::InPort => OfpPort::InPort as u32,
PseudoPort::Table => OfpPort::Table as u32,
PseudoPort::Normal => OfpPort::Normal as u32,
PseudoPort::Flood => OfpPort::Flood as u32,
PseudoPort::AllPorts => OfpPort::All as u32,
PseudoPort::Controller(_) => OfpPort::Controller as u32,
PseudoPort::Local => OfpPort::Local as u32,
// not sure how to handle unsupport
PseudoPort::Unsupport => OfpPort::Flood as u16,
PseudoPort::Unsupport => OfpPort::Flood as u32,
};
let _ = bytes.write_u16::<BigEndian>(port);
let _ = bytes.write_u32::<BigEndian>(port);
}
}
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