def run(self):
self.get_configuration()
+ def get_bridge_metadata(self, br):
+ br_meta = {}
+ br_meta["dpid"] = ""
+ br_meta["controller"] = ""
+ br_meta["manager"] = ""
+
+ res_ctl = self._runner.exec_cmd("ovs-vsctl get-controller " + br)
+ for ctl in res_ctl:
+ br_meta["controller"] = self._u.str_join(br_meta["controller"], ctl.strip(), ", ")
+
+ res_mgr = self._runner.exec_cmd("ovs-vsctl get-manager")
+ for mgr in res_mgr:
+ br_meta["manager"] = self._u.str_join(br_meta["manager"], mgr.strip(), ", ")
+
+ res_ofsw = self._runner.exec_cmd("ovs-ofctl show " + br)
+ for ofsw_spec in res_ofsw:
+ ofsw_spec = ofsw_spec.strip()
+ if self._u.d_push(re.search(r': dpid:(.*)', ofsw_spec)) is not None:
+ br_meta["dpid"] = self._u.d_pop().group(1).strip()
+ elif self._u.d_push(re.search(r'n_tables:(.*), n_buffers:(.*)', ofsw_spec)) is not None:
+ match = self._u.d_pop()
+ br_meta["tables"] = match.group(1).strip()
+ br_meta["buffers"] = match.group(2).strip()
+ elif self._u.d_push(re.search(r'capabilities:(.*)', ofsw_spec)) is not None:
+ br_meta["capabilities"] = self._u.d_pop().group(1).strip()
+ elif self._u.d_push(re.search(r'actions:(.*)', ofsw_spec)) is not None:
+ br_meta["actions"] = self._u.d_pop().group(1).strip()
+
+ #print br_meta
+ return br_meta
+
+ def get_port_metadata(self, port):
+ port_meta = {}
+ res_ovsport = self._runner.exec_cmd("ovs-vsctl show")
+ for i in range(0, len(res_ovsport)):
+ port_start = res_ovsport[i].strip()
+ if self._u.d_push(re.search(r'Port "*%s"*' % port, port_start)) is not None:
+ for j in range(i + 1, len(res_ovsport)):
+ port_spec = res_ovsport[j].strip()
+ if self._u.d_push(re.search(r'tag: (.*)', port_spec)) is not None:
+ port_meta["tag"] = self._u.d_pop().group(1).strip()
+ elif self._u.d_push(re.search(r'type: (.*)', port_spec)) is not None:
+ port_meta["type"] = self._u.d_pop().group(1).strip()
+ elif self._u.d_push(re.search(r'options: {(.*)}', port_spec)) is not None:
+ port_options = self._u.d_pop().group(1).strip().split(",")
+ for port_option in port_options:
+ (opt_name, opt_value) = port_option.split("=")
+ port_meta[opt_name] = opt_value
+ elif self._u.d_push(re.search(r'Port "*', port_spec)) is not None:
+ break
+
+ #print port_meta
+ return port_meta
+
def get_configuration(self):
patch_peers = {}
result = self._runner.exec_cmd("ovs-vsctl list-br")
for br_src in result:
br_src = br_src.rstrip()
+ br_src_meta = self.get_bridge_metadata(br_src)
result2 = self._runner.exec_cmd("ovs-dpctl show " + br_src)
for port_desc in result2:
port_desc = port_desc.rstrip()
+
+ # patch port
if self._u.d_push(
re.search(r'port \d+: (.*?) \(patch: peer=(.*?)\)',
port_desc)) is not None:
if patch_dst + ":" + patch_src in patch_peers:
continue
-
+
+ patch_src_meta = self.get_port_metadata(patch_src)
+ patch_dst_meta = self.get_port_metadata(patch_dst)
result3 = self._runner.exec_cmd(
"ovs-vsctl port-to-br " + patch_dst)
if result3 is not None and len(result3) > 0:
br_dst = result3[0].rstrip()
+ br_dst_meta = self.get_bridge_metadata(br_dst)
self._cu.add_linkpair(
- Device(br_src, Device.BR_TYPE),
- Device(br_dst, Device.BR_TYPE),
- Port(patch_src),
- Port(patch_dst),
+ Device(br_src, Device.BR_TYPE, br_src_meta),
+ Device(br_dst, Device.BR_TYPE, br_dst_meta),
+ Port(patch_src, Port.DEFAULT_TYPE, patch_src_meta),
+ Port(patch_dst, Port.DEFAULT_TYPE, patch_dst_meta),
self._formatter.PATCH_FORMAT)
else:
self._cu.add_linkpair(
- Device(br_src, Device.BR_TYPE),
+ Device(br_src, Device.BR_TYPE, br_src_meta),
Device("NOT CONNECTED", Device.NOT_CONNECTED_TYPE),
- Port(patch_src),
- Port(patch_dst),
+ Port(patch_src, Port.DEFAULT_TYPE, patch_src_meta),
+ Port(patch_dst, Port.DEFAULT_TYPE, patch_dst_meta),
self._formatter.PATCH_FORMAT)
+ # none patch port
else:
- # Internal OVSPort.
+ # NOT Internal Bridge Port.
if self._u.d_push(
re.search(
r'port \d+: ' + br_src + ' \(internal\)',
port_desc)) is None:
if self._u.d_push(re.search(r'port \d+: (.*)', port_desc)) is not None:
port = self._u.d_pop().group(1).rstrip()
+ port_meta = self.get_port_metadata(port)
+
+ # physical interface
if self._u.d_push(re.match(r'^eth\d+$', port)) \
or self._u.d_push(re.match(r'^em\d+$', port)) \
or self._u.d_push(re.match(r'^igb\d+$', port)):
self._cu._port_to_br[port] = br_src
self._cu.add_linkpair(
- Device(br_src, Device.BR_TYPE),
+ Device(br_src, Device.BR_TYPE, br_src_meta),
Device("Physical NW", Device.PHYNET_TYPE),
- Port(port),
+ Port(port, Port.DEFAULT_TYPE, port_meta),
Port(""))
+
+ # tunnel port
elif self._u.d_push(re.match(r'(vxlan\d+)', port)) \
or self._u.d_push(re.match(r'(gre\d+)', port)) \
or self._u.d_push(re.match(r'(gre-\d+)', port)):
port2 = self._u.d_pop().group(1)
+ port2_meta = self.get_port_metadata(port2)
self._cu._port_to_br[port2] = br_src
self._cu.add_linkpair(
- Device(br_src, Device.BR_TYPE),
+ Device(br_src, Device.BR_TYPE, br_src_meta),
Device("OS Routing", Device.OS_ROUTE_TYPE),
- Port(port),
+ Port(port, Port.DEFAULT_TYPE, port_meta),
Port(""))
+
+ # internal
elif re.search(r' \(internal\)', port):
port = re.sub(r' \(internal\)', '', port)
if port in self._iface_to_nss:
self._cu.add_linkpair(
- Device(br_src, Device.BR_TYPE),
+ Device(br_src, Device.BR_TYPE, br_src_meta),
Device(self._iface_to_nss[
port], Device.NAMESPACE_TYPE),
- Port(port),
+ Port(port, Port.DEFAULT_TYPE, port_meta),
Port(""),
self._formatter.NAMESPACE_FORMAT)
else:
self._cu.add_linkpair(
- Device(br_src, Device.BR_TYPE),
+ Device(br_src, Device.BR_TYPE, br_src_meta),
Device(
"INTERNAL", Device.OS_ROUTE_TYPE),
- Port(port),
+ Port(port, Port.DEFAULT_TYPE, port_meta),
Port(""))
else:
## Other OVSPort