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 Haldar. 00035 * 00036 * @(#) $Header: /cvsroot/nsnam/ns-2/mac/phy.h,v 1.7 2000/08/17 00:03:38 haoboy Exp $ 00037 * 00038 * superclass for all network interfaces 00039 00040 =================================================================== 00041 00042 * Phy represents the hardware that actually controls the channel 00043 * access for the node. Phy transmits/receives pkts from the channel 00044 * to which it is connected. No pkts are buffered at this layer as 00045 * the decision to send has already been made and the packet is on 00046 * its way to the "Channel". 00047 *================================================================== 00048 */ 00049 00050 #ifndef ns_phy_h 00051 #define ns_phy_h 00052 00053 #include <assert.h> 00054 #include "bi-connector.h" 00055 #include "lib/bsd-list.h" 00056 00057 class Phy; 00058 LIST_HEAD(if_head, Phy); 00059 00060 #include "channel.h" 00061 #include "node.h" 00062 #include "mac.h" 00063 00064 class Node; 00065 class LinkHead; 00066 /*-------------------------------------------------------------- 00067 Phy : Base class for all network interfaces used to control 00068 channel access 00069 ---------------------------------------------------------------*/ 00070 00071 class Phy : public BiConnector { 00072 public: 00073 Phy(); 00074 00075 void recv(Packet* p, Handler* h); 00076 00077 virtual void sendDown(Packet *p)=0; 00078 00079 virtual int sendUp(Packet *p)=0; 00080 00081 inline double txtime(Packet *p) { 00082 return (hdr_cmn::access(p)->size() * 8.0) / bandwidth_; } 00083 inline double txtime(int bytes) { 00084 return (8.0 * bytes / bandwidth_); } 00085 virtual double bittime() const { return 1/bandwidth_; } 00086 00087 // list of all network interfaces on a channel 00088 Phy* nextchnl(void) const { return chnl_link_.le_next; } 00089 inline void insertchnl(struct if_head *head) { 00090 LIST_INSERT_HEAD(head, this, chnl_link_); 00091 //channel_ = chnl; 00092 } 00093 // list of all network interfaces on a node 00094 Phy* nextnode(void) const { return node_link_.le_next; } 00095 inline void insertnode(struct if_head* head) { 00096 LIST_INSERT_HEAD(head, this, node_link_); 00097 //node_ = node; 00098 } 00099 inline void removechnl() { 00100 LIST_REMOVE(this, chnl_link_); 00101 } 00102 void setchnl (Channel *chnl) { channel_ = chnl; } 00103 virtual void setnode (Node *node) { node_ = node; } 00104 virtual Node* node(void) const { return node_; } 00105 virtual Channel* channel(void) const {return channel_;} 00106 00107 virtual void dump(void) const; 00108 LinkHead* head() { return head_; } 00109 00110 protected: 00111 //void drop(Packet *p); 00112 int command(int argc, const char*const* argv); 00113 int index_; 00114 00115 Node* node_; 00116 LinkHead* head_; // the entry point of this network stack 00117 00118 /* 00119 * A list of all "network interfaces" on a given channel. 00120 * Note: a node may have multiple interfaces, each of which 00121 * is on a different channel. 00122 */ 00123 LIST_ENTRY(Phy) chnl_link_; 00124 00125 /* 00126 * A list of all "network interfaces" for a given node. 00127 * Each interface is assoicated with exactly one node 00128 * and one channel. 00129 */ 00130 LIST_ENTRY(Phy) node_link_; 00131 00132 /* ============================================================ 00133 Physical Layer State 00134 ============================================================ */ 00135 00136 00137 double bandwidth_; // bit rate 00138 Channel *channel_; // the channel for output 00139 00140 }; 00141 00142 00143 #endif // ns_phy_h