Commit fbf3367d authored by Yohann D'Anello's avatar Yohann D'Anello

[monitoring] Send pings

Signed-off-by: Yohann D'Anello's avatarYohann D'ANELLO <ynerant@crans.org>
parent a6bb0d25
...@@ -376,7 +376,7 @@ class BaseTunnelManager(object): ...@@ -376,7 +376,7 @@ class BaseTunnelManager(object):
self._forward = to self._forward = to
code = ord(msg[0]) code = ord(msg[0])
if prefix == self._prefix: if prefix == self._prefix:
msg = self._processPacket(msg) msg = self._processPacket(msg, to)
if msg: if msg:
self._sendto(to, '%s\0%c%s' % (prefix, code, msg)) self._sendto(to, '%s\0%c%s' % (prefix, code, msg))
else: else:
...@@ -452,10 +452,10 @@ class BaseTunnelManager(object): ...@@ -452,10 +452,10 @@ class BaseTunnelManager(object):
elif msg: elif msg:
# We got a valid and non-empty message. Always reply # We got a valid and non-empty message. Always reply
# something so that the sender knows we're still connected. # something so that the sender knows we're still connected.
answer = self._processPacket(msg, peer.prefix) answer = self._processPacket(msg, to, peer.prefix)
self._sendto(to, msg[0] + answer if answer else "", peer) self._sendto(to, msg[0] + answer if answer else "", peer)
def _processPacket(self, msg, peer=None): def _processPacket(self, msg, sender, peer=None):
c = ord(msg[0]) c = ord(msg[0])
msg = msg[1:] msg = msg[1:]
code = c & 0x7f code = c & 0x7f
...@@ -532,6 +532,10 @@ class BaseTunnelManager(object): ...@@ -532,6 +532,10 @@ class BaseTunnelManager(object):
# XXX: Quick'n dirty way to log in a common place. # XXX: Quick'n dirty way to log in a common place.
if peer and self._prefix == self.cache.registry_prefix: if peer and self._prefix == self.cache.registry_prefix:
logging.info("%s/%s: %s", int(peer, 2), len(peer), msg) logging.info("%s/%s: %s", int(peer, 2), len(peer), msg)
elif code == 8:
print("Monitoring!")
print(sender[0])
self._getPeer(peer)._i -= 1 # Don't increment seqno with this packet
def askInfo(self, prefix): def askInfo(self, prefix):
return self.sendto(prefix, '\4' + self._info(True)) return self.sendto(prefix, '\4' + self._info(True))
...@@ -680,7 +684,8 @@ class BaseTunnelManager(object): ...@@ -680,7 +684,8 @@ class BaseTunnelManager(object):
# FIXME Replace lo by main inteface name # FIXME Replace lo by main inteface name
subprocess.check_call(('ip', '-6', 'address', 'del', address, 'dev', 'lo')) subprocess.check_call(('ip', '-6', 'address', 'del', address, 'dev', 'lo'))
subprocess.check_call(('ip', '-6', 'route', 'del', my_address, subprocess.check_call(('ip', '-6', 'route', 'del', my_address,
'from', address, 'dev', 'lo', 'table', '34071')) 'from', address, 'table', '34071'))
del self._neighbour_monitoring_addresses[prefix]
# Babel is not initialized yet. # Babel is not initialized yet.
if not hasattr(self.ctl, 'neighbours'): if not hasattr(self.ctl, 'neighbours'):
...@@ -723,6 +728,33 @@ class BaseTunnelManager(object): ...@@ -723,6 +728,33 @@ class BaseTunnelManager(object):
'via', nexthop, 'dev', iface, 'src', address, 'table', '34071'), 'via', nexthop, 'dev', iface, 'src', address, 'table', '34071'),
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
def monitorLinks(self):
"""
Try to forward packets through each direct link.
"""
my_address = utils.ipFromBin(self._network + self._prefix, '1')
for prefix, address in self._neighbour_monitoring_addresses.items():
msock = None
try:
print("Send ping from " + address + " for " + utils.ipFromBin(self._network + prefix)
+ " to " + my_address + "...")
msock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
msock.bind((address, PORT + 1))
msg = b'\x08'
peer = self._getPeer(self._prefix)
data = peer.encode(msg)
peer._j -= 1 # Don't increment seqno with this packet
msock.sendto(data, (my_address, PORT))
except Exception, e:
logging.error("Error while monitoring " + utils.ipFromBin(self._network + prefix) + ": " + str(e))
finally:
if msock:
try:
msock.close()
finally:
pass
def _updateCountry(self, address): def _updateCountry(self, address):
def update(): def update():
for a in address: for a in address:
...@@ -835,6 +867,7 @@ class TunnelManager(BaseTunnelManager): ...@@ -835,6 +867,7 @@ class TunnelManager(BaseTunnelManager):
self._next_refresh = time.time() + 5 self._next_refresh = time.time() + 5
self.checkRoutingCache() self.checkRoutingCache()
self.updateMonitoringLinks() self.updateMonitoringLinks()
self.monitorLinks()
def babel_dump(self): def babel_dump(self):
t = time.time() t = time.time()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment