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