1// Copyright 2022 The Pigweed Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may not 4// use this file except in compliance with the License. You may obtain a copy of 5// the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12// License for the specific language governing permissions and limitations under 13// the License. 14syntax = "proto3"; 15 16package pw.transfer; 17 18option java_package = "pw.transfer"; 19option java_outer_classname = "ConfigProtos"; 20 21import "pw_protobuf_protos/status.proto"; 22 23message TransferAction { 24 enum ProtocolVersion { 25 option allow_alias = true; 26 UNKNOWN_VERSION = 0; 27 V1 = 1; 28 V2 = 2; 29 LATEST = 2; 30 } 31 32 // As transfers are always client initiated, TransferType is from the client's 33 // perspective. 34 enum TransferType { 35 UNKNOWN = 0; 36 WRITE_TO_SERVER = 1; 37 READ_FROM_SERVER = 2; 38 } 39 40 // Transfer resource ID to use for this transfer. 41 uint32 resource_id = 1; 42 43 // Path to the file that data should be read from or written to (depending on 44 // transfer_type). When reading from the server, this is the path the file 45 // is written to. When writing to the server, this is the path to the file 46 // that should be read from. 47 string file_path = 2; 48 49 // Whether to write to the server, or read from it. 50 TransferType transfer_type = 3; 51 52 // Expected final status of transfer operation. 53 pw.protobuf.StatusCode expected_status = 4; 54 55 // Protocol version to initiate the transfer with. 56 ProtocolVersion protocol_version = 5; 57 58 // Initial offset to start transfer with. Defaults to 0. 59 uint32 initial_offset = 6; 60} 61 62// Configuration for the integration test client. 63message ClientConfig { 64 // The sequence of transfer actions to perform during the lifetime of this 65 // client configuration. 66 repeated TransferAction transfer_actions = 1; 67 68 // The maximum number of times this client will attempt to send a packet 69 // before the transfer aborts due to a lack of response. 70 uint32 max_retries = 2; 71 72 // The maximum time this client will wait for a response to the first 73 // packet sent to the pw_transfer server before attempting to retry. Extending 74 // this can help work around cases where transfer initialization takes a long 75 // time. 76 // 77 // Note: This parameter is only supported on Java transfer clients. 78 // TODO(tpudlik): google.protobuf.Duration? 79 uint32 initial_chunk_timeout_ms = 3; 80 81 // The maximum amount of time this client will wait for a response to a sent 82 // packet before attempting to re-send the packet. 83 // 84 // TODO(tpudlik): google.protobuf.Duration? 85 uint32 chunk_timeout_ms = 4; 86 87 // Cumulative maximum number of times to retry over the course of the transfer 88 // before giving up. 89 uint32 max_lifetime_retries = 5; 90} 91 92// Stacks of paths to use when doing transfers. Each new initiated transfer 93// on this resource gets the next file path in the stack. Once the stack is 94// exhausted, new transfers on this resource fail as though this resource is 95// unregistered. 96message ServerResourceLocations { 97 // When a client reads from this server, this stack is used to determine which 98 // file path to read data from. 99 repeated string source_paths = 3; 100 101 // When a client writes to this server, this stack is used to determine which 102 // file path to write data to. 103 repeated string destination_paths = 4; 104 105 // If source_paths is exhausted or empty, this source path can be reused 106 // as a fallback indefinitely. 107 string default_source_path = 5; 108 109 // If destination_paths is exhausted or empty, this destination path can be 110 // reused as a fallback indefinitely. 111 string default_destination_path = 6; 112 113 // Defines whether or not the resource can be read from an offset 114 bool offsettable = 7; 115} 116 117// Configuration for the integration test server. 118message ServerConfig { 119 // A mapping of transfer resource ID to files to read from or write to. 120 map<uint32, ServerResourceLocations> resources = 1; 121 122 // Size of the chunk buffer used by this server's transfer thread, in bytes. 123 uint32 chunk_size_bytes = 2; 124 125 // Window size, in bytes. 126 uint32 pending_bytes = 3; 127 128 // TODO(tpudlik): google.protobuf.Duration? 129 uint32 chunk_timeout_seconds = 4; 130 uint32 transfer_service_retries = 5; 131 uint32 extend_window_divisor = 6; 132} 133 134// Configuration for the HdlcPacketizer proxy filter. 135message HdlcPacketizerConfig {} 136 137// Configuration for the DataDropper proxy filter. 138message DataDropperConfig { 139 // Rate at which to drop data 140 float rate = 1; 141 142 // Seed to use for the rand number generator used for determining 143 // when data is dropped. 144 int64 seed = 2; 145} 146 147// Configuration for the KeepDropQueue proxy filter. 148message KeepDropQueueConfig { 149 // A KeepDropQueue filter will alternate between keeping packets and dropping 150 // chunks of data based on a keep/drop queue provided during its creation. The 151 // queue is looped over unless a negative element is found. A negative number 152 // is effectively the same as a value of infinity. 153 // 154 // This filter is typically most pratical when used with a packetizer so data 155 // can be dropped as distinct packets. 156 // 157 // Examples: 158 // 159 // keep_drop_queue = [3, 2]: 160 // Keeps 3 packets, 161 // Drops 2 packets, 162 // Keeps 3 packets, 163 // Drops 2 packets, 164 // ... [loops indefinitely] 165 // 166 // keep_drop_queue = [5, 99, 1, -1]: 167 // Keeps 5 packets, 168 // Drops 99 packets, 169 // Keeps 1 packet, 170 // Drops all further packets. 171 repeated int32 keep_drop_queue = 1; 172 173 // If true, only transfer chunks will be counted as part of the keep/drop 174 // cycle. All other types of data received will always be forwarded. 175 // Useful for testing specific transfer failure modes. Defaults to false. 176 bool only_consider_transfer_chunks = 2; 177} 178 179// Configuration for the RateLimiter proxy filter. 180message RateLimiterConfig { 181 // Rate limit, in bytes/sec. 182 float rate = 1; 183} 184 185// Configuration for the DataTransposer proxy filter. 186message DataTransposerConfig { 187 // Rate at which to transpose data. Probability of transposition 188 // between 0.0 and 1.0. 189 float rate = 1; 190 191 // Maximum time a chunk of data will be held for Transposition. After this 192 // time has elapsed, the packet is sent in order. 193 float timeout = 2; 194 195 // Seed to use for the rand number generator used for determining 196 // when data is transposed. 197 int64 seed = 3; 198} 199 200// Configuration for the ServerFailure proxy filter. 201message ServerFailureConfig { 202 // A list of numbers of packets to send before dropping all subsequent 203 // packets until a TRANSFER_START packet is seen. This process is 204 // repeated for each element in packets_before_failure. After that list 205 // is exhausted, ServerFailure will send all packets. 206 repeated uint32 packets_before_failure = 1; 207 208 // By default, the ServerFailure starts counting packets after receiving a 209 // transfer START packet. If `start_immediately` is set to `true`, the filter 210 // will begin counting packets as soon as it is initialized, before the first 211 // START is seen. 212 bool start_immediately = 2; 213 214 // If true, `packets_before_failure` will only be incremented when a transfer 215 // chunk is processed, and only transfer chunks will be dropped once the limit 216 // is reached. All other types of data received will always be forwarded. 217 // Useful for testing specific transfer failure modes. Defaults to false. 218 bool only_consider_transfer_chunks = 3; 219} 220 221// Configuration for the WindowPacketDropper proxy filter. 222message WindowPacketDropperConfig { 223 // The nth packet of every window to drop. 224 uint32 window_packet_to_drop = 1; 225} 226 227// Configuration for a single stage in the proxy filter stack. 228message FilterConfig { 229 oneof filter { 230 HdlcPacketizerConfig hdlc_packetizer = 1; 231 DataDropperConfig data_dropper = 2; 232 RateLimiterConfig rate_limiter = 3; 233 DataTransposerConfig data_transposer = 4; 234 ServerFailureConfig server_failure = 5; 235 KeepDropQueueConfig keep_drop_queue = 6; 236 WindowPacketDropperConfig window_packet_dropper = 7; 237 } 238} 239 240message ProxyConfig { 241 // Filters are listed in order of execution. I.e. the first filter listed 242 // will get the received data first then pass it on the the second listed 243 // filter. That process repeats until the last filter send the data to the 244 // other side of the proxy. 245 repeated FilterConfig client_filter_stack = 1; 246 repeated FilterConfig server_filter_stack = 2; 247} 248