Upload
sydney-black
View
223
Download
0
Embed Size (px)
Citation preview
Packet Headers Format and Trace
蕭博鴻698430007
Here comes your footer
Outline
IntroductionPacket ModulePacket HeaderPacket Header Mapping to OtclPacket Header Manager in NS2Defining a New Packet Header to NS2 [Step by Step]
Trace
Page 2
Here comes your footer
Introduction
Packet consists of packet header and data payload.
In most cases, NS2 extracts information from data payload and stores the information into packet header.
By default, NS2 includes All packet headers of All protocols in every packet.
In NS2, Class Packet is derived from class Event.
s.schedule(target_, p, txt + delay_)
Page 3
Here comes your footer Page 4
Packet Module
Here comes your footer Page 5
Here comes your footer
C++ Variables of class Packet
unsigned char* bits_ AppData* data_ int hdr_len_ bool fflag_
- Set to true if the packet is currently referred to by other objects and false otherwise
Packet* free_ - Pointer to the head of the packet free list
int ref_count_ - Number of objects which currently refer to the packet
Packet* next_ - Pointer to the next packet in the linked list of packets
Page 6
Here comes your footer
C++ Functions of class Packet
void init(Packet* )- Clears the packet header bits_ of the input packet p.
Packet* copy() - Returns a pointer to a duplicated packet.
Packet* refcopy() - Increases the number of objects, which refer to the packet
Packet* alloc() - Creates a new packet and returns a pointer to the created packet.
Packet* alloc(n) - Creates a new packet with “n” bytes of data payload and returns a pointer to
the created packet.
Page 7
Here comes your footer
Cont’
void allocdata(int)- Allocates “n” bytes of data payload to the variable data_.
void free(Packet*) - Deallocates packet.
char* access(int) - Retrieves a reference to a certain point (specified by the offset “off”) of the
variable bits_ (i.e., packet header).
Page 8
Here comes your footer
Link List of Packet
Page 9
Here comes your footer Page 10
Packet Queue
Here comes your footer
Packet Allocation
Packet* alloc() Packet* alloc(n)
Page 11
Here comes your footer
Packet Deallocation
void free(Packet*)
Page 12
Here comes your footer Page 13
Packet Header
Here comes your footer Page 14
Packet Header Module
Here comes your footer Page 15
Common Header
Structure
Here comes your footer Page 16
Packet Type
Here comes your footer Page 17
Packet Header Mapping
to OTcl
Class/Object Name
C++ Structure hdr_cmn
OTcl Class PacketHeader/Common
Mapping Class CommonHeaderClass
Mapping Variable class_cmnhdr
Here comes your footer Page 18
Here comes your footer Page 19
Packet Header Manager in NS2
Here comes your footer Page 20
Packet Header Manager
Here comes your footer Page 21
Packet Header Manager add Packet Header
Add all Packet Header to Ns2Add all Packet Header to Ns2
Init SimulatorAnd Create Packet Format
Init SimulatorAnd Create Packet Format
Allocate Packet Header OffsetIn Packet And increase header length
Allocate Packet Header OffsetIn Packet And increase header length
Here comes your footer
The Other Command
add-packet-header args- This global proc will tell simulator to include the specified packet header(s) in
your simulation.
remove-packet-header args- operates in the same syntax, but it removes the specified headers from your
simulation; notice that it does not remove the common header even it is instructed to do so.
remove-all-packet-headers- It takes no argument and removes all packet headers, except the common
header, from your simulation.
Page 22
Here comes your footer
1. Define a protocol specific header C++ struct hdr_echo_back
− Declare variable offset_
− Define function access(p)
− Include all member variables require to hold new packet attributes
2. Include new packet type into packet_t and class p_info
− Declare variable PT_ECHOBACK
− Protocol header ‘s name is “EchoBack”
3. Define a protocol specific header OTcl class PacketHeader/EchoBack
4. Derive a mapping class EchoBackHeaderClass from PacketHeaderClass
− At the construction, feed PacketHeader/EchoBack and sizeof(struct hdr_echo_back) of class PacketHeaderClass
− From within the constructor, Use bind_offset function to bind hdr_echo_back::offset_
5. Active Header into the PacketHeaderManager protocol list.
− Added EchoBack into the foreach loop
6. Edit Makefile to Compile your header, then clean the ns2 and recompile ns2.
Page 23
Defining a New Packet Header to NS2Step by Step
Here comes your footer Page 24
抽考題目
在 NS2的封包內新增一個表頭 (EchoBack)。
Here comes your footer
根據下面步驟來完成新增動作。1. Define a protocol specific header C++ struct hdr_echo_back
− Declare variable offset_
− Define function access(p)
− Include all member variables require to hold new packet attributes
2. Include new packet type into packet_t and class p_info
− Declare variable PT_ECHOBACK
− Protocol header ‘s name is “EchoBack”
3. Define a protocol specific header OTcl class PacketHeader/EchoBack
4. Derive a mapping class EchoBackHeaderClass from PacketHeaderClass
− At the construction, feed PacketHeader/EchoBack and sizeof(struct hdr_echo_back) of class PacketHeaderClass
− From within the constructor, Use bind_offset function to bind hdr_echo_back::offset_
5. Active Header into the PacketHeaderManager protocol list.
− Added EchoBack into the foreach loop
6. Edit Makefile to Compile your header, then clean the ns2 and recompile ns2.
Page 25
程式碼的部分已經完成,將 echo_back.cc 跟 echo_back.h 放到 NS2 的資料夾內,根據上面的步驟完成 2 、 5 、 6 的步驟
抽考題目 ( 提示 )
Here comes your footer Page 26
THANK YOU