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
  • Loading branch information
pedrofran12 committed Jul 5, 2020
1 parent 22b2e36 commit a79a64d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ IPv4 and IPv6 multicast is supported. By default all commands will be executed o

#### Start protocol process

In order to start the protocol you first need to explicitly start it. This will start a daemon process, which will be running in the background. The command is the following:
In order to start the protocol you first need to explicitly start it. This will start a daemon process, which will be running in the background.

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).

If `-uvrf` is not defined, the default unicast table id will be used (table id 254).

```
sudo hpim-dm -start [-mvrf MULTICAST_TABLE_ID] [-uvrf UNICAST_TABLE_ID]
```
Expand Down
10 changes: 10 additions & 0 deletions hpimdm/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ def remove_security_key(interface_name, security_identifier, ipv4=False, ipv6=Fa
kernel_v6.remove_interface_security(interface_name, security_identifier)


def list_instances():
"""
List instance information
"""
t = PrettyTable(['Instance PID', 'Multicast VRF', 'Unicast VRF'])
import os
t.add_row([os.getpid(), hpim_globals.MULTICAST_TABLE_ID, hpim_globals.UNICAST_TABLE_ID])
return str(t)


def change_initial_flood_setting():
"""
Change Initial Flood Setting, used to control the implicit interest of all neighbors
Expand Down
34 changes: 29 additions & 5 deletions hpimdm/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 faulthandler
import _pickle as pickle
from prettytable import PrettyTable
from hpimdm.tree import hpim_globals
from hpimdm.daemon.Daemon import Daemon
from hpimdm import Main

VERSION = "1.3.3.3"
VERSION = "1.3.3.4"


def client_socket(data_to_send):
def client_socket(data_to_send, print_output=True):
"""
Send command to daemon process through a socket
"""
Expand All @@ -29,7 +31,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 @@ -81,6 +86,8 @@ def run(self):
connection.sendall(pickle.dumps(Main.list_neighbors_state(ipv4=args.ipv4, ipv6=args.ipv6)))
elif 'list_sequence_numbers' in args and args.list_sequence_numbers:
connection.sendall(pickle.dumps(Main.list_sequence_numbers(ipv4=args.ipv4, ipv6=args.ipv6)))
elif 'list_instances' in args and args.list_instances:
connection.sendall(pickle.dumps(Main.list_instances()))
elif 'add_interface' in args and args.add_interface:
Main.add_hpim_interface(args.add_interface[0], ipv4=args.ipv4, ipv6=args.ipv6)
connection.shutdown(socket.SHUT_RDWR)
Expand Down Expand Up @@ -155,6 +162,8 @@ def main():
"Use -4 or -6 to specify IPv4 or IPv6 HPIM neighbor state.")
group.add_argument("-lsn", "--list_sequence_numbers", action="store_true", default=False,
help="List Sequence Numbers. Use -4 or -6 to list stored IPv4 or IPv6 HPIM sequence numbers.")
group.add_argument("-instances", "--list_instances", action="store_true", default=False,
help="List running HPIM-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.")
Expand Down Expand Up @@ -197,11 +206,11 @@ 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=[hpim_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"
" process process on a given vrf. It can also be used with the other commands "
" process on a given vrf. It can also be used with the other commands "
"(for example add, list, ...) for setting/getting information on a given daemon"
" process")
group_vrf.add_argument("-uvrf", "--unicast_vrf", nargs=1, default=[hpim_globals.UNICAST_TABLE_ID],
Expand All @@ -215,6 +224,21 @@ def main():
if os.geteuid() != 0:
sys.exit('HPIM-DM must be run as root!')

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

for pid_file in pid_files:
d = MyDaemon(pid_file)
hpim_globals.MULTICAST_TABLE_ID = pid_file[16:-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

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

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="HPIM-DM Multicast Routing Protocol HPIM Dense-Mode Router IPv4 IPv6",
version="1.3.3.3",
version="1.3.3.4",
url="http://github.com/pedrofran12/hpim_dm",
author="Pedro Oliveira",
author_email="[email protected]",
Expand Down

0 comments on commit a79a64d

Please sign in to comment.