Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to bind mobility model ticks to system clock #555

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions mn_wifi/mobility.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,41 @@ def start_mob_mod(self, mob, nodes, draw):
while self.pause_simulation:
pass

class TimedModel(model):
def __init__(self, **kwargs):
self.tick_time = kwargs.get('timed_model_mob_tick', 1)
super().__init__(**kwargs)

def start_mob_mod(self, mob, nodes, draw):
"""
:param mob: mobility params
:param nodes: list of nodes
"""
next_tick_time = time() + self.tick_time
for xy in mob:
for idx, node in enumerate(nodes):
pos = round(xy[idx][0], 2), round(xy[idx][1], 2), 0.0
self.set_pos(node, pos)
if draw:
node.update_2d()
if draw:
PlotGraph.pause()
if self.pause_simulation:
while self.pause_simulation:
pass
# When resuming simulation, reset the tick timing
next_tick_time = time() + self.tick_time
continue
# We try to use "best effort" scheduling- we want to have
# done as many ticks as there are elapsed seconds since we last
# performed a mobility tick and try to iterate the loop as consistently
# as possible
else:
while time() < next_tick_time:
# If time() has been exceeded since the while loop check, don't sleep
sleep(max(next_tick_time - time(), 0))
next_tick_time = next_tick_time + self.tick_time


class Tracked(Mobility):
"Used when the position of each node is previously defined"
Expand Down
13 changes: 9 additions & 4 deletions mn_wifi/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
master, managed, physicalMesh, PhysicalWifiDirectLink, _4addrClient, \
_4addrAP, phyAP
from mn_wifi.mobility import Tracked as TrackedMob, model as MobModel, \
Mobility as mob, ConfigMobility, ConfigMobLinks
Mobility as mob, ConfigMobility, ConfigMobLinks, TimedModel
from mn_wifi.module import Mac80211Hwsim
from mn_wifi.node import AP, Station, Car, OVSKernelAP, physicalAP
from mn_wifi.plot import Plot2D, Plot3D, PlotGraph
Expand Down Expand Up @@ -145,6 +145,8 @@ def __init__(self, accessPoint=OVSKernelAP, station=Station, car=Car,
self.wwan_module = wwan_module
self.ifbIntf = 0
self.mob_object = None
self.use_timed_model_mob = False
self.timed_model_mob_tick = 1.0
self.mob_start_time = 0
self.mob_stop_time = 0
self.mob_rep = 1
Expand Down Expand Up @@ -1231,7 +1233,10 @@ def start_mobility(self, **kwargs):
if self.roads:
self.mob_object = vanet(**kwargs)
else:
self.mob_object = MobModel(**kwargs)
if kwargs.get('use_timed_model_mob'):
self.mob_object = TimedModel(**kwargs)
else:
self.mob_object = MobModel(**kwargs)

def setMobilityModel(self, **kwargs):
for key in kwargs:
Expand Down Expand Up @@ -1267,12 +1272,12 @@ def get_mobility_params(self):
'max_x', 'max_y', 'max_z',
'min_v', 'max_v', 'min_wt', 'max_wt',
'velocity_mean', 'alpha', 'variance', 'aggregation',
'g_velocity']
'g_velocity', 'timed_model_mob_tick']
args = ['stations', 'cars', 'aps', 'draw', 'seed',
'roads', 'mob_start_time', 'mob_stop_time',
'links', 'mob_model', 'mob_rep', 'reverse',
'ac_method', 'pointlist', 'n_groups', 'aggregation_epoch', 'epoch',
'velocity']
'velocity', 'use_timed_model_mob']
args += float_args
for arg in args:
if arg in float_args:
Expand Down