How to use Packets inet 4.3.9

101 views
Skip to first unread message

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

unread,
Aug 9, 2022, 5:51:53 AM8/9/22
to OMNeT++ Users
Hello everyone I am a new user of Omnet + inet 4..3.9 and I am trying to build a package and send it to a topology of 2 nodes and a switch using c++ but I don't understand how to compose the package to send. Previously I was using inet 3.8.3 I was using EthernetIIFrame and then encapsulating the packet I wanted to send. What I am doing is the following maybe you could give me an example .
I tried to see from here (https://inet.omnetpp.org/docs/developers-guide/ch-packets.html#representing-signals) but it didn't help me or maybe I didn't understand something correctly.

inet::Packet *packet = new Packet("packet");
MacAddress sourceMac; //old -> 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);;

const auto& ethHeader = makeShared<EthernetMacHeader>();
ethHeader->enableImplicitChunkSerialization = true;
                //ethHeader->setChunkLength(B(14)); // src(6) + dest(6) + typeOrLength(2)

ethHeader->setSrc(sourceMac);;
ethHeader->setDest(destMac);;
ethHeader->setTypeOrLength(tmp_ethertype); ethHeader->setTypeOrLength(tmp_ethertype);
const auto& ethernetFcs = makeShared<EthernetFcs>();
packet->insertAtBack(ethernetFcs);

auto packetProtocolTag = packet->addTagIfAbsent<PacketProtocolTag>();
packetProtocolTag->setProtocol(&Protocol::ipv4); // set protocol of packet



 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 stripping 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];

setPayloadArray(tmp_packet, tmp_payload, tmp_packet_length);;

  // --------------- Ethernet (L2) Routing ---------------
if (L2_Routing) {
                    // how to add the tmp_packet inside of packet ,encapsulate on packet is not supported
                    send_packet=true;
                    EV<< " // --------------- Ethernet (L2) Routing ---------------"<< endl;
                }

if(send_packet){

      inet::physicallayer::EthernetSignal *ethernetSingal = new EthernetSignal();;
      ethernetSingal->setSrcMacFullDuplex(true);;
       ethernetSingal->encapsulate(packet);

        send(ethernetSingal, "gate$o");;
}

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

unread,
Aug 9, 2022, 5:55:50 AM8/9/22
to OMNeT++ Users
I Have make some fails copy .
i have insert the ethHeader at front and some duplicated lines is copy fault and not part of my code

Reply all
Reply to author
Forward
0 new messages