Search code examples
omnet++inet

What is the function of peek command in OMNet++


In INET developer's guide, I found the following `peek`` commands. Can anyone please help me explaininge the differences between peek, peekAt, peekData, peekAllAsBytes, and peekAtFront?

Example command:

peek

auto firstHalf = udpHeader->peek(B(0), B(4));

peekData

auto data = packet->peekData();

peekAllAsBytes

auto data = packet->peekAllAsBytes();

peekAt

vector<Packet *> *Mac::fragment(Packet *packet, vector<b>& sizes)
{
auto offset = b(0); // start from the packet's beginning
auto fragments = new vector<Packet *>(); // result collection
for (auto size : sizes) { // for each received size do
auto fragment = new Packet("Fragment"); // header + data part +
˓→trailer
auto header = makeShared<MacHeader>(); // create new header
header->setFragmentOffset(offset); // set fragment offset for
˓→reassembly
fragment->insertAtFront(header); // insert header into fragment
**auto data = packet->peekAt(offset, size);**
}

peekAtFront

const auto& hdr = packet->peekAtFront<MacHeaderBase>();

For peekAtFront, I know it returns the header part of a packet. However, i don't understand what is the function of "MacHeaderBase".

Thank you.


Solution

  • There is some explanation of these methods in src/inet/common/packet/Packet.h and src/inet/common/packet/chunk/Chunk.h:

    1. peek()
    /**
     * Returns the designated part of the data represented by this chunk in the
     * requested representation. If the length is unspecified, then the length of
     * the result is chosen according to the internal representation. The result
     * is mutable iff the designated part is directly represented in this chunk
     * by a mutable chunk, otherwise the result is immutable.
     */
    template <typename T>
    const Ptr<T> peek(const Iterator& iterator, b length = b(-1), int flags = 0) const
    
    1. peekData()
     /**
      * Returns the whole data part (excluding front and back popped parts) in the
      * current representation. The length of the returned chunk is the same as
      * the value returned by getDataLength(). The flags parameter is a combination
      * of Chunk::PeekFlag enumeration members.
      */
     const Ptr<const Chunk> peekData(int flags = 0) const
    
    1. peekAllAsBytes()
    /**
     * Returns the whole packet (including front and back popped parts) as a
     * sequence of bytes. The length of the returned chunk is the same as the
     * value returned by getTotalLength(). The flags parameter is a combination
     * of Chunk::PeekFlag enumeration members.
     */
    const Ptr<const BytesChunk> peekAllAsBytes(int flags = 0) const
    
    1. peekAt()
    /**
    * Returns the designated part of the packet as an immutable chunk in its
    * current representation. If the length is unspecified, then the length of
    * the result is chosen according to the current representation. The flags
    * parameter is a combination of Chunk::PeekFlag enumeration members.
    */
    const Ptr<const Chunk> peekAt(b offset, b length = b(-1), int flags = 0) const;
    
    1. peekAtFront()
    /**
     * Returns the designated part as an immutable chunk in its current
     * representation. If the length is unspecified, then the length of the
     * result is chosen according to the current representation. The flags
     * parameter is a combination of Chunk::PeekFlag enumeration members.
     */
     const Ptr<const Chunk> peekAtFront(b length = b(-1), int flags = 0) const;
    

    MacHeaderBase is class defined in src/inet/linklayer/base/MacHeaderBase.msg.