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

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

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 unified diff | Download patch
OLDNEW
(Empty)
1 #include <cinttypes>
2
3 #include "base/port.h"
4 #include "base/stringprintf.h"
5 #include "net/quic/core/congestion_control/simulation/switch.h"
6 #include "util/gtl/ptr_util.h"
7
8 namespace net {
9 namespace simulation {
10
11 Switch::Switch(Simulator* simulator,
12 std::string name,
13 SwitchPortNumber port_count,
14 QuicByteCount queue_capacity) {
15 for (size_t port_number = 1; port_number <= port_count; port_number++) {
16 ports_.emplace_back(simulator, StringPrintf("%s (port %" PRIuS ")",
17 name.c_str(), port_number),
18 this, port_number, queue_capacity);
19 }
20 }
21
22 Switch::Port::Port(Simulator* simulator,
23 std::string name,
24 Switch* parent,
25 SwitchPortNumber port_number,
26 QuicByteCount queue_capacity)
27 : Endpoint(simulator, name),
28 parent_(parent),
29 port_number_(port_number),
30 connected_(false),
31 queue_(simulator,
32 StringPrintf("%s (queue)", name.c_str()),
33 queue_capacity) {}
34
35 void Switch::Port::AcceptPacket(std::unique_ptr<Packet> packet) {
36 parent_->DispatchPacket(port_number_, std::move(packet));
37 }
38
39 void Switch::Port::EnqueuePacket(std::unique_ptr<Packet> packet) {
40 queue_.AcceptPacket(std::move(packet));
41 }
42
43 UnconstrainedPortInterface* Switch::Port::GetRxPort() {
44 return this;
45 }
46
47 void Switch::Port::SetTxPort(ConstrainedPortInterface* port) {
48 queue_.set_tx_port(port);
49 connected_ = true;
50 }
51
52 void Switch::Port::Act() {}
53
54 void Switch::DispatchPacket(SwitchPortNumber port_number,
55 std::unique_ptr<Packet> packet) {
56 Port* source_port = &ports_[port_number - 1];
57 const auto source_mapping_it = switching_table_.find(packet->source);
58 if (source_mapping_it == switching_table_.end()) {
59 switching_table_.emplace(packet->source, source_port);
60 }
61
62 const auto destination_mapping_it =
63 switching_table_.find(packet->destination);
64 if (destination_mapping_it != switching_table_.end()) {
65 destination_mapping_it->second->EnqueuePacket(std::move(packet));
66 return;
67 }
68
69 // If no mapping is available yet, broadcast the packet to all ports
70 // different from the source.
71 for (Port& egress_port : ports_) {
72 if (!egress_port.connected()) {
73 continue;
74 }
75 egress_port.EnqueuePacket(gtl::MakeUnique<Packet>(*packet));
76 }
77 }
78
79 } // namespace simulation
80 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698