Skip to content

Commit

Permalink
chore: fix reviewer's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KuangjuX committed Jul 19, 2023
1 parent 3053078 commit 12a7225
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
"apps/net/httpclient",
"apps/net/httpserver",
"apps/net/udpserver",
"apps/net/bench_bandwidth",
"apps/net/bwbench",
"apps/task/parallel",
"apps/task/sleep",
"apps/task/yield",
Expand Down
22 changes: 3 additions & 19 deletions modules/axnet/src/smoltcp_impl/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,13 @@ impl DeviceWrapper {
let mut past_send_bytes: usize = 0;
let mut past_time = InterfaceWrapper::current_time();

#[rustfmt::skip]
let pkt_data = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // dst MAC
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // src MAC
0x08, 0x00, // ether type: IPv4
0x45, 0x00, // Version, IHL, TOS
((STANDARD_MTU - 14) >> 8) as u8, // ip len excluding ethernet, high byte
((STANDARD_MTU - 14) & 0xFF) as u8, // ip len excluding ethernet, low byte
0x00, 0x00, 0x00, 0x00, // id, flags, fragmentation
0x40, 0x11, 0x00, 0x00, // TTL (64), protocol (UDP), checksum
0x0A, 0x02, 0x02, 0x02, // src ip (10.2.2.2)
0x0A, 0x02, 0x02, 0x01, // dst ip (10.2.2.1)
0x00, 0x2A, 0x05, 0x39, // src and dst ports (42 -> 1337)
((STANDARD_MTU - 20 - 14) >> 8) as u8, // udp len excluding ip & ethernet, high byte
((STANDARD_MTU - 20 - 14) & 0xFF) as u8, // udp len excluding ip & ethernet, low byte
0x00, 0x00, // udp checksum, optional
];

// Send bytes
while send_bytes < MAX_SEND_BYTES {
if let Some(tx_token) = self.transmit(InterfaceWrapper::current_time()) {
AxNetTxToken::consume(tx_token, STANDARD_MTU, |tx_buf| {
tx_buf[0..42].copy_from_slice(&pkt_data);
tx_buf[0..12].fill(1);
tx_buf[12..14].copy_from_slice(&[0x08, 0x00]);
tx_buf[14..42].fill(1);
});
send_bytes += STANDARD_MTU;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/axnet/src/smoltcp_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use alloc::vec;
use core::cell::RefCell;
use core::ops::DerefMut;

use self::listen_table::ListenTable;
use axdriver::prelude::*;
use axhal::time::{current_time_nanos, NANOS_PER_MICROS};
use axsync::Mutex;
Expand All @@ -20,6 +19,8 @@ use smoltcp::socket::{self, AnySocket};
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress, IpCidr};

use self::listen_table::ListenTable;

pub use self::dns::resolve_socket_addr;
pub use self::tcp::TcpSocket;
pub use self::udp::UdpSocket;
Expand Down
2 changes: 1 addition & 1 deletion tools/bwbench_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Benchmark BandWidth Client is a performance testing tool for measuring the netwo
## Usage
In client:
```shell
cargo run --release [sender|receiver]
cargo run --release [sender|receiver] [interface]
```

By reading the source code, you can control the behavior of the benchmark by modifying constants such as `MAX_BYTES`.
Expand Down
27 changes: 6 additions & 21 deletions tools/bwbench_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::fmt::Display;

mod device;

const INTERFACE: &str = "ens2f0";
const STANDARD_MTU: usize = 1500;

const MAX_BYTES: usize = 10 * GB;
Expand Down Expand Up @@ -40,26 +39,10 @@ fn transmit_benchmark(interface: &str) {
println!("Sender Mode!");
let mut dev = NetDevice::new(interface).unwrap();

#[rustfmt::skip]
let pkt_data = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // dst MAC
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // src MAC
0x08, 0x00, // ether type: IPv4
0x45, 0x00, // Version, IHL, TOS
((STANDARD_MTU - 14) >> 8) as u8, // ip len excluding ethernet, high byte
((STANDARD_MTU - 14) & 0xFF) as u8, // ip len excluding ethernet, low byte
0x00, 0x00, 0x00, 0x00, // id, flags, fragmentation
0x40, 0x11, 0x00, 0x00, // TTL (64), protocol (UDP), checksum
0x0A, 0x02, 0x02, 0x02, // src ip (10.2.2.2)
0x0A, 0x02, 0x02, 0x01, // dst ip (10.2.2.1)
0x00, 0x2A, 0x05, 0x39, // src and dst ports (42 -> 1337)
((STANDARD_MTU - 20 - 14) >> 8) as u8, // udp len excluding ip & ethernet, high byte
((STANDARD_MTU - 20 - 14) & 0xFF) as u8, // udp len excluding ip & ethernet, low byte
0x00, 0x00, // udp checksum, optional
];

let mut tx_buf = [0u8; 1500];
tx_buf[0..42].copy_from_slice(&pkt_data);
tx_buf[0..12].fill(1);
tx_buf[12..14].copy_from_slice(&[0x08, 0x00]);
tx_buf[14..42].fill(1);

let mut send_bytes = 0;
let mut past_send_bytes = 0;
Expand Down Expand Up @@ -141,5 +124,7 @@ fn main() {
_ => panic!("Unknown Mode!"),
};

benchmark_bandwidth(client, INTERFACE);
let interface = args[2].as_str();

benchmark_bandwidth(client, interface);
}

0 comments on commit 12a7225

Please sign in to comment.