Commit 3ac652db authored by Pedro Oliveira's avatar Pedro Oliveira

detected error in assert state machine, regarding receiving preferred assert

parent deed2e8a
......@@ -41,7 +41,7 @@ class AssertStateABC(metaclass=ABCMeta):
@staticmethod
@abstractmethod
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric):
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric, is_metric_equal):
"""
Receive Preferred Assert OR State Refresh
......@@ -134,33 +134,34 @@ class NoInfoState(AssertStateABC):
"""
@type interface: TreeInterface
"""
interface.assert_logger.debug('receivedDataFromDownstreamIf, NI -> W')
interface.set_assert_winner_metric(interface.my_assert_metric())
interface.set_assert_state(AssertState.Winner)
NoInfoState._sendAssert_setAT(interface)
#print('receivedDataFromDownstreamIf, NI -> W')
interface.assert_logger.debug('receivedDataFromDownstreamIf, NI -> W')
@staticmethod
def receivedInferiorMetricFromWinner(interface: "TreeInterfaceDownstream"):
assert False, "this should never ocurr"
@staticmethod
def receivedInferiorMetricFromNonWinner_couldAssertIsTrue(interface: "TreeInterfaceDownstream"):
interface.assert_logger.debug('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, NI -> W')
interface.set_assert_winner_metric(interface.my_assert_metric())
interface.set_assert_state(AssertState.Winner)
NoInfoState._sendAssert_setAT(interface)
#print('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, NI -> W')
interface.assert_logger.debug('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, NI -> W')
@staticmethod
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric):
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric, is_metric_equal):
'''
@type interface: TreeInterface
'''
if is_metric_equal:
return
interface.assert_logger.debug('receivedPreferedMetric, NI -> L')
state_refresh_interval = better_metric.state_refresh_interval
if state_refresh_interval is None:
# event caused by Assert Msg
......@@ -177,9 +178,6 @@ class NoInfoState(AssertStateABC):
if interface.could_assert():
interface.send_prune(holdtime=assert_timer_value)
#print('receivedPreferedMetric, NI -> L')
interface.assert_logger.debug('receivedPreferedMetric, NI -> L')
@staticmethod
def sendStateRefresh(interface: "TreeInterfaceDownstream", time):
pass
......@@ -190,12 +188,10 @@ class NoInfoState(AssertStateABC):
@staticmethod
def couldAssertIsNowFalse(interface: "TreeInterfaceDownstream"):
#print('couldAssertIsNowFalse, NI -> NI')
interface.assert_logger.debug('couldAssertIsNowFalse, NI -> NI')
@staticmethod
def couldAssertIsNowTrue(interface: "TreeInterfaceDownstream"):
#print('couldAssertIsNowTrue, NI -> NI')
interface.assert_logger.debug('couldAssertIsNowTrue, NI -> NI')
@staticmethod
......@@ -204,7 +200,6 @@ class NoInfoState(AssertStateABC):
@staticmethod
def receivedPruneOrJoinOrGraft(interface: "TreeInterfaceDownstream"):
#print('receivedPruneOrJoinOrGraft, NI -> NI')
interface.assert_logger.debug('receivedPruneOrJoinOrGraft, NI -> NI')
def __str__(self) -> str:
......@@ -224,10 +219,8 @@ class WinnerState(AssertStateABC):
"""
@type interface: TreeInterface
"""
WinnerState._sendAssert_setAT(interface)
#print('receivedDataFromDownstreamIf, W -> W')
interface.assert_logger.debug('receivedDataFromDownstreamIf, W -> W')
WinnerState._sendAssert_setAT(interface)
@staticmethod
def receivedInferiorMetricFromWinner(interface: "TreeInterfaceDownstream"):
......@@ -235,16 +228,17 @@ class WinnerState(AssertStateABC):
@staticmethod
def receivedInferiorMetricFromNonWinner_couldAssertIsTrue(interface: "TreeInterfaceDownstream"):
WinnerState._sendAssert_setAT(interface)
#print('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, W -> W')
interface.assert_logger.debug('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, W -> W')
WinnerState._sendAssert_setAT(interface)
@staticmethod
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric):
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric, is_metric_equal):
'''
@type better_metric: AssertMetric
'''
if is_metric_equal:
return
interface.assert_logger.debug('receivedPreferedMetric, W -> L')
state_refresh_interval = better_metric.state_refresh_interval
if state_refresh_interval is None:
# event caused by AssertMsg
......@@ -258,8 +252,6 @@ class WinnerState(AssertStateABC):
interface.set_assert_state(AssertState.Loser)
interface.send_prune(holdtime=assert_timer_value)
#print('receivedPreferedMetric, W -> L')
interface.assert_logger.debug('receivedPreferedMetric, W -> L')
@staticmethod
def sendStateRefresh(interface: "TreeInterfaceDownstream", state_refresh_interval):
......@@ -267,14 +259,13 @@ class WinnerState(AssertStateABC):
@staticmethod
def assertTimerExpires(interface: "TreeInterfaceDownstream"):
interface.assert_logger.debug('assertTimerExpires, W -> NI')
interface.set_assert_winner_metric(AssertMetric.infinite_assert_metric())
interface.set_assert_state(AssertState.NoInfo)
#print('assertTimerExpires, W -> NI')
interface.assert_logger.debug('assertTimerExpires, W -> NI')
@staticmethod
def couldAssertIsNowFalse(interface: "TreeInterfaceDownstream"):
interface.assert_logger.debug('couldAssertIsNowFalse, W -> NI')
interface.send_assert_cancel()
interface.clear_assert_timer()
......@@ -282,9 +273,6 @@ class WinnerState(AssertStateABC):
interface.set_assert_winner_metric(AssertMetric.infinite_assert_metric())
interface.set_assert_state(AssertState.NoInfo)
#print('couldAssertIsNowFalse, W -> NI')
interface.assert_logger.debug('couldAssertIsNowFalse, W -> NI')
@staticmethod
def couldAssertIsNowTrue(interface: "TreeInterfaceDownstream"):
assert False, "this should never ocurr"
......@@ -314,26 +302,23 @@ class LoserState(AssertStateABC):
"""
@type interface: TreeInterface
"""
#print('receivedDataFromDownstreamIf, L -> L')
interface.assert_logger.debug('receivedDataFromDownstreamIf, L -> L')
@staticmethod
def receivedInferiorMetricFromWinner(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
#print('receivedInferiorMetricFromWinner, L -> NI')
interface.assert_logger.debug('receivedInferiorMetricFromWinner, L -> NI')
LoserState._to_NoInfo(interface)
@staticmethod
def receivedInferiorMetricFromNonWinner_couldAssertIsTrue(interface: "TreeInterfaceDownstream"):
#print('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, L -> L')
interface.assert_logger.debug('receivedInferiorMetricFromNonWinner_couldAssertIsTrue, L -> L')
@staticmethod
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric):
def receivedPreferedMetric(interface: "TreeInterfaceDownstream", better_metric, is_metric_equal):
'''
@type better_metric: AssertMetric
'''
interface.assert_logger.debug('receivedPreferedMetric, L -> L')
state_refresh_interval = better_metric.state_refresh_interval
if state_refresh_interval is None:
assert_timer_value = pim_globals.ASSERT_TIME
......@@ -344,47 +329,37 @@ class LoserState(AssertStateABC):
interface.set_assert_winner_metric(better_metric)
interface.set_assert_state(AssertState.Loser)
if interface.could_assert():
if not is_metric_equal and interface.could_assert():
interface.send_prune(holdtime=assert_timer_value)
#print('receivedPreferedMetric, L -> L')
interface.assert_logger.debug('receivedPreferedMetric, L -> L')
@staticmethod
def sendStateRefresh(interface: "TreeInterfaceDownstream", time):
assert False, "this should never ocurr"
@staticmethod
def assertTimerExpires(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
#print('assertTimerExpires, L -> NI')
interface.assert_logger.debug('assertTimerExpires, L -> NI')
LoserState._to_NoInfo(interface)
@staticmethod
def couldAssertIsNowFalse(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
#print('couldAssertIsNowFalse, L -> NI')
interface.assert_logger.debug('couldAssertIsNowFalse, L -> NI')
LoserState._to_NoInfo(interface)
@staticmethod
def couldAssertIsNowTrue(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
#print('couldAssertIsNowTrue, L -> NI')
interface.assert_logger.debug('couldAssertIsNowTrue, L -> NI')
LoserState._to_NoInfo(interface)
@staticmethod
def winnerLivelinessTimerExpires(interface: "TreeInterfaceDownstream"):
LoserState._to_NoInfo(interface)
#print('winnerLivelinessTimerExpires, L -> NI')
interface.assert_logger.debug('winnerLivelinessTimerExpires, L -> NI')
LoserState._to_NoInfo(interface)
@staticmethod
def receivedPruneOrJoinOrGraft(interface: "TreeInterfaceDownstream"):
interface.send_assert()
#print('receivedPruneOrJoinOrGraft, L -> L')
interface.assert_logger.debug('receivedPruneOrJoinOrGraft, L -> L')
interface.send_assert()
@staticmethod
def _to_NoInfo(interface: "TreeInterfaceDownstream"):
......
......@@ -22,6 +22,10 @@ class AssertMetric(object):
def is_worse(self, other):
return not self.is_better_than(other)
def equal_metric(self, other):
return self.metric_preference == other.metric_preference and self.metric_preference == other.metric_preference \
and self.ip_address == other.ip_address
@staticmethod
def infinite_assert_metric():
'''
......
......@@ -114,17 +114,18 @@ class TreeInterface(metaclass=ABCMeta):
pass
def recv_assert_msg(self, received_metric: AssertMetric):
if self.my_assert_metric().is_better_than(received_metric):
# received inferior assert
if self._assert_winner_metric.ip_address == received_metric.ip_address:
# received from assert winner
self._assert_state.receivedInferiorMetricFromWinner(self)
elif self.could_assert():
# received from non assert winner and could_assert
self._assert_state.receivedInferiorMetricFromNonWinner_couldAssertIsTrue(self)
elif received_metric.is_better_than(self._assert_winner_metric):
if self._assert_winner_metric.is_better_than(received_metric) and \
self._assert_winner_metric.ip_address == received_metric.ip_address:
# received inferior assert from Assert Winner
self._assert_state.receivedInferiorMetricFromWinner(self)
elif self.my_assert_metric().is_better_than(received_metric) and self.could_assert():
# received inferior assert from non assert winner and could_assert
self._assert_state.receivedInferiorMetricFromNonWinner_couldAssertIsTrue(self)
elif received_metric.is_better_than(self._assert_winner_metric) or \
received_metric.equal_metric(self._assert_winner_metric):
#received preferred assert
self._assert_state.receivedPreferedMetric(self, received_metric)
equal_metric = received_metric.equal_metric(self._assert_winner_metric)
self._assert_state.receivedPreferedMetric(self, received_metric, equal_metric)
def recv_prune_msg(self, upstream_neighbor_address, holdtime):
if upstream_neighbor_address == self.get_ip():
......
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