00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1999 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 MASH Research 00017 * Group at the University of California Berkeley. 00018 * 4. Neither the name of the University nor of the Research Group may be 00019 * used 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 * @(#) $Header: /cvsroot/nsnam/ns-2/satellite/satroute.h,v 1.4 2005/05/19 03:19:02 tomh Exp $ 00035 * 00036 * Contributed by Tom Henderson, UCB Daedalus Research Group, June 1999 00037 */ 00038 00039 #ifndef ns_satroute_h_ 00040 #define ns_satroute_h_ 00041 00042 #include <agent.h> 00043 #include "route.h" 00044 #include "node.h" 00045 00046 #define ROUTER_PORT 0xff 00047 #define SAT_ROUTE_INFINITY 0x3fff 00048 00049 // Entry in the forwarding table 00050 struct slot_entry { 00051 int next_hop; 00052 NsObject* entry; 00053 }; 00054 00055 class SatNode; 00056 // 00057 // Currently, this only implements centralized routing. However, by 00058 // following the examples in the mobility code, one could build on this 00059 // agent to make it a distributed routing agent 00060 // 00061 class SatRouteAgent : public Agent { 00062 public: 00063 SatRouteAgent(); 00064 ~SatRouteAgent(); 00065 int command(int argc, const char * const * argv); 00066 00067 // centralized routing 00068 void clear_slots(); 00069 void install(int dst, int next_hop, NsObject* p); 00070 SatNode* node() { return node_; } 00071 int myaddr() {return myaddr_; } 00072 00073 protected: 00074 virtual void recv(Packet *, Handler *); 00075 void forwardPacket(Packet*); 00076 int myaddr_; // My address-- set from OTcl 00077 00078 // centralized routing stuff 00079 int maxslot_; 00080 int nslot_; 00081 slot_entry* slot_; // Node's forwarding table 00082 void alloc(int); // Helper function 00083 SatNode* node_; 00084 00085 }; 00086 00088 00089 // A global route computation object/genie 00090 // This class performs operations very similar to what "Simulator instproc 00091 // compute-routes" does at OTcl-level, except it performs them entirely 00092 // in C++. Single source shortest path routing is also supported. 00093 class SatRouteObject : public RouteLogic { 00094 public: 00095 SatRouteObject(); 00096 static SatRouteObject& instance() { 00097 return (*instance_); // general access to route object 00098 } 00099 void recompute(); 00100 void recompute_node(int node); 00101 int command(int argc, const char * const * argv); 00102 int data_driven_computation() { return data_driven_computation_; } 00103 void insert_link(int src, int dst, double cost); 00104 void insert_link(int src, int dst, double cost, void* entry); 00105 int wiredRouting() { return wiredRouting_;} 00106 //void hier_insert_link(int *src, int *dst, int cost); // support hier-rtg? 00107 00108 protected: 00109 void compute_topology(); 00110 void populate_routing_tables(int node = -1); 00111 int lookup(int src, int dst); 00112 void* lookup_entry(int src, int dst); 00113 void node_compute_routes(int node); 00114 void dump(); // for debugging only 00115 00116 static SatRouteObject* instance_; 00117 int metric_delay_; 00118 int suppress_initial_computation_; 00119 int data_driven_computation_; 00120 int wiredRouting_; 00121 }; 00122 00123 #endif