File: route.h

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (137 lines) | stat: -rw-r--r-- 4,981 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
 * Copyright (c) 1991-1994 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and the Network Research Group at
 *	Lawrence Berkeley Laboratory.
 * 4. Neither the name of the University nor of the Laboratory may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Routing code for general topologies based on min-cost routing algorithm in
 * Bertsekas' book.  Written originally by S. Keshav, 7/18/88
 * (his work covered by identical UC Copyright)
 *
 * @(#) $Header: /cvsroot/nsnam/ns-2/routing/route.h,v 1.9 2002/10/09 03:47:01 difa Exp $
 *
 */

#ifndef ns_route_h
#define ns_route_h

#undef INFINITY
#define INFINITY	0x3fff
#define INDEX(i, j, N) ((N) * (i) + (j))

/*** definitions for hierarchical routing support 
right now implemented for 3 levels of hierarchy --> should
be able to extend it for n levels of hierarchy in the future ***/

#define HIER_LEVEL	3
#define N_N_INDEX(i, j, a, b, c)	(((i) * (a+b+c)) + (j))
#define N_C_INDEX(i, j, a, b, c)	(((i) * (a+b+c)) + (a+j))
#define N_D_INDEX(i, j, a, b, c)	(((i) * (a+b+c)) + (a+(b-1)+j))
#define C_C_INDEX(i, j, a, b, c)	(((a+i) * (a+b+c)) + (a+j))
#define C_D_INDEX(i, j, a, b, c)	(((a+i) * (a+b+c)) + (a+(b-1)+j))
#define D_D_INDEX(i, j, a, b, c)	(((a+(b-1)+i) * (a+b+c)) + (a+(b-1)+j))

struct adj_entry {
	double cost;
	void* entry;
};

struct route_entry {
public:
	int next_hop;
	void* entry;
};

class RouteLogic : public TclObject {
public:
	RouteLogic();
	~RouteLogic();
	int command(int argc, const char*const* argv);
	virtual int lookup_flat(char* asrc, char* adst, int&result);
	virtual int lookup_flat(int sid, int did); //added for pushback - ratul
	int lookup_hier(char* asrc, char* adst, int&result);
	static void ns_strtok(char *addr, int *addrstr);
	int elements_in_level (int *addr, int level);
	inline int domains(){ return (D_-1); }
	inline int domain_size(int domain);
	inline int cluster_size(int domain, int cluster);
protected:

	void check(int);
	void alloc(int n);
	void reset(int src, int dst);
	void compute_routes();
	void insert(int src, int dst, double cost);
	adj_entry *adj_;
	route_entry *route_;
	void insert(int src, int dst, double cost, void* entry);
	void reset_all();
	int size_,
		maxnode_;

	/**** Hierarchical routing support ****/

	void hier_check(int index);
	void hier_alloc(int size);
	void hier_init(void);
	void str2address(const char*const* address, int *src, int *dst);
	void get_address(char * target, int next_hop, int index, int d, int size, int *src);
	void hier_insert(int *src, int *dst, int cost);
	void hier_reset(int *src, int *dst);
	void hier_compute();
	void hier_compute_routes(int index, int d);

	/* Debugging print functions */
	void hier_print_hadj();
	void hier_print_route();
	
	int	**hadj_;
	int	**hroute_;
	int	*hsize_;
	int	*cluster_size_;		/* no. of nodes/cluster/domain */
	char	***hconnect_;		/* holds the connectivity info --> address of target */
	int	level_;
	int	*C_;                    /* no. of clusters/domain */
	int	D_,			/* total no. of domains */
		Cmax_;			/* max value of C_ for initialization purpose */
	
};

class RouteLogicAlgo : public RouteLogic {
public:
	int lookup_flat(char* asrc, char* adst, int&result) {
		Tcl& tcl= Tcl::instance();
		tcl.evalf("%s lookup %s %s", name(), asrc, adst);
		result= atoi(tcl.result());
		return TCL_OK;
	}
};
#endif