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

change port

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