• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mac/arp.h

00001 /*-*-   Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  */
00034 /* Ported from CMU/Monarch's code, nov'98 -Padma.*/
00035 
00036 
00037 #ifndef __arp_h__
00038 #define __arp_h__
00039 
00040 #include "scheduler.h"
00041 #include "delay.h"
00042 #include "lib/bsd-list.h"
00043 
00044 #ifndef EADDRNOTAVAIL
00045 #define EADDRNOTAVAIL 125
00046 #endif /* !EADDRNOTAVAIL */
00047 
00048 class LinkDelay;
00049 class ARPEntry;
00050 class ARPTable;
00051 class LL;
00052 class Mac;
00053 
00054 LIST_HEAD(ARPTable_List, ARPTable);
00055 LIST_HEAD(ARPEntry_List, ARPEntry);
00056 
00057 
00058 /* ======================================================================
00059    Address Resolution (ARP) Header
00060    ====================================================================== */
00061 #define ARPHRD_ETHER            1       /* ethernet hardware format */
00062 
00063 #define ARPOP_REQUEST           1       /* request to resolve address */
00064 #define ARPOP_REPLY             2       /* response to previous request */
00065 #define ARPOP_REVREQUEST        3       /* request protocol address */
00066 #define ARPOP_REVREPLY          4       /* response giving protocol address */
00067 #define ARPOP_INVREQUEST        8       /* request to identify peer */
00068 #define ARPOP_INVREPLY          9       /* response identifying peer */
00069 
00070 #define ARP_HDR_LEN             28
00071 
00072 struct hdr_arp {
00073         u_int16_t       arp_hrd;
00074         u_int16_t       arp_pro;
00075         u_int8_t        arp_hln;
00076         u_int8_t        arp_pln;
00077         u_int16_t       arp_op;
00078         int             arp_sha;
00079         u_int16_t       pad1;           // so offsets are correct
00080         nsaddr_t        arp_spa;
00081         int             arp_tha;
00082         u_int16_t       pad2;           // so offsets are correct
00083         nsaddr_t        arp_tpa;
00084 
00085         // Header access methods
00086         static int offset_; // required by PacketHeaderManager
00087         inline static int& offset() { return offset_; }
00088         inline static hdr_arp* access(const Packet* p) {
00089                 return (hdr_arp*) p->access(offset_);
00090         }
00091 };
00092 
00093 class ARPEntry {
00094         friend class ARPTable;
00095 public:
00096         ARPEntry(ARPEntry_List* head, nsaddr_t dst) {
00097                 up_ = macaddr_ = count_ = 0;
00098                 ipaddr_ = dst;
00099                 hold_ = 0;
00100                 LIST_INSERT_HEAD(head, this, arp_link_);
00101         }
00102         inline ARPEntry* nextarp() { return arp_link_.le_next; }
00103 
00104 private:
00105         LIST_ENTRY(ARPEntry)    arp_link_;
00106 
00107         int                     up_;
00108         nsaddr_t        ipaddr_;
00109         int                     macaddr_;
00110         Packet          *hold_;
00111         int                     count_;
00112 #define ARP_MAX_REQUEST_COUNT   3
00113 };
00114 
00115 
00116 class ARPTable : public LinkDelay {
00117 public:
00118         ARPTable(const char *tclnode, const char *tclmac);
00119 
00120         int     command(int argc, const char*const* argv);
00121         int     arpresolve(nsaddr_t dst, Packet *p, LL *ll);
00122         void    arpinput(Packet *p, LL *ll);
00123         ARPEntry* arplookup(nsaddr_t dst);
00124         void arprequest(nsaddr_t src, nsaddr_t dst, LL *ll);
00125 
00126         void    Terminate(void);
00127 
00128 private:
00129         inline int initialized() { return node_ && mac_; }
00130 
00131         ARPEntry_List   arphead_;
00132         MobileNode      *node_;
00133         Mac             *mac_;
00134 
00135         /*
00136          * Used to purge all of the ll->hold packets at the end of the
00137          * simulation.
00138          */
00139 public:
00140         LIST_ENTRY(ARPTable) link_;
00141         static ARPTable_List athead_;
00142 };
00143 
00144 #endif /* __arp_h__ */
00145 
00146 
00147 
00148 
00149 
00150 
00151 

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1