Skip to content

Instantly share code, notes, and snippets.

@trozet
Created April 4, 2019 16:32
Show Gist options
  • Save trozet/02aaa0077ddbc4d9ffe7a86a24851c48 to your computer and use it in GitHub Desktop.
Save trozet/02aaa0077ddbc4d9ffe7a86a24851c48 to your computer and use it in GitHub Desktop.
programs rules to match on mac dest and set out vxlan port
import argparse
import ipaddress
import subprocess
import time
dpdk1_rx_dest_mac = "3c0000000019"
dpdk0_rx_dest_mac = "3c0000000099"
dpdk1_rx_int_mac = int(dpdk1_rx_dest_mac, 16)
dpdk0_rx_int_mac = int(dpdk0_rx_dest_mac, 16)
count=0
parser = argparse.ArgumentParser()
parser.add_argument("flows", type=int, help="Number of flows to add routes for")
args = parser.parse_args()
def change_mac(mac, offset):
return "{:012X}".format(int(mac, 16) + offset)
print('cleaning ovs')
subprocess.check_call(['ovs-ofctl', 'del-flows', 'br-int'])
time.sleep(5)
print('configuring rules')
while count < args.flows:
ma0 = "in_port=br1-patch,dl_dst={},actions=output:vxlan0".format(':'.join(change_mac(dpdk1_rx_dest_mac, count*256)[i:i+2] for i in range(0,12,2)))
ma1 = "in_port=br0-patch,dl_dst={},actions=output:vxlan1".format(':'.join(change_mac(dpdk0_rx_dest_mac, count*256)[i:i+2] for i in range(0,12,2)))
time.sleep(.01)
if count > 45000:
time.sleep(.02)
for match_action in ma0, ma1:
try:
subprocess.check_call(['ovs-ofctl', 'add-flow', 'br-int', match_action])
except Exception:
subprocess.check_call(['ovs-ofctl', 'add-flow', 'br-int', match_action])
time.sleep(.01)
count+=1
print('Added {} flows'.format(count*2), end="\r")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment