An overview of mac802_11.cc mac802_11.h - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

An overview of mac802_11.cc mac802_11.h

Description:

... TCP, UDP, CBR, ACK, Audio, Video, Prune, Stop, Accept, Confirm, FTP, ... initialize the packet header, length of buffer, the queues and packet free list ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 39
Provided by: sarthak3
Category:

less

Transcript and Presenter's Notes

Title: An overview of mac802_11.cc mac802_11.h


1
An overview of mac-802_11.ccmac-802_11.h
Packet Format
  • Sarthak Grover

2
Introduction
  • In ns, two MAC layer protocols are implemented
    for mobile networks
  • 802.11
  • TDMA

3
Overview
  • The 802.11 is implemented using
    ns/mac-802_11.cc, ns/mac-802_11.h
  • The MAC 802.11 doesn't try to retransmit a
    broadcast packet incase there is a collision and
    the packet is dropped

4
Overview
  • Coupled to this was the fact that mac-802.11
    didn't do random selection of slots in the
    contention window before it transmitted a packet.
  • As a result there were a high number of
    collisions at the MAC layer and a lot of packets
    were lost. This was fixed by adding random
    selection of slots before MAC tx'ed a broadcast
    packet.

5
mac-802_11.h
  • Header file to assist the mac-802_11.cc
  • Includes the following

6
Other header files included
  • ns_mac_80211_h
  • address.h
  • ip.h
  • mac-timers.h
  • marshall.h

To support even tracing
7
Frame formats(mac-802_11.h)
  • define MAC_Type_Management
  • define MAC_Type_Data
  • //Packet type
  • define MAC_Subtype_RTS
  • define MAC_Subtype_CTS
  • define MAC_Subtype_ACK
  • define MAC_Subtype_Data
  • // BSS type
  • define BSS_Infrastructure
  • define BSS_Adhoc

8
Frame formats(mac-802_11.h)
  • For each of the subtypes, there are structures
    defined
  • struct rts_frame
  • struct frame_control rf_fc
  • u_int16_t cf_duration
  • u_char rf_raETHER_ADDR_LEN
  • u_char rf_taETHER_ADDR_LEN
  • u_char rf_fcsETHER_FCS_LEN

9
Header Lengths(mac-802_11.h)
  • In this, the lengths of headers for PLCP,
    Ethernet, RTS, CTS and ACK are defined
  • define PLCP_HRD_LEN
  • ((phymib_-gtPreambleLength gtgt 3)
  • (phymib_-gtPLCPHeaderLength gtgt 3)
  • define ETHER_RTS_LEN
  • (PLCP_HDR_LEN
  • sizeof(struct rts_frame))

10
DSSS Parameters(mac-802_11.h)
  • Parameters specific to DSSS are specified here
  • define DSSS_CWmin 31
  • define DSSS_CWMax 1023
  • define DSSS_SlotTime 0.000020
  • define DSSS_PreambleLength 144
  • define DSSS_PLCPHeaderLength 48
  • define DSSS_PLCPDataRate 1.0e6

11
Default Values for MAC Attributes(mac-802_11.h)
  • define MAC_FragmentationThreshold 2346
  • define MAC_MaxTransmitMSDULifetime 512
  • define MAC_MaxReceiveLifetime 512
  • class MAC_MIB
  • public
  • MAC_MIB(Mac802_11parent)
  • private
  • u_int32_t RTSThreshold
  • u_int32_t ShortRetryLimit
  • u_int32_t LongRetryLimit
  • protected
  • u_int32_t Failedcount
  • u_int32_t RTSSuccessCount
  • u_int32_t RTSFailureCount

12
802.11 MAC class(mac-802_11.h)
  • public methods and definitions
  • void recv(Packet p, Handler h)
  • void trace_event(char , Packet )
  • EventTrace et_
  • inline int hdr_dst(char hdr, int dst -2)
  • inline int hdr_src(char hdr, int src -2)
  • inline int hdr_type(char hdr, u_int16_t type
    0)
  • //To identify the BSS
  • inline int bss_id() return bss_id

13
802.11 MAC class(mac-802_11.h)
  • Protected methods
  • void backoffHandler(void)
  • void deferHandler(void)
  • void beaconHandler(void)
  • void navHandler(void)
  • void recvHandler(void)
  • void sendHandler(void)
  • void txHandler(void)

14
802.11 MAC class(mac-802_11.h)
  • Private methods
  • //Called by the timers
  • void recv_timer(void)
  • void send_timer(void)
  • int check_pktCTRL()
  • int check_pktRTS()
  • int check_pktTx()

15
802.11 MAC class(mac-802_11.h)
  • Private methods (contd.)
  • //Packet Transmission Functions
  • void send(Packet p, Handler h)
  • void sendRTS(int dst)
  • void sendCTS(int dst, double duration)
  • void sendACK(int dst)
  • void sendDATA(Packet p)
  • void RetransmitRTS()
  • void RetransmitDATA()

16
802.11 MAC class(mac-802_11.h)
  • Private methods (contd.)
  • //Packet Transmission Functions
  • void recvRTS(Packet p)
  • void recvCTS(Packet p)
  • void recvACK(Packet p)
  • void recvDATA(Packet p)

17
Internal MAC State(mac-802_11.h)
  • Defines Network allocation vector, incoming
    state, outgoing state and if the transmitter is
    active or not
  • double nav_ //Network Allocation Vector
  • MacState rx_state //incoming state
  • MacState tx_state //outgoing state
  • int tx_active_ //Transmitter is active
  • u_int32_t cw_ //Contention Window

18
Duplicate Detection State(mac-802_11.h)
  • u_int16_t sta_seqno
  • int cache_node_count_
  • Host cache_

19
Header Files(mac-802_11.cc)
  • delay.h
  • connector.h
  • packet.h
  • random.h
  • mobilenode.h
  • arp.h
  • 11.h
  • mac.h
  • mac-timers.h
  • mac-802_11.h
  • cmu-trace.h
  • agent.h
  • basetrace.h

To support even tracing
20
Global Variables(mac-802_11.cc)
  • DSSS parameters are defined here
  • DSSS_CWMin
  • DSSS_CWMax
  • DSSS_SlotTime
  • DSSS_CCATime
  • DSSS_RxTxTurnaroundTime
  • DSSS_SIFSTime
  • DSSS_PreambleLength
  • DSSS_PLCPHeaderLength
  • DSSS_PLCPDataRate

21
Outgoing packet routines(mac-802_11.cc)
  • Checks if the medium is idle or not, if it is not
    idle, it makes sure it doesnt send CTS
  • case MAC_Subtype_CTS
  • if(!is_idle())
  • discard(pktCTRL_, DROP_MAC_BUSY) pktCTRL_
    0
  • return 0

22
Outgoing packet routines(mac-802_11.cc)
  • Timeout is then calculated by adding CTS tx time
    to the CTS duration and subtracting ACK tx time
  • timeout txtime(phymib_.getCTSlen(),
    basicRate_)
  • DSSS_MaxPropagationDelay
  • sec(mh-gtdh_duration)
  • DSSS_MaxPropagationDelay
  • - phymib_.getSIFS()
  • - txtime(phymib_.getACKlen
    (), basicRate_)

23
Outgoing packet routines(mac-802_11.cc)
  • Acknowledgements are sent after an SIFS, without
    regard to the busy/idle state of the medium
  • case MAC_Subtype_ACK
  • setTxState(MAC_ACK)
  • timeout txtime(phymib_.getACKlen(),
    basicRate_)
  • break

24
Packet Format (packet.h)
  • Enum defines the various packet types which
    include and are not limited to TCP, UDP, CBR,
    ACK, Audio, Video, Prune, Stop, Accept, Confirm,
    FTP, Inval etc
  • enum packet_t
  • PT_TCP,
  • PT_UDP,
  • PT_CBR,
  • PT_AUDIO,
  • PT_VIDEO,
  • PT_ACK,
  • PT_START,
  • PT_STOP,

25
Packet Format (Packet.h)
  • Each packet contains a packet type field used by
    Traceformat to print out the type of packet
    encountered.
  • The type field is defined in the TraceHeader
    class, and is considered to be part of the trace
    support it is not interpreted elsewhere in the
    simulator.

26
Packet Format (Packet.h)
  • Initialization of the type field in packets is
    performed by the Agentallocpkt(void) method.
  • The type field is set to integer values
    associated with the definition passed to the
    Agent constructor

27
Class Packet Info (Packet.h)
  • This class is used as a glue to bind numeric
    packet type values with their symbolic names.
  • When a new packet type is defined, its numeric
    code should be added to the enumeration packet_t
  • class p_info
  • public
  • p_info()
  • name_PT_TCP "tcp"
  • name_PT_UDP "udp"
  • name_PT_CBR "cbr"
  • name_PT_AUDIO "audio"
  • name_PT_VIDEO "video"

28
Class Packet Info (Packet.h)
  • Boolean type of data packets are also added
    within this class
  • static bool data_packet(packet_t type)
  • return ( (type) PT_TCP \
  • (type) PT_TELNET \
  • (type) PT_CBR \
  • (type) PT_AUDIO \
  • (type) PT_VIDEO \
  • (type) PT_ACK \
  • (type) PT_SCTP \
  • (type) PT_SCTP_APP1 \
  • )

29
Class Packet Event (Packet.h)
  • This class holds a pointer to a generic array of
    unsigned characters called BOB (Bag of Bits)
    where packet header fields are stored
  • Private, protected and public variables are
    defined here
  • These initialize the packet header, length of
    buffer, the queues and packet free list
  • Also provide backward compatibility i.e assuming
    user data is PacketData and return to its pointer

30
Class Packet Event (Packet.h)
  • Private
  • unsigned char bits_ // header bits
  • AppData data_ // variable size buffer for
    'data'
  • static void init(Packet) // initialize pkt
    hdr
  • bool fflag_
  • Protected
  • static Packet free_ // packet free list
  • int ref_count_ // free the pkt until count to 0

31
Class Packet Event (Packet.h)
  • Public
  • Packet next_ // for queues and the free list
  • static int hdrlen_
  • inline unsigned char const bits()return
    (bits_)
  • inline Packet copy() const
  • inline Packet refcopy() ref_count_ return
    this
  • inline int ref_count() return (ref_count_)
  • static inline Packet alloc()
  • static inline Packet alloc(int)
  • inline void allocdata(int)
  • inline void initdata() data_ 0
  • static inline void free(Packet)

32
Class Packet Event (Packet.h)
  • Backward Compatibility
  • inline unsigned char accessdata() const
  • if (data_ 0)
  • return 0
  • assert(data_-gttype() PACKET_DATA)
  • return (((PacketData)data_)-gtdata())

33
Class Packet Event (Packet.h)
  • PacketStamp txinfo_
  • The pkt stamp carries all info about how/where
    the pkt was sent needed for a receiver to
    determine if it correctly receives the pkt
  • u_int8_t incoming
  • This flag is set by the MAC layer on an incoming
    packet and is cleared by the link layer

34
hdr_cmn class(Packet.h)
  • Every packet in the simulator has a common
    header which is defined in ns/packet.h as
    follows
  • struct hdr_cmn
  • double ts_ / timestamp for q-delay measurement
    /
  • packet_t ptype_ / packet type (see above) /
  • int uid_ / unique id /
  • int size_ / simulated packet size /
  • int iface_ / receiving interface (label) /

35
hdr_cmn class(Packet.h)
  • / Packet header access functions /
  • static int offset_
  • inline static int offset() return offset_
  • inline static hdr_cmn access(Packet p)
  • return (hdr_cmn) p-gtaccess(offset_)
  • / Per-field member functions /
  • int ptype() return (ptype_)
  • int uid() return (uid_)
  • int size() return (size_)
  • int iface() return (iface_)
  • double timestamp() return (ts_)

36
hdr_cmn class(Packet.h)
  • This structure primarily defines fields used for
    tracing the flow of packets or measuring other
    quantities.
  • The time stamp field is used to measure queuing
    delay at switch nodes.
  • The ptype_ field is used to identify the type of
    packets, which makes reading traces simpler.
  • The uid_ field is used by the scheduler in
    scheduling packet arrivals.
  • The size_ field is of generaluse and gives the
    simulated packets size in bytes.
  • The iface_ field is used by the simulator when
    performing multicast distribution tree
    computations. It is a label indicating
  • (typically) on which link a packet was received.

37
Allocation and Deallocation (Packets.h)
  • The other methods of Packet are for creating new
    packets and storing old ones in a private free
    list.
  • Such allocation and deallocation is performed by
  • inline Packet Packetalloc()
  • inline Packet Packetalloc(int n)
  • inline void Packetfree(Packet p)
  • inline void Packetallocdata(int n)

38
Commands at a glance
  • Following are a few of packet-header related
    procedures
  • ns_ create_packetformat
  • This is an internal simulator procedure and is
    called once during the simulator configuration to
    setup a packetHeaderManager object.
  • pktHdrManager allochdr
  • This is another internal procedure of Class
    PacketHeaderManager that keeps track of a
    variable called hdrlen_ as new packet-headers are
    enabled. It also allows 8-byte allignment for any
    newly-enabled pkt header.
Write a Comment
User Comments (0)
About PowerShow.com