Beispiel #1
0
def show_tables(args):
    config.get_models(args, {"odl_inventory_nodes"})
    of_nodes = config.gmodels.odl_inventory_nodes.get_clist_by_key()

    tableset = set()
    for node in of_nodes.values():
        for table in node[Nodes.NODE_TABLE]:
            if table.get('flow'):
                tableset.add(table['id'])
    result = ''
    for table in (sorted(tableset)):
        result = '{:3}:{} '.format(table, tables.get_table_name(table))
        print(result)
Beispiel #2
0
def show_tables(args):
    config.get_models(args, {"odl_inventory_nodes"})
    of_nodes = config.gmodels.odl_inventory_nodes.get_clist_by_key()

    tableset = set()
    for node in of_nodes.values():
        for table in node[Nodes.NODE_TABLE]:
            if table.get('flow'):
                tableset.add(table['id'])
    result = ''
    for table in (sorted(tableset)):
        result = '{:3}:{} '.format(table, tables.get_table_name(table))
        print(result)
Beispiel #3
0
    def re_table(self, match):
        """
        regex function to add the table name to table lines

        :param match: The regex match
        :return: The new line with table name
        :rtype: str
        """
        if match.group(Flows.GOTO) is not None:
            table_id = int(match.group(Flows.GOTO))
        elif match.group(Flows.RESUBMIT) is not None:
            table_id = int(match.group(Flows.RESUBMIT))
        else:
            table_id = 256

        rep = "{}({})".format(match.group(), tables.get_table_name(table_id))
        return rep
Beispiel #4
0
    def re_table(self, match):
        """
        regex function to add the table name to table lines

        :param match: The regex match
        :return: The new line with table name
        :rtype: str
        """
        if match.group(Flows.GOTO) is not None:
            table_id = int(match.group(Flows.GOTO))
        elif match.group(Flows.RESUBMIT) is not None:
            table_id = int(match.group(Flows.RESUBMIT))
        else:
            table_id = 256

        rep = "{}({})".format(match.group(), tables.get_table_name(table_id))
        return rep
Beispiel #5
0
    def format_data(self):
        if len(self.pdata) == 0:
            logger.warn("There is no data to process")
            return self.pdata
        header = "{:3} {:9} {:8} {:13}     {:6} {:12} {:1} {:3} {:5}\n" \
                 "    {}\n" \
                 "    {}\n" \
            .format("nnn", Flows.COOKIE, Flows.DURATION, Flows.TABLE, "n_pack", Flows.N_BYTES,
                    "S", "ito", "prio",
                    Flows.MATCHES,
                    Flows.ACTIONS)
        header_under = "--- --------- -------- -------------     ------ ------------ - --- -----\n"

        # Match goto_table: nnn or resubmit(,nnn) and return as goto or resubmit match group
        re_gt = re.compile(r"goto_table:(?P<goto>\d{1,3})|"
                           r"resubmit\(,(?P<resubmit>\d{1,3})\)")

        # Add the header as the first two lines of formatted data
        self.fdata = [header, header_under]

        # Format each line of parsed data
        for i, line in enumerate(self.pdata):
            logger.debug("format_data: processing line %d: %s",
                         self.start + i + 1, line)

            if Flows.ACTIONS in line:
                nactions = re_gt.sub(self.re_table, line[Flows.ACTIONS])
            else:
                logger.warn("Missing actions in %s", line)
                nactions = ""

            fline = "{:3} {:9} {:8} {:3} {:13} {:6} {:12} {:1} {:3} {:5}\n" \
                    "    matches={}\n" \
                    "    actions={}\n" \
                .format(i + 1, line[Flows.COOKIE], line[Flows.DURATION],
                        line[Flows.TABLE], tables.get_table_name(int(line[Flows.TABLE])),
                        line[Flows.N_PACKETS], line[Flows.N_BYTES],
                        line[Flows.SEND_FLOW_REMOVED][0], line[Flows.IDLE_TIMEOUT],
                        line[Flows.PRIORITY],
                        line[Flows.MATCHES],
                        nactions)
            self.fdata.append(fline)
            logger.debug("format_data: formatted line %d: %s",
                         self.start + i + 1, fline)
        return self.fdata
Beispiel #6
0
    def format_data(self):
        if len(self.pdata) == 0:
            logger.warn("There is no data to process")
            return self.pdata
        header = "{:3} {:9} {:8} {:13}     {:6} {:12} {:1} {:3} {:5}\n" \
                 "    {}\n" \
                 "    {}\n" \
            .format("nnn", Flows.COOKIE, Flows.DURATION, Flows.TABLE, "n_pack", Flows.N_BYTES,
                    "S", "ito", "prio",
                    Flows.MATCHES,
                    Flows.ACTIONS)
        header_under = "--- --------- -------- -------------     ------ ------------ - --- -----\n"

        # Match goto_table: nnn or resubmit(,nnn) and return as goto or resubmit match group
        re_gt = re.compile(r"goto_table:(?P<goto>\d{1,3})|"
                           r"resubmit\(,(?P<resubmit>\d{1,3})\)")

        # Add the header as the first two lines of formatted data
        self.fdata = [header, header_under]

        # Format each line of parsed data
        for i, line in enumerate(self.pdata):
            logger.debug("format_data: processing line %d: %s", self.start + i + 1, line)

            if Flows.ACTIONS in line:
                nactions = re_gt.sub(self.re_table, line[Flows.ACTIONS])
            else:
                logger.warn("Missing actions in %s", line)
                nactions = ""

            fline = "{:3} {:9} {:8} {:3} {:13} {:6} {:12} {:1} {:3} {:5}\n" \
                    "    matches={}\n" \
                    "    actions={}\n" \
                .format(i + 1, line[Flows.COOKIE], line[Flows.DURATION],
                        line[Flows.TABLE], tables.get_table_name(int(line[Flows.TABLE])),
                        line[Flows.N_PACKETS], line[Flows.N_BYTES],
                        line[Flows.SEND_FLOW_REMOVED][0], line[Flows.IDLE_TIMEOUT],
                        line[Flows.PRIORITY],
                        line[Flows.MATCHES],
                        nactions)
            self.fdata.append(fline)
            logger.debug("format_data: formatted line %d: %s", self.start + i + 1, fline)
        return self.fdata
Beispiel #7
0
    def format(self):
        # Match goto_table: nnn or resubmit(,nnn) and return as goto or resubmit match group
        re_gt = re.compile(r"goto_table:(?P<goto>\d{1,3})|"
                           r"resubmit\(,(?P<resubmit>\d{1,3})\)")

        line = self.pdata
        if Flow.ACTIONS in line:
            nactions = re_gt.sub(self.re_table, line[Flow.ACTIONS])
        else:
            logger.warn("Missing actions in %s", line)
            nactions = ""

        self.fdata = "{:15}  {:10}  {:3} {:20} {:6} {:12}  {:1} {:3}  {:5}  matches={}  actions={}\n" \
            .format(line[Flow.COOKIE], line[Flow.DURATION],
                    line[Flow.TABLE], tables.get_table_name(int(line[Flow.TABLE])),
                    line[Flow.N_PACKETS], line[Flow.N_BYTES],
                    line[Flow.SEND_FLOW_REMOVED][0], line[Flow.IDLE_TIMEOUT],
                    line[Flow.PRIORITY],
                    line[Flow.MATCH],
                    nactions)

        logger.debug("format: formatted line:\l%s", self.fdata)
Beispiel #8
0
 def test_get_table_name(self):
     self.assertEqual(tables.get_table_name(17), "DISPATCHER")
Beispiel #9
0
 def test_get_table_name(self):
     self.assertEqual(tables.get_table_name(17), "DISPATCHER")