Skip to content

Instantly share code, notes, and snippets.

@djoreilly
Last active January 17, 2023 07:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djoreilly/c970226b6152e0fcf8d87c8703a69747 to your computer and use it in GitHub Desktop.
Save djoreilly/c970226b6152e0fcf8d87c8703a69747 to your computer and use it in GitHub Desktop.
Reproduce OVS v2.7 memory leak
# send vxlan pkts from netns to ovs on same host
# keep changing the src mac so learn action creates/updates 1000 flows
# ip netns exec ns1 ./send-vxlan-loop.py
import time
from scapy.all import *
# https://home.regit.org/2014/04/speeding-up-scapy-packets-sending/
sock = conf.L2socket(iface='veth-ns')
i = 1
while True:
for n in range(1000):
s = "fa7777" + "{:06x}".format(n)
smac = ':'.join(s[i:i+2] for i in range(0, 12, 2))
# doesn't have to be arp, but needs to be something and not empty
inner_pkt = Ether(src=smac, dst='ff:ff:ff:ff:ff:ff') / ARP(op="who-has", psrc='1.2.3.4', pdst='5.6.7.8')
udp = UDP(sport=45678, dport=4789) / VXLAN(vni=0xabcdef, flags=0x08) / inner_pkt
p = Ether(src='fa:00:00:00:00:01', dst='fa:00:00:00:00:02') / IP(src='10.0.0.1', dst='10.0.0.2') / udp
sock.send(p)
print("sleeping. iter %d" %i)
i += 1
# wait max-idle for datapth flows to expire
time.sleep(1.1)
ovs-vsctl add-br br0
ovs-vsctl add-port br0 vxlan1 -- set Interface vxlan1 type=vxlan option:remote_ip=10.0.0.1 option:local_ip=10.0.0.2 option:key=flow
# reduce from default 10000msec so script doesnt have to wait so long for flows to expire
ovs-vsctl set Open_vSwitch . other_config:max-idle=1000
# setup flows like neutron ml2/ovs br-tun - learn from tun flows. in_port=1 is be vxlan1
ovs-ofctl add-flow br0 "table=0,priority=1,in_port=1 actions=resubmit(,4)"
ovs-ofctl add-flow br0 "table=4,priority=1,tun_id=0xabcdef actions=mod_vlan_vid:0x666,resubmit(,10)"
ovs-ofctl add-flow br0 "table=10,priority=1 actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:OXM_OF_IN_PORT[])"
# setup netns and veth for script
ip link add veth-ns type veth peer name veth-host
ip link set dev veth-host up
ip address add 10.0.0.2/30 dev veth-host
ip link set dev veth-host address fa:00:00:00:00:02
ip netns add ns1
ip link set dev veth-ns netns ns1
ip netns exec ns1 ip link set dev veth-ns up
ip netns exec ns1 ip address add 10.0.0.1/30 dev veth-ns
ip netns exec ns1 ip link set dev veth-ns address fa:00:00:00:00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment