Skip to content

Commit 76e18bf

Browse files
committed
修改了 switch-node.cc
1 parent 98a8f4d commit 76e18bf

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

simulation/src/point-to-point/model/switch-node.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ns3/int-header.h"
1313
#include "ns3/simulator.h"
1414
#include <cmath>
15+
#include <unordered_set>
1516

1617
namespace ns3 {
1718

@@ -60,6 +61,7 @@ SwitchNode::SwitchNode(){
6061
m_u[i] = 0;
6162
}
6263

64+
std::unordered_set<uint64_t> printedFlows;
6365
int SwitchNode::GetOutDev(Ptr<const Packet> p, CustomHeader &ch){
6466
// look up entries
6567
auto entry = m_rtTable.find(ch.dip);
@@ -78,6 +80,9 @@ int SwitchNode::GetOutDev(Ptr<const Packet> p, CustomHeader &ch){
7880
} buf;
7981
buf.u32[0] = ch.sip;
8082
buf.u32[1] = ch.dip;
83+
uint32_t srcIp = ch.sip;
84+
uint32_t dstIp = ch.dip;
85+
uint64_t flowId = ((uint64_t)srcIp << 32) | dstIp;
8186
if (ch.l3Prot == 0x6)
8287
buf.u32[2] = ch.tcp.sport | ((uint32_t)ch.tcp.dport << 16);
8388
else if (ch.l3Prot == 0x11)
@@ -86,6 +91,10 @@ int SwitchNode::GetOutDev(Ptr<const Packet> p, CustomHeader &ch){
8691
buf.u32[2] = ch.ack.sport | ((uint32_t)ch.ack.dport << 16);
8792

8893
uint32_t idx = EcmpHash(buf.u8, 12, m_ecmpSeed) % nexthops.size();
94+
if (nexthops.size() > 0 && printedFlows.find(flowId) == printedFlows.end()) {
95+
std::cout << "src IP: "<< ((srcIp >> 24) & 0xFF) << "." << ((srcIp >> 16) & 0xFF) << "." << ((srcIp >> 8) & 0xFF) << "." << (srcIp & 0xFF)<<">"<<"Destination IP: "<< ((dstIp >> 24) & 0xFF) << "." << ((dstIp >> 16) & 0xFF) << "." << ((dstIp >> 8) & 0xFF) << "." << (dstIp & 0xFF)<<" in switch: "<<m_id<<" ECMP(header): "<<idx<< " selected interface: " << nexthops[idx]<<std::endl;
96+
printedFlows.insert(flowId); //记录该流已经打印
97+
}
8998
return nexthops[idx];
9099
}
91100

0 commit comments

Comments
 (0)