mirror of
https://github.com/mii443/miibgpd.git
synced 2025-08-22 15:55:26 +00:00
add Established
This commit is contained in:
@ -6,4 +6,5 @@ pub enum Event {
|
||||
TcpConnectionConfirmed,
|
||||
BgpOpen(OpenMessage),
|
||||
KeepaliveMsg(KeepaliveMessage),
|
||||
Established,
|
||||
}
|
||||
|
40
src/peer.rs
40
src/peer.rs
@ -97,6 +97,12 @@ impl Peer {
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
State::OpenConfirm => match event {
|
||||
Event::KeepaliveMsg(keepalive) => {
|
||||
self.state = State::Established;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -117,6 +123,40 @@ mod tests {
|
||||
use crate::peer::Peer;
|
||||
use crate::state::State;
|
||||
|
||||
#[tokio::test]
|
||||
async fn peer_can_transition_to_open_established_state() {
|
||||
let config: Config = "64512 127.0.0.1 64513 127.0.0.2 active".parse().unwrap();
|
||||
let mut peer = Peer::new(config);
|
||||
peer.start();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let remote_config: Config = "64513 127.0.0.2 64512 127.0.0.1 passive".parse().unwrap();
|
||||
let mut remote_peer = Peer::new(remote_config);
|
||||
remote_peer.start();
|
||||
|
||||
let max_step = 50;
|
||||
for _ in 0..max_step {
|
||||
remote_peer.next().await;
|
||||
if remote_peer.state == State::Established {
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs_f32(0.1)).await;
|
||||
}
|
||||
});
|
||||
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let max_step = 50;
|
||||
for _ in 0..max_step {
|
||||
peer.next().await;
|
||||
if peer.state == State::Established {
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs_f32(0.1)).await;
|
||||
}
|
||||
|
||||
assert_eq!(peer.state, State::Established);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn peer_can_transition_to_open_confirm_state() {
|
||||
let config: Config = "64512 127.0.0.1 64513 127.0.0.2 active".parse().unwrap();
|
||||
|
@ -4,4 +4,5 @@ pub enum State {
|
||||
Connect,
|
||||
OpenSent,
|
||||
OpenConfirm,
|
||||
Established,
|
||||
}
|
||||
|
Reference in New Issue
Block a user