Skip to content
Open
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
11 changes: 10 additions & 1 deletion packages/omamobile-modem-sit/lib/data_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def counters(stats):
return link['rx']['bytes'], link['tx']['packets']


def other_exits(routes, dev):
"""The default routes that lead out other than through the bearer. One
whose link is down leads nowhere: the USB gadget's fallback route stays
configured without a cable, and counting it kept the cellular route from
coming back after a silent spell."""
return [r for r in routes
if r.get('dev') != dev and 'linkdown' not in r.get('flags', ())]


def looks_silent(routed, before, after):
"""The routed bearer sent packets but received nothing since the last
check. Not proof: a few router solicitations get no answer on a live one."""
Expand Down Expand Up @@ -423,7 +432,7 @@ def watch():
nonlocal last, seen, check_at
routes = json.loads(run('ip', '-j', 'route', 'show', 'default'))
routed = any(r.get('dev') == dev for r in routes)
others = [r for r in routes if r.get('dev') != dev]
others = other_exits(routes, dev)
if roaming_blocked():
if routed:
run('ip', 'route', 'del', 'default', 'dev', dev, 'metric', '700')
Expand Down
21 changes: 20 additions & 1 deletion packages/omamobile-modem-sit/test/test_data_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unittest
from unittest.mock import patch
import data_network
from data_network import Resolver, SleepHold, configuration, counters, guarded, looks_silent, sleep_signal
from data_network import Resolver, SleepHold, configuration, counters, guarded, looks_silent, other_exits, sleep_signal

class ResolverTests(unittest.TestCase):
def test_fallback_restoration_preserves_new_wifi_dns(self):
Expand Down Expand Up @@ -76,6 +76,18 @@ def test_roaming_ends_the_wait(self):
hold.cancel()
self.assertFalse(hold.returns(others=True, now=301))

def test_after_a_sleep_a_route_on_a_down_link_does_not_end_the_wait(self):
usb={'dst':'default','gateway':'172.16.42.2','dev':'usb0','metric':2048,'flags':['linkdown']}
wifi={'dst':'default','gateway':'192.168.178.1','dev':'wlp1s0','metric':600,'flags':[]}
hold = SleepHold(grace=10)
hold.announced(routed=True)
hold.over(now=100)
self.assertFalse(hold.returns(bool(other_exits([usb],'rmnet0')), now=101)) # the cable is out: wait the grace
self.assertTrue(hold.returns(bool(other_exits([usb,wifi],'rmnet0')), now=102)) # Wi-Fi is back
hold.announced(routed=True)
hold.over(now=200)
self.assertTrue(hold.returns(bool(other_exits([usb],'rmnet0')), now=210)) # no Wi-Fi: after the grace

def test_counters_read_ip_json(self):
stats=[{'stats64':{'rx':{'bytes':0,'packets':0},'tx':{'bytes':900,'packets':12}}}]
self.assertEqual(counters(stats),(0,12))
Expand All @@ -85,6 +97,13 @@ def test_receiving_idle_or_unrouted_is_not_silent(self):
self.assertFalse(looks_silent(True,(100,10),(900,40)))
self.assertFalse(looks_silent(True,(0,10),(0,10)))
self.assertFalse(looks_silent(False,(0,10),(0,40)))
def test_a_route_on_a_down_link_is_no_other_exit(self):
usb={'dst':'default','gateway':'172.16.42.2','dev':'usb0','metric':2048,'flags':['linkdown']}
self.assertEqual(other_exits([usb],'rmnet0'),[])
wifi={'dst':'default','gateway':'192.168.178.1','dev':'wlp1s0','metric':600,'flags':[]}
cell={'dst':'default','dev':'rmnet0','metric':700,'flags':[]}
self.assertEqual(other_exits([usb,wifi,cell],'rmnet0'),[wifi])
self.assertEqual(other_exits([{'dst':'default','dev':'tun-home'}],'rmnet0'),[{'dst':'default','dev':'tun-home'}])

class WatchTests(unittest.TestCase):
def test_a_stalled_or_failed_ip_is_retried(self):
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-modem-sit/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.41
0.3.42