Skip to content

Commit

Permalink
Add option to bind mobility model ticks to real time clock.
Browse files Browse the repository at this point in the history
Adds parameters 'use_rtc_model_mob' and 'rtc_model_mob_tick'
to mobility model code. When enabled, these will cause mobility
ticks to only occur every 'rtc_model_mob_tick' seconds as long as
the expected number of ticks for this time interval has occurred.
  • Loading branch information
awlane committed Nov 22, 2024
1 parent 79a4014 commit e52fffe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
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 RTCModel(model):
def __init__(self, **kwargs):
self.tick_time = kwargs.get('rtc_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, RTCModel
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_rtc_model_mob = False
self.rtc_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_rtc_model_mob'):
self.mob_object = RTCModel(**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', 'rtc_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_rtc_model_mob']
args += float_args
for arg in args:
if arg in float_args:
Expand Down

0 comments on commit e52fffe

Please sign in to comment.