OLD | NEW |
(Empty) | |
| 1 #ifndef NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_ |
| 2 #define NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_ |
| 3 |
| 4 #include <unordered_map> |
| 5 |
| 6 #include "net/quic/core/congestion_control/simulation/queue.h" |
| 7 |
| 8 namespace net { |
| 9 namespace simulation { |
| 10 |
| 11 typedef size_t SwitchPortNumber; |
| 12 |
| 13 // Simulates a network switch with simple persistent learning scheme and queues |
| 14 // on every output port. |
| 15 class Switch { |
| 16 public: |
| 17 Switch(Simulator* simulator, |
| 18 std::std::string name, |
| 19 SwitchPortNumber port_count, |
| 20 QuicByteCount queue_capacity); |
| 21 |
| 22 // Returns Endpoint associated with the port under number |port_number|. Just |
| 23 // like on most real switches, port numbering starts with 1. |
| 24 inline Endpoint* port(SwitchPortNumber port_number) { |
| 25 DCHECK_NE(port_number, 0); |
| 26 return &ports_[port_number - 1]; |
| 27 } |
| 28 |
| 29 private: |
| 30 class Port : public Endpoint, public UnconstrainedPortInterface { |
| 31 public: |
| 32 Port(Simulator* simulator, |
| 33 std::std::string name, |
| 34 Switch* parent, |
| 35 SwitchPortNumber port_number, |
| 36 QuicByteCount queue_capacity); |
| 37 Port(Port&&) = delete; |
| 38 ~Port() override {} |
| 39 |
| 40 // Accepts packet to be routed into the switch. |
| 41 void AcceptPacket(std::unique_ptr<Packet> packet) override; |
| 42 // Enqueue packet to be routed out of the switch. |
| 43 void EnqueuePacket(std::unique_ptr<Packet> packet); |
| 44 |
| 45 UnconstrainedPortInterface* GetRxPort() override; |
| 46 void SetTxPort(ConstrainedPortInterface* port) override; |
| 47 |
| 48 void Act() override; |
| 49 |
| 50 inline bool connected() { return connected_; } |
| 51 |
| 52 private: |
| 53 Switch* parent_; |
| 54 SwitchPortNumber port_number_; |
| 55 bool connected_; |
| 56 |
| 57 Queue queue_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(Port); |
| 60 }; |
| 61 |
| 62 // Sends the packet to the appropriate port, or to all ports if the |
| 63 // appropriate port is not known. |
| 64 void DispatchPacket(SwitchPortNumber port_number, |
| 65 std::unique_ptr<Packet> packet); |
| 66 |
| 67 std::deque<Port> ports_; |
| 68 std::unordered_map<std::std::string, Port*> switching_table_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(Switch); |
| 71 }; |
| 72 |
| 73 } // namespace simulation |
| 74 } // namespace net |
| 75 |
| 76 #endif // NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_SWITCH_H_ |
OLD | NEW |