fn active_connection_migration_disabled()

in quic/s2n-quic-transport/src/path/manager/tests.rs [989:1111]


fn active_connection_migration_disabled() {
    // Setup:
    let mut publisher = Publisher::snapshot();
    let new_addr: SocketAddr = "127.0.0.1:1".parse().unwrap();
    let new_addr = SocketAddress::from(new_addr);
    let new_addr = RemoteAddress::from(new_addr);
    let first_path = ServerPath::new(
        new_addr,
        connection::PeerId::try_from_bytes(&[1]).unwrap(),
        connection::LocalId::TEST_ID,
        RttEstimator::default(),
        Default::default(),
        false,
        mtu::Config::default(),
        ANTI_AMPLIFICATION_MULTIPLIER,
    );
    let mut manager = manager_server(first_path);
    // Give the path manager some new CIDs so it's able to use one for an active migration.
    // id_2 will be moved to `InUse` immediately due to the handshake CID rotation feature,
    // so id_3 is added as well to have an unused CID available for connection migration
    let id_2 = connection::PeerId::try_from_bytes(b"id02").unwrap();
    assert!(manager
        .on_new_connection_id(&id_2, 1, 0, &TEST_TOKEN_1, &mut publisher)
        .is_ok());
    let id_3 = connection::PeerId::try_from_bytes(b"id03").unwrap();
    assert!(manager
        .on_new_connection_id(&id_3, 2, 0, &TEST_TOKEN_2, &mut publisher)
        .is_ok());

    let new_addr: SocketAddr = "127.0.0.2:1".parse().unwrap();
    let new_addr = SocketAddress::from(new_addr);
    let new_addr = RemoteAddress::from(new_addr);
    let new_cid_1 = connection::LocalId::try_from_bytes(b"id02").unwrap();
    let new_cid_2 = connection::LocalId::try_from_bytes(b"id03").unwrap();
    let now = NoopClock {}.get_time();
    let mut datagram = DatagramInfo {
        timestamp: now,
        payload_len: 0,
        ecn: ExplicitCongestionNotification::default(),
        destination_connection_id: new_cid_1,
        destination_connection_id_classification: connection::id::Classification::Local,
        source_connection_id: None,
    };

    // First try an active migration with active migration disabled
    let res = manager.handle_connection_migration(
        &new_addr,
        &datagram,
        &mut Default::default(),
        &mut migration::allow_all::Validator,
        &mut mtu::Manager::new(mtu::Config::default()),
        // Active connection migration is disabled
        &Limits::default()
            .with_active_connection_migration(false)
            .unwrap(),
        &mut publisher,
    );

    // The migration succeeds
    assert!(res.is_ok());
    assert_eq!(2, manager.paths.len());
    // The new path uses a new CID since there were enough supplied
    assert_eq!(
        manager.paths[res.unwrap().0.as_u8() as usize].peer_connection_id,
        id_3
    );

    // Clear the pending packet authentication to allow another migration to proceed
    manager.pending_packet_authentication = None;

    // Try an active connection migration with active migration enabled (default)
    datagram.destination_connection_id = new_cid_2;

    let res = manager.handle_connection_migration(
        &new_addr,
        &datagram,
        &mut Default::default(),
        &mut migration::allow_all::Validator,
        &mut mtu::Manager::new(mtu::Config::default()),
        &Limits::default(),
        &mut publisher,
    );

    // The migration succeeds
    assert!(res.is_ok());
    assert_eq!(3, manager.paths.len());
    // The new path uses the existing id since there wasn't a new one available
    assert_eq!(
        manager.paths[res.unwrap().0.as_u8() as usize].peer_connection_id,
        id_2
    );

    // Now try a non-active (passive) migration, with active migration disabled
    // the same CID is used, so it's not an active migration
    datagram.destination_connection_id = connection::LocalId::TEST_ID;
    let new_addr: SocketAddr = "127.0.0.3:1".parse().unwrap();
    let new_addr = SocketAddress::from(new_addr);
    let new_addr = RemoteAddress::from(new_addr);
    // Clear the pending packet authentication to allow another migration to proceed
    manager.pending_packet_authentication = None;

    let res = manager.handle_connection_migration(
        &new_addr,
        &datagram,
        &mut Default::default(),
        &mut migration::allow_all::Validator,
        &mut mtu::Manager::new(mtu::Config::default()),
        // Active connection migration is disabled
        &Limits::default()
            .with_active_connection_migration(false)
            .unwrap(),
        &mut publisher,
    );

    // The passive migration succeeds
    assert!(res.is_ok());
    assert_eq!(4, manager.paths.len());
    // The new path uses the existing id since the peer did not change their destination CID
    assert_eq!(
        manager.paths[res.unwrap().0.as_u8() as usize].peer_connection_id,
        id_2
    );
}