tbsetdest.h 5.02 KB
Newer Older
1

Timothy Stack's avatar
Timothy Stack committed
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
/*
 * Copyright (c) 1997, 1998, 2005 Carnegie Mellon University.  All Rights
 * Reserved. 
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation is hereby granted (including for
 * commercial or for-profit use), provided that both the copyright notice
 * and this permission notice appear in all copies of the software,
 * derivative works, or modified versions, and any portions thereof, and
 * that both notices appear in supporting documentation, and that credit
 * is given to Carnegie Mellon University in all publications reporting
 * on direct or indirect use of this code or its derivatives.
 * 
 * ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMU
 * MONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OF
 * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
 * SOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,
 * 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 CARNEGIE MELLON UNIVERSITY
 * 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 OR
 * INTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 * 
 * Carnegie Mellon encourages (but does not require) users of this
 * software or intellectual property to return any improvements or
 * extensions that they make, and to grant Carnegie Mellon the rights to
 * redistribute these changes without encumbrance.
 */

/*
 * Copyright (c) 2005 University of Utah and the Flux Group.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
Timothy Stack's avatar
Timothy Stack committed
58 59
 */

60 61 62 63 64
#ifndef __tbsetdest_h__
#define __tbsetdest_h__

#include "config.h"
#include <sys/queue.h>
65 66 67 68 69 70 71 72 73 74

#ifndef LIST_FIRST
#define LIST_FIRST(head)	((head)->lh_first)
#endif
#ifndef LIST_NEXT
#define LIST_NEXT(elm, field)	((elm)->field.le_next)
#endif

void ReadInMovementPattern(void);

75
class sdvector {
76
public:
77
	sdvector(double x = 0.0, double y = 0.0, double z = 0.0) {
78 79 80 81 82 83
		X = x; Y = y; Z = z;
	}
	double length() {
		return sqrt(X*X + Y*Y + Z*Z);
	}

84
	inline void sdvector::operator=(const sdvector a) {
85 86 87 88
		X = a.X;
		Y = a.Y;
		Z = a.Z;
	}
89
	inline void sdvector::operator+=(const sdvector a) {
90 91 92 93
		X += a.X;
		Y += a.Y;
		Z += a.Z;
	}
94
	inline int sdvector::operator==(const sdvector a) {
95 96
		return (X == a.X && Y == a.Y && Z == a.Z);
	}
97
	inline int sdvector::operator!=(const sdvector a) {
98 99
		return (X != a.X || Y != a.Y || Z != a.Z);
	}
100 101
	inline sdvector operator-(const sdvector a) {
		return sdvector(X-a.X, Y-a.Y, Z-a.Z);
102
	}
103 104
	friend inline sdvector operator*(const double a, const sdvector b) {
		return sdvector(a*b.X, a*b.Y, a*b.Z);
105
	}
106 107
	friend inline sdvector operator/(const sdvector a, const double b) {
		return sdvector(a.X/b, a.Y/b, a.Z/b);
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
	}

	double X;
	double Y;
	double Z;
};


class Neighbor {
public:
	u_int32_t	index;			// index into NodeList
	u_int32_t	reachable;		// != 0 --> reachable.
	double		time_transition;	// next change

};

struct setdest {
  double time;
  double X, Y, Z;
  double speed;
  LIST_ENTRY(setdest)   traj;
};

class Node {
  friend void ReadInMovementPattern(void);
public:
	Node(void);
	void	Update(void);
	void	UpdateNeighbors(void);
	void	Dump(void);

	double		time_arrival;		// time of arrival at dest
	double		time_transition;	// min of all neighbor times

	// # of optimal route changes for this node
	int		route_changes;
        int             link_changes;

private:
	void	RandomPosition(void);
	void	RandomDestination(void);
	void	RandomSpeed(void);

	u_int32_t	index;                  // unique node identifier
	u_int32_t 	first_trip;		// 1 if first trip, 0 otherwise. (by J. Yoon)

154 155 156
	sdvector	position;		// current position
	sdvector	destination;		// destination
	sdvector	direction;		// computed from pos and dest
157 158 159 160 161 162 163 164 165 166 167 168 169 170

	double		speed;
	double		time_update;		// when pos last updated

	static u_int32_t	NodeIndex;

	LIST_HEAD(traj, setdest) traj;

public:
	// An array of NODES neighbors.
	Neighbor	*neighbor;
};

#endif /* __setdest_h__ */