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 /* rtable.h -*- c++ -*- 00038 $Id: rtable.h,v 1.3 1999/03/13 03:53:15 haoboy Exp $ 00039 */ 00040 #ifndef cmu_rtable_h_ 00041 #define cmu_rtable_h_ 00042 00043 #include "config.h" 00044 #include "scheduler.h" 00045 #include "queue.h" 00046 00047 #define BIG 250 00048 00049 #define NEW_ROUTE_SUCCESS_NEWENT 0 00050 #define NEW_ROUTE_SUCCESS_OLDENT 1 00051 #define NEW_ROUTE_METRIC_TOO_HIGH 2 00052 #define NEW_ROUTE_ILLEGAL_CANCELLATION 3 00053 #define NEW_ROUTE_INTERNAL_ERROR 4 00054 00055 #ifndef uint 00056 typedef unsigned int uint; 00057 #endif // !uint 00058 00059 /* NOTE: we depend on bzero setting the booleans to ``false'' 00060 but if false != 0, so many things are screwed up, I don't 00061 know what to say... */ 00062 00063 class rtable_ent { 00064 public: 00065 rtable_ent() { bzero(this, sizeof(rtable_ent));} 00066 nsaddr_t dst; // destination 00067 nsaddr_t hop; // next hop 00068 uint metric; // distance 00069 00070 uint seqnum; // last sequence number we saw 00071 double advertise_ok_at; // when is it okay to advertise this rt? 00072 bool advert_seqnum; // should we advert rte b/c of new seqnum? 00073 bool advert_metric; // should we advert rte b/c of new metric? 00074 00075 /* 00076 00077 bool needs_advertised; // must this rte go in out in an update? 00078 bool needs_repeated_advert; // must this rte go out in all updates 00079 // until the next periodic update? 00080 */ 00081 Event *trigger_event; 00082 00083 uint last_advertised_metric; // metric carried in our last advert 00084 double changed_at; // when route last changed 00085 double new_seqnum_at; // when we last heard a new seq number 00086 double wst; // running wst info 00087 Event *timeout_event; // event used to schedule timeout action 00088 PacketQueue *q; //pkts queued for dst 00089 }; 00090 00091 // AddEntry adds an entry to the routing table with metric ent->metric+em. 00092 // You get to free the goods. 00093 // 00094 // GetEntry gets the entry for an address. 00095 00096 class RoutingTable { 00097 public: 00098 RoutingTable(); 00099 void AddEntry(const rtable_ent &ent); 00100 int RemainingLoop(); 00101 void InitLoop(); 00102 rtable_ent *NextLoop(); 00103 rtable_ent *GetEntry(nsaddr_t dest); 00104 00105 private: 00106 rtable_ent *rtab; 00107 int maxelts; 00108 int elts; 00109 int ctr; 00110 }; 00111 00112 #endif