This commit is contained in:
mustakimur khandaker 2022-03-29 17:07:01 -04:00
parent a20edcc587
commit bf6748df5c
4 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,32 @@
6
Desk1 Desktop V4 127.0.5.101
0
Desk2 Desktop V4 127.0.6.202
0
Switch1 Switch V6 2001:0db8:85a3:0000:0000:8a2e:0370:7334
1
Desk1
Router1 Router V4 192.10.12.145
2
Switch1 Desk2
Switch2 Switch V6 2001:0db8:85a3:0000:0000:8aaa:0378:7544
1
Router1
Desk3 Desktop V4 127.0.7.185
1
Switch2
1
Router1
2
V6
3
Desk1 Desk3
4
Switch2
3
Desk1 Desk3

View File

@ -0,0 +1,42 @@
Number of Devices: 6
Device Info: Desk1 Desktop V4 127.0.5.101
No. of Connections: 0
Device Info: Desk2 Desktop V4 127.0.6.202
No. of Connections: 0
Device Info: Switch1 Switch V6 2001:0db8:85a3:0000:0000:8a2e:0370:7334
No. of Connections: 1
Connections are: Desk1
Device Info: Router1 Router V4 192.10.12.145
No. of Connections: 2
Connections are: Switch1 Desk2
Device Info: Switch2 Switch V6 2001:0db8:85a3:0000:0000:8aaa:0378:7544
No. of Connections: 1
Connections are: Router1
Device Info: Desk3 Desktop V4 127.0.7.185
No. of Connections: 1
Connections are: Switch2
Choice operation:
1) Who are directly connected to <input>?
2) Who are using <input> IP Kind?
3) How does <input1> and <input2> can talk?
4) Remove the <input>?
Choice: 1
Router1
Answer: Switch1, Switch2, Desk2
Choice: 2
V6
Answer: Switch1, Switch2
Choice: 3
Desk1 Desk3
Answer: Desk1 -> Switch1 -> Router1 -> Switch2 -> Desk3
Choice: 4
Switch2
Choice: 3
Desk1 Desk3
Answer: No connection.

View File

@ -0,0 +1,84 @@
use std::vec;
enum IPAddrKind {
V4(u8, u8, u8, u8),
V6(String),
}
enum MacAddrKind {
PHYSICAL(u64),
VIRTUAL(u32),
}
enum DeviceType {
Desktop(IPAddrKind),
Switch(MacAddrKind),
Router(MacAddrKind),
}
struct Device {
dtype: DeviceType,
name: String,
}
fn dir_conn_to(query: String) -> Vec<String> {
let result = Vec::new();
result
}
fn find_ip_kind(query: IPAddrKind) -> Vec<String> {
let result = Vec::new();
result
}
fn can_talk(src: String, dst: String) -> Vec<String> {
let result = Vec::new();
result
}
fn rm_device(device: String) -> bool {
true
}
fn main() {
// you can maintain a hashmap of <device_name: String, device: Device> alongside of the other hashmap of <device: Device, list: vector<Device>>
// Note, you are free to choose any type including Box<T>, Rc<T>, RefCell<T>, etc.
// inputs will be taken from standard i/o. A file has attached to sample.
assert_eq!(
vec![
String::from("Switch1"),
String::from("Switch2"),
String::from("Desk2")
],
dir_conn_to(String::from("Router1"))
);
assert_eq!(
vec![String::from("Switch1"), String::from("Switch2")],
find_ip_kind(IPAddrKind::V6(String::from("")))
);
assert_eq!(
vec![
String::from("Desk1"),
String::from("Switch1"),
String::from("Router1"),
String::from("Switch2"),
String::from("Desk3")
],
can_talk(String::from("Desk1"), String::from("Desk3"))
);
assert!(rm_device(String::from("Switch2")));
let exp_vec: Vec<String> = Vec::new();
assert_eq!(
exp_vec,
can_talk(String::from("Desk1"), String::from("Desk3"))
);
}

View File

@ -1081,4 +1081,10 @@ hint = ""
name = "simulator"
path = "exercises/simulator/simulator.rs"
mode = "compile"
hint = ""
[[exercises]]
name = "simulatorv2"
path = "exercises/simulatorv2/simulator.rs"
mode = "compile"
hint = ""