1.1 --- a/utils/mobility-generator.cc Wed Jun 17 12:07:25 2009 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,66 +0,0 @@
1.4 -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
1.5 -/*
1.6 - * Copyright (c) 2007 INRIA
1.7 - *
1.8 - * This program is free software; you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License version 2 as
1.10 - * published by the Free Software Foundation;
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License
1.18 - * along with this program; if not, write to the Free Software
1.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.20 - *
1.21 - * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
1.22 - */
1.23 -
1.24 -#include "ns3/ns2-mobility-file-topology.h"
1.25 -#include "ns3/object.h"
1.26 -#include "ns3/simulator.h"
1.27 -#include "ns3/mobility-model-notifier.h"
1.28 -#include <iostream>
1.29 -
1.30 -using namespace ns3;
1.31 -
1.32 -static void
1.33 -CourseChange (Ptr<const MobilityModel> position)
1.34 -{
1.35 - Position pos = position->Get ();
1.36 - std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
1.37 - << ", z=" << pos.z << std::endl;
1.38 -}
1.39 -
1.40 -int main (int argc, char *argv[])
1.41 -{
1.42 - std::vector<Ptr<Object> > objects;
1.43 - while (argc > 0)
1.44 - {
1.45 - if (strncmp (*argv, "--n=", strlen ("--n=")) == 0)
1.46 - {
1.47 - uint32_t n = atoi (*argv + strlen ("--n="));
1.48 - for (uint32_t i = 0; i < n; i++)
1.49 - {
1.50 - Ptr<MobilityModelNotifier> notifier = CreateObject<MobilityModelNotifier> ();
1.51 - notifier->RegisterListener (MakeCallback (&CourseChange));
1.52 - objects.push_back (notifier);
1.53 - }
1.54 - }
1.55 - else if (strncmp (*argv, "--ns2-topology=",
1.56 - strlen ("--ns2-topology=")) == 0)
1.57 - {
1.58 - const char *filename = *argv + strlen ("--ns2-topology=");
1.59 - Ns2MobilityFileTopology topology (filename);
1.60 - topology.Layout (objects.begin (), objects.end ());
1.61 - }
1.62 - argc--;
1.63 - argv++;
1.64 - }
1.65 -
1.66 - Simulator::Run ();
1.67 - Simulator::Destroy ();
1.68 - return 0;
1.69 -}
2.1 --- a/utils/mobility-visualizer-model.cc Wed Jun 17 12:07:25 2009 +0100
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,140 +0,0 @@
2.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2.5 -
2.6 -#include <vector>
2.7 -
2.8 -#include "ns3/ptr.h"
2.9 -#include "ns3/mobility-model.h"
2.10 -#include "ns3/mobility-model-notifier.h"
2.11 -#include "ns3/position-allocator.h"
2.12 -#include "ns3/default-value.h"
2.13 -#include "ns3/command-line.h"
2.14 -#include "ns3/command-line.h"
2.15 -#include "ns3/simulator.h"
2.16 -#include "ns3/nstime.h"
2.17 -#include "ns3/node.h"
2.18 -#include "ns3/node-list.h"
2.19 -#include "ns3/rectangle-default-value.h"
2.20 -#include "ns3/type-id-default-value.h"
2.21 -#include "ns3/mobility-helper.h"
2.22 -
2.23 -#include "mobility-visualizer.h"
2.24 -
2.25 -using namespace ns3;
2.26 -
2.27 -static Time g_sampleInterval = Seconds (SAMPLE_INTERVAL);
2.28 -static uint32_t g_numNodes = 10;
2.29 -
2.30 -template <typename T>
2.31 -static const T* DefaultValueListGet (const std::string &name)
2.32 -{
2.33 - for (DefaultValueList::Iterator iter = DefaultValueList::Begin ();
2.34 - iter != DefaultValueList::End (); iter++)
2.35 - {
2.36 - const DefaultValueBase *value = *iter;
2.37 - if (value->GetName () == name)
2.38 - {
2.39 - return dynamic_cast<const T*> (value);
2.40 - }
2.41 - }
2.42 - return NULL;
2.43 -}
2.44 -
2.45 -
2.46 -
2.47 -static void
2.48 -Sample ()
2.49 -{
2.50 -
2.51 - ViewUpdateData *data = new ViewUpdateData;
2.52 - for (NodeList::Iterator nodeIter = NodeList::Begin (); nodeIter != NodeList::End (); nodeIter++)
2.53 - {
2.54 - Ptr<Node> node = *nodeIter;
2.55 - Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
2.56 - Vector pos = mobility->GetPosition ();
2.57 - Vector vel = mobility->GetVelocity ();
2.58 -
2.59 - NodeUpdate update;
2.60 - update.node = PeekPointer<Node> (node);
2.61 - update.x = pos.x;
2.62 - update.y = pos.y;
2.63 - update.vx = vel.x;
2.64 - update.vy = vel.y;
2.65 - data->updateList.push_back (update);
2.66 - }
2.67 - data->time = Simulator::Now ().GetSeconds ();
2.68 - view_update (data);
2.69 - Simulator::Schedule (g_sampleInterval, Sample);
2.70 -}
2.71 -
2.72 -
2.73 -
2.74 -int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, double *y2)
2.75 -{
2.76 - DefaultValue::Bind ("RandomWalk2dMode", "Time");
2.77 - DefaultValue::Bind ("RandomWalk2dTime", "5s");
2.78 - DefaultValue::Bind ("RandomWalk2dSpeed", "Constant:20.0");
2.79 - DefaultValue::Bind ("RandomDirection2dSpeed", "Uniform:10.0:20.0");
2.80 - DefaultValue::Bind ("RandomWalk2dBounds", "0:400:0:300");
2.81 - DefaultValue::Bind ("RandomDirection2dArea", "0:400:0:300");
2.82 - DefaultValue::Bind ("RandomWaypointSpeed", "Uniform:10:30");
2.83 -
2.84 -// DefaultValue::Bind ("RandomDiscPositionX", "100");
2.85 -// DefaultValue::Bind ("RandomDiscPositionY", "50");
2.86 -// DefaultValue::Bind ("RandomDiscPositionRho", "Uniform:0:30");
2.87 -
2.88 - DefaultValue::Bind ("RandomTopologyPositionType", "RandomRectanglePosition");
2.89 - DefaultValue::Bind ("RandomTopologyMobilityType", "RandomWalkMobilityModel");
2.90 -
2.91 -// CommandLine::AddArgValue ("sample-interval","sample interval", g_sampleInterval);
2.92 -// CommandLine::AddArgValue ("num-nodes","number of nodes", g_numNodes);
2.93 -
2.94 - CommandLine::Parse (argc, argv);
2.95 -
2.96 - MobilityHelper mobility;
2.97 -
2.98 - for (uint32_t i = 0; i < g_numNodes; i++)
2.99 - {
2.100 - Ptr<Node> node = CreateObject<Node> ();
2.101 - }
2.102 -
2.103 - mobility.EnableNotifier ();
2.104 - mobility.Layout (NodeList::Begin (), NodeList::End ());
2.105 -
2.106 - Simulator::Schedule (g_sampleInterval, Sample);
2.107 -
2.108 - // XXX: The following is not really going to work with the params.
2.109 -
2.110 - if (mobility.GetMobilityModelType () == "RandomWalk2dMobilityModel")
2.111 - {
2.112 - Rectangle bounds = DefaultValueListGet<RectangleDefaultValue> ("RandomWalk2dBounds")->GetValue ();
2.113 - *x1 = bounds.xMin;
2.114 - *y1 = bounds.yMin;
2.115 - *x2 = bounds.xMax;
2.116 - *y2 = bounds.yMax;
2.117 - std::cout << "RECT " << bounds.xMin << " " << bounds.xMax << " "
2.118 - << bounds.yMin << " " << bounds.yMax << std::endl;
2.119 - }
2.120 - else if (mobility.GetMobilityModelType () == "RandomDirection2dMobilityModel")
2.121 - {
2.122 - Rectangle bounds = DefaultValueListGet<RectangleDefaultValue> ("RandomDirection2dArea")->GetValue ();
2.123 - *x1 = bounds.xMin;
2.124 - *y1 = bounds.yMin;
2.125 - *x2 = bounds.xMax;
2.126 - *y2 = bounds.yMax;
2.127 - std::cout << "RECT " << bounds.xMin << " " << bounds.xMax << " "
2.128 - << bounds.yMin << " " << bounds.yMax << std::endl;
2.129 - }
2.130 - else if (mobility.GetMobilityModelType () == "RandomWaypointMobilityModel")
2.131 - {
2.132 - std::cerr << "bounds for RandomWaypointMobilityModel not implemented" << std::endl;
2.133 - //ClassId posType = DefaultValueList::Get<ClassIdDefaultValue> ("RandomWaypointPosition")->GetValue ();
2.134 - std::cout << "?" << std::endl; // too hard to represent an abstract/probabilistic model graphically
2.135 - }
2.136 - else
2.137 - {
2.138 - NS_FATAL_ERROR ("mobility type " << mobility.GetMobilityModelType () << " not supported");
2.139 - }
2.140 -
2.141 - std::cerr << g_sampleInterval << std::endl;
2.142 - return 0;
2.143 -}
3.1 --- a/utils/mobility-visualizer-view.cc Wed Jun 17 12:07:25 2009 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,218 +0,0 @@
3.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3.5 -
3.6 -#include <map>
3.7 -
3.8 -#include <goocanvas.h>
3.9 -#include <glib/gthread.h>
3.10 -
3.11 -#include "mobility-visualizer.h"
3.12 -#include <map>
3.13 -#include "ns3/simulator.h"
3.14 -
3.15 -#define MAX_QUEUE_LENGTH 100
3.16 -#define MAX_EVENTS 20
3.17 -#define LOOKAHEAD_SECONDS 10
3.18 -
3.19 -GtkWidget *g_canvas;
3.20 -
3.21 -int model_init (int argc, char *argv[]);
3.22 -
3.23 -struct Node
3.24 -{
3.25 - GooCanvasItem *m_item;
3.26 - GooCanvasItem *m_vector;
3.27 - void create ()
3.28 - {
3.29 - GooCanvasItem *root = goo_canvas_get_root_item (GOO_CANVAS (g_canvas));
3.30 - m_item = goo_canvas_ellipse_new (root, 0, 0, 2.0, 2.0,
3.31 - "line_width", 0.5,
3.32 - "stroke_color", "black",
3.33 - "fill_color", "red",
3.34 - NULL);
3.35 -
3.36 - m_vector = goo_canvas_polyline_new (root, FALSE, 0,
3.37 - "line_width", 0.3,
3.38 - "stroke_color", "black",
3.39 - "end-arrow", TRUE,
3.40 - "arrow-length", 10.0,
3.41 - "arrow-width", 10.0,
3.42 - NULL);
3.43 -
3.44 - }
3.45 -
3.46 -
3.47 - void update (double x, double y, double vx, double vy)
3.48 - {
3.49 - g_object_set (m_item, "center_x", x, "center_y", y, NULL);
3.50 -
3.51 - if (vx == 0 && vy == 0)
3.52 - {
3.53 - GooCanvasPoints *points = goo_canvas_points_new (0);
3.54 - g_object_set (m_vector, "points", points, NULL);
3.55 - goo_canvas_points_unref (points);
3.56 - }
3.57 - else
3.58 - {
3.59 - GooCanvasPoints *points = goo_canvas_points_new (2);
3.60 -
3.61 - points->coords[0] = x;
3.62 - points->coords[1] = y;
3.63 - points->coords[2] = x + vx;
3.64 - points->coords[3] = y + vy;
3.65 -
3.66 - g_object_set (m_vector, "points", points, NULL);
3.67 - goo_canvas_points_unref (points);
3.68 - }
3.69 - }
3.70 -};
3.71 -
3.72 -std::map<void*, Node> g_nodes;
3.73 -
3.74 -GTimeVal initialTime = {-1, -1};
3.75 -gboolean firstTime = TRUE;
3.76 -double g_lookaheadTime = 0;
3.77 -GStaticMutex g_lookaheadTimeMux = G_STATIC_MUTEX_INIT;
3.78 -ViewUpdateData *g_nextData = NULL;
3.79 -
3.80 -
3.81 -GAsyncQueue *queue;
3.82 -
3.83 -#define TIME_SCALE 1
3.84 -
3.85 -double get_current_time ()
3.86 -{
3.87 - GTimeVal currTime;
3.88 - g_get_current_time (&currTime);
3.89 - GTimeVal relativeTime;
3.90 - relativeTime.tv_sec = currTime.tv_sec - initialTime.tv_sec + LOOKAHEAD_SECONDS;
3.91 - relativeTime.tv_usec = currTime.tv_usec;
3.92 - g_time_val_add (&relativeTime, -initialTime.tv_usec);
3.93 - return (relativeTime.tv_sec + 1.0e-6*relativeTime.tv_usec)*TIME_SCALE;
3.94 -}
3.95 -
3.96 -// called from the simulation thread
3.97 -void view_update (ViewUpdateData *updateData)
3.98 -{
3.99 - while ((g_static_mutex_lock (&g_lookaheadTimeMux), g_lookaheadTime) != 0 and updateData->time >= g_lookaheadTime)
3.100 - {
3.101 - g_static_mutex_unlock (&g_lookaheadTimeMux);
3.102 - g_usleep ((gulong) 10e3);
3.103 - }
3.104 - g_static_mutex_unlock (&g_lookaheadTimeMux);
3.105 - g_async_queue_push (queue, updateData);
3.106 -}
3.107 -
3.108 -void view_update_process (ViewUpdateData *updateData)
3.109 -{
3.110 - for (std::vector<NodeUpdate>::const_iterator update
3.111 - = updateData->updateList.begin ();
3.112 - update != updateData->updateList.end ();
3.113 - update++)
3.114 - {
3.115 - if (g_nodes.find (update->node) == g_nodes.end ())
3.116 - {
3.117 - g_nodes[update->node].create ();
3.118 - }
3.119 - g_nodes[update->node].update (update->x, update->y, update->vx, update->vy);
3.120 - }
3.121 - delete updateData;
3.122 -}
3.123 -
3.124 -gboolean view_update_consumer ()
3.125 -{
3.126 - if (firstTime)
3.127 - {
3.128 - firstTime = FALSE;
3.129 - g_get_current_time (&initialTime);
3.130 - }
3.131 -
3.132 - double now = get_current_time ();
3.133 - g_static_mutex_lock (&g_lookaheadTimeMux);
3.134 - g_lookaheadTime = now + LOOKAHEAD_SECONDS;
3.135 - g_static_mutex_unlock (&g_lookaheadTimeMux);
3.136 -
3.137 - if (!g_nextData)
3.138 - g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue);
3.139 -
3.140 - if (!g_nextData)
3.141 - return TRUE;
3.142 -
3.143 - if (g_nextData->time > now)
3.144 - return TRUE;
3.145 -
3.146 - do
3.147 - {
3.148 - view_update_process (g_nextData);
3.149 - g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue);
3.150 - }
3.151 - while (g_nextData && g_nextData->time <= now);
3.152 -
3.153 - return TRUE;
3.154 -}
3.155 -
3.156 -void zoom_changed (GtkAdjustment *adj)
3.157 -{
3.158 - goo_canvas_set_scale (GOO_CANVAS (g_canvas), gtk_adjustment_get_value (adj));
3.159 -}
3.160 -
3.161 -int main (int argc, char *argv[])
3.162 -{
3.163 - g_thread_init (NULL);
3.164 - gtk_init (&argc, &argv);
3.165 - double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
3.166 -
3.167 - model_init (argc, argv, &x1, &y1, &x2, &y2);
3.168 -
3.169 - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3.170 - gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
3.171 - gtk_widget_show (window);
3.172 - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
3.173 -
3.174 - GtkWidget *scrolled_win = gtk_scrolled_window_new (NULL, NULL);
3.175 - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
3.176 - gtk_widget_show (scrolled_win);
3.177 -
3.178 - GtkWidget *vbox = gtk_vbox_new (FALSE, 4);
3.179 - gtk_widget_show (vbox);
3.180 - gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, 1, 1, 4);
3.181 - gtk_container_add (GTK_CONTAINER (window), vbox);
3.182 -
3.183 - GtkWidget *hbox = gtk_hbox_new (FALSE, 4);
3.184 - gtk_widget_show (hbox);
3.185 - gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 4);
3.186 -
3.187 - GtkObject *zoom = gtk_adjustment_new (3.0, 0.1, 10.0, 0.2, 1.0, 1.0);
3.188 - gtk_box_pack_start(GTK_BOX (hbox),
3.189 - GTK_WIDGET (g_object_new (GTK_TYPE_SPIN_BUTTON, "adjustment", zoom,
3.190 - "visible", true, "digits", 2, NULL)),
3.191 - false, false, 4);
3.192 -
3.193 - g_canvas = goo_canvas_new ();
3.194 - gtk_widget_set_size_request (GTK_WIDGET (g_canvas), 600, 450);
3.195 - goo_canvas_set_bounds (GOO_CANVAS (g_canvas), -500, -500, 500, 500);
3.196 - g_signal_connect (zoom, "value-changed", G_CALLBACK (zoom_changed), NULL);
3.197 - gtk_adjustment_value_changed (GTK_ADJUSTMENT (zoom));
3.198 - gtk_widget_show (g_canvas);
3.199 - gtk_container_add (GTK_CONTAINER (scrolled_win), g_canvas);
3.200 -
3.201 - goo_canvas_scroll_to (GOO_CANVAS (g_canvas), 0, 0);
3.202 -
3.203 - // create the bounds rectangle
3.204 - if (x1 != x2)
3.205 - {
3.206 - GooCanvasItem *item =
3.207 - goo_canvas_rect_new (goo_canvas_get_root_item (GOO_CANVAS (g_canvas)),
3.208 - x1, y1, x2-x1, y2-y1, NULL);
3.209 - g_object_set (item, "line-width", 1.0, "stroke-color", "grey", NULL);
3.210 - }
3.211 -
3.212 - queue = g_async_queue_new ();
3.213 -
3.214 - g_timeout_add ((guint) (SAMPLE_INTERVAL*1000), (GSourceFunc) view_update_consumer, NULL);
3.215 -
3.216 - g_thread_create (GThreadFunc (ns3::Simulator::Run), NULL, FALSE, NULL);
3.217 -
3.218 - gtk_main ();
3.219 -
3.220 - return 0;
3.221 -}
4.1 --- a/utils/mobility-visualizer.h Wed Jun 17 12:07:25 2009 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,23 +0,0 @@
4.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4.5 -#include <vector>
4.6 -
4.7 -int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, double *y2);
4.8 -
4.9 -struct NodeUpdate
4.10 -{
4.11 - void *node;
4.12 - double x;
4.13 - double y;
4.14 - double vx;
4.15 - double vy;
4.16 -};
4.17 -
4.18 -struct ViewUpdateData
4.19 -{
4.20 - std::vector<NodeUpdate> updateList;
4.21 - double time;
4.22 -};
4.23 -
4.24 -void view_update (ViewUpdateData *updateData);
4.25 -
4.26 -#define SAMPLE_INTERVAL (1.0/30)
5.1 --- a/utils/wscript Wed Jun 17 12:07:25 2009 +0100
5.2 +++ b/utils/wscript Wed Jun 17 17:05:51 2009 +0200
5.3 @@ -1,11 +1,6 @@
5.4 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
5.5 import os.path
5.6
5.7 -def configure(conf):
5.8 - conf.env['ENABLE_MOBILITY_VISUALIZER'] = conf.pkg_check_modules(
5.9 - 'MOBILITY_VISUALIZER', 'goocanvas gthread-2.0', mandatory=False)
5.10 -
5.11 -
5.12 def build(bld):
5.13 env = bld.env
5.14
5.15 @@ -25,13 +20,3 @@
5.16 ['internet-stack', 'csma-cd', 'point-to-point'])
5.17 obj.source = 'print-introspected-doxygen.cc'
5.18
5.19 -# XXX: disable mobility visualizer code temporarily.
5.20 - env['ENABLE_MOBILITY_VISUALIZER'] = ''
5.21 - if env['ENABLE_MOBILITY_VISUALIZER']:
5.22 - obj = bld.create_ns3_program('mobility-visualizer',
5.23 - ['internet-stack', 'mobility'])
5.24 - obj.source = ['mobility-visualizer-model.cc', 'mobility-visualizer-view.cc']
5.25 - obj.uselib = 'MOBILITY_VISUALIZER'
5.26 - if os.path.basename(obj.env['CXX']).startswith("g++"):
5.27 - obj.env.append_value('CXXFLAGS', '-fno-strict-aliasing')
5.28 -
6.1 --- a/wscript Wed Jun 17 12:07:25 2009 +0100
6.2 +++ b/wscript Wed Jun 17 17:05:51 2009 +0200
6.3 @@ -273,7 +273,6 @@
6.4 env['WL_SONAME_SUPPORTED'] = True
6.5
6.6 conf.sub_config('src')
6.7 - conf.sub_config('utils')
6.8 conf.sub_config('bindings/python')
6.9
6.10 if Options.options.enable_modules: