Do not use alloc::prelude

master
Jiajie Chen 6 years ago
parent 2e6a9eb7b5
commit a739f17988

@ -7,11 +7,12 @@ extern crate rcore_user;
extern crate alloc; extern crate alloc;
use rcore_user::syscall::*; use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
use isomorphic_drivers::net::ethernet::intel::ixgbe; use isomorphic_drivers::net::ethernet::intel::ixgbe;
use isomorphic_drivers::provider; use isomorphic_drivers::provider;
use alloc::prelude::*; use rcore_user::syscall::*;
use alloc::vec;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Provider; pub struct Provider;
@ -51,7 +52,6 @@ impl provider::Provider for Provider {
} }
} }
// IMPORTANT: Must define main() like this // IMPORTANT: Must define main() like this
#[no_mangle] #[no_mangle]
pub fn main() { pub fn main() {
@ -63,14 +63,16 @@ pub fn main() {
println!("IXGBE driver up"); println!("IXGBE driver up");
loop { loop {
println!("IXGBE driver sending data"); println!("IXGBE driver sending data");
let data = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // mac let data = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // mac
0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac 0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac
0x08, 0x06, // arp 0x08, 0x06, // arp
0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // mac 0xff, // mac
0x0a, 0x00, 0x00, 0x02, // ip 0x0a, 0x00, 0x00, 0x02, // ip
0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac 0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac
0x0a, 0x00, 0x00, 0x01]; // ip 0x0a, 0x00, 0x00, 0x01,
]; // ip
ixgbe.send(&data); ixgbe.send(&data);
sys_sleep(1); sys_sleep(1);
} }

@ -7,11 +7,12 @@ extern crate rcore_user;
extern crate alloc; extern crate alloc;
use rcore_user::syscall::*; use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
use isomorphic_drivers::net::ethernet::intel::ixgbe; use isomorphic_drivers::net::ethernet::intel::ixgbe;
use isomorphic_drivers::provider; use isomorphic_drivers::provider;
use alloc::prelude::*; use rcore_user::syscall::*;
use alloc::vec;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Provider; pub struct Provider;
@ -51,7 +52,6 @@ impl provider::Provider for Provider {
} }
} }
// IMPORTANT: Must define main() like this // IMPORTANT: Must define main() like this
#[no_mangle] #[no_mangle]
pub fn main() { pub fn main() {
@ -62,14 +62,16 @@ pub fn main() {
println!("IXGBE addr at {:#X}", addr); println!("IXGBE addr at {:#X}", addr);
let ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), addr as usize, 0x20000); let ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), addr as usize, 0x20000);
println!("IXGBE driver up"); println!("IXGBE driver up");
let data = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // mac let data = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // mac
0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac 0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac
0x08, 0x06, // arp 0x08, 0x06, // arp
0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // mac 0xff, // mac
0x0a, 0x00, 0x00, 0x02, // ip 0x0a, 0x00, 0x00, 0x02, // ip
0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac 0x00, 0x16, 0x31, 0xff, 0xa4, 0x9f, // mac
0x0a, 0x00, 0x00, 0x01]; // ip 0x0a, 0x00, 0x00, 0x01,
]; // ip
let size = 2048; let size = 2048;
let tx_batch = vec![&data[..]; size]; let tx_batch = vec![&data[..]; size];
println!("IXGBE driver waiting for link up"); println!("IXGBE driver waiting for link up");

@ -7,12 +7,14 @@ extern crate rcore_user;
extern crate alloc; extern crate alloc;
use rcore_user::syscall::*; use alloc::boxed::Box;
use isomorphic_drivers::net::ethernet::intel::ixgbe;
use isomorphic_drivers::provider;
use alloc::prelude::*;
use alloc::collections::BTreeMap; use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::vec; use alloc::vec;
use alloc::vec::Vec;
use isomorphic_drivers::net::ethernet::intel::ixgbe;
use isomorphic_drivers::provider;
use rcore_user::syscall::*;
use smoltcp::iface::*; use smoltcp::iface::*;
use smoltcp::phy; use smoltcp::phy;
@ -62,7 +64,7 @@ impl provider::Provider for Provider {
#[derive(Clone)] #[derive(Clone)]
struct IXGBEDriver { struct IXGBEDriver {
inner: ixgbe::IXGBEDriver inner: ixgbe::IXGBEDriver,
} }
pub struct IXGBERxToken(Vec<u8>); pub struct IXGBERxToken(Vec<u8>);
@ -95,7 +97,7 @@ impl<'a> phy::Device<'a> for IXGBEDriver {
fn capabilities(&self) -> DeviceCapabilities { fn capabilities(&self) -> DeviceCapabilities {
let mut caps = DeviceCapabilities::default(); let mut caps = DeviceCapabilities::default();
caps.max_transmission_unit = ixgbe::IXGBEDriver::get_mtu(); // max MTU caps.max_transmission_unit = ixgbe::IXGBEDriver::get_mtu(); // max MTU
//caps.max_transmission_unit = 1500; // max MTU //caps.max_transmission_unit = 1500; // max MTU
caps.max_burst_size = Some(256); caps.max_burst_size = Some(256);
// IP Rx checksum is offloaded with RXCSUM // IP Rx checksum is offloaded with RXCSUM
caps.checksum.ipv4 = Checksum::Tx; caps.checksum.ipv4 = Checksum::Tx;
@ -136,7 +138,7 @@ enum State {
DATA_SOCKET_CONNECT, DATA_SOCKET_CONNECT,
DATA_COOKIE_SENT, DATA_COOKIE_SENT,
TEST_START, TEST_START,
TEST_RUNNING TEST_RUNNING,
} }
// IMPORTANT: Must define main() like this // IMPORTANT: Must define main() like this
@ -156,7 +158,7 @@ pub fn main() {
let ethernet_addr = ixgbe.get_mac(); let ethernet_addr = ixgbe.get_mac();
let ip_addrs = [IpCidr::new(IpAddress::v4(10, 0, 0, 2), 24)]; let ip_addrs = [IpCidr::new(IpAddress::v4(10, 0, 0, 2), 24)];
let neighbor_cache = NeighborCache::new(BTreeMap::new()); let neighbor_cache = NeighborCache::new(BTreeMap::new());
let mut iface = EthernetInterfaceBuilder::new(IXGBEDriver{ inner:ixgbe }) let mut iface = EthernetInterfaceBuilder::new(IXGBEDriver { inner: ixgbe })
.ethernet_addr(EthernetAddress::from_bytes(&ethernet_addr.as_bytes())) .ethernet_addr(EthernetAddress::from_bytes(&ethernet_addr.as_bytes()))
.ip_addrs(ip_addrs) .ip_addrs(ip_addrs)
.neighbor_cache(neighbor_cache) .neighbor_cache(neighbor_cache)
@ -183,7 +185,7 @@ pub fn main() {
let mut sockets = SocketSet::new(vec![]); let mut sockets = SocketSet::new(vec![]);
let tcp_handle = sockets.add(tcp_socket); let tcp_handle = sockets.add(tcp_socket);
let tcp2_handle = sockets.add(tcp2_socket); let tcp2_handle = sockets.add(tcp2_socket);
let mut tick = 0; let mut tick = 0;
let mut state = State::BEGIN; let mut state = State::BEGIN;
let mut last_state = State::BEGIN; let mut last_state = State::BEGIN;
@ -194,8 +196,12 @@ pub fn main() {
{ {
let mut socket = sockets.get::<TcpSocket>(tcp_handle); let mut socket = sockets.get::<TcpSocket>(tcp_handle);
if let State::BEGIN = state { if let State::BEGIN = state {
socket.connect(IpEndpoint::new(IpAddress::v4(10, 0, 0, 1), 5201), socket
IpEndpoint::new(IpAddress::v4(10, 0, 0, 2), 5201)).unwrap(); .connect(
IpEndpoint::new(IpAddress::v4(10, 0, 0, 1), 5201),
IpEndpoint::new(IpAddress::v4(10, 0, 0, 2), 5201),
)
.unwrap();
state = State::CONTROL_SOCKET_CONNECT; state = State::CONTROL_SOCKET_CONNECT;
} else if let State::CONTROL_SOCKET_CONNECT = state { } else if let State::CONTROL_SOCKET_CONNECT = state {
if socket.may_send() { if socket.may_send() {
@ -250,8 +256,12 @@ pub fn main() {
{ {
let mut socket = sockets.get::<TcpSocket>(tcp2_handle); let mut socket = sockets.get::<TcpSocket>(tcp2_handle);
if let State::CREATE_STREAMS = state { if let State::CREATE_STREAMS = state {
socket.connect(IpEndpoint::new(IpAddress::v4(10, 0, 0, 1), 5201), socket
IpEndpoint::new(IpAddress::v4(10, 0, 0, 2), 5202)).unwrap(); .connect(
IpEndpoint::new(IpAddress::v4(10, 0, 0, 1), 5201),
IpEndpoint::new(IpAddress::v4(10, 0, 0, 2), 5202),
)
.unwrap();
state = State::DATA_SOCKET_CONNECT; state = State::DATA_SOCKET_CONNECT;
} else if let State::DATA_SOCKET_CONNECT = state { } else if let State::DATA_SOCKET_CONNECT = state {
if socket.may_send() { if socket.may_send() {

Loading…
Cancel
Save