Skip to content

Commit

Permalink
Add command to list instances && fix issue of -mvr and -uvrf being mu…
Browse files Browse the repository at this point in the history
…tually exclusive && fix state refresh deadlock && include originator state on -ls
  • Loading branch information
pedrofran12 committed Jul 5, 2020
1 parent 4f60a67 commit 1a64d22
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ In order to start the protocol you first need to explicitly start it. This will

IPv4 and IPv6 multicast is supported. By default all commands will be executed on IPv4 daemon. To execute a command on the IPv6 daemon use `-6`.

We support multiple tables. Each daemon process will be bind to a given multicast and unicast table id, with can be defined at startup with `-mvrf` and `-uvrf`.
We support multiple tables. Each daemon process will be bind to a given multicast and unicast table id, which can be defined at startup with `-mvrf` and `-uvrf`.

If `-mvrf` is not defined, the default multicast table id will be used (table id 0).

Expand Down
13 changes: 6 additions & 7 deletions pimdm/InterfacePIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,14 @@ def is_state_refresh_capable(self):
"""
Check StateRefresh capability of interface neighbors
"""
with self.neighbors_lock.genWlock():
if len(self.neighbors) == 0:
return False
if len(self.neighbors) == 0:
return False

state_refresh_capable = True
for neighbor in list(self.neighbors.values()):
state_refresh_capable &= neighbor.state_refresh_capable
state_refresh_capable = True
for neighbor in list(self.neighbors.values()):
state_refresh_capable &= neighbor.state_refresh_capable

return state_refresh_capable
return state_refresh_capable

'''
def change_interface(self):
Expand Down
18 changes: 16 additions & 2 deletions pimdm/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import logging.handlers
from prettytable import PrettyTable
from pimdm.tree import pim_globals

from pimdm import UnicastRouting
from pimdm.TestLogger import RootFilter
Expand Down Expand Up @@ -158,7 +159,7 @@ def list_routing_state(ipv4=False, ipv6=False):
for b in list(a.values()):
routing_entries.append(b)

t = PrettyTable(['SourceIP', 'GroupIP', 'Interface', 'PruneState', 'AssertState', 'LocalMembership', "Is Forwarding?"])
t = PrettyTable(['SourceIP', 'GroupIP', 'Interface', 'OriginatorState', 'PruneState', 'AssertState', 'LocalMembership', "Is Forwarding?"])
for entry in routing_entries:
ip = entry.source_ip
group = entry.group_ip
Expand All @@ -172,16 +173,29 @@ def list_routing_state(ipv4=False, ipv6=False):
assert_state = type(interface_state._assert_state).__name__
if index != upstream_if_index:
prune_state = type(interface_state._prune_state).__name__
originator_state = "-"
is_forwarding = interface_state.is_forwarding()
else:
prune_state = type(interface_state._graft_prune_state).__name__
is_forwarding = "upstream"
originator_state = type(interface_state._originator_state).__name__
except:
originator_state = "-"
prune_state = "-"
assert_state = "-"
is_forwarding = "-"

t.add_row([ip, group, interface_name, prune_state, assert_state, local_membership, is_forwarding])
t.add_row([ip, group, interface_name, originator_state, prune_state, assert_state, local_membership, is_forwarding])
return str(t)


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)


Expand Down
32 changes: 28 additions & 4 deletions pimdm/Run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import os
import sys
import glob
import socket
import argparse
import traceback
import _pickle as pickle
from prettytable import PrettyTable

from pimdm import Main
from pimdm.tree import pim_globals
from pimdm.daemon.Daemon import Daemon

VERSION = "1.1.1.2"
VERSION = "1.1.1.3"


def client_socket(data_to_send):
def client_socket(data_to_send, print_output=True):
# Create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

Expand All @@ -26,7 +28,10 @@ def client_socket(data_to_send):
sock.sendall(pickle.dumps(data_to_send))
data_rcv = sock.recv(1024 * 256)
if data_rcv:
print(pickle.loads(data_rcv))
if print_output:
print(pickle.loads(data_rcv))
else:
return pickle.loads(data_rcv)
except socket.error:
pass
finally:
Expand Down Expand Up @@ -92,6 +97,8 @@ def run(self):
elif 'remove_interface_mld' in args and args.remove_interface_mld:
Main.remove_interface(args.remove_interface_mld[0], membership=True, ipv4=False, ipv6=True)
connection.shutdown(socket.SHUT_RDWR)
elif 'list_instances' in args and args.list_instances:
connection.sendall(pickle.dumps(Main.list_instances()))
elif 'stop' in args and args.stop:
Main.stop()
connection.shutdown(socket.SHUT_RDWR)
Expand Down Expand Up @@ -121,6 +128,8 @@ def main():
"Use -4 or -6 to specify IPv4 or IPv6 PIM neighbors.")
group.add_argument("-ls", "--list_state", action="store_true", default=False, help="List IGMP/MLD and PIM-DM state machines."
" Use -4 or -6 to specify IPv4 or IPv6 state respectively.")
group.add_argument("-instances", "--list_instances", action="store_true", default=False,
help="List running PIM-DM daemon processes.")
group.add_argument("-mr", "--multicast_routes", action="store_true", default=False, help="List Multicast Routing table. "
"Use -4 or -6 to specify IPv4 or IPv6 multicast routing table.")
group.add_argument("-ai", "--add_interface", nargs=1, metavar='INTERFACE_NAME', help="Add PIM interface. "
Expand All @@ -139,7 +148,7 @@ def main():
group_ipversion = parser.add_mutually_exclusive_group(required=False)
group_ipversion.add_argument("-4", "--ipv4", action="store_true", default=False, help="Setting for IPv4")
group_ipversion.add_argument("-6", "--ipv6", action="store_true", default=False, help="Setting for IPv6")
group_vrf = parser.add_mutually_exclusive_group(required=False)
group_vrf = parser.add_argument_group()
group_vrf.add_argument("-mvrf", "--multicast_vrf", nargs=1, default=[pim_globals.MULTICAST_TABLE_ID],
metavar='MULTICAST_VRF_NUMBER', type=int,
help="Define multicast table id. This can be used on -start to explicitly start the daemon"
Expand All @@ -157,6 +166,21 @@ def main():
if os.geteuid() != 0:
sys.exit('PIM-DM must be run as root!')

if args.list_instances:
pid_files = glob.glob("/tmp/Daemon-pim*.pid")
t = PrettyTable(['Instance PID', 'Multicast VRF', 'Unicast VRF'])

for pid_file in pid_files:
d = MyDaemon(pid_file)
pim_globals.MULTICAST_TABLE_ID = pid_file[15:-4]
if not d.is_running():
continue

t_new = client_socket(args, print_output=False)
t.add_row(t_new.replace(" ", "").split("\n")[3].split("|")[1:4])
print(t)
return

pim_globals.MULTICAST_TABLE_ID = args.multicast_vrf[0]
pim_globals.UNICAST_TABLE_ID = args.unicast_vrf[0]

Expand Down
2 changes: 1 addition & 1 deletion pimdm/tree/KernelEntry.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def recv_state_refresh_msg(self, index, packet):
return
# refresh limit
timestamp = time()
if (timestamp - self.timestamp_of_last_state_refresh_message_received) < interval:
if (timestamp - self.timestamp_of_last_state_refresh_message_received) < interval - 5:
return
self.timestamp_of_last_state_refresh_message_received = timestamp
if ttl == 0:
Expand Down
1 change: 1 addition & 0 deletions pimdm/tree/tree_if_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def recv_graft_msg(self, upstream_neighbor_address, source_ip):
# Send messages
######################################
def send_state_refresh(self, state_refresh_msg_received):
print("send state refresh")
if state_refresh_msg_received is None:
return

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.2",
version="1.1.1.3",
url="http://github.com/pedrofran12/pim_dm",
author="Pedro Oliveira",
author_email="pedro.francisco.oliveira@tecnico.ulisboa.pt",
Expand Down

0 comments on commit 1a64d22

Please sign in to comment.