• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/routing/route.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1991-1994 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 University of
00017  *      California, Berkeley and the Network Research Group at
00018  *      Lawrence Berkeley Laboratory.
00019  * 4. Neither the name of the University nor of the Laboratory may be used
00020  *    to endorse or promote products derived from this software without
00021  *    specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * Routing code for general topologies based on min-cost routing algorithm in
00036  * Bertsekas' book.  Written originally by S. Keshav, 7/18/88
00037  * (his work covered by identical UC Copyright)
00038  *
00039  * @(#) $Header: /cvsroot/nsnam/ns-2/routing/route.h,v 1.9 2002/10/09 03:47:01 difa Exp $
00040  *
00041  */
00042 
00043 #ifndef ns_route_h
00044 #define ns_route_h
00045 
00046 #undef INFINITY
00047 #define INFINITY        0x3fff
00048 #define INDEX(i, j, N) ((N) * (i) + (j))
00049 
00050 /*** definitions for hierarchical routing support 
00051 right now implemented for 3 levels of hierarchy --> should
00052 be able to extend it for n levels of hierarchy in the future ***/
00053 
00054 #define HIER_LEVEL      3
00055 #define N_N_INDEX(i, j, a, b, c)        (((i) * (a+b+c)) + (j))
00056 #define N_C_INDEX(i, j, a, b, c)        (((i) * (a+b+c)) + (a+j))
00057 #define N_D_INDEX(i, j, a, b, c)        (((i) * (a+b+c)) + (a+(b-1)+j))
00058 #define C_C_INDEX(i, j, a, b, c)        (((a+i) * (a+b+c)) + (a+j))
00059 #define C_D_INDEX(i, j, a, b, c)        (((a+i) * (a+b+c)) + (a+(b-1)+j))
00060 #define D_D_INDEX(i, j, a, b, c)        (((a+(b-1)+i) * (a+b+c)) + (a+(b-1)+j))
00061 
00062 struct adj_entry {
00063         double cost;
00064         void* entry;
00065 };
00066 
00067 struct route_entry {
00068 public:
00069         int next_hop;
00070         void* entry;
00071 };
00072 
00073 class RouteLogic : public TclObject {
00074 public:
00075         RouteLogic();
00076         ~RouteLogic();
00077         int command(int argc, const char*const* argv);
00078         virtual int lookup_flat(char* asrc, char* adst, int&result);
00079         virtual int lookup_flat(int sid, int did); //added for pushback - ratul
00080         int lookup_hier(char* asrc, char* adst, int&result);
00081         static void ns_strtok(char *addr, int *addrstr);
00082         int elements_in_level (int *addr, int level);
00083         inline int domains(){ return (D_-1); }
00084         inline int domain_size(int domain);
00085         inline int cluster_size(int domain, int cluster);
00086 protected:
00087 
00088         void check(int);
00089         void alloc(int n);
00090         void reset(int src, int dst);
00091         void compute_routes();
00092         void insert(int src, int dst, double cost);
00093         adj_entry *adj_;
00094         route_entry *route_;
00095         void insert(int src, int dst, double cost, void* entry);
00096         void reset_all();
00097         int size_,
00098                 maxnode_;
00099 
00100         /**** Hierarchical routing support ****/
00101 
00102         void hier_check(int index);
00103         void hier_alloc(int size);
00104         void hier_init(void);
00105         void str2address(const char*const* address, int *src, int *dst);
00106         void get_address(char * target, int next_hop, int index, int d, int size, int *src);
00107         void hier_insert(int *src, int *dst, int cost);
00108         void hier_reset(int *src, int *dst);
00109         void hier_compute();
00110         void hier_compute_routes(int index, int d);
00111 
00112         /* Debugging print functions */
00113         void hier_print_hadj();
00114         void hier_print_route();
00115         
00116         int     **hadj_;
00117         int     **hroute_;
00118         int     *hsize_;
00119         int     *cluster_size_;         /* no. of nodes/cluster/domain */
00120         char    ***hconnect_;           /* holds the connectivity info --> address of target */
00121         int     level_;
00122         int     *C_;                    /* no. of clusters/domain */
00123         int     D_,                     /* total no. of domains */
00124                 Cmax_;                  /* max value of C_ for initialization purpose */
00125         
00126 };
00127 
00128 class RouteLogicAlgo : public RouteLogic {
00129 public:
00130         int lookup_flat(char* asrc, char* adst, int&result) {
00131                 Tcl& tcl= Tcl::instance();
00132                 tcl.evalf("%s lookup %s %s", name(), asrc, adst);
00133                 result= atoi(tcl.result());
00134                 return TCL_OK;
00135         }
00136 };
00137 #endif

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1