Skip to content

Commit

Permalink
fix Assert state machine: verification of preferred assert
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrofran12 committed Jul 10, 2020
1 parent 1a64d22 commit 3896b38
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
7 changes: 3 additions & 4 deletions pimdm/Main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import time
import netifaces
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions pimdm/Run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions pimdm/tree/assert_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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"):
"""
Expand Down Expand Up @@ -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"):
"""
Expand Down Expand Up @@ -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"):
"""
Expand Down
3 changes: 1 addition & 2 deletions pimdm/tree/tree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3896b38

Please sign in to comment.