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

Unified Diff: net/quic/core/congestion_control/simulation/switch.h

Issue 2323963002: Implement an event-based simulator for QuicConnection (Closed)
Patch Set: Adding missing files. 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 side-by-side diff with in-line comments
Download patch
Index: net/quic/core/congestion_control/simulation/switch.h
diff --git a/net/quic/core/congestion_control/simulation/switch.h b/net/quic/core/congestion_control/simulation/switch.h
new file mode 100644
index 0000000000000000000000000000000000000000..6a2a9d01bbb7029a057dde707a52ac6267b6efc5
--- /dev/null
+++ b/net/quic/core/congestion_control/simulation/switch.h
@@ -0,0 +1,76 @@
+#ifndef NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_
+#define NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_
+
+#include <unordered_map>
+
+#include "net/quic/core/congestion_control/simulation/queue.h"
+
+namespace net {
+namespace simulation {
+
+typedef size_t SwitchPortNumber;
+
+// Simulates a network switch with simple persistent learning scheme and queues
+// on every output port.
+class Switch {
+ public:
+ Switch(Simulator* simulator,
+ std::std::string name,
+ SwitchPortNumber port_count,
+ QuicByteCount queue_capacity);
+
+ // Returns Endpoint associated with the port under number |port_number|. Just
+ // like on most real switches, port numbering starts with 1.
+ inline Endpoint* port(SwitchPortNumber port_number) {
+ DCHECK_NE(port_number, 0);
+ return &ports_[port_number - 1];
+ }
+
+ private:
+ class Port : public Endpoint, public UnconstrainedPortInterface {
+ public:
+ Port(Simulator* simulator,
+ std::std::string name,
+ Switch* parent,
+ SwitchPortNumber port_number,
+ QuicByteCount queue_capacity);
+ Port(Port&&) = delete;
+ ~Port() override {}
+
+ // Accepts packet to be routed into the switch.
+ void AcceptPacket(std::unique_ptr<Packet> packet) override;
+ // Enqueue packet to be routed out of the switch.
+ void EnqueuePacket(std::unique_ptr<Packet> packet);
+
+ UnconstrainedPortInterface* GetRxPort() override;
+ void SetTxPort(ConstrainedPortInterface* port) override;
+
+ void Act() override;
+
+ inline bool connected() { return connected_; }
+
+ private:
+ Switch* parent_;
+ SwitchPortNumber port_number_;
+ bool connected_;
+
+ Queue queue_;
+
+ DISALLOW_COPY_AND_ASSIGN(Port);
+ };
+
+ // Sends the packet to the appropriate port, or to all ports if the
+ // appropriate port is not known.
+ void DispatchPacket(SwitchPortNumber port_number,
+ std::unique_ptr<Packet> packet);
+
+ std::deque<Port> ports_;
+ std::unordered_map<std::std::string, Port*> switching_table_;
+
+ DISALLOW_COPY_AND_ASSIGN(Switch);
+};
+
+} // namespace simulation
+} // namespace net
+
+#endif // NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_

Powered by Google App Engine
This is Rietveld 408576698