pub fn connection_setup(
    ctx: &mut Context,
    now: &mut Instant,
    server: &mut Engine<TestRuntime>,
    client: &mut Engine<TestRuntime>,
    listen_port: ip::Port,
    listen_addr: ipv4::Endpoint,
) -> (FileDescriptor, FileDescriptor) {
    // Server: LISTEN state at T(0).
    let mut accept_future: AcceptFuture<TestRuntime> =
        connection_setup_closed_listen(server, listen_addr);

    // T(0) -> T(1)
    advance_clock(Some(server), Some(client), now);

    // Client: SYN_SENT state at T(1).
    let (client_fd, mut connect_future, mut bytes): (
        FileDescriptor,
        ConnectFuture<TestRuntime>,
        Bytes,
    ) = connection_setup_listen_syn_sent(client, listen_addr);

    // Sanity check packet.
    check_packet_pure_syn(
        bytes.clone(),
        test_helpers::ALICE_MAC,
        test_helpers::BOB_MAC,
        test_helpers::ALICE_IPV4,
        test_helpers::BOB_IPV4,
        listen_port,
    );

    // T(1) -> T(2)
    advance_clock(Some(server), Some(client), now);

    // Server: SYN_RCVD state at T(2).
    bytes = connection_setup_listen_syn_rcvd(server, bytes);

    // Sanity check packet.
    check_packet_syn_ack(
        bytes.clone(),
        test_helpers::BOB_MAC,
        test_helpers::ALICE_MAC,
        test_helpers::BOB_IPV4,
        test_helpers::ALICE_IPV4,
        listen_port,
    );

    // T(2) -> T(3)
    advance_clock(Some(server), Some(client), now);

    // Client: ESTABLISHED at T(3).
    bytes = connection_setup_syn_sent_established(client, bytes);

    // Sanity check sent packet.
    check_packet_pure_ack_on_syn_ack(
        bytes.clone(),
        test_helpers::ALICE_MAC,
        test_helpers::BOB_MAC,
        test_helpers::ALICE_IPV4,
        test_helpers::BOB_IPV4,
        listen_port,
    );
    // T(3) -> T(4)
    advance_clock(Some(server), Some(client), now);

    // Server: ESTABLISHED at T(4).
    connection_setup_sync_rcvd_established(server, bytes);

    must_let!(let Poll::Ready(Ok(server_fd)) = Future::poll(Pin::new(&mut accept_future), ctx));
    must_let!(let Poll::Ready(Ok(())) = Future::poll(Pin::new(&mut connect_future), ctx));

    (server_fd, client_fd)
}
/// Runs 3-way connection setup.
Runs 3-way connection setup.
Runs 3 - way connection setup .
pub fn connection_setup(
    ctx: &mut Context,
    now: &mut Instant,
    server: &mut Engine<TestRuntime>,
    client: &mut Engine<TestRuntime>,
    listen_port: ip::Port,
    listen_addr: ipv4::Endpoint,
) -> (FileDescriptor, FileDescriptor) {
    // Server: LISTEN state at T(0).
    let mut accept_future: AcceptFuture<TestRuntime> =
        connection_setup_closed_listen(server, listen_addr);
    // T(0) -> T(1)
    advance_clock(Some(server), Some(client), now);
    // Client: SYN_SENT state at T(1).
    let (client_fd, mut connect_future, mut bytes): (
        FileDescriptor,
        ConnectFuture<TestRuntime>,
        Bytes,
    ) = connection_setup_listen_syn_sent(client, listen_addr);
    // Sanity check packet.
    check_packet_pure_syn(
        bytes.clone(),
        test_helpers::ALICE_MAC,
        test_helpers::BOB_MAC,
        test_helpers::ALICE_IPV4,
        test_helpers::BOB_IPV4,
        listen_port,
    );
    // T(1) -> T(2)
    advance_clock(Some(server), Some(client), now);
    // Server: SYN_RCVD state at T(2).
    bytes = connection_setup_listen_syn_rcvd(server, bytes);
    // Sanity check packet.
    check_packet_syn_ack(
        bytes.clone(),
        test_helpers::BOB_MAC,
        test_helpers::ALICE_MAC,
        test_helpers::BOB_IPV4,
        test_helpers::ALICE_IPV4,
        listen_port,
    );
    // T(2) -> T(3)
    advance_clock(Some(server), Some(client), now);
    // Client: ESTABLISHED at T(3).
    bytes = connection_setup_syn_sent_established(client, bytes);
    // Sanity check sent packet.
    check_packet_pure_ack_on_syn_ack(
        bytes.clone(),
        test_helpers::ALICE_MAC,
        test_helpers::BOB_MAC,
        test_helpers::ALICE_IPV4,
        test_helpers::BOB_IPV4,
        listen_port,
    );
    // T(3) -> T(4)
    advance_clock(Some(server), Some(client), now);
    // Server: ESTABLISHED at T(4).
    connection_setup_sync_rcvd_established(server, bytes);
    must_let!(let Poll::Ready(Ok(server_fd)) = Future::poll(Pin::new(&mut accept_future), ctx));
    must_let!(let Poll::Ready(Ok(())) = Future::poll(Pin::new(&mut connect_future), ctx));
    (server_fd, client_fd)
}
pub fn connection_setup ( ctx : & mut Context , now : & mut Instant , server : & mut Engine < TestRuntime > , client : & mut Engine < TestRuntime > , listen_port : ip :: Port , listen_addr : ipv4 :: Endpoint , ) -> ( FileDescriptor , FileDescriptor ) { // Server: LISTEN state at T(0). let mut accept_future : AcceptFuture < TestRuntime > = connection_setup_closed_listen ( server , listen_addr ) ; // T(0) -> T(1) advance_clock ( Some ( server ) , Some ( client ) , now ) ; // Client: SYN_SENT state at T(1). let ( client_fd , mut connect_future , mut bytes ) : ( FileDescriptor , ConnectFuture < TestRuntime > , Bytes , ) = connection_setup_listen_syn_sent ( client , listen_addr ) ; // Sanity check packet. check_packet_pure_syn ( bytes . clone ( ) , test_helpers :: ALICE_MAC , test_helpers :: BOB_MAC , test_helpers :: ALICE_IPV4 , test_helpers :: BOB_IPV4 , listen_port , ) ; // T(1) -> T(2) advance_clock ( Some ( server ) , Some ( client ) , now ) ; // Server: SYN_RCVD state at T(2). bytes = connection_setup_listen_syn_rcvd ( server , bytes ) ; // Sanity check packet. check_packet_syn_ack ( bytes . clone ( ) , test_helpers :: BOB_MAC , test_helpers :: ALICE_MAC , test_helpers :: BOB_IPV4 , test_helpers :: ALICE_IPV4 , listen_port , ) ; // T(2) -> T(3) advance_clock ( Some ( server ) , Some ( client ) , now ) ; // Client: ESTABLISHED at T(3). bytes = connection_setup_syn_sent_established ( client , bytes ) ; // Sanity check sent packet. check_packet_pure_ack_on_syn_ack ( bytes . clone ( ) , test_helpers :: ALICE_MAC , test_helpers :: BOB_MAC , test_helpers :: ALICE_IPV4 , test_helpers :: BOB_IPV4 , listen_port , ) ; // T(3) -> T(4) advance_clock ( Some ( server ) , Some ( client ) , now ) ; // Server: ESTABLISHED at T(4). connection_setup_sync_rcvd_established ( server , bytes ) ; must_let ! ( let Poll Ready ( Ok ( server_fd ) ) Future poll ( Pin new ( mut accept_future ) ctx ) ) ; must_let ! ( let Poll Ready ( Ok ( ( ) ) ) Future poll ( Pin new ( mut connect_future ) ctx ) ) ; ( server_fd , client_fd ) }
Runs 3-way connection setup.
Runs 3 - way connection setup .
ctx
&mut Context
now
&mut Instant
server
&mut Engine<TestRuntime>
client
&mut Engine<TestRuntime>
listen_port
ip::Port
listen_addr
ipv4::Endpoint
ctx
&mut Context
now
&mut Instant
server
&mut Engine<TestRuntime>
client
&mut Engine<TestRuntime>
listen_port
ip::Port
listen_addr
ipv4::Endpoint