how to find TCP ack number

674 views
Skip to first unread message

Aniesh Chawla

unread,
Jan 16, 2015, 4:44:50 AM1/16/15
to ns-3-...@googlegroups.com
Hi,
I was looking at TCP flow through Wifi channel and I am not able to find a way to see the TCP ack number at side A.

A (sending data) ----------------------> B (receiving data)

For finding the TCP data sequence number, I made a trace at the phy layer of receiver and use the metadata information of the packet to find the TCP header and thereby the sequence number. However, when I am doing the same for finding the ACK number at side A, I am not able to get any TCP acks?? (I also tried putting the trace source at the transmission side B and still I am not able to find the ACK number).

What I am doing wrong here? Doesn't A which is receiving the TCP ACK (I know it is receiving TCP acks because I looked at the pcap dump on wireshark) should have the TCP ACK information?

The snipper of code is as follows:
static void PhyRxTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble){
  SequenceNumber32 seq;
  Ptr<Packet> q = packet->Copy();
  // Use indicator to search the packet
    PacketMetadata::ItemIterator metadataIterator = q->BeginItem();
    PacketMetadata::Item item;
    while (metadataIterator.HasNext())
    {
      item = metadataIterator.Next();
        if(item.tid.GetName()=="ns3::TcpHeader"){
          Callback<ObjectBase *> constr = item.tid.GetConstructor();
                NS_ASSERT(!constr.IsNull());
          
                // Ptr<> and DynamicCast<> won't work here as all headers are from ObjectBase, not Object
                ObjectBase *instance = constr();
                NS_ASSERT(instance != 0);
          
                TcpHeader* tcpHeader = dynamic_cast<TcpHeader*> (instance);
                NS_ASSERT(tcpHeader != 0);
          
                tcpHeader->Deserialize(item.current);
          
                // The tcp sequence can now obtain the source of the packet
                seq = tcpHeader->GetSequenceNumber(); // or tcpHeader.GetAckNumber() at other side.

Aniesh Chawla

unread,
Jan 19, 2015, 6:08:59 AM1/19/15
to ns-3-...@googlegroups.com
Hi all,
Can anybody help me with this or need any clarification please let me know.

Thanks
Aniesh

Tommaso Pecorella

unread,
Jan 19, 2015, 8:52:42 AM1/19/15
to ns-3-...@googlegroups.com
Hi,

did you enable the Packet Metadata ?
Because if you don't do... well, I guess you can understand what will not work.

T.

Aniesh Chawla

unread,
Jan 20, 2015, 12:36:02 AM1/20/15
to ns-3-...@googlegroups.com
Hi,

Thanks T for your reply. Yes, I had enabled the packet metadata that is how I was able to get the sequence number of TCP data stream but I am not able to get the same for TCP ACK stream. Infact I am not able to trace TCP ACKs through traces at Phy/MAC layer but I can see them on pcap files on wireshark.

Regards
Aniesh

Tommaso Pecorella

unread,
Jan 20, 2015, 3:14:01 AM1/20/15
to ns-3-...@googlegroups.com
Hi,

I think there's some misunderstanding here.
TCP ACK number isn't an optional header, it's a number in any TCP header. What are you not able to do, to find the TCP header, to print the AckNumber, to see it varying or what ?
Please be precise.

T.

Aniesh Chawla

unread,
Jan 20, 2015, 3:44:47 AM1/20/15
to ns-3-...@googlegroups.com
Hi T,
Thanks for your reply.
For a data packet received, the receiver sends an ACK with the next sequence number it expects to receive. I am not able to print this ACK number.
I hope I am clear.

Aniesh

Tommaso Pecorella

unread,
Jan 20, 2015, 4:00:41 AM1/20/15
to ns-3-...@googlegroups.com
... and how are you trying to print it ?

T.

Matt Anonyme

unread,
Jan 20, 2015, 5:18:55 AM1/20/15
to ns-3-...@googlegroups.com
You can use the tracing system to export frames in a .pcap file. then you can see the traffic with wireshark, it's quite convenient.

For instance:
  PointToPointHelper p2p;

  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
  NetDeviceContainer cont = p2p.Install(node0,node1);
  p2p.EnablePcapAll("test",true);

If you want to process the  data, then you can export the .pcap to a .csv with "tshark".

Hope that helps

Aniesh Chawla

unread,
Jan 20, 2015, 5:26:31 AM1/20/15
to ns-3-...@googlegroups.com
Hi,
@T:  I am trying to print this using packet metadata approach i.e. by finding tcp header and then using tcpheader.GetAckNumber( ) for the TCP ACKs. ( if I am doing this for TCP Data, I constantly get the value of 1 in tcpdataheader.GetAckNumber( ) )

@Matt; I am already getting the pcap files in which I can see on wireshark, but I want the info during the simulations. I want to leverage the information of ack number in my program.


Thanks a lot
Aniesh

Konstantinos

unread,
Jan 20, 2015, 5:36:11 AM1/20/15
to ns-3-...@googlegroups.com
Hi Aniesh,

Is the TcpSocketBase/NetxTxSequence trace source you want?
  • NextTxSequence: Next sequence number to send (SND.NXT)
TracedValue<SequenceNumber32> ns3::TcpSocketBase::m_nextTxSequence
protected

Next seqnum to be sent (SND.NXT), ReTx pushes it back.

Aniesh Chawla

unread,
Jan 20, 2015, 5:39:08 AM1/20/15
to ns-3-...@googlegroups.com
Hi Konstantinos,

I have already tried it, it gives the next sequence of the data packet but not the acknowledgement packet sequence.

Thanks
Aniesh

Tommaso Pecorella

unread,
Jan 20, 2015, 5:39:13 AM1/20/15
to ns-3-...@googlegroups.com
I asked the [CENSORED] instruction you are using.
Sometimes the print function you use is sensitive to the data you feed to it. Try executing this [CENSORED]: "std::cout << uint8_t(10) << std::endl;"

T.

Aniesh Chawla

unread,
Jan 20, 2015, 5:43:02 AM1/20/15
to ns-3-...@googlegroups.com
Hi T,
Its not the problem of the print statement because in the metadata packet approach, I am printing the header for the TCP ACKs and it is only giving wifimacheader but in case of TCP data stream it is giving wifimacheader, LLlcheader, ipv4header and tcpheader. I am not getting tcp header in case of TCP ACK stream.

Aniesh

Tommaso Pecorella

unread,
Jan 20, 2015, 6:00:51 AM1/20/15
to ns-3-...@googlegroups.com
Hi,

thanks for using your and our time in this useful discussion.

The problem you are experiencing is that you can't find the TCP header where you think it should be one. The "missing" ACK number is a mere consequence.
Please, in order to avoid unnecessary hypothesis, describe your issues more precisely.

About this problem, we can't help without a script showing the problem.

T.

Aniesh Chawla

unread,
Jan 21, 2015, 12:34:01 AM1/21/15
to ns-3-...@googlegroups.com
Hi ,
Thanks for your time, I really appreciate taking your time
Please find the attached test file along with this post and let me know your thoughts that why I am not able to trace TCP ACK stream.

Thanks
Aniesh
test_case.cc

Aniesh Chawla

unread,
Jan 21, 2015, 12:44:27 AM1/21/15
to ns-3-...@googlegroups.com
to add on I am using ns-3.21, OS: ubuntu 14.04 (got that from reading tommasso's blog on how to ask questions on ns-3 group http://tommy-ns-3-corner.blogspot.in/2014/03/how-to-ask-for-help-in-user-forum.html - a nice read and very useful ) -

P.S.: I thought I was precise in asking the question but I guess I was not...I hope you understood the problem now that I am facing, I was not able to put the code earlier because of some IP issues but I have modified it for the question purpose only.

Thanks again
Aniesh

Aniesh Chawla

unread,
Feb 2, 2015, 11:02:23 PM2/2/15
to ns-3-...@googlegroups.com
Hi all,
Can anyone help me with this problem of not able to trace the TCP ACK stream?

Thanks
Aniesh

Tommaso Pecorella

unread,
Feb 3, 2015, 3:03:43 AM2/3/15
to ns-3-...@googlegroups.com
Hi,

two mistakes, the main one can be summarized as: Indentation - it's not just for pretty-printing.

    while (metadataIterator.HasNext())
   
{
      item
= metadataIterator.Next();
     
if(item.tid.GetName()=="ns3::TcpHeader"){
     
}

     
break;
   
}

This will execute only ONCE. The break should have been inside the "if" statement.
In this way you'll see the ACKs.

The second issue is: they're all 1 (except the last one). Simple: you hooked the wrong trace or the wrong node. Easy to fix.
It surprises me that the fact that only the WiFi header metadata was found didn't ring you a bell...

Have fun,

T.

PS: IPR and stuff released with this in front doesn't really go hand in hand.
 * This program is free software; you can redistribute it and/or modify
 
* it under the terms of the GNU General Public License version 2 as
 
* published by the Free Software Foundation;

aniesh chawla

unread,
Feb 3, 2015, 3:44:39 AM2/3/15
to ns-3-...@googlegroups.com
Thanks T.,

That was very bad on my behalf to have put the "break" at the wrong place and I kept on looking for errors at other places.

The other part of wrong trace is that I was trying something different and I guess I forgot to change the code for that. I was putting the trace at the right node.

IP issues was with the algo I was using and not with the simulator part

Thanks a lot for your help.

Aniesh

--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/yi3EyEV8TKs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Tommaso Pecorella

unread,
Feb 3, 2015, 3:59:01 AM2/3/15
to ns-3-...@googlegroups.com
Yo,

don't worry, stupid mistakes happens all the time. That's why in some form of Agile Programming you put TWO devs at the same time on the very same piece of code (with a code editor similar to Google Docs).

About IPRs, don't worry either. It's a very common thing to have the APIs and base classes public and some private parts under IPR. It happens all the times and I don't think it's against the GPL licence. What GPL covers (and protects from) is someone taking the code, just do some minor stuff and sells it as a whole.

Have fun,

T.
Reply all
Reply to author
Forward
0 new messages