@ -21,6 +21,8 @@ functions = {
}
}
# Stores information about already created chains and tables on each router. If a router is in this list, it means the chain and table for nftables were already created
shortcut_nftables_memory = [ ]
def get_tests ( topo ) :
available_tests = [ ]
@ -33,13 +35,20 @@ def get_tests(topo):
print ( ' Currently available tests are: ' + str ( available_tests ) )
def implement_shortcut ( router , interface , dest_ip , gateway , queue_id ) :
def implement_shortcut ( net , router , interface , dest_ip , gateway , queue_id ) :
# implement hook
info ( f " Adding hook for { interface } to { dest_ip } in Queue { queue_id } \n " )
router . cmd (
f " iptables -I FORWARD -p all --in-interface { interface } --destination { dest_ip } -j NFQUEUE --queue-num { queue_id } " )
#net[router].cmd(
# f"iptables -I FORWARD -p all --in-interface {interface} --destination {dest_ip} -j NFQUEUE --queue-num {queue_id}")
if router not in shortcut_nftables_memory :
net [ router ] . cmd ( " nft add table ip filter " )
net [ router ] . cmd ( " nft ' add chain ip filter INPUT { type filter hook input priority 0; policy accept; } ' " )
net [ router ] . cmd ( " nft ' add chain ip filter FORWARD { type filter hook forward priority 0; policy accept; } ' " )
net [ router ] . cmd ( " nft ' add chain ip filter OUTPUT { type filter hook output priority 0; policy accept; } ' " )
shortcut_nftables_memory . append ( router )
net [ router ] . cmd ( f " nft add rule ip filter FORWARD iifname ' { interface } ' ip daddr { dest_ip } counter queue num { queue_id } " )
# execute listener
router . cmd ( f " sudo python3 shortcut_listener.py -g { gateway } -id { queue_id } -s 24 &> listener.log & " )
net [ router ] . cmd ( f " sudo python3 shortcut_listener.py -g { gateway } -id { queue_id } -s 24 &> listener.log & " )
def connection_shutdown ( net , connection , names , interfaces ) :
@ -91,7 +100,7 @@ def configure_mininet(net, topo):
cut_gateway = interface_gateway_map [ incoming_interface ]
shortcut_identification = f " { incoming_interface } - { address } - { cut_gateway } "
if shortcut_identification not in shortcut_memory :
implement_shortcut ( net [ router ] , incoming_interface , address , cut_gateway , shortcut_queue_id )
implement_shortcut ( net , router , incoming_interface , address , cut_gateway , shortcut_queue_id )
shortcut_memory . append ( shortcut_identification )
shortcut_queue_id + = 1