Commit 15388f3c authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

prepare for packet_out

parent ecb47c2e
use tenjin::etherparser::ethernet::EthernetFrame;
use tenjin::openflow::{Controller, Msg, OfpHeader};
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};
extern crate byteorder;
fn main() -> Result<(), std::io::Error> {
let controller = Controller::new(Controller::OFP_1_0);
let mut controller = Controller::new(Controller::OFP_1_0);
let listener = TcpListener::bind(("127.0.0.1", 6633)).unwrap();
let mut buf = vec![0u8; 8];
......@@ -41,7 +42,11 @@ fn main() -> Result<(), std::io::Error> {
println!("Hello event");
}
Msg::PacketIn(b) => {
controller.packetIn(packet.xid, EthernetFrame::parse(&payload), &mut stream);
controller.packetIn(
packet.xid,
PacketInEvent::parse(&payload),
&mut stream,
);
println!("PacketIn event");
}
_ => {
......
......@@ -4,7 +4,7 @@ use byteorder::{BigEndian, WriteBytesExt};
use crate::etherparser::ethernet::EthernetFrame;
use super::OfpHeader;
use super::{events::packet_in::PacketInEvent, OfpHeader};
pub struct Controller {
version: u8,
......@@ -33,7 +33,12 @@ impl Controller {
stream.write_all(&bytes).unwrap();
}
pub fn packetIn(&self, xid: u32, payload: EthernetFrame, stream: &mut TcpStream) {}
pub fn packetIn(&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) {
let length = size_of::<OfpHeader>() + payload.len();
......
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