I create a small topology of network with some nodes, and I install for every node a sink using SinkApplication and a source using OnOffApplication. For time being, the source from every node will send packets to every other nodes using TCP. My target is to trace the packet, from which node flow the packet to another nodes. So from my trace output I can get the information that packet did come from some nodes to another nodes, but when I try to extract header from the packets, the ip address is uninitialized address 102.102.102.102. But when I enable the Print header function, I do get metadata of header and tell from which ip flows to which ip. So my problem is why I can't get correct information from Peek header function just as Print header?
The Trace Source looks like this:
AsciiTraceHelper ascii;
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream("simulation_received");
std::ostringstream oss;
oss<<"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/PhyRxEnd";
Config::Connect(oss.str(),MakeBoundCallback(&PacketReceived,stream));
And I hook with this function to get Output
static void
PacketReceived (Ptr<OutputStreamWrapper> stream, std::string context, Ptr< const Packet > p)
{
Ipv4Header header;
p->PeekHeader(header);
p->Print(*stream->GetStream());
*stream->GetStream()<<std::endl;
*stream->GetStream ()<<"Sent from "<<header.GetSource()<<" Received by "<<header.GetDestination()<<" at "<<Simulator::Now().GetSeconds()<<std::endl;
}
So, from print header I do get what i need(but with a lot of other information that I don't need), but from PeekHeader, I only get 102.102.102.102. So what's the problem with my code?
The output I get is like this:
ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 6 offset (bytes) 0 flags [none] length: 56 10.0.147.2 > 10.0.105.1) ns3::TcpHeader (49153 > 9 [SYN] Seq=0 Ack=0 Win=32768 ns3::TcpOptionWinScale(2) ns3::TcpOptionTS(2000;0) ns3::TcpOptionEnd(EOL))
Sent from 102.102.102.102 Received by 102.102.102.102 at 2.00229
Hi, thank you for your reply. Now I get at least a little bit clue what's going on. But I still have some questions on it.1. If I want to directly get the ip header, which layer/which component should I observe(as trace source)?
2. I know that there is different headers for different layers, but I don't know how they represent themselves in NS3. Like PPP header, Ipv4Header, some other headers, etc. How can I get information of available headers in NS3? Is there any literature or website has introduction about it? I usually look at Doxygen, but I can only get what functions I have in one particular header(only if I knew or guess right about the header name) but not the "big picture" of those headers.