Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: webrtc/media/sctp/sctptransport_unittest.cc

Issue 2743653005: Fixed invalid filtering of SCTP datachannel packets on high ports. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/sctp/sctptransport.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 }; 123 };
124 124
125 // SCTP Data Engine testing framework. 125 // SCTP Data Engine testing framework.
126 class SctpTransportTest : public testing::Test, public sigslot::has_slots<> { 126 class SctpTransportTest : public testing::Test, public sigslot::has_slots<> {
127 protected: 127 protected:
128 // usrsctp uses the NSS random number generator on non-Android platforms, 128 // usrsctp uses the NSS random number generator on non-Android platforms,
129 // so we need to initialize SSL. 129 // so we need to initialize SSL.
130 static void SetUpTestCase() {} 130 static void SetUpTestCase() {}
131 131
132 void SetupConnectedTransportsWithTwoStreams() { 132 void SetupConnectedTransportsWithTwoStreams() {
133 SetupConnectedTransportsWithTwoStreams(kTransport1Port, kTransport2Port);
134 }
135
136 void SetupConnectedTransportsWithTwoStreams(int port1, int port2) {
133 fake_dtls1_.reset(new FakeDtlsTransport("fake dtls 1", 0)); 137 fake_dtls1_.reset(new FakeDtlsTransport("fake dtls 1", 0));
134 fake_dtls2_.reset(new FakeDtlsTransport("fake dtls 2", 0)); 138 fake_dtls2_.reset(new FakeDtlsTransport("fake dtls 2", 0));
135 recv1_.reset(new SctpFakeDataReceiver()); 139 recv1_.reset(new SctpFakeDataReceiver());
136 recv2_.reset(new SctpFakeDataReceiver()); 140 recv2_.reset(new SctpFakeDataReceiver());
137 transport1_.reset(CreateTransport(fake_dtls1_.get(), recv1_.get())); 141 transport1_.reset(CreateTransport(fake_dtls1_.get(), recv1_.get()));
138 transport1_->set_debug_name_for_testing("transport1"); 142 transport1_->set_debug_name_for_testing("transport1");
139 transport1_->SignalReadyToSendData.connect( 143 transport1_->SignalReadyToSendData.connect(
140 this, &SctpTransportTest::OnChan1ReadyToSend); 144 this, &SctpTransportTest::OnChan1ReadyToSend);
141 transport2_.reset(CreateTransport(fake_dtls2_.get(), recv2_.get())); 145 transport2_.reset(CreateTransport(fake_dtls2_.get(), recv2_.get()));
142 transport2_->set_debug_name_for_testing("transport2"); 146 transport2_->set_debug_name_for_testing("transport2");
143 transport2_->SignalReadyToSendData.connect( 147 transport2_->SignalReadyToSendData.connect(
144 this, &SctpTransportTest::OnChan2ReadyToSend); 148 this, &SctpTransportTest::OnChan2ReadyToSend);
145 // Setup two connected transports ready to send and receive. 149 // Setup two connected transports ready to send and receive.
146 bool asymmetric = false; 150 bool asymmetric = false;
147 fake_dtls1_->SetDestination(fake_dtls2_.get(), asymmetric); 151 fake_dtls1_->SetDestination(fake_dtls2_.get(), asymmetric);
148 152
149 LOG(LS_VERBOSE) << "Transport setup ----------------------------- "; 153 LOG(LS_VERBOSE) << "Transport setup ----------------------------- ";
150 AddStream(1); 154 AddStream(1);
151 AddStream(2); 155 AddStream(2);
152 156
153 LOG(LS_VERBOSE) << "Connect the transports -----------------------------"; 157 LOG(LS_VERBOSE) << "Connect the transports -----------------------------";
154 // Both transports need to have started (with matching ports) for an 158 // Both transports need to have started (with matching ports) for an
155 // association to be formed. 159 // association to be formed.
156 transport1_->Start(kTransport1Port, kTransport2Port); 160 transport1_->Start(port1, port2);
157 transport2_->Start(kTransport2Port, kTransport1Port); 161 transport2_->Start(port2, port1);
158 } 162 }
159 163
160 bool AddStream(int sid) { 164 bool AddStream(int sid) {
161 bool ret = true; 165 bool ret = true;
162 ret = ret && transport1_->OpenStream(sid); 166 ret = ret && transport1_->OpenStream(sid);
163 ret = ret && transport2_->OpenStream(sid); 167 ret = ret && transport2_->OpenStream(sid);
164 return ret; 168 return ret;
165 } 169 }
166 170
167 SctpTransport* CreateTransport(FakeDtlsTransport* fake_dtls, 171 SctpTransport* CreateTransport(FakeDtlsTransport* fake_dtls,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 448 }
445 449
446 // Trying to send data for a nonexistent stream should fail. 450 // Trying to send data for a nonexistent stream should fail.
447 TEST_F(SctpTransportTest, SendDataWithNonexistentStreamFails) { 451 TEST_F(SctpTransportTest, SendDataWithNonexistentStreamFails) {
448 SetupConnectedTransportsWithTwoStreams(); 452 SetupConnectedTransportsWithTwoStreams();
449 SendDataResult result; 453 SendDataResult result;
450 EXPECT_FALSE(SendData(transport2(), 123, "some data", &result)); 454 EXPECT_FALSE(SendData(transport2(), 123, "some data", &result));
451 EXPECT_EQ(SDR_ERROR, result); 455 EXPECT_EQ(SDR_ERROR, result);
452 } 456 }
453 457
458 TEST_F(SctpTransportTest, SendDataHighPorts) {
459 SetupConnectedTransportsWithTwoStreams(32768, 32769);
460
461 SendDataResult result;
462 ASSERT_TRUE(SendData(transport1(), 1, "hello?", &result));
463 EXPECT_EQ(SDR_SUCCESS, result);
464 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), kDefaultTimeout);
465
466 ASSERT_TRUE(SendData(transport2(), 2, "hi transport1", &result));
467 EXPECT_EQ(SDR_SUCCESS, result);
468 EXPECT_TRUE_WAIT(ReceivedData(receiver1(), 2, "hi transport1"),
469 kDefaultTimeout);
470 }
471
454 TEST_F(SctpTransportTest, ClosesRemoteStream) { 472 TEST_F(SctpTransportTest, ClosesRemoteStream) {
455 SetupConnectedTransportsWithTwoStreams(); 473 SetupConnectedTransportsWithTwoStreams();
456 SignalTransportClosedObserver transport1_sig_receiver, 474 SignalTransportClosedObserver transport1_sig_receiver,
457 transport2_sig_receiver; 475 transport2_sig_receiver;
458 transport1_sig_receiver.BindSelf(transport1()); 476 transport1_sig_receiver.BindSelf(transport1());
459 transport2_sig_receiver.BindSelf(transport2()); 477 transport2_sig_receiver.BindSelf(transport2());
460 478
461 SendDataResult result; 479 SendDataResult result;
462 ASSERT_TRUE(SendData(transport1(), 1, "hello?", &result)); 480 ASSERT_TRUE(SendData(transport1(), 1, "hello?", &result));
463 EXPECT_EQ(SDR_SUCCESS, result); 481 EXPECT_EQ(SDR_SUCCESS, result);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 AddStream(1); 572 AddStream(1);
555 ASSERT_TRUE(SendData(transport1(), 1, "hi?", &result)); 573 ASSERT_TRUE(SendData(transport1(), 1, "hi?", &result));
556 EXPECT_EQ(SDR_SUCCESS, result); 574 EXPECT_EQ(SDR_SUCCESS, result);
557 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), kDefaultTimeout); 575 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), kDefaultTimeout);
558 transport1()->ResetStream(1); 576 transport1()->ResetStream(1);
559 EXPECT_TRUE_WAIT(transport2_sig_receiver.StreamCloseCount(1) == 2, 577 EXPECT_TRUE_WAIT(transport2_sig_receiver.StreamCloseCount(1) == 2,
560 kDefaultTimeout); 578 kDefaultTimeout);
561 } 579 }
562 580
563 } // namespace cricket 581 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/sctp/sctptransport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698