How to build Ipv4 Packet

183 views
Skip to first unread message

Nick Gian

unread,
Dec 26, 2022, 2:03:15 PM12/26/22
to OMNeT++ Users
Hello everyone

I want to build an Ipv4 packet to going host ->ethernetline -> mirco router aodv and the reserver steps at receive side.

I know the need Ipv4header , byteChunks, Tail as EthernetFCS

The already examples gets me confuse. 
I want an example with C++ code.

Alfonso Ariza Quintana

unread,
Dec 28, 2022, 4:40:48 AM12/28/22
to omn...@googlegroups.com

And why you don’t use the Ipv4 module? The ipv4 module will encapsulate the packet

 

Enviado desde Correo para Windows

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/828a6ca9-4b05-45ae-94dc-75a599c40e3an%40googlegroups.com.

 

Νίκος Γιαννόπουλος

unread,
Dec 28, 2022, 4:54:18 AM12/28/22
to omn...@googlegroups.com
How I do that? 
Can you give one example? 

--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh

Alfonso Ariza Quintana

unread,
Dec 30, 2022, 5:08:31 PM12/30/22
to omn...@googlegroups.com
Most of the examples use the Ipv4 module, if you run an example with a network layer you can see how the ipv4 module includes the header, ask if it is necessary to the arp to search the mac address of the next hop, and send the packet to the next hop using the routing tables.

To include the network header is not the only thing that the network layer does.

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: miércoles, 28 de diciembre de 2022 10:54
Para: omn...@googlegroups.com <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to build Ipv4 Packet
 

Nick Gian

unread,
Jan 3, 2023, 1:43:46 PM1/3/23
to OMNeT++ Users
Hello Alfonso and thanks for your reply have a great new year,

In my C++ code i do this:
inet::Ptr<inet::Ipv4Header> datagram = makeShared<Ipv4Header>();


Ipv4Address IP_src,IP_dest;
IP_src.set(my_source_ip[0],my_source_ip[1],my_source_ip[2],my_source_ip[3]);
IP_dest.set(my_dest_ip[0],my_dest_ip[1],my_dest_ip[2],my_dest_ip[3]);

//------ set datagram ---
datagram->setVersion(my_Version);
datagram->setHeaderLength(my_IHL);
datagram->setTypeOfService(my_TOS);
datagram->setTotalLengthField(my_Total_Length);
datagram->setIdentification(my_Identification);

datagram->setDontFragment(my_Flags_DF);
datagram->setMoreFragments(my_Flags_MF);
datagram->setFragmentOffset(my_Fragment_Offset);
datagram->setTimeToLive(my_Time_to_Live);
datagram->setProtocolId(my_Protocol);

datagram->setSrcAddress(IP_src);
datagram->setDestAddress(IP_dest);
datagram->setTotalLengthField(ETHER_MAC_HEADER_BYTES);

datagram->setCrcMode(CRC_DECLARED_CORRECT);


auto ethHeader = makeShared<EthernetMacHeader>();
ethHeader->setDest(destMac);
ethHeader->setSrc(sourceMac);
ethHeader->setTypeOrLength(tmp_ethertype);

auto ethernetFcs = makeShared<EthernetFcs>();
ethernetFcs->setFcsMode(FCS_DECLARED_CORRECT);

packet->insertAtFront(datagram);
packet->insertAtFront(ethHeader);
packet->insertAtBack(ethernetFcs);

We have 2 aodvrouters and in the above way when one AODV router sends a request to the other, the second one replies with request instead of reply.

Alfonso Ariza Quintana

unread,
Jan 3, 2023, 5:20:24 PM1/3/23
to omn...@googlegroups.com
If the addresses are not correct, the packet will be discarded. The mac must be the next hop mac address.

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Nick Gian <giannop...@gmail.com>
Enviado: martes, 3 de enero de 2023 19:43
Para: OMNeT++ Users <omn...@googlegroups.com>

Νίκος Γιαννόπουλος

unread,
Jan 3, 2023, 5:49:42 PM1/3/23
to omn...@googlegroups.com
Can you give a specific example using this module ipv4? 



--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh

Alfonso Ariza Quintana

unread,
Jan 4, 2023, 5:59:04 AM1/4/23
to omn...@googlegroups.com
Do you know how works ipv4?

When ip receives a packet of the upper layer, encapsulates it, and forwards. If it is necessary, fragment it.
If it receives from the lower layer, and the destination is the node, decapsulates it and sends it to the upper layer.
If forwards, search in the routing table for the next-hop address to the destination.
If it doesn't exist the entry, discard the packet.
If it exists, request the mac address of the next-hop node to the ARP module (in Ipv6 is the neighbor protocol that find this mac address) and send it to the mac.

In your case, the destination mac address must be of the neighbor node.

It is possible to inject directly the packet into the IP layer.
If you want something more similar to Raw sockets, you can add an entry in the Ethernet module where you could inject your packets directly. The injection can be before the Ethernet encapsulation, in this case, using tags, you can set the destination address or, after the encapsulate module, in this case, you need to encapsulate the packet in your code


De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: martes, 3 de enero de 2023 23:49

Nick Gian

unread,
Jan 4, 2023, 3:54:06 PM1/4/23
to OMNeT++ Users
Thank you for the answer , how do I encapsulate my package can you give me a specific example of code that shows this (that work for the IP level)? 

Alfonso Ariza Quintana

unread,
Jan 5, 2023, 5:55:24 AM1/5/23
to omn...@googlegroups.com
The dsr code can inject directly the packets in the ip layer
The code uses the method injectDirectToIp
This method is defined in
void ManetRoutingBase::injectDirectToIp(Packet *msg, double delay, NetworkInterface *ie)

the dsr code creates the ip packet and injects the packet with the interface that you want to use directly in the ip layer
Also, DSR avoid the use of the IP routing table forcing the next hop destination using the tag NextHopAddressReq
pkt->addTagIfAbsent<NextHopAddressReq>()->setNextHopAddress(dp->nxt_hop.s_addr);

Enviado: miércoles, 4 de enero de 2023 21:54

Νίκος Γιαννόπουλος

unread,
Jan 6, 2023, 2:20:13 AM1/6/23
to omn...@googlegroups.com
Thank you for the answer but I'm looking for the solution decoupled from the inet framework do you know how I can do the same with inet ? or an example of how to build the ip packet and have it accepted by the ip layer and then work correctly on the aodv router

Alfonso Ariza Quintana

unread,
Jan 8, 2023, 6:15:19 AM1/8/23
to omn...@googlegroups.com
You can modify the ipv4 module as it is in inetmanet to allow direct injection of frames

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: viernes, 6 de enero de 2023 8:19

Νίκος Γιαννόπουλος

unread,
Jan 8, 2023, 7:02:04 AM1/8/23
to omn...@googlegroups.com
There is no other way to do this? 


--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh

Alfonso Ariza Quintana

unread,
Jan 8, 2023, 12:00:51 PM1/8/23
to omn...@googlegroups.com
If you want to inject directly packets in the IP layer, this is the only that I know

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: domingo, 8 de enero de 2023 13:01

Νίκος Γιαννόπουλος

unread,
Jan 9, 2023, 5:04:53 AM1/9/23
to omn...@googlegroups.com
Can you help me to use the ipv4.cc code about build Ipv4 packet as example? 


--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh

Nick Gian

unread,
Jan 10, 2023, 9:40:35 AM1/10/23
to OMNeT++ Users
I want to build up Ipv4 Packet which .cc code i will use do this? any idea?

Alfonso Ariza Quintana

unread,
Jan 10, 2023, 12:20:52 PM1/10/23
to omn...@googlegroups.com
The problem is not building the packet, the problem is how to inject the packet into the network.
If you replace the IP module, others protocols cannot work.
If you only want to inject some information, it is better to implement an application module and use ip sockets.
If you want to create directly the ip packets, the best in my opinion is to create it and inject them directly into the ip module using hooks.






Enviado: martes, 10 de enero de 2023 15:40

Νίκος Γιαννόπουλος

unread,
Jan 10, 2023, 1:45:59 PM1/10/23
to omn...@googlegroups.com
Can you give specific examples using hooks to do this? 


--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh

Nick Gian

unread,
Jan 11, 2023, 3:37:28 AM1/11/23
to OMNeT++ Users
I have this topology of network
topology.png

Alfonso Ariza Quintana

unread,
Jan 11, 2023, 3:52:01 AM1/11/23
to omn...@googlegroups.com
And, what do you want to do?

Enviado: miércoles, 11 de enero de 2023 9:37

Νίκος Γιαννόπουλος

unread,
Jan 11, 2023, 4:16:22 AM1/11/23
to omn...@googlegroups.com
I want to send packet from node0 via AODV to node1 as ip packet. 


--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh

topology.png

Alfonso Ariza Quintana

unread,
Jan 11, 2023, 6:21:45 AM1/11/23
to omn...@googlegroups.com
It doesn't have sense, AODV is only a routing protocol, it searches for a valid route, but the actual implementation only supports an interface only.

The logic is to send the packets using a transport protocol, TCP, or UDP, the encapsulation in IP packet will be done by the network layer, you don't need to do any about this. The only thing that you need is to configure the routing tables. Or, modify the Aodv protocol to support several interfaces.


De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: miércoles, 11 de enero de 2023 10:15

Νίκος Γιαννόπουλος

unread,
Jan 11, 2023, 6:55:45 AM1/11/23
to omn...@googlegroups.com
OK then, we have specific example using this method building a packet? 


--
Με εκτίμηση - Yours sincerely,
Γιαννόπουλος Νικόλαος - Giannopoulos Nikolaos
Φοιτητής ΗΜΜΥ ΑΠΘ - ECE Student AUTh
You received this message because you are subscribed to a topic in the Google Groups "OMNeT++ Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omnetpp/iLuORQciWvc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/AS2P195MB21553E6CB67B2FF0B6F0B9C38CFC9%40AS2P195MB2155.EURP195.PROD.OUTLOOK.COM.

Alfonso Ariza Quintana

unread,
Jan 11, 2023, 1:59:36 PM1/11/23
to omn...@googlegroups.com
You can check the examples, for example ComplexConfiguratorNetwork

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: miércoles, 11 de enero de 2023 12:55

Nick Gian

unread,
Jan 13, 2023, 3:03:01 PM1/13/23
to OMNeT++ Users
My config1.xml looking like this: 
<config>
     <interface hosts='**' address='10.0.x.x' netmask='255.255.255.0'/>
    <autoroute metric='errorRate' />
</config>
 
I try the same config as  ComplexConfiguratorNetwork and didn't work.

My packet build like this

EthernetPhyHeader| EthernetMacHeader|Ipv4Header|  BytesChunk | EthernetFCS | and the Ipv4 layer of Aodv router give me this message:
WARN: The same packet has arrived within PATH_DISCOVERY_TIME= 5.6. Discarding it

How to fix this?

Nick Gian

unread,
Jan 13, 2023, 3:15:15 PM1/13/23
to OMNeT++ Users
But if i run my code with this below topology working fine without errors

topology 2.png

Nick Gian

unread,
Jan 16, 2023, 12:20:51 AM1/16/23
to OMNeT++ Users
How can I build the package and place it so that it is accepted by the physicallayer (ethernet line) and then the aodv router takes over the routing?

Alfonso Ariza Quintana

unread,
Jan 16, 2023, 4:01:34 AM1/16/23
to omn...@googlegroups.com
If you want to use Aodv, you will need to modify a bit the source code, the actual implementation only works with wireless interfaces.

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Nick Gian <giannop...@gmail.com>
Enviado: viernes, 13 de enero de 2023 21:15

Νίκος Γιαννόπουλος

unread,
Feb 2, 2023, 10:05:13 AM2/2/23
to omn...@googlegroups.com
The PingApp that we have to see the fields it sends? Also does pingApp L3 (ICMP) not use it? How does it work with the AODV routers?

Alfonso Ariza Quintana

unread,
Feb 6, 2023, 11:07:58 AM2/6/23
to omn...@googlegroups.com
For Aodv the ping protocol is transparent, Aodv will search the path

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: jueves, 2 de febrero de 2023 16:04
Reply all
Reply to author
Forward
0 new messages