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