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 00035 * @(#) $Header: 00036 00037 * 00038 * Ported from CMU/Monarch's code, nov'98 -Padma Haldar. 00039 * phy.cc 00040 */ 00041 00042 #include <math.h> 00043 00044 #include "config.h" 00045 #include <packet.h> 00046 #include <phy.h> 00047 #include <dsr/hdr_sr.h> 00048 00049 class Mac; 00050 00051 static int InterfaceIndex = 0; 00052 00053 00054 Phy::Phy() : BiConnector() { 00055 index_ = InterfaceIndex++; 00056 bandwidth_ = 0.0; 00057 channel_ = 0; 00058 node_ = 0; 00059 head_ = 0; 00060 } 00061 00062 int 00063 Phy::command(int argc, const char*const* argv) { 00064 if (argc == 2) { 00065 Tcl& tcl = Tcl::instance(); 00066 00067 if(strcmp(argv[1], "id") == 0) { 00068 tcl.resultf("%d", index_); 00069 return TCL_OK; 00070 } 00071 } 00072 00073 else if(argc == 3) { 00074 00075 TclObject *obj; 00076 00077 if( (obj = TclObject::lookup(argv[2])) == 0) { 00078 fprintf(stderr, "%s lookup failed\n", argv[1]); 00079 return TCL_ERROR; 00080 } 00081 if (strcmp(argv[1], "channel") == 0) { 00082 assert(channel_ == 0); 00083 channel_ = (Channel*) obj; 00084 downtarget_ = (NsObject*) obj; 00085 // LIST_INSERT_HEAD() is done by Channel 00086 return TCL_OK; 00087 } 00088 else if (strcmp(argv[1], "node") == 0) { 00089 assert(node_ == 0); 00090 node_ = (Node*) obj; 00091 // LIST_INSERT_HEAD() is done by Node 00092 return TCL_OK; 00093 } 00094 else if (strcmp(argv[1], "linkhead") == 0) { 00095 head_ = (LinkHead*) obj; 00096 return (TCL_OK); 00097 } 00098 00099 } 00100 return BiConnector::command(argc, argv); 00101 } 00102 00103 00104 00105 void 00106 Phy::recv(Packet* p, Handler*) 00107 { 00108 struct hdr_cmn *hdr = HDR_CMN(p); 00109 //struct hdr_sr *hsr = HDR_SR(p); 00110 00111 /* 00112 * Handle outgoing packets 00113 */ 00114 switch(hdr->direction()) { 00115 case hdr_cmn::DOWN : 00116 /* 00117 * The MAC schedules its own EOT event so we just 00118 * ignore the handler here. It's only purpose 00119 * it distinguishing between incoming and outgoing 00120 * packets. 00121 */ 00122 sendDown(p); 00123 return; 00124 case hdr_cmn::UP : 00125 if (sendUp(p) == 0) { 00126 /* 00127 * XXX - This packet, even though not detected, 00128 * contributes to the Noise floor and hence 00129 * may affect the reception of other packets. 00130 */ 00131 Packet::free(p); 00132 return; 00133 } else { 00134 uptarget_->recv(p, (Handler*) 0); 00135 } 00136 break; 00137 default: 00138 printf("Direction for pkt-flow not specified; Sending pkt up the stack on default.\n\n"); 00139 if (sendUp(p) == 0) { 00140 /* 00141 * XXX - This packet, even though not detected, 00142 * contributes to the Noise floor and hence 00143 * may affect the reception of other packets. 00144 */ 00145 Packet::free(p); 00146 return; 00147 } else { 00148 uptarget_->recv(p, (Handler*) 0); 00149 } 00150 } 00151 00152 } 00153 00154 /* NOTE: this might not be the best way to structure the relation 00155 between the actual interfaces subclassed from net-if(phy) and 00156 net-if(phy). 00157 It's fine for now, but if we were to decide to have the interfaces 00158 themselves properly handle multiple incoming packets (they currently 00159 require assistance from the mac layer to do this), then it's not as 00160 generic as I'd like. The way it is now, each interface will have to 00161 have it's own logic to keep track of the packets that are arriving. 00162 Seems like this is general service that net-if could provide. 00163 00164 Ok. A fair amount of restructuring is going to have to happen here 00165 when/if net-if keep track of the noise floor at their location. I'm 00166 gonna punt on it for now. 00167 00168 Actually, this may be all wrong. Perhaps we should keep a separate 00169 noise floor per antenna, which would mean the particular interface types 00170 would have to track noise floor themselves, since only they know what 00171 kind of antenna diversity they have. -dam 8/7/98 */ 00172 00173 00174 // double 00175 // Phy::txtime(Packet *p) const 00176 // { 00177 // hdr_cmn *hdr = HDR_CMN(p); 00178 // return hdr->size() * 8.0 / Rb_; 00179 // } 00180 00181 00182 void 00183 Phy::dump(void) const 00184 { 00185 fprintf(stdout, "\tINDEX: %d\n", 00186 index_); 00187 fprintf(stdout, "\tuptarget: %lx, channel: %lx", 00188 (long) uptarget_, (long) channel_); 00189 00190 } 00191 00192
1.4.6