How to setup the EthernetIIFrame with omnet++ 6.0 && inet 4.3.9

48 views
Skip to first unread message

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

unread,
Aug 6, 2022, 3:20:33 AM8/6/22
to OMNeT++ Users
Hello all
i try to do something like this

auto eth2FramePacket = new Packet("Packet");
MacAddress sourceMac;   //old -> MACAddress sourceMac;
MacAddress destMac;     //old -> MACAddress destMac ;
for (int i=0;i<6;i++) tmp_dst[i]=(unsigned char)Rcvpacket->data[i];
for (int i=0;i<6;i++) tmp_src[i]=(unsigned char)Rcvpacket->data[i+6];
tmp_ethertype = (int) ((Rcvpacket->data[12] << 8) + (Rcvpacket->data[13] & 0xFF)  );//-1000000; // 12-13 bits are ethertype bits

sourceMac.setAddressBytes(tmp_src);
destMac.setAddressBytes(tmp_dst);
rame->setSrc(sourceMac);

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

myPacket *tmp_packet= new myPacket("tmp_packet");
unsigned int tmp_packet_length=(unsigned int) (Rcvpacket->length-14);
tmp_packet->setLength(tmp_packet_length); //only the payload after striping dst, src, ethertype



total_bytes_sent=total_bytes_sent+tmp_packet_length;


for (unsigned int i=0;i<tmp_packet_length;i++) tmp_payload[i]= (uint8_t)Rcvpacket->data[i+14];


if (L2_Routing) {
                    eth2FramePacket->encapsulate(tmp_packet);         // tmp_packet -> myPacket_m.h extend with cPacket
                    send_packet=true;
                    EV<< " // --------------- Ethernet (L2) Routing ---------------"<< endl;
                }

 if (send_packet){
                                        send(eth2FramePacket,"gate$o");

}
else { //------- Receive real message from OMNET++ network (other OMNET++ node) -------
         bubble("-----just got a real message from OMNET++ network------");

         TOGGLE=!TOGGLE;


         //EV<< "//------- Receive real message from OMNET++ network (other OMNET++ node " << endl;

         //EtherTraffic *msgTraffic = check_and_cast<EtherTraffic *>(msg);
         //EtherPhyFrame * etherPhyReceived = dynamic_cast<EtherPhyFrame *>(msgTraffic);
         //cPacket *frame_cPacket = etherPhyReceived->decapsulate();
         //EtherFrame *frame_received = check_and_cast<EtherFrame *>(frame_cPacket);

         //EtherFrame *eth2Frame2 = nullptr;

         auto eth2Frame2 = new Packet();

         if (dynamic_cast<EthernetMacHeader*>(msg) != nullptr){
             EV<< "EthernetMacHeader"<< endl;

             cout<<"\n EthernetIIFrame taken";
             inet::EthernetMacHeader  *eth2Frame = new EthernetMacHeader();
             eth2Frame = (EthernetMacHeader*)(msg);

             ethertype=eth2Frame->getTypeOrLength();
             eth2Frame2=(Packet*)eth2Frame;
             ethertype_dec[0]=(uint8_t) ((ethertype  >> 8) & 0xFF);
             ethertype_dec[1]=(uint8_t)(ethertype  & 0xFF);
         }

         else if(dynamic_cast<Ieee8022LlcSnapHeader*>(msg) != nullptr){
             EV<< "Ieee8022LlcSnapHeader"<< endl;
             cout<<"\n EtherFrameWithSNAP taken";
             Ieee8022LlcSnapHeader  *snapFrame = new Ieee8022LlcSnapHeader();
             snapFrame =(Ieee8022LlcSnapHeader*)(msg);
             snap_local_code=snapFrame->getProtocolId();

             eth2Frame2=(Packet*)snapFrame;
         }
         


             
       
            /* need to be fixed
         auto macHeader = eth2Frame2->popAtFront<MacHeader>();
         MacAddress sourceMac = macHeader->getSrc();   unsigned char tmp_src[6];
         MacAddress destMac   = macHeader->getDest();  unsigned char tmp_dst[6];

         sourceMac.getAddressBytes(tmp_src);
         destMac.getAddressBytes(tmp_dst);
         */


         myPacket *from_eth_packet_pt;
         unsigned int from_eth_payload_length;

         // --------------- Ethernet (L2) Routing ---------------
         if (L2_Routing) {
             from_eth_packet_pt=   (myPacket*) (eth2Frame2->decapsulate());
             from_eth_payload_length=from_eth_packet_pt->getLength();
             getPayloadArray(from_eth_packet_pt,from_eth_payload,from_eth_payload_length);

        }

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

unread,
Aug 6, 2022, 3:21:52 AM8/6/22
to OMNeT++ Users

To make an etherIIframe and using L2_Routing but the simulation crush and i need to fix the macheader (see the commnet section) any help ?

Alfonso Ariza Quintana

unread,
Aug 8, 2022, 4:55:21 AM8/8/22
to omn...@googlegroups.com

Probably, the easier is to replace the encapsulate module with your module that implements routing,

 

You can create a new class that is derived from encapsulate class and implement your functionality in this module

 

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/4bc8ea30-37a9-431d-9af4-efc1c30f1274n%40googlegroups.com.

 

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

unread,
Aug 8, 2022, 5:14:06 AM8/8/22
to OMNeT++ Users
So you tell me to make a class that will be extended at EthernetEncapsulate to add logic of encapsulation?

Alfonso Ariza Quintana

unread,
Aug 8, 2022, 6:44:50 AM8/8/22
to omn...@googlegroups.com
It will possibly  be the easiest. If you want to be "legal" (for example, on Linux you want to implement it without modify the kernel you use the hooks), you can use the IHook mechanism, you can steal the packet received from the link layer in the network layer and re-inject it with your modifications


De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νικος Γιαννόπουλος <giannop...@gmail.com>
Enviado: lunes, 8 de agosto de 2022 11:14
Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] Re: How to setup the EthernetIIFrame with omnet++ 6.0 && inet 4.3.9
 

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

unread,
Aug 8, 2022, 7:36:04 AM8/8/22
to omn...@googlegroups.com
Can I have an example? 

--
Με εκτίμηση
Γιαννόπουλος Νικόλαος
Φοιτητής ΗΜΜΥ ΑΠΘ

Alfonso Ariza Quintana

unread,
Aug 10, 2022, 4:39:01 AM8/10/22
to omn...@googlegroups.com
The hock is used by the aodv routing protocol inet and DSR protocol inetmanet

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de Νίκος Γιαννόπουλος <giannop...@gmail.com>
Enviado: lunes, 8 de agosto de 2022 13:35
Para: omn...@googlegroups.com <omn...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages