📄 mac.h
字号:
/* -*- c++ -*- $Id: mac.h,v 1.12 1998/11/19 06:37:05 dmaltz Exp $*/#ifndef __mac_h__#define __mac_h__#include <assert.h>#include <connector.h>#include <packet.h>#include <cmu/ll.h>#include <cmu/net-if.h>#include <cmu/marshall.h>class Mac;/* ====================================================================== Defines / Macros used by all MACs. ====================================================================== */#define ETHER_ADDR(x) (GET4BYTE(x))#define MAC_HDR_LEN 64#define MAC_BROADCAST ((u_int32_t) 0xffffffff)#define ETHER_ADDR_LEN 6#define ETHER_TYPE_LEN 2#define ETHER_FCS_LEN 4#define ETHERTYPE_IP 0x0800#define ETHERTYPE_ARP 0x0806enum MacState { MAC_IDLE = 0x0000, MAC_POLLING = 0x0001, MAC_RECV = 0x0010, MAC_SEND = 0x0100, MAC_RTS = 0x0200, MAC_CTS = 0x0400, MAC_ACK = 0x0800, MAC_COLL = 0x1000,};/* ====================================================================== This packet header is just a place holder. The real headers are defined by their respective MAC protocols. ====================================================================== */struct hdr_mac { static int offset_;};/* ====================================================================== Objects that want to promiscously listen to the packets before address filtering must inherit from class Tap in order to plug into the tap ====================================================================== */class Tap {public: virtual void tap(const Packet *p) = 0; // tap is given all packets received by the host. // it must not alter or free the pkt. If you want to frob it, copy it.};/* ====================================================================== MAC data structure ====================================================================== */class Mac : public Connector {public: Mac(); inline u_int32_t address() { return index; } virtual void recv(Packet* p, Handler* h) = 0; virtual inline int hdr_dst(char* hdr, u_int32_t dst = 0) = 0; virtual inline int hdr_src(char* hdr, u_int32_t src = 0) = 0; virtual inline int hdr_type(char *hdr, u_int16_t type = 0) = 0; virtual void installTap(Tap *t) { tap = t; }private: virtual void discard(Packet *p, const char* why = 0) = 0; virtual void send(Packet *p, Handler *h) = 0;protected: virtual int command(int argc, const char*const* argv); virtual int initialized() { return (netif_ && recvtarget_ && sendtarget_); } u_int32_t index; // MAC Address double bitRate; int off_mac_; // MAC header offset NsObject *recvtarget_; NsObject *sendtarget_; NetIf *netif_; Tap *tap; LL *ll_; Handler *upcall_; // callback for end-of-transmission /* ============================================================ Internal MAC State ============================================================ */ MacState state; // MAC's current state Packet *pktRx; Packet *pktTx;};#endif /* __mac_h__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -