src/net/third_party/quiche/src/quic/core/quic_connection_test.cc
// Receive a padded PING packet with a port change on server side.
Receive a padded PING packet with a port change on server side.
Receive a padded PING packet with a port change on server side .
TEST_P(QuicConnectionTest, ReceivePaddedPingWithPortChangeAtServer) {
  set_perspective(Perspective::IS_SERVER);
  QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false);
  EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective());
  QuicConnectionPeer::SetDirectPeerAddress(&connection_, QuicSocketAddress());
  QuicConnectionPeer::SetEffectivePeerAddress(&connection_,
                                              QuicSocketAddress());
  EXPECT_FALSE(connection_.effective_peer_address().IsInitialized());
  QuicFrame frame;
  if (GetParam().version.UsesCryptoFrames()) {
    frame = QuicFrame(&crypto_frame_);
    EXPECT_CALL(visitor_, OnCryptoFrame(_)).Times(AnyNumber());
  } else {
    frame = QuicFrame(QuicStreamFrame(
        QuicUtils::GetCryptoStreamId(connection_.transport_version()), false,
        0u, quiche::QuicheStringPiece()));
    EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AnyNumber());
  }
  ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress);
  EXPECT_EQ(kPeerAddress, connection_.peer_address());
  EXPECT_EQ(kPeerAddress, connection_.effective_peer_address());
  if (GetParam().version.HasIetfQuicFrames()) {
    EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)).Times(1);
    EXPECT_CALL(visitor_, OnPacketReceived(_, _, _)).Times(0);
  } else {
    EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)).Times(0);
    EXPECT_CALL(visitor_,
                OnPacketReceived(_, _, true))
        .Times(1);
  }
  const QuicSocketAddress kNewPeerAddress =
      QuicSocketAddress(QuicIpAddress::Loopback6(), 23456);
  QuicFrames frames;
  QuicPingFrame ping_frame;
  frames.push_back(QuicFrame(ping_frame));
  QuicPaddingFrame padding_frame;
  frames.push_back(QuicFrame(padding_frame));
  uint64_t num_probing_received =
      connection_.GetStats().num_connectivity_probing_received;
  ProcessFramesPacketWithAddresses(frames, kSelfAddress, kNewPeerAddress);
  if (GetParam().version.HasIetfQuicFrames()) {
    EXPECT_EQ(num_probing_received,
              connection_.GetStats().num_connectivity_probing_received);
    EXPECT_EQ(kNewPeerAddress, connection_.peer_address());
    EXPECT_EQ(kNewPeerAddress, connection_.effective_peer_address());
  } else {
    EXPECT_EQ(num_probing_received + 1,
              connection_.GetStats().num_connectivity_probing_received);
    EXPECT_EQ(kPeerAddress, connection_.peer_address());
    EXPECT_EQ(kPeerAddress, connection_.effective_peer_address());
  }
  if (GetParam().version.HasIetfQuicFrames()) {
    EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)).Times(1);
  } else {
    EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)).Times(0);
  }
  ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress);
  EXPECT_EQ(kPeerAddress, connection_.peer_address());
  EXPECT_EQ(kPeerAddress, connection_.effective_peer_address());
}
TEST_P ( QuicConnectionTest , ReceivePaddedPingWithPortChangeAtServer ) { set_perspective ( Perspective :: IS_SERVER ) ; QuicPacketCreatorPeer :: SetSendVersionInPacket ( creator_ , false ) ; EXPECT_EQ ( Perspective :: IS_SERVER , connection_ . perspective ( ) ) ; QuicConnectionPeer :: SetDirectPeerAddress ( & connection_ , QuicSocketAddress ( ) ) ; QuicConnectionPeer :: SetEffectivePeerAddress ( & connection_ , QuicSocketAddress ( ) ) ; EXPECT_FALSE ( connection_ . effective_peer_address ( ) . IsInitialized ( ) ) ; QuicFrame frame ; if ( GetParam ( ) . version . UsesCryptoFrames ( ) ) { frame = QuicFrame ( & crypto_frame_ ) ; EXPECT_CALL ( visitor_ , OnCryptoFrame ( _ ) ) . Times ( AnyNumber ( ) ) ; } else { frame = QuicFrame ( QuicStreamFrame ( QuicUtils :: GetCryptoStreamId ( connection_ . transport_version ( ) ) , false , 0u , quiche :: QuicheStringPiece ( ) ) ) ; EXPECT_CALL ( visitor_ , OnStreamFrame ( _ ) ) . Times ( AnyNumber ( ) ) ; } ProcessFramePacketWithAddresses ( frame , kSelfAddress , kPeerAddress ) ; EXPECT_EQ ( kPeerAddress , connection_ . peer_address ( ) ) ; EXPECT_EQ ( kPeerAddress , connection_ . effective_peer_address ( ) ) ; if ( GetParam ( ) . version . HasIetfQuicFrames ( ) ) { EXPECT_CALL ( visitor_ , OnConnectionMigration ( PORT_CHANGE ) ) . Times ( 1 ) ; EXPECT_CALL ( visitor_ , OnPacketReceived ( _ , _ , _ ) ) . Times ( 0 ) ; } else { EXPECT_CALL ( visitor_ , OnConnectionMigration ( PORT_CHANGE ) ) . Times ( 0 ) ; EXPECT_CALL ( visitor_ , OnPacketReceived ( _ , _ , true ) ) . Times ( 1 ) ; } const QuicSocketAddress kNewPeerAddress = QuicSocketAddress ( QuicIpAddress :: Loopback6 ( ) , 23456 ) ; QuicFrames frames ; QuicPingFrame ping_frame ; frames . push_back ( QuicFrame ( ping_frame ) ) ; QuicPaddingFrame padding_frame ; frames . push_back ( QuicFrame ( padding_frame ) ) ; uint64_t num_probing_received = connection_ . GetStats ( ) . num_connectivity_probing_received ; ProcessFramesPacketWithAddresses ( frames , kSelfAddress , kNewPeerAddress ) ; if ( GetParam ( ) . version . HasIetfQuicFrames ( ) ) { EXPECT_EQ ( num_probing_received , connection_ . GetStats ( ) . num_connectivity_probing_received ) ; EXPECT_EQ ( kNewPeerAddress , connection_ . peer_address ( ) ) ; EXPECT_EQ ( kNewPeerAddress , connection_ . effective_peer_address ( ) ) ; } else { EXPECT_EQ ( num_probing_received + 1 , connection_ . GetStats ( ) . num_connectivity_probing_received ) ; EXPECT_EQ ( kPeerAddress , connection_ . peer_address ( ) ) ; EXPECT_EQ ( kPeerAddress , connection_ . effective_peer_address ( ) ) ; } if ( GetParam ( ) . version . HasIetfQuicFrames ( ) ) { EXPECT_CALL ( visitor_ , OnConnectionMigration ( PORT_CHANGE ) ) . Times ( 1 ) ; } else { EXPECT_CALL ( visitor_ , OnConnectionMigration ( PORT_CHANGE ) ) . Times ( 0 ) ; } ProcessFramePacketWithAddresses ( frame , kSelfAddress , kPeerAddress ) ; EXPECT_EQ ( kPeerAddress , connection_ . peer_address ( ) ) ; EXPECT_EQ ( kPeerAddress , connection_ . effective_peer_address ( ) ) ; }
Receive a padded PING packet with a port change on server side.
Receive a padded PING packet with a port change on server side .
// Clear direct_peer_address. // Clear effective_peer_address, it is the same as direct_peer_address for // this test. // In IETF version, a padded PING packet with port change is not taken as // connectivity probe. // In non-IETF version, process a padded PING packet from a new peer // address on server side is effectively receiving a connectivity probing. /*is_connectivity_probe=*/ /*port=*/ // Write a PING frame, which has no data payload. // Add padding to the rest of the packet. // Padded PING with port changen is not considered as connectivity probe but // a PORT CHANGE. // Process another packet with the old peer address on server side.