CoRE Simulation Models for Real-time Networks

Changeset 07ab5ff in oppResultManagers


Ignore:
Timestamp:
04/11/16 19:00:19 (3 years ago)
Author:
Till Steinbach <till.steinbach@…>
Branches:
master
Children:
a975bbc
Parents:
70c7bec
Message:

now uses path of gates instead of modules

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • examples/pcapng/omnetpp.ini

    r70c7bec r07ab5ff  
    1111eventlogmanager-class = "PCAPNGEventlogManager"
    1212
    13 pcapng-interfaces = "Network.node1.mac, Network.node2.mac"
    14 pcapng-capturelength = 32
     13pcapng-interfaces = "Network.node1.mac.phys$i, Network.node1.mac.phys$o, Network.node2.mac.phys$i"
     14pcapng-capturelength = 3200
    1515
    1616
  • src/oppresultmanagers/eventlog/pcapng/PCAPNGEventlogManager.cc

    r70c7bec r07ab5ff  
    7979            interfaceModule != interfaceModules.end(); ++interfaceModule)
    8080    {
    81         omnetpp::cModule *module = omnetpp::getSimulation()->getModuleByPath((*interfaceModule).c_str());
     81        std::size_t pos = (*interfaceModule).rfind('.');
     82        std::string modulePath;
     83        std::string gateName;
     84        if (pos != std::string::npos)
     85        {
     86            modulePath = (*interfaceModule).substr(0, pos);
     87            gateName = (*interfaceModule).substr(pos + 1);
     88        }
     89        else
     90        {
     91            //throw
     92        }
     93        //TODO: allow interfaces to be named with sim.mod.gate$i=eth1 This could be great to group things together!
     94        //TODO: check if an interface already exists ($i/$o should be on the same interface!)
     95        //TODO: allow kind of autodetection (e.g. find mac modules in nodes, have to find a clever way to do that)
     96        omnetpp::cModule *module = omnetpp::getSimulation()->getModuleByPath(modulePath.c_str());
     97        omnetpp::cGate *gate = module->gate(gateName.c_str());
    8298        if (!module)
    8399        {
    84             throw omnetpp::cRuntimeError("error in ini file (pcapng-interfaces option): Module \"%s\" cannot be found",
    85                     (*interfaceModule).c_str());
     100            throw omnetpp::cRuntimeError(
     101                    "PCAPEventlogManager: error in ini file (pcapng-interfaces option): Gate \"%s\" of module \"%s\" cannot be found",
     102                    gateName.c_str(), modulePath.c_str());
    86103        }
    87         interfaceMap[module] = pcapwriter->addInterface("", module->getFullPath(),
    88                 static_cast<uint32_t>(capture_length), static_cast<uint8_t>(abs(omnetpp::simTime().getScaleExp())));
     104        if(!module->isSimple()){
     105            throw omnetpp::cRuntimeError(
     106                    "PCAPEventlogManager: Sorry, module \"%s\" is no simple module. We can only capture packets at simple modules", modulePath.c_str());
     107        }
     108        uint64_t speed = 0;
     109        omnetpp::cChannel* channel = nullptr;
     110        if (gate->getType() == cGate::INPUT)
     111        {
     112            channel = gate->findIncomingTransmissionChannel();
     113        }
     114        else
     115        {
     116            channel = gate->findTransmissionChannel();
     117        }
     118        if (omnetpp::cDatarateChannel* datarateChannel = dynamic_cast<omnetpp::cDatarateChannel*>(channel))
     119        {
     120            speed = static_cast<uint64_t>(datarateChannel->getDatarate());
     121            //TODO check if channel is an EtherLink, or other hints that we have an etherlink. getProperties and check type of frames for the gate
     122        }
     123        interfaceMap[gate] = pcapwriter->addInterface("", gate->getFullPath(), static_cast<uint32_t>(capture_length),
     124                static_cast<uint8_t>(abs(omnetpp::simTime().getScaleExp())), speed);
    89125    }
    90126    recordingStarted = true;
     
    114150            if (omnetpp::cPacket* pkt = dynamic_cast<omnetpp::cPacket*>(event))
    115151            {
    116                 //Was the Packet sent over an actual datarate channel
    117                 if (dynamic_cast<omnetpp::cDatarateChannel*>(pkt->getArrivalGate()->findIncomingTransmissionChannel()))
     152                std::map<omnetpp::cGate*, size_t>::iterator senderGate = interfaceMap.find(pkt->getSenderGate());
     153                std::map<omnetpp::cGate*, size_t>::iterator arrivalGate = interfaceMap.find(pkt->getArrivalGate());
     154                //Serialize if sender or receiver is in capture interfaces
     155                if (senderGate != interfaceMap.end() || arrivalGate != interfaceMap.end())
    118156                {
    119                     std::map<omnetpp::cModule*, size_t>::iterator senderModule = interfaceMap.find(
    120                             pkt->getSenderModule());
    121                     std::map<omnetpp::cModule*, size_t>::iterator arrivalModule = interfaceMap.find(
    122                             pkt->getArrivalModule());
    123                     //Serialize if sender or receiver is in capture interfaces
    124                     if (senderModule != interfaceMap.end() || arrivalModule != interfaceMap.end())
     157                    char serializeBuffer[10000];
     158                    inet::serializer::Buffer wb(serializeBuffer, sizeof(serializeBuffer));
     159                    inet::serializer::Context c;
     160                    c.throwOnSerializerNotFound = false;
     161                    c.throwOnSerializedSizeMissmatch = false;
     162                    inet::serializer::SerializerBase::lookupAndSerialize(pkt, wb, c, inet::serializer::LINKTYPE,
     163                            inet::serializer::LINKTYPE_ETHERNET, static_cast<unsigned int>(capture_length));
     164                    inet::EtherFrame * ethPkt = check_and_cast<inet::EtherFrame*>(pkt);
     165
     166                    //write out if sender is in interfaces
     167                    if (senderGate != interfaceMap.end())
    125168                    {
    126                         char serializeBuffer[10000];
    127                         inet::serializer::Buffer wb(serializeBuffer, sizeof(serializeBuffer));
    128                         inet::serializer::Context c;
    129                         c.throwOnSerializerNotFound = false;
    130                         c.throwOnSerializedSizeMissmatch = false;
    131                         inet::serializer::SerializerBase::lookupAndSerialize(pkt, wb, c, inet::serializer::LINKTYPE,
    132                                 inet::serializer::LINKTYPE_ETHERNET, static_cast<unsigned int>(capture_length));
    133                         inet::EtherFrame * ethPkt = check_and_cast<inet::EtherFrame*>(pkt);
    134 
    135                         //write out if sender is in interfaces
    136                         if (senderModule != interfaceMap.end())
    137                         {
    138                             pcapwriter->addEnhancedPacket(static_cast<uint32_t>(interfaceMap[pkt->getSenderModule()]),
    139                                     true, static_cast<uint64_t>(pkt->getSendingTime().raw()),
    140                                     static_cast<uint32_t>(ethPkt->getFrameByteLength()), wb.getPos(), serializeBuffer);
    141                         }
    142                         //write out if receiver is in interfaces
    143                         if (arrivalModule != interfaceMap.end())
    144                         {
    145                             pcapwriter->addEnhancedPacket(static_cast<uint32_t>(interfaceMap[pkt->getArrivalModule()]),
    146                                     false, static_cast<uint64_t>(pkt->getArrivalTime().raw()),
    147                                     static_cast<uint32_t>(ethPkt->getFrameByteLength()), wb.getPos(), serializeBuffer);
    148                         }
     169                        pcapwriter->addEnhancedPacket(static_cast<uint32_t>(senderGate->second), true,
     170                                static_cast<uint64_t>(pkt->getSendingTime().raw()),
     171                                static_cast<uint32_t>(ethPkt->getFrameByteLength()), wb.getPos(), serializeBuffer);
     172                    }
     173                    //write out if receiver is in interfaces
     174                    if (arrivalGate != interfaceMap.end())
     175                    {
     176                        pcapwriter->addEnhancedPacket(static_cast<uint32_t>(arrivalGate->second), false,
     177                                static_cast<uint64_t>(pkt->getArrivalTime().raw()),
     178                                static_cast<uint32_t>(ethPkt->getFrameByteLength()), wb.getPos(), serializeBuffer);
    149179                    }
    150180                }
  • src/oppresultmanagers/eventlog/pcapng/PCAPNGEventlogManager.h

    r70c7bec r07ab5ff  
    5050        PCAPNGWriter *pcapwriter;
    5151        bool recordingStarted = false;
    52         std::map<omnetpp::cModule*,size_t> interfaceMap;
     52        std::map<omnetpp::cGate*,size_t> interfaceMap;
    5353        size_t capture_length;
    5454
  • src/oppresultmanagers/eventlog/pcapng/PCAPNGWriter.cc

    r70c7bec r07ab5ff  
    182182}
    183183
    184 size_t PCAPNGWriter::addInterface(std::string name, std::string description, uint32_t snaplen, uint8_t tsresol)
     184size_t PCAPNGWriter::addInterface(std::string name, std::string description, uint32_t snaplen, uint8_t tsresol, uint64_t speed)
    185185{
    186186
     
    195195    }
    196196    addUint8Option(IF_TSRESOL, tsresol);
     197    if(speed>0){
     198        addUint64Option(IF_SPEED, speed);
     199    }
    197200    endOptions();
    198201    closeBlock();
  • src/oppresultmanagers/eventlog/pcapng/PCAPNGWriter.h

    r70c7bec r07ab5ff  
    8888
    8989        void openSection(std::string hardware, std::string os, std::string application);
    90         size_t addInterface(std::string name, std::string description, uint32_t snaplen, uint8_t tsresol);
     90        size_t addInterface(std::string name, std::string description, uint32_t snaplen, uint8_t tsresol, uint64_t speed);
    9191        void addEnhancedPacket(uint32_t interfaceId, bool sender, uint64_t timestamp, uint32_t len, uint32_t caplen, void* data);
    9292};
Note: See TracChangeset for help on using the changeset viewer.