Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cstdio> | 5 #include <cstdio> |
| 6 #include <cstdlib> | 6 #include <cstdlib> |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 base::Bind(&CheckByteCounters), | 113 base::Bind(&CheckByteCounters), |
| 114 base::TimeDelta::FromMilliseconds(100)); | 114 base::TimeDelta::FromMilliseconds(100)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 int main(int argc, char** argv) { | 117 int main(int argc, char** argv) { |
| 118 if (argc != 5 && argc != 3) { | 118 if (argc != 5 && argc != 3) { |
| 119 fprintf(stderr, | 119 fprintf(stderr, |
| 120 "Usage: udp_proxy <localport> <remotehost> <remoteport> <type>\n" | 120 "Usage: udp_proxy <localport> <remotehost> <remoteport> <type>\n" |
| 121 "or:\n" | 121 "or:\n" |
| 122 " udp_proxy <localport> <type>\n" | 122 " udp_proxy <localport> <type>\n" |
| 123 "Where type is one of: perfect, wifi, bad, evil\n"); | 123 "Where type is one of: perfect, wifi, bad, evil, ipp\n"); |
|
hubbe
2014/11/10 19:31:48
ipp is not very descriptive
Is there a better name
| |
| 124 exit(1); | 124 exit(1); |
| 125 } | 125 } |
| 126 | 126 |
| 127 base::AtExitManager exit_manager; | 127 base::AtExitManager exit_manager; |
| 128 CommandLine::Init(argc, argv); | 128 CommandLine::Init(argc, argv); |
| 129 InitLogging(logging::LoggingSettings()); | 129 InitLogging(logging::LoggingSettings()); |
| 130 | 130 |
| 131 net::IPAddressNumber remote_ip_number; | 131 net::IPAddressNumber remote_ip_number; |
| 132 net::IPAddressNumber local_ip_number; | 132 net::IPAddressNumber local_ip_number; |
| 133 std::string network_type; | 133 std::string network_type; |
| 134 int local_port = atoi(argv[1]); | 134 int local_port = atoi(argv[1]); |
| 135 int remote_port = 0; | 135 int remote_port = 0; |
| 136 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_number)); | 136 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_number)); |
| 137 | 137 |
| 138 if (argc == 5) { | 138 if (argc == 5) { |
| 139 // V2 proxy | 139 // V2 proxy |
| 140 CHECK(net::ParseIPLiteralToNumber(argv[2], &remote_ip_number)); | 140 CHECK(net::ParseIPLiteralToNumber(argv[2], &remote_ip_number)); |
| 141 remote_port = atoi(argv[3]); | 141 remote_port = atoi(argv[3]); |
| 142 network_type = argv[4]; | 142 network_type = argv[4]; |
| 143 } else { | 143 } else { |
| 144 // V1 proxy | 144 // V1 proxy |
| 145 network_type = argv[2]; | 145 network_type = argv[2]; |
| 146 } | 146 } |
| 147 net::IPEndPoint remote_endpoint(remote_ip_number, remote_port); | 147 net::IPEndPoint remote_endpoint(remote_ip_number, remote_port); |
| 148 net::IPEndPoint local_endpoint(local_ip_number, local_port); | 148 net::IPEndPoint local_endpoint(local_ip_number, local_port); |
| 149 scoped_ptr<media::cast::test::PacketPipe> in_pipe, out_pipe; | 149 scoped_ptr<media::cast::test::PacketPipe> in_pipe, out_pipe; |
| 150 scoped_ptr<media::cast::test::InterruptedPoissonProcess> ipp( | |
| 151 media::cast::test::DefaultInterruptedPoissonProcess()); | |
| 150 | 152 |
| 151 if (network_type == "perfect") { | 153 if (network_type == "perfect") { |
| 152 // No action needed. | 154 // No action needed. |
| 153 } else if (network_type == "wifi") { | 155 } else if (network_type == "wifi") { |
| 154 in_pipe = media::cast::test::WifiNetwork().Pass(); | 156 in_pipe = media::cast::test::WifiNetwork().Pass(); |
| 155 out_pipe = media::cast::test::WifiNetwork().Pass(); | 157 out_pipe = media::cast::test::WifiNetwork().Pass(); |
| 156 } else if (network_type == "bad") { | 158 } else if (network_type == "bad") { |
| 157 in_pipe = media::cast::test::BadNetwork().Pass(); | 159 in_pipe = media::cast::test::BadNetwork().Pass(); |
| 158 out_pipe = media::cast::test::BadNetwork().Pass(); | 160 out_pipe = media::cast::test::BadNetwork().Pass(); |
| 159 } else if (network_type == "evil") { | 161 } else if (network_type == "evil") { |
| 160 in_pipe = media::cast::test::EvilNetwork().Pass(); | 162 in_pipe = media::cast::test::EvilNetwork().Pass(); |
| 161 out_pipe = media::cast::test::EvilNetwork().Pass(); | 163 out_pipe = media::cast::test::EvilNetwork().Pass(); |
| 164 } else if (network_type == "ipp") { | |
| 165 in_pipe = ipp->NewBuffer(128 * 1024).Pass(); | |
| 166 out_pipe = ipp->NewBuffer(128 * 1024).Pass(); | |
| 162 } else { | 167 } else { |
| 163 fprintf(stderr, "Unknown network type.\n"); | 168 fprintf(stderr, "Unknown network type.\n"); |
| 164 exit(1); | 169 exit(1); |
| 165 } | 170 } |
| 166 | 171 |
| 167 SetupByteCounters(&in_pipe, &in_pipe_input_counter, &in_pipe_output_counter); | 172 SetupByteCounters(&in_pipe, &in_pipe_input_counter, &in_pipe_output_counter); |
| 168 SetupByteCounters( | 173 SetupByteCounters( |
| 169 &out_pipe, &out_pipe_input_counter, &out_pipe_output_counter); | 174 &out_pipe, &out_pipe_input_counter, &out_pipe_output_counter); |
| 170 | 175 |
| 171 printf("Press Ctrl-C when done.\n"); | 176 printf("Press Ctrl-C when done.\n"); |
| 172 scoped_ptr<media::cast::test::UDPProxy> proxy( | 177 scoped_ptr<media::cast::test::UDPProxy> proxy( |
| 173 media::cast::test::UDPProxy::Create(local_endpoint, | 178 media::cast::test::UDPProxy::Create(local_endpoint, |
| 174 remote_endpoint, | 179 remote_endpoint, |
| 175 in_pipe.Pass(), | 180 in_pipe.Pass(), |
| 176 out_pipe.Pass(), | 181 out_pipe.Pass(), |
| 177 NULL)); | 182 NULL)); |
| 178 base::MessageLoop message_loop; | 183 base::MessageLoop message_loop; |
| 179 last_printout = base::TimeTicks::Now(); | 184 last_printout = base::TimeTicks::Now(); |
| 180 CheckByteCounters(); | 185 CheckByteCounters(); |
| 181 message_loop.Run(); | 186 message_loop.Run(); |
| 182 return 1; | 187 return 1; |
| 183 } | 188 } |
| OLD | NEW |