From 3896b38d2e56c15151fe1e04acb07b34a1be967c Mon Sep 17 00:00:00 2001 From: Pedro Oliveira Date: Fri, 10 Jul 2020 22:48:05 +0100 Subject: [PATCH] fix Assert state machine: verification of preferred assert --- pimdm/Main.py | 7 +++---- pimdm/Run.py | 4 ++-- pimdm/tree/assert_state.py | 18 ++++++++++++++++++ pimdm/tree/tree_interface.py | 3 +-- setup.py | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pimdm/Main.py b/pimdm/Main.py index 75994c7..9ce7cdf 100644 --- a/pimdm/Main.py +++ b/pimdm/Main.py @@ -1,3 +1,4 @@ +import os import sys import time import netifaces @@ -193,10 +194,8 @@ def list_instances(): """ List instance information """ - t = PrettyTable(['Instance PID', 'Multicast VRF', 'Unicast VRF']) - import os - t.add_row([os.getpid(), pim_globals.MULTICAST_TABLE_ID, pim_globals.UNICAST_TABLE_ID]) - return str(t) + t = "{}|{}|{}" + return t.format(os.getpid(), pim_globals.MULTICAST_TABLE_ID, pim_globals.UNICAST_TABLE_ID) def stop(): diff --git a/pimdm/Run.py b/pimdm/Run.py index d1c0751..12a9bca 100644 --- a/pimdm/Run.py +++ b/pimdm/Run.py @@ -13,7 +13,7 @@ from pimdm.tree import pim_globals from pimdm.daemon.Daemon import Daemon -VERSION = "1.1.1.3" +VERSION = "1.1.1.4" def client_socket(data_to_send, print_output=True): @@ -177,7 +177,7 @@ def main(): continue t_new = client_socket(args, print_output=False) - t.add_row(t_new.replace(" ", "").split("\n")[3].split("|")[1:4]) + t.add_row(t_new.split("|")) print(t) return diff --git a/pimdm/tree/assert_state.py b/pimdm/tree/assert_state.py index 871d21e..26023fb 100644 --- a/pimdm/tree/assert_state.py +++ b/pimdm/tree/assert_state.py @@ -116,6 +116,11 @@ def _sendAssert_setAT(interface: "TreeInterfaceDownstream"): interface.set_assert_timer(pim_globals.ASSERT_TIME) interface.send_assert() + @staticmethod + @abstractmethod + def is_preferred_assert(interface: "TreeInterfaceDownstream", received_metric): + raise NotImplementedError() + # Override def __str__(self) -> str: return "AssertSM:" + self.__class__.__name__ @@ -127,6 +132,10 @@ class NoInfoState(AssertStateABC): This router has no (S,G) Assert state on interface I. ''' + @staticmethod + def is_preferred_assert(interface: "TreeInterfaceDownstream", received_metric): + return received_metric.is_better_than(interface._assert_winner_metric) + @staticmethod def receivedDataFromDownstreamIf(interface: "TreeInterfaceDownstream"): """ @@ -212,6 +221,10 @@ class WinnerState(AssertStateABC): interface I. ''' + @staticmethod + def is_preferred_assert(interface: "TreeInterfaceDownstream", received_metric): + return received_metric.is_better_than(interface.my_assert_metric()) + @staticmethod def receivedDataFromDownstreamIf(interface: "TreeInterfaceDownstream"): """ @@ -294,6 +307,11 @@ class LoserState(AssertStateABC): forward packets from S destined for G onto interface I. ''' + @staticmethod + def is_preferred_assert(interface: "TreeInterfaceDownstream", received_metric): + return received_metric.is_better_than(interface._assert_winner_metric) or \ + received_metric.equal_metric(interface._assert_winner_metric) + @staticmethod def receivedDataFromDownstreamIf(interface: "TreeInterfaceDownstream"): """ diff --git a/pimdm/tree/tree_interface.py b/pimdm/tree/tree_interface.py index 3e8fe95..ece5765 100644 --- a/pimdm/tree/tree_interface.py +++ b/pimdm/tree/tree_interface.py @@ -112,8 +112,7 @@ def recv_assert_msg(self, received_metric: AssertMetric): 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): + elif self._assert_state.is_preferred_assert(self, received_metric): #received preferred assert equal_metric = received_metric.equal_metric(self._assert_winner_metric) self._assert_state.receivedPreferedMetric(self, received_metric, equal_metric) diff --git a/setup.py b/setup.py index 3e7898f..972f1f5 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ long_description=open("README.md", "r").read(), long_description_content_type="text/markdown", keywords="PIM-DM Multicast Routing Protocol PIM Dense-Mode Router RFC3973 IPv4 IPv6", - version="1.1.1.3", + version="1.1.1.4", url="http://github.com/pedrofran12/pim_dm", author="Pedro Oliveira", author_email="pedro.francisco.oliveira@tecnico.ulisboa.pt",