Beruflich Dokumente
Kultur Dokumente
mac-802_11.h
Go to the documentation of this file.
1 of 7 12/03/2010 04:56 PM
NS2.26SourcesOriginal: mac-802_11.h Source File http://www-rp.lip6.fr/ns-doc/ns226-doc/html/mac-8...
00048
00049 /* ======================================================================
00050 Frame Formats
00051 ====================================================================== */
00052
00053 #define MAC_ProtocolVersion 0x00
00054
00055 #define MAC_Type_Management 0x00
00056 #define MAC_Type_Control 0x01
00057 #define MAC_Type_Data 0x02
00058 #define MAC_Type_Reserved 0x03
00059
00060 #define MAC_Subtype_RTS 0x0B
00061 #define MAC_Subtype_CTS 0x0C
00062 #define MAC_Subtype_ACK 0x0D
00063 #define MAC_Subtype_Data 0x00
00064
00065 struct frame_control {
00066 u_char fc_subtype : 4;
00067 u_char fc_type : 2;
00068 u_char fc_protocol_version : 2;
00069
00070 u_char fc_order : 1;
00071 u_char fc_wep : 1;
00072 u_char fc_more_data : 1;
00073 u_char fc_pwr_mgt : 1;
00074 u_char fc_retry : 1;
00075 u_char fc_more_frag : 1;
00076 u_char fc_from_ds : 1;
00077 u_char fc_to_ds : 1;
00078 };
00079
00080 struct rts_frame {
00081 struct frame_control rf_fc;
00082 u_int16_t rf_duration;
00083 u_char rf_ra[ETHER_ADDR_LEN];
00084 u_char rf_ta[ETHER_ADDR_LEN];
00085 u_char rf_fcs[ETHER_FCS_LEN];
00086 };
00087
00088 struct cts_frame {
00089 struct frame_control cf_fc;
00090 u_int16_t cf_duration;
00091 u_char cf_ra[ETHER_ADDR_LEN];
00092 u_char cf_fcs[ETHER_FCS_LEN];
00093 };
00094
00095 struct ack_frame {
00096 struct frame_control af_fc;
00097 u_int16_t af_duration;
00098 u_char af_ra[ETHER_ADDR_LEN];
00099 u_char af_fcs[ETHER_FCS_LEN];
00100 };
00101
00102 // XXX This header does not have its header access function because it shares
00103 // the same header space with hdr_mac.
00104 struct hdr_mac802_11 {
00105 struct frame_control dh_fc;
2 of 7 12/03/2010 04:56 PM
NS2.26SourcesOriginal: mac-802_11.h Source File http://www-rp.lip6.fr/ns-doc/ns226-doc/html/mac-8...
3 of 7 12/03/2010 04:56 PM
NS2.26SourcesOriginal: mac-802_11.h Source File http://www-rp.lip6.fr/ns-doc/ns226-doc/html/mac-8...
4 of 7 12/03/2010 04:56 PM
NS2.26SourcesOriginal: mac-802_11.h Source File http://www-rp.lip6.fr/ns-doc/ns226-doc/html/mac-8...
00222 };
00223
00224
00225 /* ======================================================================
00226 The actual 802.11 MAC class.
00227 ====================================================================== */
00228 class Mac802_11 : public Mac {
00229 friend class DeferTimer;
00230 friend class BackoffTimer;
00231 friend class IFTimer;
00232 friend class NavTimer;
00233 friend class RxTimer;
00234 friend class TxTimer;
00235 public:
00236 Mac802_11(PHY_MIB* p, MAC_MIB *m);
00237 void recv(Packet *p, Handler *h);
00238 inline int hdr_dst(char* hdr, int dst = -2);
00239 inline int hdr_src(char* hdr, int src = -2);
00240 inline int hdr_type(char* hdr, u_int16_t type = 0);
00241
00242 protected:
00243 void backoffHandler(void);
00244 void deferHandler(void);
00245 void navHandler(void);
00246 void recvHandler(void);
00247 void sendHandler(void);
00248 void txHandler(void);
00249
00250 private:
00251 int command(int argc, const char*const* argv);
00252
00253 /*
00254 * Called by the timers.
00255 */
00256 void recv_timer(void);
00257 void send_timer(void);
00258 int check_pktCTRL();
00259 int check_pktRTS();
00260 int check_pktTx();
00261
00262 /*
00263 * Packet Transmission Functions.
00264 */
00265 void send(Packet *p, Handler *h);
00266 void sendRTS(int dst);
00267 void sendCTS(int dst, double duration);
00268 void sendACK(int dst);
00269 void sendDATA(Packet *p);
00270 void RetransmitRTS();
00271 void RetransmitDATA();
00272
00273 /*
00274 * Packet Reception Functions.
00275 */
00276 void recvRTS(Packet *p);
00277 void recvCTS(Packet *p);
00278 void recvACK(Packet *p);
00279 void recvDATA(Packet *p);
5 of 7 12/03/2010 04:56 PM
NS2.26SourcesOriginal: mac-802_11.h Source File http://www-rp.lip6.fr/ns-doc/ns226-doc/html/mac-8...
00280
00281 void capture(Packet *p);
00282 void collision(Packet *p);
00283 void discard(Packet *p, const char* why);
00284 void rx_resume(void);
00285 void tx_resume(void);
00286
00287 inline int is_idle(void);
00288
00289 /*
00290 * Debugging Functions.
00291 */
00292 void trace_pkt(Packet *p);
00293 void dump(char* fname);
00294
00295 inline int initialized() {
00296 return (phymib_ && macmib_ && cache_ && logtarget_ &&
00297 Mac::initialized());
00298 }
00299 void mac_log(Packet *p) {
00300 logtarget_->recv(p, (Handler*) 0);
00301 }
00302 double txtime(Packet *p);
00303 double txtime(double psz, double drt);
00304 double txtime(int bytes) { /* clobber inherited txtime() */ abort(); }
00305
00306 inline void inc_cw() {
00307 cw_ = (cw_ << 1) + 1;
00308 if(cw_ > phymib_->CWMax)
00309 cw_ = phymib_->CWMax;
00310 }
00311 inline void rst_cw() { cw_ = phymib_->CWMin; }
00312 inline double sec(double t) { return(t *= 1.0e-6); }
00313 inline u_int16_t usec(double t) {
00314 u_int16_t us = (u_int16_t)floor((t *= 1e6) + 0.5);
00315 /* u_int16_t us = (u_int16_t)rint(t *= 1e6); */
00316 return us;
00317 }
00318 inline void set_nav(u_int16_t us) {
00319 double now = Scheduler::instance().clock();
00320 double t = us * 1e-6;
00321
00322 if((now + t) > nav_) {
00323 nav_ = now + t;
00324 if(mhNav_.busy())
00325 mhNav_.stop();
00326 mhNav_.start(t);
00327 }
00328 }
00329
00330 protected:
00331 PHY_MIB *phymib_;
00332 MAC_MIB *macmib_;
00333
00334 private:
00335 double basicRate_;
00336 double dataRate_;
00337
6 of 7 12/03/2010 04:56 PM
NS2.26SourcesOriginal: mac-802_11.h Source File http://www-rp.lip6.fr/ns-doc/ns226-doc/html/mac-8...
00338 /*
00339 * Mac Timers
00340 */
00341 IFTimer mhIF_; // interface timer
00342 NavTimer mhNav_; // NAV timer
00343 RxTimer mhRecv_; // incoming packets
00344 TxTimer mhSend_; // outgoing packets
00345
00346 DeferTimer mhDefer_; // defer timer
00347 BackoffTimer mhBackoff_; // backoff timer
00348
00349 /* ============================================================
00350 Internal MAC State
00351 ============================================================ */
00352 double nav_; // Network Allocation Vector
00353
00354 MacState rx_state_; // incoming state (MAC_RECV or MAC_IDLE)
00355 MacState tx_state_; // outgoint state
00356 int tx_active_; // transmitter is ACTIVE
00357
00358 Packet *pktRTS_; // outgoing RTS packet
00359 Packet *pktCTRL_; // outgoing non-RTS packet
00360
00361 u_int32_t cw_; // Contention Window
00362 u_int32_t ssrc_; // STA Short Retry Count
00363 u_int32_t slrc_; // STA Long Retry Count
00364 double sifs_; // Short Interface Space
00365 double pifs_; // PCF Interframe Space
00366 double difs_; // DCF Interframe Space
00367 double eifs_; // Extended Interframe Space
00368 double tx_sifs_;
00369 double tx_pifs_;
00370 double tx_difs_;
00371
00372 int min_frame_len_;
00373
00374 NsObject* logtarget_;
00375
00376 /* ============================================================
00377 Duplicate Detection state
00378 ============================================================ */
00379 u_int16_t sta_seqno_; // next seqno that I'll use
00380 int cache_node_count_;
00381 Host *cache_;
00382 };
00383
00384 #endif /* __mac_80211_h__ */
00385
7 of 7 12/03/2010 04:56 PM