bfd_bridge = "vtep_bfd"
bfd_ref = {}
+
def call_prog(prog, args_list):
cmd = [prog, "-vconsole:off"] + args_list
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
- if len(output) == 0 or output[0] == None:
+ if len(output) == 0 or output[0] is None:
output = ""
else:
output = output[0].strip()
return output
+
def ovs_vsctl(args):
return call_prog("ovs-vsctl", shlex.split(args))
+
def ovs_ofctl(args):
return call_prog("ovs-ofctl", shlex.split(args))
+
def vtep_ctl(args):
return call_prog("vtep-ctl", shlex.split(args))
column = vtep_ctl("--columns=tunnel_key find logical_switch "
"name=%s" % self.name)
tunnel_key = column.partition(":")[2].strip()
- if (tunnel_key and type(eval(tunnel_key)) == types.IntType):
+ if tunnel_key and isinstance(eval(tunnel_key), types.IntType):
self.tunnel_key = tunnel_key
vlog.info("using tunnel key %s in %s"
% (self.tunnel_key, self.name))
self.update_remote_macs()
self.update_stats()
+
def get_vtep_tunnel(remote_ip):
# Get the physical_locator record for the local tunnel end point.
column = vtep_ctl("--columns=_uuid find physical_locator "
return (local, remote, tunnel)
+
def create_vtep_tunnel(remote_ip):
local, remote, tunnel = get_vtep_tunnel(remote_ip)
if not local or not remote:
%(ps_name, local, remote))
return tunnel
+
def destroy_vtep_tunnel(remote_ip):
local, remote, tunnel = get_vtep_tunnel(remote_ip)
if tunnel:
"-- --if-exists destroy tunnel %s"
% (ps_name, tunnel, tunnel))
+
def add_bfd(remote_ip):
# The VTEP emulator creates one OVS bridge for every logical switch.
# Multiple logical switches can have multiple OVS tunnels to the
# conditions, pass the responsibility of creating a 'tunnel' record
# to run_bfd() which runs more often.
+
def del_bfd(remote_ip):
if remote_ip in bfd_ref:
if bfd_ref[remote_ip] == 1:
else:
bfd_ref[remote_ip] -= 1
+
def run_bfd():
bfd_ports = ovs_vsctl("list-ports %s" % bfd_bridge).split()
for port in bfd_ports:
bfd_lconf_default['bfd_config_local:bfd_dst_mac'],
bfd_dst_mac))
+
def add_binding(binding, ls):
vlog.info("adding binding %s" % binding)
ls.add_lbinding(lbinding)
Bindings[binding] = ls.name
+
def del_binding(binding, ls):
vlog.info("removing binding %s" % binding)
del Bindings[binding]
+
def handle_physical():
# Gather physical ports except the patch ports we created
ovs_ports = ovs_vsctl("list-ports %s" % ps_name).split()
add_binding(binding, ls)
-
dead_bindings = set(Bindings.keys()).difference(new_bindings)
for binding in dead_bindings:
ls_name = Bindings[binding]
vtep_ctl("clear-local-macs %s" % Lswitches[ls_name].name)
del Lswitches[ls_name]
+
def setup():
br_list = ovs_vsctl("list-br").split()
if (ps_name not in br_list):