Commit caa61fc7 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

add ether_type to Ether_Frame

parent 48c16b03
...@@ -34,6 +34,9 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> { ...@@ -34,6 +34,9 @@ impl<OME: OfpMsgEvent> ControllerFrame<OME> for Controller<OME> {
let mac_dst = pkt.mac_des; let mac_dst = pkt.mac_des;
let mac_src = pkt.mac_src; let mac_src = pkt.mac_src;
// if pkt.
let out_port = self.mac_to_port.get(&mac_dst); let out_port = self.mac_to_port.get(&mac_dst);
match out_port { match out_port {
Some(p) => { Some(p) => {
......
...@@ -12,4 +12,26 @@ pub enum EtherType { ...@@ -12,4 +12,26 @@ pub enum EtherType {
IEEE802_3 = 0x05dc, IEEE802_3 = 0x05dc,
CFM = 0x8902, CFM = 0x8902,
NSH = 0x894f, NSH = 0x894f,
Unparsable = 0xffff,
}
impl EtherType {
pub fn parse(ether: u16) -> EtherType {
match ether {
tp if tp == EtherType::IP as u16 => EtherType::IP,
tp if tp == EtherType::ARP as u16 => EtherType::ARP,
tp if tp == EtherType::TEB as u16 => EtherType::TEB,
tp if tp == EtherType::VLAN as u16 => EtherType::VLAN,
tp if tp == EtherType::IPV6 as u16 => EtherType::IPV6,
tp if tp == EtherType::SLOW as u16 => EtherType::SLOW,
tp if tp == EtherType::MPLS as u16 => EtherType::MPLS,
tp if tp == EtherType::SVLAN as u16 => EtherType::SVLAN,
tp if tp == EtherType::LLDP as u16 => EtherType::LLDP,
tp if tp == EtherType::PBB as u16 => EtherType::PBB,
tp if tp == EtherType::IEEE802_3 as u16 => EtherType::IEEE802_3,
tp if tp == EtherType::CFM as u16 => EtherType::CFM,
tp if tp == EtherType::NSH as u16 => EtherType::NSH,
_ => EtherType::Unparsable,
}
}
} }
...@@ -9,6 +9,7 @@ use super::{ ...@@ -9,6 +9,7 @@ use super::{
}; };
pub struct EthernetFrame { pub struct EthernetFrame {
pub ether_type: EtherType,
pub mac_des: u64, pub mac_des: u64,
pub mac_src: u64, pub mac_src: u64,
pub vlan_pcp: u8, pub vlan_pcp: u8,
...@@ -60,6 +61,7 @@ impl EthernetFrame { ...@@ -60,6 +61,7 @@ impl EthernetFrame {
_ => Network::Unparsable(typ, bytes.fill_buf().unwrap().to_vec()), _ => Network::Unparsable(typ, bytes.fill_buf().unwrap().to_vec()),
}; };
EthernetFrame { EthernetFrame {
ether_type: EtherType::parse(typ),
mac_des: mac_to_bytes(mac_des), mac_des: mac_to_bytes(mac_des),
mac_src: mac_to_bytes(mac_src), mac_src: mac_to_bytes(mac_src),
vlan_pcp, vlan_pcp,
......
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