create ipv6 paquet with new extension header

213 views
Skip to first unread message

Hajar Hantouti

unread,
Aug 12, 2015, 6:48:30 AM8/12/15
to ns-3-users
Hello,
I am new to Ns-3 environement, i want to create a paquet with a new Ipv6 extension header wich is not yet defined in ns-3 .
 for doing so I checked the list of extension headers defined in ns-3 but i couldn't know yet how to define my new extension so first of all I want to personalize a paquet and test this on a router node ,after that i will search to understand how to implement my new extension header in ns-3.
could you please advice me how to personalize a paquet and what is the procedure that i should follow to implement a new extension header.
Thanks for your help.

Tommaso Pecorella

unread,
Aug 12, 2015, 7:25:12 AM8/12/15
to ns-3-users
Hi,

please don't use google translate, it's horrible. It's packet, not paquet.
Anyway, my suggestion is to study how header extensions are implemented in ns-3 first. How can you "personalize a packet" if you don't know how to make one ? I mean, you want to build a personalized packet and test it without knowing how to implement the extension header you want to use in this packet ? there's something deeply wrong here...

Have fun studying,

T.

Hajar Hantouti

unread,
Aug 12, 2015, 7:39:59 AM8/12/15
to ns-3-...@googlegroups.com
Thanks Tommaso for your reply,
Actually, the only information I found about the extension header is the class reference , I can't understand by only few information. could you suggest me a way how can I get detailed informations about ns-3 extension header and packet.
Cordially.

--
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/IUr0JifHqgM/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.



--
Cordialement ;

Hajar HANTOUTI

Phd student -Umi University.


Tommaso Pecorella

unread,
Aug 12, 2015, 7:59:51 AM8/12/15
to ns-3-users
What you should look for is Ipv6Extension, not Ipv6ExtensionHeader. The header will need to be defined (of course), but the element processing the header is in Ipv6Extension.
If you correctly define a new Extension and the corresponding header, the "Process" method should be automatically be called when that extension is found.

Happy studying,

T.

Hajar Hantouti

unread,
Aug 20, 2015, 2:18:42 PM8/20/15
to ns-3-users
Hello Tomasso,
I wonder what is the difference between the extension class and the extension  header class ?

Tommaso Pecorella

unread,
Aug 20, 2015, 4:23:00 PM8/20/15
to ns-3-users
Hi

one is the header (the one that is sent and received), the other is what performs an action then the corresponding extension header is found (or the opposite, it helps in creating the header).
E.g., Ipv6ExtensionFragment::Process will be called when a Ipv6ExtensionFragment is found (it will handle the fragment), while Ipv6ExtensionFragment::GetFragments does the opposite: it fragments a packet.

Hope this helps,

T.

Hajar Hantouti

unread,
Aug 25, 2015, 6:38:45 AM8/25/15
to ns-3-...@googlegroups.com
Thanks Tomasso , I could define my extension into ns-3 , I added its definition to the files : ipv6-extension{.c,.h} ,ipv6-extension-header{.c,.h} and ipv6header.h :) !
Now I want to send a personalized packet that contains my extension, to do so I used the PacketSocket::Sendto (Ptr< Packet > p, uint32_t flags, const Address &toAddress) . unfortunately this is not working , could you advice me about the ways to send the packet .
Thank you for your precious help :)

--
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/IUr0JifHqgM/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,
Aug 25, 2015, 4:13:19 PM8/25/15
to ns-3-users
Hi,

there are different ways to send a packet with the new extension.

I the extension is a Hop by Hop one, you're in a bit of trouble (see later on). If it's an End to End, it's "easy". In both cases the source node is "easy".
You can find the trick in ping6.cc, and specifically in this code:
  /* use Loose Routing (routing type 0) */
 
if (m_routers.size ())
   
{
     
Ipv6ExtensionLooseRoutingHeader routingHeader;
      routingHeader
.SetNextHeader (Ipv6Header::IPV6_ICMPV6);
      routingHeader
.SetLength (m_routers.size () * 16 + 8);
      routingHeader
.SetTypeRouting (0);
      routingHeader
.SetSegmentsLeft (m_routers.size ());
      routingHeader
.SetRoutersAddress (m_routers);
      p
->AddHeader (routingHeader);
      m_socket
->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_EXT_ROUTING));
   
}


Translated: take socket (it's a IPv6 raw socket) and forge the header. As you can see, it's not exactly portable, but so far we had little or no need to add extension headers.
Me and Tom Henderson had a discussion some times ago about how to add extension headers in a more flexible way, but we didn't reach an agreement. We'll have to talk again about this.
Anyway, as a temporary thing, this is a perfectly valid solution.

The Hop by Hop case is a bit more complex, as there's a sub.case that is... a real issue: the mutable case.
If your extension is mutable (i.e., routers should process it AND change it), then you're in trouble, as there's not yet an active support for this. It could be done in a limited subset of cases by changing some functions, but it's still an open issue in general. It depends on what your extension will do.

Hope this helps,

T.

Hajar Hantouti

unread,
Aug 25, 2015, 4:40:18 PM8/25/15
to ns-3-...@googlegroups.com
Hello Tomaso ,
my new extension header is hop by hop, and I didn't think how to deal with it yet.
I first try to send a simple packet with the extension to a peer , the ping6.cc cares of sending an amount of icmp messages to a destination ,unfortunately it is not clear how they did it in this file(ping6). concerning the looserouting code , they created a pcket "p" , but it isn't shown how they send it.
could you please tell me the different ways that I can try to send a personalized packet ?
I tried socket::SendTo(const uint8_t *buf, uint32_t size, uint32_t flags, const Address &address) , but I get error checking the address parameter. is there another ways for ipv6 addresses ?
Thank you very much :)
Hajar

Tommaso Pecorella

unread,
Aug 25, 2015, 5:12:02 PM8/25/15
to ns-3-users
Hi,

that function should work, and if it throws errors in checking the address either you found a bug, or you opened the wrong socket type (e.g., a IPv4RawSocket instead of an Ipv6RawSocket).
However, that function is not very used. It purpose is to send a packet with an arbitrary payload, in case of headers it's better to sue another approach - purely because in this way you can easily print the headers.

If you look at Ping6::Send, the operations sequence is:
1) Decide the output address and interface - this is necessary in case you want to ping another host using a link-local address and you have more than one interface.
2) Build  the packet payload - in this case it's an ICMP packet, so we just use an Icmpv6Header.
3) Perform a magical trick - add another header between the ICMP header and the IP header.
4) Send the packet.

You're interested into points 3 and 4.
Also, note that the socket is an Ipv6RawSocket. It will add JUST the IP header, and nothing more. Moreover, you have to set manually the IP "Protocol" field, i.e., the next header type.

Point 3: why it's a magical trick.
Normally you'd send a packet to the socket and it will add the header to the packet you're sending. Since it's a Ipv6RawSocket, it will set the Protocol field to the value you have set when you opened the socket.
In ping.cc, the "protocol" is set at line 113:
      m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
because we know that we'r going to send an ICMP later on.

If you want to add a Loose Routing Extension header, this is not anymore true. You need to change the Protocol. Line 222:
      m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_EXT_ROUTING));
moreover, you build a new routing header (the lines above the 222) and you add them to the packet.

At this point, the packet will contain your ICMP header and the Extension header routing header. The socket will add the IP header and the trick is done.

Point 4 is "simply" sending a packet to a destination, line 225:
m_socket->SendTo (p, 0, Inet6SocketAddress (m_peerAddress, 0));

Hope this helps,

T.

PS. sorry if I didn't point out before... but there's a big thing to consider: if you're writing a kind of hop-by-hop extension, you need to consider the presence of *others* HbH extensions....
Basically what you want to define isn't an extension, it's an option.
The files you need (then) are:
src/internet/model/ipv6-option.cc
src/internet/model/ipv6-option.h
src/internet/model/ipv6-option-demux.cc
src/internet/model/ipv6-option-demux.h
src/internet/model/ipv6-option-header.cc
src/internet/model/ipv6-option-header.h

The logic is the very same. When an HbH extension is found, its options are processed.
Sadly, there's no way to easily *create* an HbH extension with its options. Basically this part of code is to be done.
The nice part is that it's something I'd very much like to include in ns-3, so if anyone has proposals, I'll be happy to review 'em.

Cheers,

T.

Hajar Hantouti

unread,
Aug 26, 2015, 6:27:20 PM8/26/15
to ns-3-...@googlegroups.com
Hello Tomaso,
Oh Thank you very much for your detailed explanation :)
To send the packet following your indications , I replaced the Routing extension with my extension . I get an error :"Removing unexpected header" file=../src/network/model/packet-metadata.cc, line=702 .
do you think the origine of the error is because of my new extension header ?

NB: I could add the extension to a packet and print it using Packet::print() without problems.

Thank you :)
Hajar


--
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/IUr0JifHqgM/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.

Hajar Hantouti

unread,
Aug 26, 2015, 6:30:36 PM8/26/15
to ns-3-...@googlegroups.com
Hello Tomaso,
Oh Thank you very much for your detailed explanation :)
To send the packet following your indications , I replaced the Routing extension with my extension . I get an error :"Removing unexpected header" file=../src/network/model/packet-metadata.cc, line=702 .
do you think the origine of the error is because of my new extension header ?

NB: I could add the extension to a packet and print it using Packet::print() without problems.

Thank you :)
Hajar

--
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/IUr0JifHqgM/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.

Hajar Hantouti

unread,
Aug 27, 2015, 8:47:28 AM8/27/15
to ns-3-...@googlegroups.com
Hello Tomasso ,
I could send the message when I bringed into comments this condition:
File : src/network/model/packet-metadata.cc
Lines :  700-704
 /**if (m_enableChecking)
        {
          NS_FATAL_ERROR ("Removing unexpected header.");
        }*/
Do you think its a bug , or I should check my code one again ?
NB: My ns-3 version is 3.23
Thanks for your time , and I'm sorry for bothering you .
Hajar

Tommaso Pecorella

unread,
Aug 27, 2015, 11:26:12 AM8/27/15
to ns-3-users
Hi,

sorry for the late reply.

Check your code. The assert means that something, somewhere is trying to extract an header that is not really there. A quite dangerous case, as it can produce unforeseeable results.
Usually the problem is in the "next header" section (if you forcefully built your packet, check the next header field), or in the serialize / deserialize (check the GetSerializedLength and the consistency with serialization and deserialization).
Another clue can come from the code immediately preceding the assert. What header was being removed (or was about to be removed) ? Should be that header there ? Why it's not there ?

Cheers,

T.

Hajar Hantouti

unread,
Aug 29, 2015, 8:20:13 AM8/29/15
to ns-3-...@googlegroups.com
Hello Tomaso,
Thanks for your response,I found that the function that generates the error:
msg="Removing unexpected header.", file=../src/network/model/packet-metadata.cc, line=702 terminate called without an active exception.

The function responsible for that is Packet::EnableChecking().
I tried hard to find out the source of the problem but I couldn't find out why,could you please review my code?

here are the sizes that I used :
the Packet(GetSize):86uint32
My Ext serializedsize: 4 uint32
ipv6 Serialized size: 40 uin32
payload size 42 uint32.

You'll find attached to this email my cpp code and the wireshark output files.
Thanks in advance.
Hajar
ext-0-1.pcap
ext-1-1.pcap
my_ext.cc

Tommaso Pecorella

unread,
Sep 3, 2015, 4:39:29 AM9/3/15
to ns-3-users
Hi,

sorry for the late reply.

The main problem seems to be that you're adding the IP header twice to the packet (!).
Consider that the IPv6RawSocket will add its own IPv6 header. What you have to do is just add the extension one. Otherwise you'll end up with an IP-over-IP case and I'm not that sure that this is handled by ns-3. In any case the next header field would be different.
If you look at the wireshark trace, you'l see clearly that the packet is not decoded in the right way, and if you carefully look at the header's bytes, you'll see the IPv6 header repeated twice.
I can't go further on because I don't have your extension code, but I guess you can go ahead from this point.

Cheers,

T.

Hajar Hantouti

unread,
Sep 3, 2015, 5:10:46 AM9/3/15
to ns-3-...@googlegroups.com
Hello ,
Thank you Tomasso for your help along this task.
it worked when I removed the ipv6 header because in my case they were two IPV6 headers.
For everyone interested in creating packet with extension header, find attached to this email my program.
Cordially;

--
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/IUr0JifHqgM/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.
my_ext.cc
Reply all
Reply to author
Forward
0 new messages