Commit 58dd3f58 authored by Pedro Oliveira's avatar Pedro Oliveira

fix issues related with assert state machine & remove some unused code

parent 4c12b098
......@@ -104,10 +104,8 @@ class AssertStateABC(metaclass=ABCMeta):
def _sendAssert_setAT(interface: "TreeInterfaceDownstream"):
#interface.assert_timer.set_timer(pim_globals.ASSERT_TIME)
interface.set_assert_timer(pim_globals.ASSERT_TIME)
interface.send_assert()
#interface.assert_timer.reset()
@staticmethod
def rprint(interface: "TreeInterfaceDownstream", msg, *entrys):
......@@ -134,11 +132,10 @@ class NoInfoState(AssertStateABC):
"""
@type interface: TreeInterface
"""
interface.set_assert_state(AssertState.Winner)
interface.set_assert_winner_metric(interface.my_assert_metric())
interface.set_assert_state(AssertState.Winner)
NoInfoState._sendAssert_setAT(interface)
#interface.assert_winner_metric = interface.assert_metric
print('receivedDataFromDownstreamIf, NI -> W')
......@@ -148,12 +145,10 @@ class NoInfoState(AssertStateABC):
@staticmethod
def receivedInferiorMetricFromNonWinner_couldAssertIsTrue(interface: "TreeInterfaceDownstream"):
interface.set_assert_state(AssertState.Winner)
interface.set_assert_winner_metric(interface.my_assert_metric())
interface.set_assert_state(AssertState.Winner)
NoInfoState._sendAssert_setAT(interface)
#interface.assert_state = AssertState.Winner
#interface.assert_winner_metric = interface.assert_metric
print(
'receivedInferiorMetricFromNonWinner_couldAssertIsTrue, NI -> W')
......@@ -260,9 +255,8 @@ class WinnerState(AssertStateABC):
@staticmethod
def assertTimerExpires(interface: "TreeInterfaceDownstream"):
#interface.assert_state = AssertState.NoInfo
interface.set_assert_state(AssertState.NoInfo)
interface.set_assert_winner_metric(AssertMetric.infinite_assert_metric())
interface.set_assert_state(AssertState.NoInfo)
print('assertTimerExpires, W -> NI')
......@@ -270,13 +264,10 @@ class WinnerState(AssertStateABC):
def couldAssertIsNowFalse(interface: "TreeInterfaceDownstream"):
interface.send_assert_cancel()
#interface.assert_timer.stop()
interface.clear_assert_timer()
#interface.assert_state = AssertState.NoInfo
interface.set_assert_state(AssertState.NoInfo)
interface.set_assert_winner_metric(AssertMetric.infinite_assert_metric())
interface.set_assert_state(AssertState.NoInfo)
print('couldAssertIsNowFalse, W -> NI')
......@@ -330,9 +321,6 @@ class LoserState(AssertStateABC):
assert_timer_value = state_refresh_interval*3
interface.set_assert_timer(assert_timer_value)
#has_winner_changed = interface.assert_winner_metric.node != better_metric.node
interface.set_assert_winner_metric(better_metric)
if interface.could_assert():
......@@ -348,21 +336,16 @@ class LoserState(AssertStateABC):
@staticmethod
def assertTimerExpires(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
if interface.could_assert():
interface.evaluate_ingroup()
print('assertTimerExpires, L -> NI')
@staticmethod
def couldAssertIsNowFalse(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
print('couldAssertIsNowFalse, L -> NI')
@staticmethod
def couldAssertIsNowTrue(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
print('couldAssertIsNowTrue, L -> NI')
@staticmethod
......@@ -379,10 +362,9 @@ class LoserState(AssertStateABC):
@staticmethod
def _to_NoInfo(interface: "TreeInterfaceDownstream"):
#interface.assert_timer.stop()
interface.clear_assert_timer()
interface.set_assert_state(AssertState.NoInfo)
interface.set_assert_winner_metric(AssertMetric.infinite_assert_metric())
interface.set_assert_state(AssertState.NoInfo)
class AssertState():
......
......@@ -45,8 +45,7 @@ class AssertMetric(object):
def i_am_assert_winner(self, tree_if):
interface_ip = ipaddress.ip_address(tree_if.get_ip())
return self._ip_address == interface_ip
return self.get_ip() == tree_if.get_ip()
@property
def metric_preference(self):
......@@ -84,6 +83,5 @@ class AssertMetric(object):
def state_refresh_interval(self, value):
self._state_refresh_interval = value
def get_ip(self):
return str(self._ip_address)
......@@ -116,14 +116,11 @@ class TreeInterfaceDownstream(TreeInterface):
# Send messages
######################################
def send_state_refresh(self, state_refresh_msg_received):
if not self.get_interface().is_state_refresh_enabled():
if self.lost_assert() or not self.get_interface().is_state_refresh_enabled():
return
interval = state_refresh_msg_received.interval
if self.lost_assert():
return
self._assert_state.sendStateRefresh(self, interval)
self._prune_state.send_state_refresh(self)
......@@ -166,17 +163,18 @@ class TreeInterfaceDownstream(TreeInterface):
# Override
def is_forwarding(self):
return ((self.has_neighbors() and not self.is_pruned()) or self.igmp_has_members()) and not self.lost_assert()
#return self._assert_state == AssertState.Winner and self.is_in_group()
def is_pruned(self):
return self._prune_state == DownstreamState.Pruned
def lost_assert(self):
return self._assert_state == AssertState.Loser
#def lost_assert(self):
# return not AssertMetric.i_am_assert_winner(self) and \
# self._assert_winner_metric.is_better_than(AssertMetric.spt_assert_metric(self))
# Override
def nbr_connected(self):
self._prune_state.new_nbr(self)
# TODO resend last state refresh messages
return
# Override
def delete(self):
......@@ -185,21 +183,5 @@ class TreeInterfaceDownstream(TreeInterface):
self.clear_prune_timer()
self.clear_prune_pending_timer()
def get_metric(self):
return AssertMetric.spt_assert_metric(self)
def _get_winner_metric(self):
'''
@rtype: SFMRAssertMetric
'''
return self._assert_metric
def _set_winner_metric(self, value):
assert isinstance(value, AssertMetric) or value is None
# todo
self._assert_metric = value
def is_downstream(self):
return True
......@@ -159,7 +159,7 @@ class TreeInterfaceUpstream(TreeInterface):
# Recv packets
###########################################
def recv_data_msg(self):
if self.is_olist_null() and not self.is_prune_limit_timer_running() and not self.is_S_directly_conn():
if not self.is_prune_limit_timer_running() and not self.is_S_directly_conn() and self.is_olist_null():
self._graft_prune_state.dataArrivesRPFinterface_OListNull_PLTstoped(self)
elif self.is_S_directly_conn() and self.get_interface().is_state_refresh_enabled():
self._originator_state.recvDataMsgFromSource(self)
......
......@@ -377,7 +377,7 @@ class TreeInterface(metaclass=ABCMeta):
if not self.is_downstream():
return False
else:
return not AssertMetric.i_am_assert_winner(self) and \
return not self._assert_winner_metric.i_am_assert_winner(self) and \
self._assert_winner_metric.is_better_than(AssertMetric.spt_assert_metric(self))
def could_assert(self):
......
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