Skip to content

Commit

Permalink
Use multicast and unicast table id on startup for starting multiple h…
Browse files Browse the repository at this point in the history
…pim-dm daemon processes
  • Loading branch information
pedrofran12 committed Jul 3, 2020
1 parent b1132fe commit 22b2e36
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 22 deletions.
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,36 @@ IPv4 and IPv6 multicast is supported. By default all commands will be executed o

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:

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

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
sudo hpim-dm -start [-mvrf MULTICAST_TABLE_ID] [-uvrf UNICAST_TABLE_ID]
```

After starting the protocol process, if the default multicast table is not used, the following commands (for adding interfaces and listing state) need to have the argument `-mvrf` defined to specify the corresponding daemon process.

#### Add interface

After starting the protocol process you can enable the protocol in specific interfaces. You need to specify which interfaces will have IGMP/MLD enabled and which interfaces will have HPIM-DM enabled.
* To have a given interface being monitored by HPIM-DM (to exchange control packets with it), you need to run the following command:

```
sudo hpim-dm -ai INTERFACE_NAME [-4 | -6]
sudo hpim-dm -ai INTERFACE_NAME [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```

* To have a given interface being monitored by IGMPv2 (to monitor the IPv4 multicast interest of directly connected hosts), you need to run the following command:

```
sudo hpim-dm -aiigmp INTERFACE_NAME
sudo hpim-dm -aiigmp INTERFACE_NAME [-mvrf MULTICAST_TABLE_ID]
```

* To have a given interface being monitored by MLDv1 (to monitor the IPv6 multicast interest of directly connected hosts), you need to run the following command:

```
sudo hpim-dm -aimld INTERFACE_NAME
sudo hpim-dm -aimld INTERFACE_NAME [-mvrf MULTICAST_TABLE_ID]
```
Expand All @@ -85,28 +91,30 @@ To remove a previously added interface, you need to run the following commands:
* To remove a previously added HPIM-DM interface:
```
sudo hpim-dm -ri INTERFACE_NAME [-4 | -6]
sudo hpim-dm -ri INTERFACE_NAME [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
* To remove a previously added IGMP interface:
```
sudo hpim-dm -riigmp INTERFACE_NAME
sudo hpim-dm -riigmp INTERFACE_NAME [-mvrf MULTICAST_TABLE_ID]
```
* To remove a previously added MLD interface:
```
sudo hpim-dm -rimld INTERFACE_NAME
sudo hpim-dm -rimld INTERFACE_NAME [-mvrf MULTICAST_TABLE_ID]
```
#### Stop protocol process
If you want to stop the protocol process, and stop the daemon process, you need to explicitly run this command:
If a specific multicast table id was defined on startup, you need to define the daemon by its multicast table id.
```
sudo hpim-dm -stop
sudo hpim-dm -stop [-mvrf MULTICAST_TABLE_ID]
```
Expand All @@ -121,23 +129,23 @@ All control messages carry a Security Identifier, which is a number that identif
List all available hash algorithms that can be used to create the HMAC.
```
sudo hpim-dm -lsec
sudo hpim-dm -lsec [-mvrf MULTICAST_TABLE_ID]
```
- #### Add security on interface:
Enable security on HPIM-DM interface named INTERFACE_NAME. The SECURITY_IDENTIFIER is a number and identifies the algorithm and key of the HMAC. To check the available algorithms run -lsec.
```
sudo hpim-dm -aisec INTERFACE_NAME SECURITY_IDENTIFIER SECURITY_ALGORITHM SECURITY_KEY [-4 | -6]
sudo hpim-dm -aisec INTERFACE_NAME SECURITY_IDENTIFIER SECURITY_ALGORITHM SECURITY_KEY [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
- #### Remove security from interface:
Disable security identified by SECURITY_IDENTIFIER from HPIM-DM interface named INTERFACE_NAME.
```
sudo hpim-dm -risec INTERFACE_NAME SECURITY_IDENTIFIER [-4 | -6]
sudo hpim-dm -risec INTERFACE_NAME SECURITY_IDENTIFIER [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
Expand All @@ -150,47 +158,47 @@ We have built some list commands that can be used to check the "internals" of th
Show all router interfaces and which ones have HPIM-DM and IGMP/MLD enabled. For IGMP/MLD enabled interfaces outputs the Querier state. For HPIM enabled interfaces outputs security settings.
```
sudo hpim-dm -li [-4 | -6]
sudo hpim-dm -li [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
- #### List neighbors:
Verify neighbors that have established a neighborhood relationship.
```
sudo hpim-dm -ln [-4 | -6]
sudo hpim-dm -ln [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
- #### List sequence numbers:
Verify all stored sequence numbers.
```
sudo hpim-dm -lsn [-4 | -6]
sudo hpim-dm -lsn [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
- #### List neighbor state:
Verify all state regarding each neighbor, whether they are UPSTREAM or NOT UPSTREAM and in the latter whether they are INTERESTED or NOT INTERESTED in receiving data packets.
```
sudo hpim-dm -lns [-4 | -6]
sudo hpim-dm -lns [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
- #### List state machines:
List all state machines and corresponding state of all trees that are being monitored. Also list IGMP/MLD state for each group being monitored.
```
sudo hpim-dm -ls [-4 | -6]
sudo hpim-dm -ls [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
- #### Multicast Routing Table:
List Linux Multicast Routing Table (equivalent to `ip mroute show`)
```
sudo hpim-dm -mr [-4 | -6]
sudo hpim-dm -mr [-4 | -6] [-mvrf MULTICAST_TABLE_ID]
```
Expand All @@ -201,15 +209,15 @@ We have built some list commands that can be used to check the "internals" of th
Control flooding behavior (whether to flood or not data packets during the broadcast tree formation)
```
sudo hpim-dm -fid
sudo hpim-dm -fid [-mvrf MULTICAST_TABLE_ID]
```
- #### Hold Forwarding State:
This setting allows during an AW replacement (for example due to RPC changes) for the previous AW to hold its forwarding state for a small amount of time. This way it is possible to prevent loss of data packets during this event, however it may introduce traffic duplication (while the new and the previous AW both forward traffic). By default this setting is enabled with a time period of 2 seconds.
```
sudo hpim-dm -hfs
sudo hpim-dm -hfs [-mvrf MULTICAST_TABLE_ID]
```
Files tree/hpim_globals.py, igmp/igmp_globals.py and mld/mld_globals.py store all timer values and some configurations regarding HPIM-DM, IGMPv2 and MLDv1. If you want to tune the protocol, you can change the values of these files. These configurations are used by all interfaces, meaning that there is no tuning per interface.
Expand All @@ -221,7 +229,7 @@ Files tree/hpim_globals.py, igmp/igmp_globals.py and mld/mld_globals.py store al
To see the logs run:
```
hpim-dm -v
hpim-dm -v [-mvrf MULTICAST_TABLE_ID]
```
Currently the logs are not very expressive... Better logging is planned for a future release.
Expand Down
20 changes: 20 additions & 0 deletions hpimdm/Kernel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import socket
import struct
import traceback
Expand Down Expand Up @@ -415,6 +416,12 @@ def create_virtual_interface(self, ip_interface: str or bytes, interface_name: s
if type(ip_interface) is str:
ip_interface = socket.inet_aton(ip_interface)

os.system("ip mrule del iif {}".format(interface_name))
os.system("ip mrule del oif {}".format(interface_name))
if hpim_globals.MULTICAST_TABLE_ID != 0:
os.system("ip mrule add iif {} lookup {}".format(interface_name, hpim_globals.MULTICAST_TABLE_ID))
os.system("ip mrule add oif {} lookup {}".format(interface_name, hpim_globals.MULTICAST_TABLE_ID))

struct_mrt_add_vif = struct.pack("HBBI 4s 4s", index, flags, 1, 0, ip_interface,
socket.inet_aton("0.0.0.0"))
self.socket.setsockopt(socket.IPPROTO_IP, Kernel4.MRT_ADD_VIF, struct_mrt_add_vif)
Expand All @@ -439,6 +446,9 @@ def remove_virtual_interface(self, interface_name):
struct_vifctl = struct.pack("HBBI 4s 4s", index, 0, 0, 0, socket.inet_aton("0.0.0.0"),
socket.inet_aton("0.0.0.0"))

os.system("ip mrule del iif {}".format(interface_name))
os.system("ip mrule del oif {}".format(interface_name))

try:
self.socket.setsockopt(socket.IPPROTO_IP, Kernel4.MRT_DEL_VIF, struct_vifctl)
except socket.error:
Expand Down Expand Up @@ -692,6 +702,13 @@ def __init__(self):
'''
def create_virtual_interface(self, ip_interface, interface_name: str, index, flags=0x0):
physical_if_index = if_nametoindex(interface_name)

os.system("ip -6 mrule del iif {}".format(interface_name))
os.system("ip -6 mrule del oif {}".format(interface_name))
if hpim_globals.MULTICAST_TABLE_ID != 0:
os.system("ip -6 mrule add iif {} lookup {}".format(interface_name, hpim_globals.MULTICAST_TABLE_ID))
os.system("ip -6 mrule add oif {} lookup {}".format(interface_name, hpim_globals.MULTICAST_TABLE_ID))

struct_mrt_add_vif = struct.pack("HBBHI", index, flags, 1, physical_if_index, 0)
self.socket.setsockopt(socket.IPPROTO_IPV6, Kernel6.MRT6_ADD_MIF, struct_mrt_add_vif)
self.vif_index_to_name_dic[index] = interface_name
Expand All @@ -717,6 +734,9 @@ def remove_virtual_interface(self, interface_name):
physical_if_index = if_nametoindex(interface_name)
struct_vifctl = struct.pack("HBBHI", mif_index, 0, 0, physical_if_index, 0)

os.system("ip -6 mrule del iif {}".format(interface_name))
os.system("ip -6 mrule del oif {}".format(interface_name))

try:
self.socket.setsockopt(socket.IPPROTO_IPV6, Kernel6.MRT6_DEL_MIF, struct_vifctl)
except socket.error:
Expand Down
16 changes: 15 additions & 1 deletion hpimdm/Run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hpimdm.daemon.Daemon import Daemon
from hpimdm import Main

VERSION = "1.3.3.2"
VERSION = "1.3.3.3"


def client_socket(data_to_send):
Expand Down Expand Up @@ -197,13 +197,27 @@ 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.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 "
"(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],
metavar='UNICAST_VRF_NUMBER', type=int,
help="Define unicast table id for getting unicast information (RPF checks, RPC costs, ...). "
"This information can only be defined at startup with -start command")
args = parser.parse_args()

#print(parser.parse_args())
# This script must be run as root!
if os.geteuid() != 0:
sys.exit('HPIM-DM must be run as root!')

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

daemon = MyDaemon('/tmp/Daemon-hpim' + str(hpim_globals.MULTICAST_TABLE_ID) + '.pid')
if args.start:
print("start")
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.2",
version="1.3.3.3",
url="http://github.com/pedrofran12/hpim_dm",
author="Pedro Oliveira",
author_email="pedro.francisco.oliveira@tecnico.ulisboa.pt",
Expand Down

0 comments on commit 22b2e36

Please sign in to comment.