I am trying to simulate a fattree network in NS3. I have Udp traffic generated between two hosts the sender and the receiver having 192.168.1.1 and 192.168.1.7 respectively as source and destination ip addresses , the udp traffic passing by several switches (ofswitch13 switches) to reach it's destination. Then I use

Config::Connect("NodeList/*/$ns3::Node/$ns3::OFSwitch13Device/PortList/*/$ns3::OFSwitch13Port/SwitchPortRx"

Or

Config::Connect("/NodeList/*/DeviceList/*/MacRx", MakeCallback(&TracePacketReceive));

to fire my sink method TracePacketReceive(string context,Ptr packet) which is called successfully :

void TracePacketReceive(string context,Ptr<const Packet> packet)
    {
        regex pattern("[0-9]+");
        cout << context << endl;
        smatch sm;
        regex_search(context, sm, pattern);
        
        cout << stoi(sm.str()) - 6 << " here" << endl;
        cout << "txPacket: " << packet->GetSize() << " \t simTime: " <<    
                                                            Simulator::Now().GetSeconds() << endl;
        

    Ptr<Packet> p = packet->Copy();
    Ipv4Header ipHeader;
    p->PeekHeader(ipHeader);

    
    Ipv4Address sourceIp = Ipv4Address::ConvertFrom(ipHeader.GetSource());
    Ipv4Address destIp = ipHeader.GetDestination();

    std::cout << "Source IP: " <<  sourceIp << std::endl;
    std::cout << "Destination IP: " << destIp << std::endl;
    
    }

but i'm receiving the IP address "102.102.102.102" as the output for both the source and destination IP addresses as shown below:

this is the output of Config::Connect("/NodeList/*/DeviceList/*/MacRx", MakeCallback(&TracePacketReceive));

/NodeList/0/DeviceList/0/MacTx
-6 here
txPacket: 558    simTime: 7.66183
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
/NodeList/7/DeviceList/2/MacTx
1 here
txPacket: 558    simTime: 7.66194
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
/NodeList/8/DeviceList/1/MacTx
2 here
txPacket: 558    simTime: 7.66305
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
/NodeList/11/DeviceList/3/MacTx
5 here
txPacket: 558    simTime: 7.66416
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
/NodeList/12/DeviceList/3/MacTx

this is the output of

Config::Connect("NodeList/*/$ns3::Node/$ns3::OFSwitch13Device/PortList/*/$ns3::OFSwitch13Port/SwitchPortRx"

NodeList/0/$ns3::Node/$ns3::OFSwitch13Device/PortList/0/$ns3::OFSwitch13Port/SwitchPortRx
-6 here
txPacket: 558    simTime: 7.66183
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
/NodeList/7/DeviceList/2/MacTx
1 here
txPacket: 558    simTime: 7.66194
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
NodeList/8/$ns3::Node/$ns3::OFSwitch13Device/PortList/1/$ns3::OFSwitch13Port/SwitchPortRx
2 here
txPacket: 558    simTime: 7.66305
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
/NodeList/11/DeviceList/3/MacTx
5 here
txPacket: 558    simTime: 7.66416
Source IP: 102.102.102.102
Destination IP: 102.102.102.102
NodeList/12/$ns3::Node/$ns3::OFSwitch13Device/PortList/3/$ns3::OFSwitch13Port/SwitchPortRx

but i'm expected as output to get the correct source and destination ip addresses which they are 192.168.1.1 and 192.168.1.7.

i think that the header that i peeked from the packet is empty or i made a mistake when i parsing the packet to get the ip Header so i will be thankful if anyone can help me.

0

There are 0 best solutions below