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 __mrcl_arp_h__ 00038 #define __mrcl_arp_h__ 00039 00040 #include "scheduler.h" 00041 #include "delay.h" 00042 //#include "arp.h" 00043 #include "lib/bsd-list.h" 00044 00045 #ifndef EADDRNOTAVAIL 00046 #define EADDRNOTAVAIL 125 00047 #endif /* !EADDRNOTAVAIL */ 00048 00049 class LinkDelay; 00050 class MrclARPEntry; 00051 class MrclARPTable; 00052 class MrclLL; 00053 class Mac; 00054 00055 LIST_HEAD(MrclARPTable_List, MrclARPTable); 00056 LIST_HEAD(MrclARPEntry_List, MrclARPEntry); 00057 00058 00059 /* ====================================================================== 00060 Address Resolution (ARP) Header 00061 ====================================================================== */ 00062 #define ARPHRD_ETHER 1 /* ethernet hardware format */ 00063 00064 #define ARPOP_REQUEST 1 /* request to resolve address */ 00065 #define ARPOP_REPLY 2 /* response to previous request */ 00066 #define ARPOP_REVREQUEST 3 /* request protocol address */ 00067 #define ARPOP_REVREPLY 4 /* response giving protocol address */ 00068 #define ARPOP_INVREQUEST 8 /* request to identify peer */ 00069 #define ARPOP_INVREPLY 9 /* response identifying peer */ 00070 00071 #define ARP_HDR_LEN 28 00072 00073 // struct hdr_arp { 00074 // u_int16_t arp_hrd; 00075 // u_int16_t arp_pro; 00076 // u_int8_t arp_hln; 00077 // u_int8_t arp_pln; 00078 // u_int16_t arp_op; 00079 // int arp_sha; 00080 // u_int16_t pad1; // so offsets are correct 00081 // nsaddr_t arp_spa; 00082 // int arp_tha; 00083 // u_int16_t pad2; // so offsets are correct 00084 // nsaddr_t arp_tpa; 00085 // 00086 // // Header access methods 00087 // static int offset_; // required by PacketHeaderManager 00088 // inline static int& offset() { return offset_; } 00089 // inline static hdr_arp* access(const Packet* p) { 00090 // return (hdr_arp*) p->access(offset_); 00091 // } 00092 // }; 00093 00094 class MrclARPEntry { 00095 friend class MrclARPTable; 00096 public: 00097 MrclARPEntry(MrclARPEntry_List* head, nsaddr_t dst) { 00098 up_ = macaddr_ = count_ = 0; 00099 ipaddr_ = dst; 00100 hold_ = 0; 00101 LIST_INSERT_HEAD(head, this, arp_link_); 00102 } 00103 inline MrclARPEntry* nextarp() { return arp_link_.le_next; } 00104 00105 private: 00106 LIST_ENTRY(MrclARPEntry) arp_link_; 00107 00108 int up_; 00109 nsaddr_t ipaddr_; 00110 int macaddr_; 00111 Packet *hold_; 00112 int count_; 00113 #define ARP_MAX_REQUEST_COUNT 3 00114 }; 00115 00116 00117 class MrclARPTable : public LinkDelay { 00118 public: 00119 MrclARPTable(const char *IPaddr, const char *tclmac); 00120 00121 int command(int argc, const char*const* argv); 00122 int arpresolve(nsaddr_t dst, Packet *p, MrclLL *ll); 00123 void arpinput(Packet *p, MrclLL *ll); 00124 MrclARPEntry* arplookup(nsaddr_t dst); 00125 void arprequest(nsaddr_t src, nsaddr_t dst, MrclLL *ll); 00126 00127 void Terminate(void); 00128 00129 private: 00130 inline int initialized() { return (mac_!=0); } 00131 00132 MrclARPEntry_List arphead_; 00133 //MobileNode *node_; 00134 int IPaddress_; // Node IP address 00135 Mac *mac_; 00136 00137 /* 00138 * Used to purge all of the ll->hold packets at the end of the 00139 * simulation. 00140 */ 00141 public: 00142 LIST_ENTRY(MrclARPTable) link_; 00143 static MrclARPTable_List athead_; 00144 }; 00145 00146 #endif /* __arp_h__ */ 00147 00148 00149 00150 00151 00152 00153