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

Side by Side Diff: net/quic/core/congestion_control/simulation/switch.h

Issue 2322233004: Landing Recent QUIC changes until Sun Sep 4 03:41:00 (Closed)
Patch Set: Remove simulation files from the build. Created 4 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_
6 #define NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_
7
8 #include <unordered_map>
9
10 #include "net/quic/core/congestion_control/simulation/queue.h"
11
12 namespace net {
13 namespace simulation {
14
15 typedef size_t SwitchPortNumber;
16
17 // Simulates a network switch with simple persistent learning scheme and queues
18 // on every output port.
19 class Switch {
20 public:
21 Switch(Simulator* simulator,
22 std::string name,
23 SwitchPortNumber port_count,
24 QuicByteCount queue_capacity);
25 ~Switch();
26
27 // Returns Endpoint associated with the port under number |port_number|. Just
28 // like on most real switches, port numbering starts with 1.
29 inline Endpoint* port(SwitchPortNumber port_number) {
30 DCHECK_NE(port_number, 0u);
31 return &ports_[port_number - 1];
32 }
33
34 private:
35 class Port : public Endpoint, public UnconstrainedPortInterface {
36 public:
37 Port(Simulator* simulator,
38 std::string name,
39 Switch* parent,
40 SwitchPortNumber port_number,
41 QuicByteCount queue_capacity);
42 Port(Port&&) = delete;
43 ~Port() override {}
44
45 // Accepts packet to be routed into the switch.
46 void AcceptPacket(std::unique_ptr<Packet> packet) override;
47 // Enqueue packet to be routed out of the switch.
48 void EnqueuePacket(std::unique_ptr<Packet> packet);
49
50 UnconstrainedPortInterface* GetRxPort() override;
51 void SetTxPort(ConstrainedPortInterface* port) override;
52
53 void Act() override;
54
55 inline bool connected() { return connected_; }
56
57 private:
58 Switch* parent_;
59 SwitchPortNumber port_number_;
60 bool connected_;
61
62 Queue queue_;
63
64 DISALLOW_COPY_AND_ASSIGN(Port);
65 };
66
67 // Sends the packet to the appropriate port, or to all ports if the
68 // appropriate port is not known.
69 void DispatchPacket(SwitchPortNumber port_number,
70 std::unique_ptr<Packet> packet);
71
72 std::deque<Port> ports_;
73 std::unordered_map<std::string, Port*> switching_table_;
74
75 DISALLOW_COPY_AND_ASSIGN(Switch);
76 };
77
78 } // namespace simulation
79 } // namespace net
80
81 #endif // NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_
OLDNEW
« no previous file with comments | « net/quic/core/congestion_control/simulation/simulator_test.cc ('k') | net/quic/core/congestion_control/simulation/switch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698