Get TCP information at physical layer in ns3

 I have to get lost packet TCP header information at physical layer on ns3. The following operation of removing or peeking tcp header would not do.

void RxDrop(Ptr<Packet>packet)
{
    TcpHeader header;
    packet->PeekHeader(header);
    NS_LOG_INFO(Simulator::Now().GetSeconds()<<"drop packet "<<header.GetSequenceNumber());
}

 In the point to point device situation, the packets flowing from transport layer to physical layer, ns3 would add TcpHeader, Ipv4Header, PppHeader. So if you intend to get the layer4 header, the layer2 and layer3 header should be removed first. And I give the right operation here.

void RxDrop(Ptr<const Packet>p)
{
    Ptr<Packet> packet=p->Copy(); 
    PppHeader ppp;
    packet->RemoveHeader(ppp);
    Ipv4Header ipHeader;
    packet->RemoveHeader (ipHeader);
    if(packet->GetSize()>500)//when the packet size=12,deserializing
    // tcp header get segment fault,and not figure out why.
    {
    TcpHeader header;
    packet->RemoveHeader(header);
    NS_LOG_INFO(Simulator::Now().GetSeconds()<<" drop packet "<<header.GetSequenceNumber()<<" source port "<<header.GetSourcePort ()<<" dest port "<<header.GetDestinationPort ());              
    }
    NS_LOG_INFO("size "<<packet->GetSize()<<"source "<<ipHeader.GetSource()<<"dest "<<ipHeader.GetDestination());
}

 It costs me nearly three hours to get the right tcp header information at physical layer.
[1]Getting a packet’s IP header

猜你喜欢

转载自blog.csdn.net/u010643777/article/details/80202667