@@ -5,9 +5,11 @@ from ovs.flows.ofp import OFPFlowFactory
from ovs.ovs_ofparse.ofp_logic import LogicFlowProcessor
from ovs.ovs_ofparse.main import maincli
from ovs.ovs_ofparse.process import (
+ FlowProcessor,
JSONProcessor,
ConsoleProcessor,
)
+from ovs.ovs_ofparse.html import HTMLBuffer, HTMLFormatter, HTMLStyle
factory = OFPFlowFactory()
@@ -90,3 +92,71 @@ def logic(opts, show_flows, cookie_flag, heat_map):
processor = LogicFlowProcessor(opts, factory, cookie_flag)
processor.process()
processor.print(show_flows, heat_map)
+
+
+class HTMLProcessor(FlowProcessor):
+ def __init__(self, opts, factory):
+ super().__init__(opts, factory)
+ self.data = dict()
+
+ def start_file(self, name, filename):
+ self.tables = dict()
+
+ def stop_file(self, name, filename):
+ self.data[name] = self.tables
+
+ def process_flow(self, flow, name):
+ table = flow.info.get("table") or 0
+ if not self.tables.get(table):
+ self.tables[table] = list()
+ self.tables[table].append(flow)
+
+ def html(self):
+ html_obj = ""
+ for name, tables in self.data.items():
+ name = name.replace(" ", "_")
+ html_obj += "<h1>{}</h1>".format(name)
+ html_obj += "<div id=flow_list>"
+ for table, flows in tables.items():
+ formatter = HTMLFormatter(self.opts)
+
+ def anchor(x):
+ return "#table_%s_%s" % (name, x.value["table"])
+
+ formatter.style.set_value_style(
+ "resubmit",
+ HTMLStyle(
+ formatter.style.get("value.resubmit"),
+ anchor_gen=anchor,
+ ),
+ )
+ html_obj += (
+ "<h2 id=table_{name}_{table}> Table {table}</h2>".format(
+ name=name, table=table
+ )
+ )
+ html_obj += "<ul id=table_{}_flow_list>".format(table)
+ for flow in flows:
+ html_obj += "<li id=flow_{}>".format(flow.id)
+ highlighted = None
+ if self.opts.get("highlight"):
+ result = self.opts.get("highlight").evaluate(flow)
+ if result:
+ highlighted = result.kv
+ buf = HTMLBuffer()
+ formatter.format_flow(buf, flow, highlighted)
+ html_obj += buf.text
+ html_obj += "</li>"
+ html_obj += "</ul>"
+ html_obj += "</div>"
+
+ return html_obj
+
+
+@openflow.command()
+@click.pass_obj
+def html(opts):
+ """Print the flows in an HTML list"""
+ processor = HTMLProcessor(opts, factory)
+ processor.process()
+ print(processor.html())
Create a flow table that uses a hyperlink from resubmit() to the target table Signed-off-by: Adrian Moreno <amorenoz@redhat.com> --- python/ovs/ovs_ofparse/openflow.py | 70 ++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)