| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_QUIC_TEST_TOOLS_SIMULATOR_SWITCH_H_ | 5 #ifndef NET_QUIC_TEST_TOOLS_SIMULATOR_SWITCH_H_ |
| 6 #define NET_QUIC_TEST_TOOLS_SIMULATOR_SWITCH_H_ | 6 #define NET_QUIC_TEST_TOOLS_SIMULATOR_SWITCH_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 | 9 |
| 10 #include "net/quic/test_tools/simulator/queue.h" | 10 #include "net/quic/test_tools/simulator/queue.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 QuicByteCount queue_capacity); | 24 QuicByteCount queue_capacity); |
| 25 ~Switch(); | 25 ~Switch(); |
| 26 | 26 |
| 27 // Returns Endpoint associated with the port under number |port_number|. Just | 27 // Returns Endpoint associated with the port under number |port_number|. Just |
| 28 // like on most real switches, port numbering starts with 1. | 28 // like on most real switches, port numbering starts with 1. |
| 29 inline Endpoint* port(SwitchPortNumber port_number) { | 29 inline Endpoint* port(SwitchPortNumber port_number) { |
| 30 DCHECK_NE(port_number, 0u); | 30 DCHECK_NE(port_number, 0u); |
| 31 return &ports_[port_number - 1]; | 31 return &ports_[port_number - 1]; |
| 32 } | 32 } |
| 33 | 33 |
| 34 inline const Queue* port_queue(SwitchPortNumber port_number) { |
| 35 return ports_[port_number - 1].queue(); |
| 36 } |
| 37 |
| 34 private: | 38 private: |
| 35 class Port : public Endpoint, public UnconstrainedPortInterface { | 39 class Port : public Endpoint, public UnconstrainedPortInterface { |
| 36 public: | 40 public: |
| 37 Port(Simulator* simulator, | 41 Port(Simulator* simulator, |
| 38 std::string name, | 42 std::string name, |
| 39 Switch* parent, | 43 Switch* parent, |
| 40 SwitchPortNumber port_number, | 44 SwitchPortNumber port_number, |
| 41 QuicByteCount queue_capacity); | 45 QuicByteCount queue_capacity); |
| 42 Port(Port&&) = delete; | 46 Port(Port&&) = delete; |
| 43 ~Port() override {} | 47 ~Port() override {} |
| 44 | 48 |
| 45 // Accepts packet to be routed into the switch. | 49 // Accepts packet to be routed into the switch. |
| 46 void AcceptPacket(std::unique_ptr<Packet> packet) override; | 50 void AcceptPacket(std::unique_ptr<Packet> packet) override; |
| 47 // Enqueue packet to be routed out of the switch. | 51 // Enqueue packet to be routed out of the switch. |
| 48 void EnqueuePacket(std::unique_ptr<Packet> packet); | 52 void EnqueuePacket(std::unique_ptr<Packet> packet); |
| 49 | 53 |
| 50 UnconstrainedPortInterface* GetRxPort() override; | 54 UnconstrainedPortInterface* GetRxPort() override; |
| 51 void SetTxPort(ConstrainedPortInterface* port) override; | 55 void SetTxPort(ConstrainedPortInterface* port) override; |
| 52 | 56 |
| 53 void Act() override; | 57 void Act() override; |
| 54 | 58 |
| 55 inline bool connected() { return connected_; } | 59 inline bool connected() const { return connected_; } |
| 60 inline const Queue* queue() const { return &queue_; } |
| 56 | 61 |
| 57 private: | 62 private: |
| 58 Switch* parent_; | 63 Switch* parent_; |
| 59 SwitchPortNumber port_number_; | 64 SwitchPortNumber port_number_; |
| 60 bool connected_; | 65 bool connected_; |
| 61 | 66 |
| 62 Queue queue_; | 67 Queue queue_; |
| 63 | 68 |
| 64 DISALLOW_COPY_AND_ASSIGN(Port); | 69 DISALLOW_COPY_AND_ASSIGN(Port); |
| 65 }; | 70 }; |
| 66 | 71 |
| 67 // Sends the packet to the appropriate port, or to all ports if the | 72 // Sends the packet to the appropriate port, or to all ports if the |
| 68 // appropriate port is not known. | 73 // appropriate port is not known. |
| 69 void DispatchPacket(SwitchPortNumber port_number, | 74 void DispatchPacket(SwitchPortNumber port_number, |
| 70 std::unique_ptr<Packet> packet); | 75 std::unique_ptr<Packet> packet); |
| 71 | 76 |
| 72 std::deque<Port> ports_; | 77 std::deque<Port> ports_; |
| 73 std::unordered_map<std::string, Port*> switching_table_; | 78 std::unordered_map<std::string, Port*> switching_table_; |
| 74 | 79 |
| 75 DISALLOW_COPY_AND_ASSIGN(Switch); | 80 DISALLOW_COPY_AND_ASSIGN(Switch); |
| 76 }; | 81 }; |
| 77 | 82 |
| 78 } // namespace simulator | 83 } // namespace simulator |
| 79 } // namespace net | 84 } // namespace net |
| 80 | 85 |
| 81 #endif // NET_QUIC_TEST_TOOLS_SIMULATOR_SWITCH_H_ | 86 #endif // NET_QUIC_TEST_TOOLS_SIMULATOR_SWITCH_H_ |
| OLD | NEW |