Commit dbafd143 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

clear warning and unused;

parent 35dbe4ad
...@@ -92,6 +92,7 @@ where ...@@ -92,6 +92,7 @@ where
fn echo_request_handler(&self, xid: u32, echo: EchoRequestEvent, stream: &mut TcpStream) { fn echo_request_handler(&self, xid: u32, echo: EchoRequestEvent, stream: &mut TcpStream) {
self.send_msg(EchoReplyEvent::new(echo.payload), xid, stream); self.send_msg(EchoReplyEvent::new(echo.payload), xid, stream);
} }
#[allow(unused)]
fn switch_features_handler( fn switch_features_handler(
&self, &self,
xid: u32, xid: u32,
......
use crate::{etherparser::MacAddr, openflow::ofp13::PseudoPort}; use crate::{etherparser::MacAddr, openflow::ofp13::PseudoPort};
use byteorder::{BigEndian, WriteBytesExt}; use byteorder::{BigEndian, WriteBytesExt};
use std::net::{Ipv4Addr, Ipv6Addr}; use std::{
io::Error,
net::{Ipv4Addr, Ipv6Addr},
};
use super::flow_mod::{ use super::flow_mod::{
instructions::InstructActions, instructions::InstructActions,
...@@ -31,8 +34,9 @@ enum ActionType { ...@@ -31,8 +34,9 @@ enum ActionType {
} }
impl ActionType { impl ActionType {
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) -> Result<(), Error> {
bytes.write_u16::<BigEndian>(self.clone().into()); bytes.write_u16::<BigEndian>(self.clone().into())?;
Ok(())
} }
} }
...@@ -42,6 +46,7 @@ impl From<ActionType> for u16 { ...@@ -42,6 +46,7 @@ impl From<ActionType> for u16 {
} }
} }
#[allow(unused)]
#[derive(Clone)] #[derive(Clone)]
#[repr(u16)] #[repr(u16)]
enum ControllerMaxLen { enum ControllerMaxLen {
...@@ -55,31 +60,6 @@ impl From<ControllerMaxLen> for u16 { ...@@ -55,31 +60,6 @@ impl From<ControllerMaxLen> for u16 {
} }
} }
struct ActionOutput {
typ: ActionType, // u16
port: PseudoPort, // u32
max_len: ControllerMaxLen,
}
impl ActionOutput {
pub const LEN: usize = 16;
pub fn marshal(&self, bytes: &mut Vec<u8>) {
self.typ.marshal(bytes);
self.port.marshal(bytes);
bytes.write_u16::<BigEndian>(self.max_len.clone().into());
// write padding 48 bytes [32 + 16]
bytes.write_u32::<BigEndian>(0);
bytes.write_u16::<BigEndian>(0);
}
pub fn new(port: PseudoPort, max_len: ControllerMaxLen) -> Self {
Self {
typ: ActionType::Output,
port,
max_len,
}
}
}
#[derive(Clone)] #[derive(Clone)]
pub enum SetField { pub enum SetField {
InPort(PseudoPort), // Ingress port. This may be a physical or switch-defined logical port. InPort(PseudoPort), // Ingress port. This may be a physical or switch-defined logical port.
...@@ -98,67 +78,68 @@ pub enum SetField { ...@@ -98,67 +78,68 @@ pub enum SetField {
} }
impl SetField { impl SetField {
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) -> Result<(), Error> {
match &self { match &self {
SetField::InPort(port) => { SetField::InPort(port) => {
OxmHeader::new(OxmMatchFields::InPort, 4, false).marshal(bytes); OxmHeader::new(OxmMatchFields::InPort, 4, false).marshal(bytes)?;
port.marshal(bytes); port.marshal(bytes);
} }
SetField::EthDst(mac) => { SetField::EthDst(mac) => {
OxmHeader::new(OxmMatchFields::EthDst, 12, true).marshal(bytes); OxmHeader::new(OxmMatchFields::EthDst, 12, true).marshal(bytes)?;
mac.marshal(bytes); mac.marshal(bytes);
MacAddr::from(!0).marshal(bytes); MacAddr::from(!0).marshal(bytes);
} }
SetField::EthSrc(mac) => { SetField::EthSrc(mac) => {
OxmHeader::new(OxmMatchFields::EthSrc, 12, true).marshal(bytes); OxmHeader::new(OxmMatchFields::EthSrc, 12, true).marshal(bytes)?;
mac.marshal(bytes); mac.marshal(bytes);
MacAddr::from(!0).marshal(bytes); MacAddr::from(!0).marshal(bytes);
} }
SetField::EthTyp(eth) => { SetField::EthTyp(eth) => {
OxmHeader::new(OxmMatchFields::EthType, 2, false).marshal(bytes); OxmHeader::new(OxmMatchFields::EthType, 2, false).marshal(bytes)?;
bytes.write_u16::<BigEndian>(*eth); bytes.write_u16::<BigEndian>(*eth)?;
} }
SetField::IpProto(proto) => { SetField::IpProto(proto) => {
OxmHeader::new(OxmMatchFields::IpProto, 1, false).marshal(bytes); OxmHeader::new(OxmMatchFields::IpProto, 1, false).marshal(bytes)?;
bytes.write_u8(*proto); bytes.write_u8(*proto)?;
} }
SetField::Ipv4Src(ipv4) => { SetField::Ipv4Src(ipv4) => {
OxmHeader::new(OxmMatchFields::Ipv4Src, 8, true).marshal(bytes); OxmHeader::new(OxmMatchFields::Ipv4Src, 8, true).marshal(bytes)?;
bytes.write_u32::<BigEndian>(ipv4.clone().into()); bytes.write_u32::<BigEndian>(ipv4.clone().into())?;
bytes.write_u32::<BigEndian>(!0); bytes.write_u32::<BigEndian>(!0)?;
} }
SetField::Ipv4Dst(ipv4) => { SetField::Ipv4Dst(ipv4) => {
OxmHeader::new(OxmMatchFields::Ipv4Dst, 8, true).marshal(bytes); OxmHeader::new(OxmMatchFields::Ipv4Dst, 8, true).marshal(bytes)?;
bytes.write_u32::<BigEndian>(ipv4.clone().into()); bytes.write_u32::<BigEndian>(ipv4.clone().into())?;
bytes.write_u32::<BigEndian>(!0); bytes.write_u32::<BigEndian>(!0)?;
} }
SetField::Ipv6Src(ipv6) => { SetField::Ipv6Src(ipv6) => {
OxmHeader::new(OxmMatchFields::Ipv6Src, 32, true).marshal(bytes); OxmHeader::new(OxmMatchFields::Ipv6Src, 32, true).marshal(bytes)?;
bytes.write_u128::<BigEndian>(ipv6.clone().into()); bytes.write_u128::<BigEndian>(ipv6.clone().into())?;
bytes.write_u128::<BigEndian>(!0); bytes.write_u128::<BigEndian>(!0)?;
} }
SetField::Ipv6Dst(ipv6) => { SetField::Ipv6Dst(ipv6) => {
OxmHeader::new(OxmMatchFields::Ipv6Dst, 32, true).marshal(bytes); OxmHeader::new(OxmMatchFields::Ipv6Dst, 32, true).marshal(bytes)?;
bytes.write_u128::<BigEndian>(ipv6.clone().into()); bytes.write_u128::<BigEndian>(ipv6.clone().into())?;
bytes.write_u128::<BigEndian>(!0); bytes.write_u128::<BigEndian>(!0)?;
} }
SetField::TcpSrc(tcp) => { SetField::TcpSrc(tcp) => {
OxmHeader::new(OxmMatchFields::TcpSrc, 2, false).marshal(bytes); OxmHeader::new(OxmMatchFields::TcpSrc, 2, false).marshal(bytes)?;
bytes.write_u16::<BigEndian>(*tcp); bytes.write_u16::<BigEndian>(*tcp)?;
} }
SetField::TcpDst(tcp) => { SetField::TcpDst(tcp) => {
OxmHeader::new(OxmMatchFields::TcpDst, 2, false).marshal(bytes); OxmHeader::new(OxmMatchFields::TcpDst, 2, false).marshal(bytes)?;
bytes.write_u16::<BigEndian>(*tcp); bytes.write_u16::<BigEndian>(*tcp)?;
} }
SetField::UdpSrc(udp) => { SetField::UdpSrc(udp) => {
OxmHeader::new(OxmMatchFields::UdpSrc, 2, false).marshal(bytes); OxmHeader::new(OxmMatchFields::UdpSrc, 2, false).marshal(bytes)?;
bytes.write_u16::<BigEndian>(*udp); bytes.write_u16::<BigEndian>(*udp)?;
} }
SetField::UdpDst(udp) => { SetField::UdpDst(udp) => {
OxmHeader::new(OxmMatchFields::UdpDst, 2, false).marshal(bytes); OxmHeader::new(OxmMatchFields::UdpDst, 2, false).marshal(bytes)?;
bytes.write_u16::<BigEndian>(*udp); bytes.write_u16::<BigEndian>(*udp)?;
} }
} }
Ok(())
} }
} }
...@@ -189,7 +170,7 @@ pub enum Action { ...@@ -189,7 +170,7 @@ pub enum Action {
} }
impl Action { impl Action {
pub fn action_type(&self) -> ActionType { fn action_type(&self) -> ActionType {
match &self { match &self {
Action::Oputput(_) => ActionType::Output, Action::Oputput(_) => ActionType::Output,
Action::CopyTtlOut => ActionType::CopyTtlOut, Action::CopyTtlOut => ActionType::CopyTtlOut,
...@@ -210,78 +191,79 @@ impl Action { ...@@ -210,78 +191,79 @@ impl Action {
Action::Experimenter(_) => ActionType::Experimenter, Action::Experimenter(_) => ActionType::Experimenter,
} }
} }
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) -> Result<(), Error> {
match &self { match &self {
Action::Oputput(port) => { Action::Oputput(port) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(16); // len bytes.write_u16::<BigEndian>(16)?; // len
port.marshal(bytes); port.marshal(bytes);
bytes.write_u16::<BigEndian>(ControllerMaxLen::NoBuffer.into()); bytes.write_u16::<BigEndian>(ControllerMaxLen::NoBuffer.into())?;
// padding 48bit // padding 48bit
bytes.write_u32::<BigEndian>(0); bytes.write_u32::<BigEndian>(0)?;
bytes.write_u16::<BigEndian>(0); bytes.write_u16::<BigEndian>(0)?;
} }
Action::SetMplsTtl(mpls_ttl) => { Action::SetMplsTtl(mpls_ttl) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u8(*mpls_ttl); bytes.write_u8(*mpls_ttl)?;
// padding 24bit // padding 24bit
bytes.write_u16::<BigEndian>(0); bytes.write_u16::<BigEndian>(0)?;
bytes.write_u8(0); bytes.write_u8(0)?;
} }
Action::PushVlan(ethertype) Action::PushVlan(ethertype)
| Action::PushMpls(ethertype) | Action::PushMpls(ethertype)
| Action::PushPbb(ethertype) => { | Action::PushPbb(ethertype) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u16::<BigEndian>(*ethertype); bytes.write_u16::<BigEndian>(*ethertype)?;
// padding 16 bit // padding 16 bit
bytes.write_u16::<BigEndian>(0); bytes.write_u16::<BigEndian>(0)?;
} }
Action::PopVlan(ethertype) | Action::PopMpls(ethertype) | Action::PopPbb(ethertype) => { Action::PopVlan(ethertype) | Action::PopMpls(ethertype) | Action::PopPbb(ethertype) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u16::<BigEndian>(*ethertype); bytes.write_u16::<BigEndian>(*ethertype)?;
bytes.write_u16::<BigEndian>(0); bytes.write_u16::<BigEndian>(0)?;
} }
Action::SetQueue(queue_id) => { Action::SetQueue(queue_id) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u32::<BigEndian>(*queue_id); bytes.write_u32::<BigEndian>(*queue_id)?;
} }
Action::Group(group_id) => { Action::Group(group_id) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u32::<BigEndian>(*group_id); bytes.write_u32::<BigEndian>(*group_id)?;
} }
Action::SetNwTtl(nw_ttl) => { Action::SetNwTtl(nw_ttl) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u8(*nw_ttl); bytes.write_u8(*nw_ttl)?;
// padding 24bit // padding 24bit
bytes.write_u16::<BigEndian>(0); bytes.write_u16::<BigEndian>(0)?;
bytes.write_u8(0); bytes.write_u8(0)?;
} }
Action::SetField(omx_field) => { Action::SetField(omx_field) => {
let mut field_bytes: Vec<u8> = Vec::new(); let mut field_bytes: Vec<u8> = Vec::new();
omx_field.marshal(&mut field_bytes); omx_field.marshal(&mut field_bytes)?;
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(4 + field_bytes.len() as u16); bytes.write_u16::<BigEndian>(4 + field_bytes.len() as u16)?;
bytes.append(&mut field_bytes); bytes.append(&mut field_bytes);
} }
Action::Experimenter(exper_id) => { Action::Experimenter(exper_id) => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
bytes.write_u32::<BigEndian>(*exper_id); bytes.write_u32::<BigEndian>(*exper_id)?;
} }
Action::DecMplsTtl | Action::DecNwTtl | Action::CopyTtlOut | Action::CopyTtlIn => { Action::DecMplsTtl | Action::DecNwTtl | Action::CopyTtlOut | Action::CopyTtlIn => {
self.action_type().marshal(bytes); self.action_type().marshal(bytes)?;
bytes.write_u16::<BigEndian>(8); bytes.write_u16::<BigEndian>(8)?;
// padding 32 bit // padding 32 bit
bytes.write_u32::<BigEndian>(0); bytes.write_u32::<BigEndian>(0)?;
} }
} }
Ok(())
} }
// TODO // TODO
......
...@@ -366,10 +366,3 @@ impl TableFeaturesFailed { ...@@ -366,10 +366,3 @@ impl TableFeaturesFailed {
} }
} }
} }
#[derive(Debug)]
pub struct ErrorExperimenter {
typ: u16,
exp_typ: u16,
experimenter: u32,
}
...@@ -113,8 +113,8 @@ impl MessageMarshal for FlowModEvent { ...@@ -113,8 +113,8 @@ impl MessageMarshal for FlowModEvent {
self.flags.marshal(bytes); self.flags.marshal(bytes);
// padding // padding
bytes.write_u16::<BigEndian>(0); let _ = bytes.write_u16::<BigEndian>(0);
self.match_fields.marshal(bytes); let _ = self.match_fields.marshal(bytes);
self.instruction.marshal(bytes); self.instruction.marshal(bytes);
} }
} }
...@@ -20,7 +20,7 @@ pub enum InstructType { ...@@ -20,7 +20,7 @@ pub enum InstructType {
impl InstructType { impl InstructType {
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) {
bytes.write_u16::<BigEndian>(self.clone().into()); let _ = bytes.write_u16::<BigEndian>(self.clone().into());
} }
} }
...@@ -49,11 +49,11 @@ impl GotoTable { ...@@ -49,11 +49,11 @@ impl GotoTable {
impl InstructTrait for GotoTable { impl InstructTrait for GotoTable {
fn marshal(&self, bytes: &mut Vec<u8>) { fn marshal(&self, bytes: &mut Vec<u8>) {
self.typ.marshal(bytes); self.typ.marshal(bytes);
bytes.write_u16::<BigEndian>(self.len); let _ = bytes.write_u16::<BigEndian>(self.len);
bytes.write_u8(self.table_id); let _ = bytes.write_u8(self.table_id);
// padding // padding
bytes.write_u16::<BigEndian>(0); let _ = bytes.write_u16::<BigEndian>(0);
bytes.write_u8(0); let _ = bytes.write_u8(0);
} }
} }
...@@ -78,12 +78,12 @@ impl WriteMetadata { ...@@ -78,12 +78,12 @@ impl WriteMetadata {
impl InstructTrait for WriteMetadata { impl InstructTrait for WriteMetadata {
fn marshal(&self, bytes: &mut Vec<u8>) { fn marshal(&self, bytes: &mut Vec<u8>) {
self.typ.marshal(bytes); self.typ.marshal(bytes);
bytes.write_u16::<BigEndian>(self.len); let _ = bytes.write_u16::<BigEndian>(self.len);
// padding // padding
bytes.write_u32::<BigEndian>(0); let _ = bytes.write_u32::<BigEndian>(0);
// ******* // *******
bytes.write_u64::<BigEndian>(self.metadata); let _ = bytes.write_u64::<BigEndian>(self.metadata);
bytes.write_u64::<BigEndian>(self.meta_mask); let _ = bytes.write_u64::<BigEndian>(self.meta_mask);
} }
} }
...@@ -110,12 +110,12 @@ impl InstructTrait for InstructActions { ...@@ -110,12 +110,12 @@ impl InstructTrait for InstructActions {
fn marshal(&self, bytes: &mut Vec<u8>) { fn marshal(&self, bytes: &mut Vec<u8>) {
let mut builder = Vec::new(); let mut builder = Vec::new();
for act in self.actions.iter() { for act in self.actions.iter() {
act.marshal(&mut builder); let _ = act.marshal(&mut builder);
} }
self.typ.marshal(bytes); self.typ.marshal(bytes);
bytes.write_u16::<BigEndian>(self.len + (builder.len() as u16)); let _ = bytes.write_u16::<BigEndian>(self.len + (builder.len() as u16));
// padding // padding
bytes.write_u32::<BigEndian>(0); let _ = bytes.write_u32::<BigEndian>(0);
bytes.append(&mut builder); bytes.append(&mut builder);
} }
} }
...@@ -139,8 +139,8 @@ impl InstructMeter { ...@@ -139,8 +139,8 @@ impl InstructMeter {
impl InstructTrait for InstructMeter { impl InstructTrait for InstructMeter {
fn marshal(&self, bytes: &mut Vec<u8>) { fn marshal(&self, bytes: &mut Vec<u8>) {
self.typ.marshal(bytes); self.typ.marshal(bytes);
bytes.write_u16::<BigEndian>(self.len); let _ = bytes.write_u16::<BigEndian>(self.len);
bytes.write_u32::<BigEndian>(self.meter_id); let _ = bytes.write_u32::<BigEndian>(self.meter_id);
} }
} }
......
...@@ -30,11 +30,13 @@ impl OfpMatch { ...@@ -30,11 +30,13 @@ impl OfpMatch {
oxm_fields: Vec::new(), oxm_fields: Vec::new(),
} }
} }
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) -> Result<(), Error> {
bytes.write_u16::<BigEndian>(self.typ.clone().into()); bytes.write_u16::<BigEndian>(self.typ.clone().into())?;
bytes.write_u16::<BigEndian>(self.length + (self.oxm_fields.len() as u16)); bytes.write_u16::<BigEndian>(self.length + (self.oxm_fields.len() as u16))?;
bytes.append(&mut self.oxm_fields.clone()); bytes.append(&mut self.oxm_fields.clone());
bytes.write_u32::<BigEndian>(0); // padding
bytes.write_u32::<BigEndian>(0)?;
Ok(())
} }
} }
...@@ -73,6 +75,7 @@ impl From<MatchType> for u16 { ...@@ -73,6 +75,7 @@ impl From<MatchType> for u16 {
* *
*/ */
#[allow(unused)]
pub struct OxmHeader { pub struct OxmHeader {
class: OxmClass, // Match class: member class or reserved class class: OxmClass, // Match class: member class or reserved class
field: OxmMatchFields, // 7bit Match field within the class field: OxmMatchFields, // 7bit Match field within the class
...@@ -91,14 +94,15 @@ impl OxmHeader { ...@@ -91,14 +94,15 @@ impl OxmHeader {
experimenter: None, experimenter: None,
} }
} }
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) -> Result<(), Error> {
bytes.write_u16::<BigEndian>(self.class.clone().into()); bytes.write_u16::<BigEndian>(self.class.clone().into())?;
let field: u8 = self.field.clone().into(); let field: u8 = self.field.clone().into();
bytes.write_u8(field << 1 | if self.hasmask { 1 } else { 0 }); bytes.write_u8(field << 1 | if self.hasmask { 1 } else { 0 })?;
bytes.write_u8(self.length); bytes.write_u8(self.length)?;
// if let Some(exp) = self.experimenter { // if let Some(exp) = self.experimenter {
// bytes.write_u32::<BigEndian>(exp); // bytes.write_u32::<BigEndian>(exp);
// } // }
Ok(())
} }
} }
...@@ -221,84 +225,85 @@ impl MatchFields { ...@@ -221,84 +225,85 @@ impl MatchFields {
udp_dst: None, udp_dst: None,
} }
} }
pub fn marshal(&self, bytes: &mut Vec<u8>) { pub fn marshal(&self, bytes: &mut Vec<u8>) -> Result<(), Error>{
let mut ofp_match = OfpMatch::new(); let mut ofp_match = OfpMatch::new();
let ofp_byte = ofp_match.oxm_fields.as_mut(); let ofp_byte = ofp_match.oxm_fields.as_mut();
if let Some(in_port) = &self.in_port { if let Some(in_port) = &self.in_port {
let header = OxmHeader::new(OxmMatchFields::InPort, 4, false); let header = OxmHeader::new(OxmMatchFields::InPort, 4, false);
header.marshal(ofp_byte); header.marshal(ofp_byte)?;
ofp_byte.write_u32::<BigEndian>(*in_port); ofp_byte.write_u32::<BigEndian>(*in_port)?;
} }
if let Some(eth_dst) = &self.eth_dst { if let Some(eth_dst) = &self.eth_dst {
let header = OxmHeader::new(OxmMatchFields::EthDst, 12, true); let header = OxmHeader::new(OxmMatchFields::EthDst, 12, true);
header.marshal(ofp_byte); header.marshal(ofp_byte)?;
eth_dst.marshal(ofp_byte); eth_dst.marshal(ofp_byte);
// mac mask // mac mask
MacAddr::from(!0).marshal(ofp_byte); MacAddr::from(!0).marshal(ofp_byte);
} }
if let Some(eth_src) = &self.eth_src { if let Some(eth_src) = &self.eth_src {
let header = OxmHeader::new(OxmMatchFields::EthSrc, 12, true); let header = OxmHeader::new(OxmMatchFields::EthSrc, 12, true);
header.marshal(ofp_byte); header.marshal(ofp_byte)?;
eth_src.marshal(ofp_byte); eth_src.marshal(ofp_byte);
// mac mask // mac mask
MacAddr::from(!0).marshal(ofp_byte); MacAddr::from(!0).marshal(ofp_byte);
} }
if let Some(eth_typ) = &self.eth_typ { if let Some(eth_typ) = &self.eth_typ {
OxmHeader::new(OxmMatchFields::EthType, 2, false).marshal(ofp_byte); OxmHeader::new(OxmMatchFields::EthType, 2, false).marshal(ofp_byte)?;
ofp_byte.write_u16::<BigEndian>(*eth_typ); ofp_byte.write_u16::<BigEndian>(*eth_typ)?;
} }
if let Some(ip_proto) = &self.ip_proto { if let Some(ip_proto) = &self.ip_proto {
OxmHeader::new(OxmMatchFields::IpProto, 1, false).marshal(ofp_byte); OxmHeader::new(OxmMatchFields::IpProto, 1, false).marshal(ofp_byte)?;
ofp_byte.write_u8(*ip_proto); ofp_byte.write_u8(*ip_proto)?;
} }
if let Some(ipv4_src) = &self.ipv4_src { if let Some(ipv4_src) = &self.ipv4_src {
OxmHeader::new(OxmMatchFields::Ipv4Src, 8, true).marshal(ofp_byte); OxmHeader::new(OxmMatchFields::Ipv4Src, 8, true).marshal(ofp_byte)?;
bytes.write_u32::<BigEndian>(ipv4_src.clone().into()); bytes.write_u32::<BigEndian>(ipv4_src.clone().into())?;
bytes.write_u32::<BigEndian>(!0); bytes.write_u32::<BigEndian>(!0)?;
} }
if let Some(ipv4_dst) = &self.ipv4_dst { if let Some(ipv4_dst) = &self.ipv4_dst {
OxmHeader::new(OxmMatchFields::Ipv4Dst, 8, true).marshal(ofp_byte); OxmHeader::new(OxmMatchFields::Ipv4Dst, 8, true).marshal(ofp_byte)?;
bytes.write_u32::<BigEndian>(ipv4_dst.clone().into()); bytes.write_u32::<BigEndian>(ipv4_dst.clone().into())?;
bytes.write_u32::<BigEndian>(!0); bytes.write_u32::<BigEndian>(!0)?;
} }
if let Some(ipv6_src) = &self.ipv6_src { if let Some(ipv6_src) = &self.ipv6_src {
OxmHeader::new(OxmMatchFields::Ipv6Src, 32, true).marshal(ofp_byte); OxmHeader::new(OxmMatchFields::Ipv6Src, 32, true).marshal(ofp_byte)?;
ofp_byte.write_u128::<BigEndian>(ipv6_src.clone().into()); ofp_byte.write_u128::<BigEndian>(ipv6_src.clone().into())?;
ofp_byte.write_u128::<BigEndian>(!0); ofp_byte.write_u128::<BigEndian>(!0)?;
} }
if let Some(ipv6_dst) = &self.ipv6_dst { if let Some(ipv6_dst) = &self.ipv6_dst {
OxmHeader::new(OxmMatchFields::Ipv6Dst, 32, true).marshal(ofp_byte); OxmHeader::new(OxmMatchFields::Ipv6Dst, 32, true).marshal(ofp_byte)?;
ofp_byte.write_u128::<BigEndian>(ipv6_dst.clone().into()); ofp_byte.write_u128::<BigEndian>(ipv6_dst.clone().into())?;
ofp_byte.write_u128::<BigEndian>(!0); ofp_byte.write_u128::<BigEndian>(!0)?;
} }
if let Some(tcp_src) = &self.tcp_src { if let Some(tcp_src) = &self.tcp_src {
OxmHeader::new(OxmMatchFields::TcpSrc, 2, false); OxmHeader::new(OxmMatchFields::TcpSrc, 2, false);
ofp_byte.write_u16::<BigEndian>(*tcp_src); ofp_byte.write_u16::<BigEndian>(*tcp_src)?;
} }
if let Some(tcp_dst) = &self.tcp_dst { if let Some(tcp_dst) = &self.tcp_dst {
OxmHeader::new(OxmMatchFields::TcpDst, 2, false); OxmHeader::new(OxmMatchFields::TcpDst, 2, false);
ofp_byte.write_u16::<BigEndian>(*tcp_dst); ofp_byte.write_u16::<BigEndian>(*tcp_dst)?;
} }
if let Some(udp_src) = &self.udp_src { if let Some(udp_src) = &self.udp_src {
OxmHeader::new(OxmMatchFields::UdpSrc, 2, false); OxmHeader::new(OxmMatchFields::UdpSrc, 2, false);
ofp_byte.write_u16::<BigEndian>(*udp_src); ofp_byte.write_u16::<BigEndian>(*udp_src)?;
} }
if let Some(udp_dst) = &self.udp_dst { if let Some(udp_dst) = &self.udp_dst {
OxmHeader::new(OxmMatchFields::UdpDst, 2, false); OxmHeader::new(OxmMatchFields::UdpDst, 2, false);
ofp_byte.write_u16::<BigEndian>(*udp_dst); ofp_byte.write_u16::<BigEndian>(*udp_dst)?;
} }
ofp_match.marshal(bytes); ofp_match.marshal(bytes)?;
Ok(())
} }
pub fn parse(bytes: &mut Cursor<Vec<u8>>) -> Result<MatchFields, 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: MatchType = bytes.read_u16::<BigEndian>()?.into(); let _typ: MatchType = bytes.read_u16::<BigEndian>()?.into();
let length = bytes.read_u16::<BigEndian>()?; let length = bytes.read_u16::<BigEndian>()?;
let mut pkt_len = length - 4; let mut pkt_len = length - 4;
while pkt_len > 0 { while pkt_len > 0 {
let oxm_class = bytes.read_u16::<BigEndian>()?; let _oxm_class = bytes.read_u16::<BigEndian>()?;
let oxm_field = bytes.read_u8()?; let oxm_field = bytes.read_u8()?;
let hash_mask = oxm_field & 1 == 1; let hash_mask = oxm_field & 1 == 1;
let oxm_field: OxmMatchFields = (oxm_field >> 1).into(); let oxm_field: OxmMatchFields = (oxm_field >> 1).into();
...@@ -306,7 +311,7 @@ impl MatchFields { ...@@ -306,7 +311,7 @@ impl MatchFields {
match oxm_field { match oxm_field {
OxmMatchFields::InPort => { OxmMatchFields::InPort => {
let port = bytes.read_u32::<BigEndian>()?; let port = bytes.read_u32::<BigEndian>()?;
let mask = if hash_mask { let _mask = if hash_mask {
Some(bytes.read_u32::<BigEndian>()) Some(bytes.read_u32::<BigEndian>())
} else { } else {
None None
......
...@@ -29,12 +29,12 @@ impl MessageMarshal for PacketOutEvent { ...@@ -29,12 +29,12 @@ impl MessageMarshal for PacketOutEvent {
} }
let mut action_byte: Vec<u8> = Vec::new(); let mut action_byte: Vec<u8> = Vec::new();
for act in self.actions.iter() { for act in self.actions.iter() {
act.marshal(&mut action_byte); let _ = act.marshal(&mut action_byte);
} }
let _ = bytes.write_u16::<BigEndian>(action_byte.len() as u16); let _ = bytes.write_u16::<BigEndian>(action_byte.len() as u16);
// padding 48 bit // padding 48 bit
bytes.write_u32::<BigEndian>(0); let _ = bytes.write_u32::<BigEndian>(0);
bytes.write_u16::<BigEndian>(0); let _ = bytes.write_u16::<BigEndian>(0);
bytes.append(&mut action_byte); bytes.append(&mut action_byte);
self.payload.marshal(bytes); self.payload.marshal(bytes);
......
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