Search code examples
omnet++ethernetinet

Omnet++ - Ethernet packet, unknow protocol


im trying to build a network where the nodes communicate using Ethernet. My plan is to create a message which will be used in multiple simple modules inside the nodes and pass that information to a inet::Packet and send it between the nodes. So, im first trying to understand how to use the communication protocol by implementing a simple network where one of the nodes creates a packet and the other receives it. Im amble to create the Packet but upon receiving it, the node informs that the protocol is unknown and drops it. I'm following the examples of the EtherTrafficGen.cc, EtherAppClient.cc in the inet folder and the Developer's Guide to try to implement it but i think im a bit lost.

The code for the packet creation is the following:

void masterDispatcher::initialize()
{
    // Message test that will be used in other modules
    Frame *test = new Frame;
    test->setTest(24);

    // Ethernet Packet
    inet::MacAddress destMACAddress;

    inet::Packet *datapacket = new inet::Packet("test", inet::IEEE802CTRL_DATA);

    // Data
    const auto& frame = inet::makeShared<EthernetFrame>();
    frame->setChunkLength(inet::B(1));
    frame->setTestEther(test->getTest());
    datapacket->insertAtBack(frame);

    // Header
    datapacket->addTagIfAbsent<inet::MacAddressReq>()->setDestAddress(destMACAddress.BROADCAST_ADDRESS);


    auto ieee802SapReq = datapacket->addTagIfAbsent<inet::Ieee802SapReq>();
    ieee802SapReq->setSsap(-1);
    ieee802SapReq->setDsap(-1);

    send(datapacket, "lowerLayerOut");

}

The network that im using is the one in the image: Implemented Network. Similiar to the EtherHost of INET, llc is the EtherEncap and the eth is the IEthernetInterface. Can anyone give me some tips of how to use this protocol?


Solution

  • Seemingly, you want to implement an application that is directly communicating using ethernet (and you do NOT want to use IP or UDP for whatever reason). You should take a look how for exampleEtherAppClient is implemented. Your code is almost right, but you should use a Ieee8022LlcSocket to send a packet from an application to the link layer directly.

    https://github.com/inet-framework/inet/blob/v4.2.0/src/inet/applications/ethernet/EtherAppClient.cc#L185

    The ISO layers inside a host are using protocol IDs for properly routing the packets. Protocol registration is handled by the Ieee8022LlcSocket. If you send the packet directly using send, the protocol id will not be filled and various issues will happen.

    Generally, applications should always use sockets to communicate to/from lower OSI layers.