Commit deed2e8a authored by Pedro Oliveira's avatar Pedro Oliveira

log events more verbose

parent 8fec9cb1
......@@ -8,11 +8,11 @@ import ipaddress
from RWLock.RWLock import RWLockWrite
import Main
import UnicastRouting
from InterfacePIM import InterfacePim
from InterfaceIGMP import InterfaceIGMP
from tree.KernelEntry import KernelEntry
class Kernel:
# MRT
MRT_BASE = 200
......@@ -237,6 +237,20 @@ class Kernel:
struct_mfcctl = struct.pack("4s 4s H " + "B"*Kernel.MAXVIFS + " IIIi", source_ip, group_ip, kernel_entry.inbound_interface_index, *outbound_interfaces_and_other_parameters)
self.socket.setsockopt(socket.IPPROTO_IP, Kernel.MRT_ADD_MFC, struct_mfcctl)
def set_flood_multicast_route(self, source_ip, group_ip, inbound_interface_index):
source_ip = socket.inet_aton(source_ip)
group_ip = socket.inet_aton(group_ip)
outbound_interfaces = [1]*self.MAXVIFS
outbound_interfaces[inbound_interface_index] = 0
#outbound_interfaces_and_other_parameters = list(kernel_entry.outbound_interfaces) + [0]*4
outbound_interfaces_and_other_parameters = outbound_interfaces + [0]*3 + [20]
#outbound_interfaces, 0, 0, 0, 0 <- only works with python>=3.5
#struct_mfcctl = struct.pack("4s 4s H " + "B"*Kernel.MAXVIFS + " IIIi", source_ip, group_ip, inbound_interface_index, *outbound_interfaces, 0, 0, 0, 0)
struct_mfcctl = struct.pack("4s 4s H " + "B"*Kernel.MAXVIFS + " IIIi", source_ip, group_ip, inbound_interface_index, *outbound_interfaces_and_other_parameters)
self.socket.setsockopt(socket.IPPROTO_IP, Kernel.MRT_ADD_MFC, struct_mfcctl)
def remove_multicast_route(self, kernel_entry: KernelEntry):
source_ip = socket.inet_aton(kernel_entry.source_ip)
......@@ -341,6 +355,8 @@ class Kernel:
if ip_src not in self.routing:
self.routing[ip_src] = {}
iif = self.vif_dic.get(UnicastRouting.check_rpf(ip_src))
self.set_flood_multicast_route(ip_src, ip_dst, iif)
self.routing[ip_src][ip_dst] = kernel_entry
return kernel_entry
else:
......
from pyroute2 import IPDB, IPRoute
import socket
import RWLock
import Main
import ipaddress
from threading import RLock
from pyroute2 import IPDB, IPRoute
import Main
def get_route(ip_dst: str):
return UnicastRouting.get_route(ip_dst)
def get_metric(ip_dst: str):
return UnicastRouting.get_metric(ip_dst)
def check_rpf(ip_dst):
return UnicastRouting.check_rpf(ip_dst)
......@@ -18,36 +20,37 @@ def check_rpf(ip_dst):
class UnicastRouting(object):
ipr = None
ipdb = None
lock = RLock()
def __init__(self):
UnicastRouting.ipr = IPRoute()
UnicastRouting.ipdb = IPDB()
self._ipdb = UnicastRouting.ipdb
self._ipdb.register_callback(UnicastRouting.unicast_changes)
self._ipdb.register_callback(UnicastRouting.unicast_changes, mode="post")
@staticmethod
def get_route(ip_dst: str):
ipdb = UnicastRouting.ipdb
ip_bytes = socket.inet_aton(ip_dst)
ip_int = int.from_bytes(ip_bytes, byteorder='big')
info = None
for mask_len in range(32, 0, -1):
ip_bytes = (ip_int & (0xFFFFFFFF << (32 - mask_len))).to_bytes(4, "big")
ip_dst = socket.inet_ntoa(ip_bytes) + "/" + str(mask_len)
print(ip_dst)
try:
info = ipdb.routes[ip_dst]
break
except:
continue
if not info:
print("0.0.0.0/0")
info = ipdb.routes["default"]
print(info)
return info
with UnicastRouting.lock:
ipdb = UnicastRouting.ipdb # type:IPDB
for mask_len in range(32, 0, -1):
ip_bytes = (ip_int & (0xFFFFFFFF << (32 - mask_len))).to_bytes(4, "big")
ip_dst = socket.inet_ntoa(ip_bytes) + "/" + str(mask_len)
print(ip_dst)
if ip_dst in ipdb.routes:
info = ipdb.routes[ip_dst]
break
else:
continue
if not info:
print("0.0.0.0/0")
info = ipdb.routes["default"]
print(info)
return info
# get metrics (routing preference and cost) to IP ip_dst
@staticmethod
......@@ -60,7 +63,6 @@ class UnicastRouting(object):
entry_cost = 0
return (entry_protocol, entry_cost, mask)
# get output interface IP, used to send data to IP ip_dst
# (root interface IP to ip_dst)
@staticmethod
......@@ -74,11 +76,11 @@ class UnicastRouting(object):
rpf_interface_source = UnicastRouting.ipr.get_routes(family=socket.AF_INET, dst=ip_dst)[0]['attrs'][3][1]
return rpf_interface_source
@staticmethod
def unicast_changes(ipdb, msg, action):
print("unicast change?")
print(action)
UnicastRouting.lock.acquire()
UnicastRouting.ipdb = ipdb
if action == "RTM_NEWROUTE" or action == "RTM_DELROUTE":
print(ipdb.routes)
......@@ -87,7 +89,7 @@ class UnicastRouting(object):
attrs = msg["attrs"]
print(attrs)
for (key, value) in attrs:
print((key,value))
print((key, value))
if key == "RTA_DST":
network_address = value
break
......@@ -98,8 +100,10 @@ class UnicastRouting(object):
print(network_address + "/" + str(mask_len))
subnet = ipaddress.ip_network(network_address + "/" + str(mask_len))
print(str(subnet))
UnicastRouting.lock.release()
Main.kernel.notify_unicast_changes(subnet)
elif action == "RTM_NEWADDR" or action == "RTM_DELADDR":
UnicastRouting.lock.release()
# TODO ALTERACOES NA INTERFACE
'''
print(action)
......@@ -111,11 +115,11 @@ class UnicastRouting(object):
if key == "IFA_LABEL":
interface_name = value
break
Main.kernel.notify_interface_change(interface_name)
'''
pass
else:
UnicastRouting.lock.release()
def stop(self):
if UnicastRouting.ipr:
......
......@@ -19,24 +19,9 @@ class KernelEntry:
self.source_ip = source_ip
self.group_ip = group_ip
# ip of neighbor of the rpf
#next_hop = UnicastRouting.get_route(source_ip)["gateway"]
#self.rpf_node = source_ip if next_hop is None else next_hop
'''
next_hop = UnicastRouting.get_route(source_ip)["gateway"]
multipaths = UnicastRouting.get_route(source_ip)["multipath"]
self.rpf_node = next_hop if next_hop is not None else source_ip
print("MUL", multipaths)
#self.rpf_node = multipaths[0]["gateway"]
for m in multipaths:
if m["gateway"] is None:
self.rpf_node = source_ip
break
else:
self.rpf_node = m["gateway"]
'''
# CHECK UNICAST ROUTING INFORMATION###################################################
# CHOSE RPC INTERFACE
# GET RPC TO SOURCE
unicast_route = UnicastRouting.get_route(source_ip)
next_hop = unicast_route["gateway"]
multipaths = unicast_route["multipath"]
......
from abc import ABCMeta, abstractstaticmethod
from abc import ABCMeta, abstractmethod
import tree.globals as pim_globals
from .metric import AssertMetric
......@@ -8,7 +8,8 @@ if TYPE_CHECKING:
class AssertStateABC(metaclass=ABCMeta):
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedDataFromDownstreamIf(interface: "TreeInterfaceDownstream"):
"""
An (S,G) Data packet received on downstream interface
......@@ -17,7 +18,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedInferiorMetricFromWinner(interface: "TreeInterfaceDownstream"):
"""
Receive Inferior (Assert OR State Refresh) from Assert Winner
......@@ -26,7 +28,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedInferiorMetricFromNonWinner_couldAssertIsTrue(interface: "TreeInterfaceDownstream"):
"""
Receive Inferior (Assert OR State Refresh) from non-Assert Winner
......@@ -36,7 +39,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric):
"""
Receive Preferred Assert OR State Refresh
......@@ -46,7 +50,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def sendStateRefresh(interface: "TreeInterfaceDownstream", time):
"""
Send State Refresh
......@@ -57,7 +62,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def assertTimerExpires(interface: "TreeInterfaceDownstream"):
"""
AT(S,G) Expires
......@@ -66,7 +72,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def couldAssertIsNowFalse(interface: "TreeInterfaceDownstream"):
"""
CouldAssert -> FALSE
......@@ -75,7 +82,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def couldAssertIsNowTrue(interface: "TreeInterfaceDownstream"):
"""
CouldAssert -> TRUE
......@@ -84,7 +92,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def winnerLivelinessTimerExpires(interface: "TreeInterfaceDownstream"):
"""
Winner’s NLT(N,I) Expires
......@@ -93,7 +102,8 @@ class AssertStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedPruneOrJoinOrGraft(interface: "TreeInterfaceDownstream"):
"""
Receive Prune(S,G), Join(S,G) or Graft(S,G)
......@@ -198,7 +208,7 @@ class NoInfoState(AssertStateABC):
interface.assert_logger.debug('receivedPruneOrJoinOrGraft, NI -> NI')
def __str__(self) -> str:
return "NI"
return "NoInfo"
class WinnerState(AssertStateABC):
......@@ -288,7 +298,7 @@ class WinnerState(AssertStateABC):
pass
def __str__(self) -> str:
return "W"
return "Winner"
......@@ -383,7 +393,7 @@ class LoserState(AssertStateABC):
interface.set_assert_state(AssertState.NoInfo)
def __str__(self) -> str:
return "L"
return "Loser"
class AssertState():
NoInfo = NoInfoState()
......
from abc import ABCMeta, abstractstaticmethod
from abc import ABCMeta, abstractmethod
from tree import globals as pim_globals
from utils import TYPE_CHECKING
......@@ -6,7 +6,8 @@ if TYPE_CHECKING:
from .tree_if_downstream import TreeInterfaceDownstream
class DownstreamStateABS(metaclass=ABCMeta):
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedPrune(interface: "TreeInterfaceDownstream", holdtime):
"""
Receive Prune(S,G)
......@@ -15,7 +16,8 @@ class DownstreamStateABS(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedJoin(interface: "TreeInterfaceDownstream"):
"""
Receive Join(S,G)
......@@ -24,7 +26,8 @@ class DownstreamStateABS(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def receivedGraft(interface: "TreeInterfaceDownstream", source_ip):
"""
Receive Graft(S,G)
......@@ -33,7 +36,8 @@ class DownstreamStateABS(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def PPTexpires(interface: "TreeInterfaceDownstream"):
"""
PPT(S,G) Expires
......@@ -42,7 +46,8 @@ class DownstreamStateABS(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def PTexpires(interface: "TreeInterfaceDownstream"):
"""
PT(S,G) Expires
......@@ -51,7 +56,8 @@ class DownstreamStateABS(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def is_now_RPF_Interface(interface: "TreeInterfaceDownstream"):
"""
RPF_Interface(S) becomes I
......@@ -60,7 +66,8 @@ class DownstreamStateABS(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def send_state_refresh(interface: "TreeInterfaceDownstream"):
"""
Send State Refresh(S,G) out I
......@@ -88,6 +95,7 @@ class NoInfo(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug("receivedPrune, NI -> PP")
interface.set_prune_state(DownstreamState.PrunePending)
time = 0
......@@ -96,9 +104,6 @@ class NoInfo(DownstreamStateABS):
interface.set_prune_pending_timer(time)
#print("receivedPrune, NI -> PP")
interface.join_prune_logger.debug("receivedPrune, NI -> PP")
@staticmethod
def receivedJoin(interface: "TreeInterfaceDownstream"):
"""
......@@ -106,9 +111,7 @@ class NoInfo(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
# Do nothing
#print("receivedJoin, NI -> NI")
interface.join_prune_logger.debug("receivedJoin, NI -> NI")
@staticmethod
......@@ -118,10 +121,8 @@ class NoInfo(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.send_graft_ack(source_ip)
#print('receivedGraft, NI -> NI')
interface.join_prune_logger.debug('receivedGraft, NI -> NI')
interface.send_graft_ack(source_ip)
@staticmethod
def PPTexpires(interface: "TreeInterfaceDownstream"):
......@@ -164,7 +165,7 @@ class NoInfo(DownstreamStateABS):
return
def __str__(self):
return "NI"
return "NoInfo"
......@@ -185,8 +186,6 @@ class PrunePending(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
#print('receivedPrune, PP -> PP')
interface.join_prune_logger.debug('receivedPrune, PP -> PP')
......@@ -197,12 +196,12 @@ class PrunePending(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('receivedJoin, PP -> NI')
interface.clear_prune_pending_timer()
interface.set_prune_state(DownstreamState.NoInfo)
#print('receivedJoin, PP -> NI')
interface.join_prune_logger.debug('receivedJoin, PP -> NI')
@staticmethod
def receivedGraft(interface: "TreeInterfaceDownstream", source_ip):
......@@ -211,14 +210,13 @@ class PrunePending(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('receivedGraft, PP -> NI')
interface.clear_prune_pending_timer()
interface.set_prune_state(DownstreamState.NoInfo)
interface.send_graft_ack(source_ip)
#print('receivedGraft, PP -> NI')
interface.join_prune_logger.debug('receivedGraft, PP -> NI')
@staticmethod
def PPTexpires(interface: "TreeInterfaceDownstream"):
"""
......@@ -226,15 +224,13 @@ class PrunePending(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('PPTexpires, PP -> P')
interface.set_prune_state(DownstreamState.Pruned)
interface.set_prune_timer(interface.get_received_prune_holdtime() - pim_globals.JP_OVERRIDE_INTERVAL)
if len(interface.get_interface().neighbors) > 1:
interface.send_pruneecho()
#print('PPTexpires, PP -> P')
interface.join_prune_logger.debug('PPTexpires, PP -> P')
@staticmethod
def PTexpires(interface: "TreeInterfaceDownstream"):
"""
......@@ -242,7 +238,6 @@ class PrunePending(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
#assert False, "PTexpires in state PP"
return
......@@ -253,12 +248,12 @@ class PrunePending(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('is_now_RPF_Interface, PP -> NI')
interface.clear_prune_pending_timer()
interface.set_prune_state(DownstreamState.NoInfo)
print('is_now_RPF_Interface, PP -> NI')
@staticmethod
def send_state_refresh(interface: "TreeInterfaceDownstream"):
"""
......@@ -269,7 +264,7 @@ class PrunePending(DownstreamStateABS):
return
def __str__(self):
return "PP"
return "PrunePending"
class Pruned(DownstreamStateABS):
'''
......@@ -287,12 +282,10 @@ class Pruned(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('receivedPrune, P -> P')
if holdtime > interface.remaining_prune_timer():
interface.set_prune_timer(holdtime)
#print('receivedPrune, P -> P')
interface.join_prune_logger.debug('receivedPrune, P -> P')
@staticmethod
def receivedJoin(interface: "TreeInterfaceDownstream"):
"""
......@@ -300,13 +293,12 @@ class Pruned(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('receivedPrune, P -> NI')
interface.clear_prune_timer()
interface.set_prune_state(DownstreamState.NoInfo)
#print('receivedPrune, P -> NI')
interface.join_prune_logger.debug('receivedPrune, P -> NI')
@staticmethod
def receivedGraft(interface: "TreeInterfaceDownstream", source_ip):
"""
......@@ -314,13 +306,11 @@ class Pruned(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('receivedGraft, P -> NI')
interface.clear_prune_timer()
interface.set_prune_state(DownstreamState.NoInfo)
interface.send_graft_ack(source_ip)
#print('receivedGraft, P -> NI')
interface.join_prune_logger.debug('receivedGraft, P -> NI')
@staticmethod
def PPTexpires(interface: "TreeInterfaceDownstream"):
"""
......@@ -338,10 +328,8 @@ class Pruned(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.set_prune_state(DownstreamState.NoInfo)
#print('PTexpires, P -> NI')
interface.join_prune_logger.debug('PTexpires, P -> NI')
interface.set_prune_state(DownstreamState.NoInfo)
@staticmethod
def is_now_RPF_Interface(interface: "TreeInterfaceDownstream"):
......@@ -350,11 +338,10 @@ class Pruned(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger('is_now_RPF_Interface, P -> NI')
interface.clear_prune_timer()
interface.set_prune_state(DownstreamState.NoInfo)
print('is_now_RPF_Interface, P -> NI')
@staticmethod
def send_state_refresh(interface: "TreeInterfaceDownstream"):
"""
......@@ -362,14 +349,12 @@ class Pruned(DownstreamStateABS):
@type interface: TreeInterfaceDownstreamDownstream
"""
interface.join_prune_logger.debug('send_state_refresh, P -> P')
if interface.get_interface().is_state_refresh_capable():
interface.set_prune_timer(interface.get_received_prune_holdtime())
#print('send_state_refresh, P -> P')
interface.join_prune_logger.debug('send_state_refresh, P -> P')
def __str__(self):
return "P"
return "Pruned"
class DownstreamState():
NoInfo = NoInfo()
......
......@@ -30,30 +30,25 @@ class Originator(OriginatorStateABC):
'''
@type tree: Tree
'''
tree.originator_logger.debug('SRT expired, O -> O')
tree.set_state_refresh_timer()
tree.create_state_refresh_msg()
#print('SRT expired, O to O')
tree.originator_logger.debug('SRT expired, O -> O')
@staticmethod
def SATexpires(tree):
tree.originator_logger.debug('SAT expired, O -> NO')
tree.clear_state_refresh_timer()
tree.set_originator_state(OriginatorState.NotOriginator)
#print('SAT expired, O to NO')
tree.originator_logger.debug('SAT expired, O -> NO')
@staticmethod
def SourceNotConnected(tree):
tree.originator_logger.debug('Source no longer directly connected, O -> NO')
tree.clear_state_refresh_timer()
tree.clear_source_active_timer()
tree.set_originator_state(OriginatorState.NotOriginator)
#print('Source no longer directly connected, O to NO')
tree.originator_logger.debug('Source no longer directly connected, O -> NO')
def __str__(self):
return 'O'
return 'Originator'
class NotOriginator(OriginatorStateABC):
@staticmethod
......@@ -61,14 +56,12 @@ class NotOriginator(OriginatorStateABC):
'''
@type interface: Tree
'''
tree.originator_logger.debug('new DataMsg from Source, NO -> O')
tree.set_originator_state(OriginatorState.Originator)
tree.set_state_refresh_timer()
tree.set_source_active_timer()
#print('new DataMsg from Source, NO to O')
tree.originator_logger.debug('new DataMsg from Source, NO -> O')
@staticmethod
def SRTexpires(tree):
assert False, "SRTexpires in NO"
......@@ -82,7 +75,7 @@ class NotOriginator(OriginatorStateABC):
return
def __str__(self):
return 'NO'
return 'NotOriginator'
class OriginatorState():
......
......@@ -25,7 +25,7 @@ class TreeInterfaceDownstream(TreeInterface):
logger = logging.LoggerAdapter(TreeInterfaceDownstream.LOGGER, extra_dict_logger)
TreeInterface.__init__(self, kernel_entry, interface_id, logger)
self.logger.debug('Created DownstreamInterface')
self.join_prune_logger.debug(str(self._prune_state))
self.join_prune_logger.debug('Downstream state transitions to ' + str(self._prune_state))
# Last state refresh message sent (resend in case of new neighbors)
self._last_state_refresh_message = None
......@@ -37,7 +37,7 @@ class TreeInterfaceDownstream(TreeInterface):
with self.get_state_lock():
if new_state != self._prune_state:
self._prune_state = new_state
self.join_prune_logger.debug(str(new_state))
self.join_prune_logger.debug('Downstream state transitions to ' + str(new_state))
self.change_tree()
self.evaluate_ingroup()
......
......@@ -35,7 +35,7 @@ class TreeInterfaceUpstream(TreeInterface):
self._override_timer = None
self._prune_limit_timer = None
self._last_rpf = self.get_neighbor_RPF()
self.join_prune_logger.debug(str(self._graft_prune_state))
self.join_prune_logger.debug('Upstream state transitions to ' + str(self._graft_prune_state))
# Originator state
self._originator_state = OriginatorState.NotOriginator
......@@ -43,7 +43,7 @@ class TreeInterfaceUpstream(TreeInterface):
self._source_active_timer = None
self._prune_now_counter = 0
self.originator_logger = logging.LoggerAdapter(TreeInterfaceUpstream.LOGGER.getChild('Originator'), extra_dict_logger)
self.originator_logger.debug(str(self._originator_state))
self.originator_logger.debug('StateRefresh state transitions to ' + str(self._originator_state))
if self.is_S_directly_conn():
self._graft_prune_state.sourceIsNowDirectConnect(self)
......@@ -82,7 +82,7 @@ class TreeInterfaceUpstream(TreeInterface):
with self.get_state_lock():
if new_state != self._graft_prune_state:
self._graft_prune_state = new_state
self.join_prune_logger.debug(str(new_state))
self.join_prune_logger.debug('Upstream state transitions to ' + str(new_state))
self.change_tree()
self.evaluate_ingroup()
......@@ -90,7 +90,7 @@ class TreeInterfaceUpstream(TreeInterface):
def set_originator_state(self, new_state: OriginatorStateABC):
if new_state != self._originator_state:
self._originator_state = new_state
self.originator_logger.debug(str(new_state))
self.originator_logger.debug('StateRefresh state transitions to ' + str(new_state))
##########################################
# Check timers
......
......@@ -55,7 +55,7 @@ class TreeInterface(metaclass=ABCMeta):
self._assert_state = AssertState.NoInfo
self._assert_winner_metric = AssertMetric()
self._assert_timer = None
self.assert_logger.debug("NI")
self.assert_logger.debug("Assert state transitions to NoInfo")
# Received prune hold time
self._received_prune_holdtime = None
......@@ -70,7 +70,7 @@ class TreeInterface(metaclass=ABCMeta):
with self.get_state_lock():
if new_state != self._assert_state:
self._assert_state = new_state
self.assert_logger.debug(str(new_state))
self.assert_logger.debug('Assert state transitions to ' + str(new_state))
self.change_tree()
self.evaluate_ingroup()
......
from abc import ABCMeta, abstractstaticmethod
from abc import ABCMeta, abstractmethod
from utils import TYPE_CHECKING
if TYPE_CHECKING:
from .tree_if_upstream import TreeInterfaceUpstream
class UpstreamStateABC(metaclass=ABCMeta):
@abstractstaticmethod
@staticmethod
@abstractmethod
def dataArrivesRPFinterface_OListNull_PLTstoped(interface: "TreeInterfaceUpstream"):
"""
Data arrives on RPF_Interface(S) AND
......@@ -15,7 +16,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def stateRefreshArrivesRPFnbr_pruneIs1(interface: "TreeInterfaceUpstream"):
"""
State Refresh(S,G) received from RPF‘(S) AND
......@@ -25,7 +27,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped(interface: "TreeInterfaceUpstream"):
"""
State Refresh(S,G) received from RPF‘(S) AND
......@@ -36,7 +39,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def seeJoinToRPFnbr(interface: "TreeInterfaceUpstream"):
"""
See Join(S,G) to RPF’(S)
......@@ -45,7 +49,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def seePrune(interface: "TreeInterfaceUpstream"):
"""
See Prune(S,G)
......@@ -54,7 +59,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def OTexpires(interface: "TreeInterfaceUpstream"):
"""
OT(S,G) Expires
......@@ -63,7 +69,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def olistIsNowNull(interface: "TreeInterfaceUpstream"):
"""
olist(S,G)->NULL
......@@ -72,7 +79,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def olistIsNowNotNull(interface: "TreeInterfaceUpstream"):
"""
olist(S,G)->non-NULL
......@@ -81,7 +89,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def RPFnbrChanges_olistIsNotNull(interface: "TreeInterfaceUpstream"):
"""
RPF’(S) Changes AND
......@@ -92,7 +101,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def RPFnbrChanges_olistIsNull(interface: "TreeInterfaceUpstream"):
"""
RPF’(S) Changes AND
......@@ -102,7 +112,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def sourceIsNowDirectConnect(interface: "TreeInterfaceUpstream"):
"""
S becomes directly connected
......@@ -111,7 +122,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def GRTexpires(interface: "TreeInterfaceUpstream"):
"""
GRT(S,G) Expires
......@@ -120,7 +132,8 @@ class UpstreamStateABC(metaclass=ABCMeta):
"""
raise NotImplementedError()
@abstractstaticmethod
@staticmethod
@abstractmethod
def recvGraftAckFromRPFnbr(interface: "TreeInterfaceUpstream"):
"""
Receive GraftAck(S,G) from RPF’(S)
......@@ -148,13 +161,12 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug("dataArrivesRPFinterface_OListNull_PLTstoped, F -> P")
interface.set_state(UpstreamState.Pruned)
interface.send_prune()
interface.set_prune_limit_timer()
#print("dataArrivesRPFinterface_OListNull_PLTstoped, F -> P")
interface.join_prune_logger.debug("dataArrivesRPFinterface_OListNull_PLTstoped, F -> P")
@staticmethod
def stateRefreshArrivesRPFnbr_pruneIs1(interface: "TreeInterfaceUpstream"):
"""
......@@ -164,12 +176,10 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
# if OT is not running the router must set OT to t_override seconds
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs1, F -> F')
if not interface.is_override_timer_running():
interface.set_override_timer()
#print('stateRefreshArrivesRPFnbr_pruneIs1, F -> F')
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs1, F -> F')
@staticmethod
def stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped(interface: "TreeInterfaceUpstream"):
"""
......@@ -179,7 +189,6 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
#print('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, F -> F')
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, F -> F')
@staticmethod
......@@ -189,10 +198,8 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.clear_override_timer()
#print('seeJoinToRPFnbr, F -> F')
interface.join_prune_logger.debug('seeJoinToRPFnbr, F -> F')
interface.clear_override_timer()
@staticmethod
def seePrune(interface: "TreeInterfaceUpstream"):
......@@ -201,12 +208,10 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('seePrune, F -> F')
if not interface.is_S_directly_conn() and not interface.is_override_timer_running():
interface.set_override_timer()
#print('seePrune, F -> F')
interface.join_prune_logger.debug('seePrune, F -> F')
@staticmethod
def OTexpires(interface: "TreeInterfaceUpstream"):
"""
......@@ -214,12 +219,10 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('OTexpires, F -> F')
if not interface.is_S_directly_conn():
interface.send_join()
#print('OTexpires, F -> F')
interface.join_prune_logger.debug('OTexpires, F -> F')
@staticmethod
def olistIsNowNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -228,15 +231,13 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug("olistIsNowNull, F -> P")
interface.set_state(UpstreamState.Pruned)
interface.send_prune()
interface.set_prune_limit_timer()
#print("olistIsNowNull, F -> P")
interface.join_prune_logger.debug("olistIsNowNull, F -> P")
@staticmethod
def olistIsNowNotNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -257,14 +258,13 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNotNull, F -> AP')
interface.set_state(UpstreamState.AckPending)
interface.send_graft()
interface.set_graft_retry_timer()
#print('RPFnbrChanges_olistIsNotNull, F -> AP')
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNotNull, F -> AP')
@staticmethod
def RPFnbrChanges_olistIsNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -273,10 +273,8 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.set_state(UpstreamState.Pruned)
#print('RPFnbrChanges_olistIsNull, F -> P')
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNull, F -> P')
interface.set_state(UpstreamState.Pruned)
@staticmethod
def sourceIsNowDirectConnect(interface: "TreeInterfaceUpstream"):
......@@ -285,7 +283,6 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
#print("sourceIsNowDirectConnect, F -> F")
interface.join_prune_logger.debug("sourceIsNowDirectConnect, F -> F")
@staticmethod
......@@ -305,11 +302,10 @@ class Forward(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
#print('recvGraftAckFromRPFnbr, F -> F')
interface.join_prune_logger.debug("recvGraftAckFromRPFnbr, F -> F")
def __str__(self):
return "F"
return "Forwarding"
class Pruned(UpstreamStateABC):
......@@ -329,12 +325,10 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug("dataArrivesRPFinterface_OListNull_PLTstoped, P -> P")
interface.set_prune_limit_timer()
interface.send_prune()
#print("dataArrivesRPFinterface_OListNull_PLTstoped, P -> P")
interface.join_prune_logger.debug("dataArrivesRPFinterface_OListNull_PLTstoped, P -> P")
@staticmethod
def stateRefreshArrivesRPFnbr_pruneIs1(interface: "TreeInterfaceUpstream"):
"""
......@@ -343,9 +337,8 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.set_prune_limit_timer()
#print('stateRefreshArrivesRPFnbr_pruneIs1, P -> P')
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs1, P -> P')
interface.set_prune_limit_timer()
@staticmethod
def stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped(interface: "TreeInterfaceUpstream"):
......@@ -356,10 +349,9 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, P -> P')
interface.send_prune()
interface.set_prune_limit_timer()
#print('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, P -> P')
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, P -> P')
@staticmethod
def seeJoinToRPFnbr(interface: "TreeInterfaceUpstream"):
......@@ -369,7 +361,6 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
# Do nothing
#print('seeJoinToRPFnbr, P -> P')
interface.join_prune_logger.debug('seeJoinToRPFnbr, P -> P')
@staticmethod
......@@ -379,10 +370,9 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('seePrune, P -> P')
if interface.get_received_prune_holdtime() > interface.remaining_prune_limit_timer():
interface.set_prune_limit_timer(time=interface.get_received_prune_holdtime())
#print('seePrune, P -> P')
interface.join_prune_logger.debug('seePrune, P -> P')
@staticmethod
def OTexpires(interface: "TreeInterfaceUpstream"):
......@@ -412,6 +402,8 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug('olistIsNowNotNull, P -> AP')
interface.clear_prune_limit_timer()
interface.set_state(UpstreamState.AckPending)
......@@ -419,9 +411,6 @@ class Pruned(UpstreamStateABC):
interface.send_graft()
interface.set_graft_retry_timer()
#print('olistIsNowNotNull, P -> AP')
interface.join_prune_logger.debug('olistIsNowNotNull, P -> AP')
@staticmethod
def RPFnbrChanges_olistIsNotNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -432,6 +421,8 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNotNull, P -> AP')
interface.clear_prune_limit_timer()
interface.set_state(UpstreamState.AckPending)
......@@ -439,9 +430,6 @@ class Pruned(UpstreamStateABC):
interface.send_graft()
interface.set_graft_retry_timer()
#print('RPFnbrChanges_olistIsNotNull, P -> AP')
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNotNull, P -> AP')
@staticmethod
def RPFnbrChanges_olistIsNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -451,10 +439,8 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.clear_prune_limit_timer()
#print('RPFnbrChanges_olistIsNull, P -> P')
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNull, P -> P')
interface.clear_prune_limit_timer()
@staticmethod
def sourceIsNowDirectConnect(interface: "TreeInterfaceUpstream"):
......@@ -463,7 +449,6 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
#print("sourceIsNowDirectConnect, P -> P")
interface.join_prune_logger.debug('sourceIsNowDirectConnect, P -> P')
@staticmethod
......@@ -483,11 +468,10 @@ class Pruned(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
#print('recvGraftAckFromRPFnbr, P -> P')
interface.join_prune_logger.debug('recvGraftAckFromRPFnbr, P -> P')
def __str__(self):
return "P"
return "Pruned"
class AckPending(UpstreamStateABC):
......@@ -521,12 +505,10 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs1, AP -> AP')
if not interface.is_override_timer_running():
interface.set_override_timer()
#print('stateRefreshArrivesRPFnbr_pruneIs1, AP -> AP')
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs1, AP -> AP')
@staticmethod
def stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped(interface: "TreeInterfaceUpstream"):
"""
......@@ -536,12 +518,11 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, AP -> F')
interface.clear_graft_retry_timer()
interface.set_state(UpstreamState.Forward)
#print('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, AP -> F')
interface.join_prune_logger.debug('stateRefreshArrivesRPFnbr_pruneIs0_PLTstoped, AP -> F')
@staticmethod
def seeJoinToRPFnbr(interface: "TreeInterfaceUpstream"):
"""
......@@ -549,10 +530,8 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.clear_override_timer()
#print('seeJoinToRPFnbr, AP -> AP')
interface.join_prune_logger.debug('seeJoinToRPFnbr, AP -> AP')
interface.clear_override_timer()
@staticmethod
def seePrune(interface: "TreeInterfaceUpstream"):
......@@ -561,12 +540,10 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('seePrune, AP -> AP')
if not interface.is_override_timer_running():
interface.set_override_timer()
#print('seePrune, AP -> AP')
interface.join_prune_logger.debug('seePrune, AP -> AP')
@staticmethod
def OTexpires(interface: "TreeInterfaceUpstream"):
"""
......@@ -574,10 +551,8 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.send_join()
#print('OTexpires, AP -> AP')
interface.join_prune_logger.debug('OTexpires, AP -> AP')
interface.send_join()
@staticmethod
def olistIsNowNull(interface: "TreeInterfaceUpstream"):
......@@ -586,6 +561,7 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('olistIsNowNull, AP -> P')
interface.set_state(UpstreamState.Pruned)
interface.send_prune()
......@@ -593,9 +569,6 @@ class AckPending(UpstreamStateABC):
interface.clear_graft_retry_timer()
interface.set_prune_limit_timer()
#print("olistIsNowNull, AP -> P")
interface.join_prune_logger.debug('olistIsNowNull, AP -> P')
@staticmethod
def olistIsNowNotNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -616,12 +589,11 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNotNull, AP -> AP')
interface.send_graft()
interface.set_graft_retry_timer()
#print('RPFnbrChanges_olistIsNotNull, AP -> AP')
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNotNull, AP -> AP')
@staticmethod
def RPFnbrChanges_olistIsNull(interface: "TreeInterfaceUpstream"):
"""
......@@ -631,12 +603,11 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
if not interface.is_S_directly_conn():
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNull, AP -> P')
interface.clear_graft_retry_timer()
interface.set_state(UpstreamState.Pruned)
#print('RPFnbrChanges_olistIsNull, AP -> P')
interface.join_prune_logger.debug('RPFnbrChanges_olistIsNull, AP -> P')
@staticmethod
def sourceIsNowDirectConnect(interface: "TreeInterfaceUpstream"):
"""
......@@ -644,12 +615,11 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('sourceIsNowDirectConnect, AP -> F')
interface.set_state(UpstreamState.Forward)
interface.clear_graft_retry_timer()
#print("sourceIsNowDirectConnect, AP -> F")
interface.join_prune_logger.debug('sourceIsNowDirectConnect, AP -> F')
@staticmethod
def GRTexpires(interface: "TreeInterfaceUpstream"):
"""
......@@ -657,12 +627,11 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('GRTexpires, AP -> AP')
interface.set_graft_retry_timer()
interface.send_graft()
#print('GRTexpires, AP -> AP')
interface.join_prune_logger.debug('GRTexpires, AP -> AP')
@staticmethod
def recvGraftAckFromRPFnbr(interface: "TreeInterfaceUpstream"):
"""
......@@ -670,14 +639,13 @@ class AckPending(UpstreamStateABC):
@type interface: TreeInterfaceUpstream
"""
interface.join_prune_logger.debug('recvGraftAckFromRPFnbr, AP -> F')
interface.clear_graft_retry_timer()
interface.set_state(UpstreamState.Forward)
#print('recvGraftAckFromRPFnbr, AP -> F')
interface.join_prune_logger.debug('recvGraftAckFromRPFnbr, AP -> F')
def __str__(self):
return "AP"
return "AckPending"
class UpstreamState():
Forward = Forward()
......
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