Commit 55d2aee1 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

fix warning code

parent 15388f3c
...@@ -2,10 +2,17 @@ use super::{tcp::TCP, udp::UDP, ICMP}; ...@@ -2,10 +2,17 @@ use super::{tcp::TCP, udp::UDP, ICMP};
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
use std::io::{BufRead, Cursor, Read}; use std::io::{BufRead, Cursor, Read};
struct Flags { pub struct Flags {
dont_flagment: bool, pub dont_flagment: bool,
more_fragments: bool, pub more_fragments: bool,
} }
pub enum IpProtocol {
ICMP = 0x01,
TCP = 0x06,
UDP = 0x11,
}
pub struct IP { pub struct IP {
pub version: u8, pub version: u8,
pub ihl: u8, pub ihl: u8,
...@@ -20,12 +27,7 @@ pub struct IP { ...@@ -20,12 +27,7 @@ pub struct IP {
pub src: u32, pub src: u32,
pub des: u32, pub des: u32,
pub options: Vec<u8>, pub options: Vec<u8>,
} pub ptcol: EtherData,
pub enum IpProtocol {
ICMP = 0x01,
TCP = 0x06,
UDP = 0x11,
} }
impl IP { impl IP {
...@@ -96,6 +98,7 @@ impl IP { ...@@ -96,6 +98,7 @@ impl IP {
src, src,
des, des,
options, options,
ptcol,
}) })
} }
} }
......
use std::io::Read; use std::io::Read;
use std::net::TcpListener; use std::net::TcpListener;
use tenjin::etherparser::ethernet::EthernetFrame;
use tenjin::openflow::events::packet_in::PacketInEvent; use tenjin::openflow::events::packet_in::PacketInEvent;
use tenjin::openflow::{Controller, Msg, OfpHeader}; use tenjin::openflow::{Controller, Msg, OfpHeader};
...@@ -32,7 +31,7 @@ fn main() -> Result<(), std::io::Error> { ...@@ -32,7 +31,7 @@ fn main() -> Result<(), std::io::Error> {
let length_payload = packet.size(); let length_payload = packet.size();
let mut payload = vec![0u8; length_payload]; let mut payload = vec![0u8; length_payload];
stream.read(&mut payload)?; stream.read(&mut payload)?;
let message = Msg::parse(packet.message, &payload); let message = Msg::parse(packet.message);
match message { match message {
// 0 is Hello message // 0 is Hello message
...@@ -41,8 +40,8 @@ fn main() -> Result<(), std::io::Error> { ...@@ -41,8 +40,8 @@ fn main() -> Result<(), std::io::Error> {
controller.feture_req(packet.xid, &mut stream); controller.feture_req(packet.xid, &mut stream);
println!("Hello event"); println!("Hello event");
} }
Msg::PacketIn(b) => { Msg::PacketIn => {
controller.packetIn( controller.packet_in(
packet.xid, packet.xid,
PacketInEvent::parse(&payload), PacketInEvent::parse(&payload),
&mut stream, &mut stream,
......
use std::{collections::HashMap, io::Write, mem::size_of, net::TcpStream}; use std::{collections::HashMap, io::Write, mem::size_of, net::TcpStream};
use byteorder::{BigEndian, WriteBytesExt};
use crate::etherparser::ethernet::EthernetFrame;
use super::{events::packet_in::PacketInEvent, OfpHeader}; use super::{events::packet_in::PacketInEvent, OfpHeader};
pub struct Controller { pub struct Controller {
...@@ -33,11 +29,9 @@ impl Controller { ...@@ -33,11 +29,9 @@ impl Controller {
stream.write_all(&bytes).unwrap(); stream.write_all(&bytes).unwrap();
} }
pub fn packetIn(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream) { pub fn packet_in(&mut self, xid: u32, packetin: PacketInEvent, stream: &mut TcpStream) {
let ether = packetin.payload; let ether = packetin.payload;
self.mac_to_port.insert(ether.mac_src, packetin.port); self.mac_to_port.insert(ether.mac_src, packetin.port);
} }
pub fn send(&self, xid: u32, message: u8, payload: &Vec<u8>, stream: &mut TcpStream) { pub fn send(&self, xid: u32, message: u8, payload: &Vec<u8>, stream: &mut TcpStream) {
......
pub enum Msg { pub enum Msg {
Hello, Hello,
PacketIn(Vec<u8>), PacketIn,
NotFound, NotFound,
} }
impl Msg { impl Msg {
pub fn parse(message_code: u8, payload: &Vec<u8>) -> Self { pub fn parse(message_code: u8) -> Self {
match message_code { match message_code {
0 => Msg::Hello, 0 => Msg::Hello,
8 => Msg::PacketIn(payload.clone()), 8 => Msg::PacketIn,
_ => Msg::NotFound, _ => Msg::NotFound,
} }
} }
......
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