Skip to content

Commit 0dcbfee

Browse files
committed
Add load balance example
1 parent 34cc027 commit 0dcbfee

18 files changed

Lines changed: 3475 additions & 78 deletions

examples/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ build_lib_example(
7272
${libcsma}
7373
)
7474

75+
# 4 hosts 4 switches topology [Link Monitoring]
76+
build_lib_example(
77+
NAME p4-spine-leaf-topo
78+
SOURCE_FILES p4-spine-leaf-topo.cc
79+
LIBRARIES_TO_LINK
80+
${libp4sim}
81+
${libinternet}
82+
${libapplications}
83+
${libnetwork}
84+
${libcsma}
85+
)
86+
7587
# [ ================= PSA Arch ================= ]
7688

7789
# simple 2 hosts 1 switch topology [ipv4 forwarding]

examples/p4-basic-tunnel.cc

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ double client_stop_time = client_start_time + 5; // sending time
4444
double sink_stop_time = client_stop_time + 5;
4545
double global_stop_time = sink_stop_time + 5;
4646

47-
bool first_tx = true;
48-
bool first_rx = true;
47+
// bool first_tx = true;
48+
// bool first_rx = true;
4949
int counter_sender_10 = 10;
5050
int counter_receiver_10 = 10;
5151
double first_packet_send_time_tx = 0.0;
@@ -91,81 +91,29 @@ ConvertMacToHex(Address macAddr)
9191
void
9292
TxCallback(Ptr<const Packet> packet)
9393
{
94-
if (first_tx)
95-
{
96-
// here we just simple jump the first 10 pkts (include some of ARP packets)
97-
first_packet_send_time_tx = Simulator::Now().GetSeconds();
98-
counter_sender_10--;
99-
if (counter_sender_10 == 0)
100-
{
101-
first_tx = false;
102-
}
103-
}
104-
else
105-
{
106-
totalTxBytes_1 += packet->GetSize();
107-
last_packet_send_time_tx = Simulator::Now().GetSeconds();
108-
}
94+
totalTxBytes_1 += packet->GetSize();
95+
last_packet_send_time_tx = Simulator::Now().GetSeconds();
10996
}
11097

11198
void
11299
RxCallback(Ptr<const Packet> packet, const Address& addr)
113100
{
114-
if (first_rx)
115-
{
116-
// here we just simple jump the first 10 pkts (include some of ARP packets)
117-
first_packet_received_time_rx = Simulator::Now().GetSeconds();
118-
counter_receiver_10--;
119-
if (counter_receiver_10 == 0)
120-
{
121-
first_rx = false;
122-
}
123-
}
124-
else
125-
{
126-
totalRxBytes_1 += packet->GetSize();
127-
last_packet_received_time_rx = Simulator::Now().GetSeconds();
128-
}
101+
totalRxBytes_1 += packet->GetSize();
102+
last_packet_received_time_rx = Simulator::Now().GetSeconds();
129103
}
130104

131105
void
132106
TxCallback_2(Ptr<const Packet> packet)
133107
{
134-
if (first_tx)
135-
{
136-
// here we just simple jump the first 10 pkts (include some of ARP packets)
137-
first_packet_send_time_tx = Simulator::Now().GetSeconds();
138-
counter_sender_10--;
139-
if (counter_sender_10 == 0)
140-
{
141-
first_tx = false;
142-
}
143-
}
144-
else
145-
{
146-
totalTxBytes_2 += packet->GetSize();
147-
last_packet_send_time_tx = Simulator::Now().GetSeconds();
148-
}
108+
totalTxBytes_2 += packet->GetSize();
109+
last_packet_send_time_tx = Simulator::Now().GetSeconds();
149110
}
150111

151112
void
152113
RxCallback_2(Ptr<const Packet> packet, const Address& addr)
153114
{
154-
if (first_rx)
155-
{
156-
// here we just simple jump the first 10 pkts (include some of ARP packets)
157-
first_packet_received_time_rx = Simulator::Now().GetSeconds();
158-
counter_receiver_10--;
159-
if (counter_receiver_10 == 0)
160-
{
161-
first_rx = false;
162-
}
163-
}
164-
else
165-
{
166-
totalRxBytes_2 += packet->GetSize();
167-
last_packet_received_time_rx = Simulator::Now().GetSeconds();
168-
}
115+
totalRxBytes_2 += packet->GetSize();
116+
last_packet_received_time_rx = Simulator::Now().GetSeconds();
169117
}
170118

171119
void
@@ -231,6 +179,8 @@ main(int argc, char* argv[])
231179
{
232180
LogComponentEnable("P4BasicTunnel", LOG_LEVEL_INFO);
233181

182+
Packet::EnablePrinting();
183+
234184
// ============================ parameters ============================
235185

236186
int running_number = 0;
@@ -397,7 +347,7 @@ main(int argc, char* argv[])
397347
// Bridge or P4 switch configuration
398348
P4Helper p4SwitchHelper;
399349
p4SwitchHelper.SetDeviceAttribute("JsonPath", StringValue(p4JsonPath));
400-
p4SwitchHelper.SetDeviceAttribute("ChannelType", UintegerValue(0));
350+
// p4SwitchHelper.SetDeviceAttribute("ChannelType", UintegerValue(0));
401351
p4SwitchHelper.SetDeviceAttribute("P4SwitchArch", UintegerValue(0));
402352
p4SwitchHelper.SetDeviceAttribute("ChannelType", UintegerValue(1));
403353

@@ -460,7 +410,7 @@ main(int argc, char* argv[])
460410
onOff1.SetAttribute("DataRate", StringValue(appDataRate[0]));
461411
onOff1.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
462412
onOff1.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
463-
// onOff1.SetAttribute ("MaxBytes", UintegerValue (3000));
413+
onOff1.SetAttribute("MaxBytes", UintegerValue(5000));
464414

465415
ApplicationContainer app1 = onOff1.Install(terminals.Get(clientI));
466416
app1.Start(Seconds(client_start_time));
@@ -491,15 +441,15 @@ main(int argc, char* argv[])
491441
onOff2.SetAttribute("DataRate", StringValue(appDataRate[1]));
492442
onOff2.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
493443
onOff2.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
494-
// onOff2.SetAttribute("MaxBytes", UintegerValue(500));
444+
onOff2.SetAttribute("MaxBytes", UintegerValue(10000));
495445

496446
ApplicationContainer app2 = onOff2.Install(terminals.Get(clientI));
497447
app2.Start(Seconds(client_start_time));
498448
app2.Stop(Seconds(client_stop_time));
499449

500450
// === Setup Tracing ===
501451
Ptr<OnOffApplication> ptr_app2 =
502-
DynamicCast<OnOffApplication>(terminals.Get(clientI)->GetApplication(0));
452+
DynamicCast<OnOffApplication>(terminals.Get(clientI)->GetApplication(1));
503453
ptr_app2->TraceConnectWithoutContext("Tx", MakeCallback(&TxCallback_2));
504454
sinkApp2.Get(0)->TraceConnectWithoutContext("Rx", MakeCallback(&RxCallback_2));
505455

0 commit comments

Comments
 (0)