LCOV - code coverage report
Current view: top level - lib - ofp-print.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1708 1930 88.5 %
Date: 2016-09-14 01:02:56 Functions: 129 131 98.5 %
Branches: 754 992 76.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at:
       7                 :            :  *
       8                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <config.h>
      18                 :            : 
      19                 :            : #include <errno.h>
      20                 :            : #include <inttypes.h>
      21                 :            : #include <sys/types.h>
      22                 :            : #include <netinet/in.h>
      23                 :            : #include <sys/wait.h>
      24                 :            : #include <stdarg.h>
      25                 :            : #include <stdlib.h>
      26                 :            : #include <ctype.h>
      27                 :            : 
      28                 :            : #include "bundle.h"
      29                 :            : #include "byte-order.h"
      30                 :            : #include "colors.h"
      31                 :            : #include "compiler.h"
      32                 :            : #include "dp-packet.h"
      33                 :            : #include "flow.h"
      34                 :            : #include "learn.h"
      35                 :            : #include "multipath.h"
      36                 :            : #include "netdev.h"
      37                 :            : #include "nx-match.h"
      38                 :            : #include "odp-util.h"
      39                 :            : #include "openflow/nicira-ext.h"
      40                 :            : #include "openflow/openflow.h"
      41                 :            : #include "openvswitch/dynamic-string.h"
      42                 :            : #include "openvswitch/meta-flow.h"
      43                 :            : #include "openvswitch/ofp-actions.h"
      44                 :            : #include "openvswitch/ofp-errors.h"
      45                 :            : #include "openvswitch/ofp-msgs.h"
      46                 :            : #include "openvswitch/ofp-print.h"
      47                 :            : #include "openvswitch/ofp-util.h"
      48                 :            : #include "openvswitch/ofpbuf.h"
      49                 :            : #include "openvswitch/type-props.h"
      50                 :            : #include "packets.h"
      51                 :            : #include "unaligned.h"
      52                 :            : #include "util.h"
      53                 :            : #include "uuid.h"
      54                 :            : 
      55                 :            : static void ofp_print_queue_name(struct ds *string, uint32_t port);
      56                 :            : static void ofp_print_error(struct ds *, enum ofperr);
      57                 :            : 
      58                 :            : /* Returns a string that represents the contents of the Ethernet frame in the
      59                 :            :  * 'len' bytes starting at 'data'.  The caller must free the returned string.*/
      60                 :            : char *
      61                 :       3737 : ofp_packet_to_string(const void *data, size_t len)
      62                 :            : {
      63                 :       3737 :     struct ds ds = DS_EMPTY_INITIALIZER;
      64                 :            :     struct dp_packet buf;
      65                 :            :     struct flow flow;
      66                 :            :     size_t l4_size;
      67                 :            : 
      68                 :       3737 :     dp_packet_use_const(&buf, data, len);
      69                 :       3737 :     flow_extract(&buf, &flow);
      70                 :       3737 :     flow_format(&ds, &flow);
      71                 :            : 
      72                 :       3737 :     l4_size = dp_packet_l4_size(&buf);
      73                 :            : 
      74 [ +  + ][ +  + ]:       3996 :     if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
      75                 :        259 :         struct tcp_header *th = dp_packet_l4(&buf);
      76                 :        259 :         ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum));
      77 [ +  + ][ +  - ]:       3872 :     } else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
      78                 :        394 :         struct udp_header *uh = dp_packet_l4(&buf);
      79                 :        394 :         ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum));
      80 [ +  + ][ +  - ]:       3102 :     } else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) {
      81                 :         18 :         struct sctp_header *sh = dp_packet_l4(&buf);
      82                 :         18 :         ds_put_format(&ds, " sctp_csum:%"PRIx32,
      83                 :         18 :                       ntohl(get_16aligned_be32(&sh->sctp_csum)));
      84 [ +  + ][ +  + ]:       3955 :     } else if (flow.nw_proto == IPPROTO_ICMP && l4_size >= ICMP_HEADER_LEN) {
      85                 :        889 :         struct icmp_header *icmph = dp_packet_l4(&buf);
      86                 :        889 :         ds_put_format(&ds, " icmp_csum:%"PRIx16,
      87                 :        889 :                       ntohs(icmph->icmp_csum));
      88 [ +  + ][ +  - ]:       2177 :     } else if (flow.nw_proto == IPPROTO_ICMPV6 && l4_size >= ICMP6_HEADER_LEN) {
      89                 :         22 :         struct icmp6_header *icmp6h = dp_packet_l4(&buf);
      90                 :         22 :         ds_put_format(&ds, " icmp6_csum:%"PRIx16,
      91                 :         22 :                       ntohs(icmp6h->icmp6_cksum));
      92                 :            :     }
      93                 :            : 
      94                 :       3737 :     ds_put_char(&ds, '\n');
      95                 :            : 
      96                 :       3737 :     return ds_cstr(&ds);
      97                 :            : }
      98                 :            : 
      99                 :            : static void
     100                 :        466 : format_hex_arg(struct ds *s, const uint8_t *data, size_t len)
     101                 :            : {
     102         [ +  + ]:      25713 :     for (size_t i = 0; i < len; i++) {
     103         [ +  + ]:      25247 :         if (i) {
     104                 :      24781 :             ds_put_char(s, '.');
     105                 :            :         }
     106                 :      25247 :         ds_put_format(s, "%02"PRIx8, data[i]);
     107                 :            :     }
     108                 :        466 : }
     109                 :            : 
     110                 :            : static void
     111                 :       1914 : ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
     112                 :            :                     int verbosity)
     113                 :            : {
     114                 :            :     char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
     115                 :            :     struct ofputil_packet_in_private pin;
     116                 :       1914 :     const struct ofputil_packet_in *public = &pin.public;
     117                 :            :     uint32_t buffer_id;
     118                 :            :     size_t total_len;
     119                 :            :     enum ofperr error;
     120                 :            : 
     121                 :       1914 :     error = ofputil_decode_packet_in_private(oh, true,
     122                 :            :                                              &pin, &total_len, &buffer_id);
     123         [ -  + ]:       1914 :     if (error) {
     124                 :          0 :         ofp_print_error(string, error);
     125                 :          0 :         return;
     126                 :            :     }
     127                 :            : 
     128         [ +  + ]:       1914 :     if (public->table_id) {
     129                 :        589 :         ds_put_format(string, " table_id=%"PRIu8, public->table_id);
     130                 :            :     }
     131                 :            : 
     132         [ +  + ]:       1914 :     if (public->cookie != OVS_BE64_MAX) {
     133                 :       1716 :         ds_put_format(string, " cookie=0x%"PRIx64, ntohll(public->cookie));
     134                 :            :     }
     135                 :            : 
     136                 :       1914 :     ds_put_format(string, " total_len=%"PRIuSIZE" ", total_len);
     137                 :            : 
     138                 :       1914 :     match_format(&public->flow_metadata, string, OFP_DEFAULT_PRIORITY);
     139                 :            : 
     140                 :       1914 :     ds_put_format(string, " (via %s)",
     141                 :            :                   ofputil_packet_in_reason_to_string(public->reason,
     142                 :            :                                                      reasonbuf,
     143                 :            :                                                      sizeof reasonbuf));
     144                 :            : 
     145                 :       1914 :     ds_put_format(string, " data_len=%"PRIuSIZE, public->packet_len);
     146         [ +  + ]:       1914 :     if (buffer_id == UINT32_MAX) {
     147                 :       1904 :         ds_put_format(string, " (unbuffered)");
     148         [ -  + ]:       1904 :         if (total_len != public->packet_len) {
     149                 :       1904 :             ds_put_format(string, " (***total_len != data_len***)");
     150                 :            :         }
     151                 :            :     } else {
     152                 :         10 :         ds_put_format(string, " buffer=0x%08"PRIx32, buffer_id);
     153         [ -  + ]:         10 :         if (total_len < public->packet_len) {
     154                 :          0 :             ds_put_format(string, " (***total_len < data_len***)");
     155                 :            :         }
     156                 :            :     }
     157                 :       1914 :     ds_put_char(string, '\n');
     158                 :            : 
     159         [ +  + ]:       1914 :     if (public->userdata_len) {
     160                 :        466 :         ds_put_cstr(string, " userdata=");
     161                 :        466 :         format_hex_arg(string, pin.public.userdata, pin.public.userdata_len);
     162                 :        466 :         ds_put_char(string, '\n');
     163                 :            :     }
     164                 :            : 
     165         [ +  + ]:       1914 :     if (!uuid_is_zero(&pin.bridge)) {
     166                 :        786 :         ds_put_format(string, " continuation.bridge="UUID_FMT"\n",
     167                 :       2358 :                       UUID_ARGS(&pin.bridge));
     168                 :            :     }
     169                 :            : 
     170         [ -  + ]:       1914 :     if (pin.n_stack) {
     171                 :          0 :         ds_put_cstr(string, " continuation.stack=");
     172         [ #  # ]:          0 :         for (size_t i = 0; i < pin.n_stack; i++) {
     173         [ #  # ]:          0 :             if (i) {
     174                 :          0 :                 ds_put_char(string, ' ');
     175                 :            :             }
     176                 :          0 :             mf_subvalue_format(&pin.stack[i], string);
     177                 :            :         }
     178                 :            :     }
     179                 :            : 
     180         [ +  + ]:       1914 :     if (pin.mirrors) {
     181                 :         36 :         ds_put_format(string, " continuation.mirrors=0x%"PRIx32"\n",
     182                 :            :                       pin.mirrors);
     183                 :            :     }
     184                 :            : 
     185         [ -  + ]:       1914 :     if (pin.conntracked) {
     186                 :          0 :         ds_put_cstr(string, " continuation.conntracked=true\n");
     187                 :            :     }
     188                 :            : 
     189         [ +  + ]:       1914 :     if (pin.actions_len) {
     190                 :        730 :         ds_put_cstr(string, " continuation.actions=");
     191                 :        730 :         ofpacts_format(pin.actions, pin.actions_len, string);
     192                 :        730 :         ds_put_char(string, '\n');
     193                 :            :     }
     194                 :            : 
     195         [ +  + ]:       1914 :     if (pin.action_set_len) {
     196                 :          8 :         ds_put_cstr(string, " continuation.action_set=");
     197                 :          8 :         ofpacts_format(pin.action_set, pin.action_set_len, string);
     198                 :          8 :         ds_put_char(string, '\n');
     199                 :            :     }
     200                 :            : 
     201         [ +  - ]:       1914 :     if (verbosity > 0) {
     202                 :       1914 :         char *packet = ofp_packet_to_string(public->packet,
     203                 :            :                                             public->packet_len);
     204                 :       1914 :         ds_put_cstr(string, packet);
     205                 :       1914 :         free(packet);
     206                 :            :     }
     207         [ +  + ]:       1914 :     if (verbosity > 2) {
     208                 :         43 :         ds_put_hex_dump(string, public->packet, public->packet_len, 0, false);
     209                 :            :     }
     210                 :            : 
     211                 :       1914 :     ofputil_packet_in_private_destroy(&pin);
     212                 :            : }
     213                 :            : 
     214                 :            : static void
     215                 :       1619 : ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
     216                 :            :                      int verbosity)
     217                 :            : {
     218                 :            :     struct ofputil_packet_out po;
     219                 :            :     struct ofpbuf ofpacts;
     220                 :            :     enum ofperr error;
     221                 :            : 
     222                 :       1619 :     ofpbuf_init(&ofpacts, 64);
     223                 :       1619 :     error = ofputil_decode_packet_out(&po, oh, &ofpacts);
     224         [ -  + ]:       1619 :     if (error) {
     225                 :          0 :         ofpbuf_uninit(&ofpacts);
     226                 :          0 :         ofp_print_error(string, error);
     227                 :          0 :         return;
     228                 :            :     }
     229                 :            : 
     230                 :       1619 :     ds_put_cstr(string, " in_port=");
     231                 :       1619 :     ofputil_format_port(po.in_port, string);
     232                 :            : 
     233                 :       1619 :     ds_put_cstr(string, " actions=");
     234                 :       1619 :     ofpacts_format(po.ofpacts, po.ofpacts_len, string);
     235                 :            : 
     236         [ +  + ]:       1619 :     if (po.buffer_id == UINT32_MAX) {
     237                 :       1617 :         ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
     238 [ +  - ][ +  - ]:       1617 :         if (verbosity > 0 && po.packet_len > 0) {
     239                 :       1617 :             char *packet = ofp_packet_to_string(po.packet, po.packet_len);
     240                 :       1617 :             ds_put_char(string, '\n');
     241                 :       1617 :             ds_put_cstr(string, packet);
     242                 :       1617 :             free(packet);
     243                 :            :         }
     244         [ +  + ]:       1617 :         if (verbosity > 2) {
     245                 :       1617 :             ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
     246                 :            :         }
     247                 :            :     } else {
     248                 :          2 :         ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
     249                 :            :     }
     250                 :            : 
     251                 :       1619 :     ofpbuf_uninit(&ofpacts);
     252                 :            : }
     253                 :            : 
     254                 :            : /* qsort comparison function. */
     255                 :            : static int
     256                 :        551 : compare_ports(const void *a_, const void *b_)
     257                 :            : {
     258                 :        551 :     const struct ofputil_phy_port *a = a_;
     259                 :        551 :     const struct ofputil_phy_port *b = b_;
     260                 :        551 :     uint16_t ap = ofp_to_u16(a->port_no);
     261                 :        551 :     uint16_t bp = ofp_to_u16(b->port_no);
     262                 :            : 
     263         [ +  + ]:        551 :     return ap < bp ? -1 : ap > bp;
     264                 :            : }
     265                 :            : 
     266                 :            : static void
     267                 :       6667 : ofp_print_bit_names(struct ds *string, uint32_t bits,
     268                 :            :                     const char *(*bit_to_name)(uint32_t bit),
     269                 :            :                     char separator)
     270                 :            : {
     271                 :       6667 :     int n = 0;
     272                 :            :     int i;
     273                 :            : 
     274         [ +  + ]:       6667 :     if (!bits) {
     275                 :       1265 :         ds_put_cstr(string, "0");
     276                 :       1265 :         return;
     277                 :            :     }
     278                 :            : 
     279         [ +  + ]:     178266 :     for (i = 0; i < 32; i++) {
     280                 :     172864 :         uint32_t bit = UINT32_C(1) << i;
     281                 :            : 
     282         [ +  + ]:     172864 :         if (bits & bit) {
     283                 :      13701 :             const char *name = bit_to_name(bit);
     284         [ +  - ]:      13701 :             if (name) {
     285         [ +  + ]:      13701 :                 if (n++) {
     286                 :       8299 :                     ds_put_char(string, separator);
     287                 :            :                 }
     288                 :      13701 :                 ds_put_cstr(string, name);
     289                 :      13701 :                 bits &= ~bit;
     290                 :            :             }
     291                 :            :         }
     292                 :            :     }
     293                 :            : 
     294         [ -  + ]:       5402 :     if (bits) {
     295         [ #  # ]:          0 :         if (n) {
     296                 :          0 :             ds_put_char(string, separator);
     297                 :            :         }
     298                 :          0 :         ds_put_format(string, "0x%"PRIx32, bits);
     299                 :            :     }
     300                 :            : }
     301                 :            : 
     302                 :            : static const char *
     303                 :        186 : netdev_feature_to_name(uint32_t bit)
     304                 :            : {
     305                 :        186 :     enum netdev_features f = bit;
     306                 :            : 
     307   [ +  +  +  +  :        186 :     switch (f) {
          -  -  +  -  -  
          -  -  +  -  +  
                -  -  - ]
     308                 :         22 :     case NETDEV_F_10MB_HD:    return "10MB-HD";
     309                 :         20 :     case NETDEV_F_10MB_FD:    return "10MB-FD";
     310                 :         20 :     case NETDEV_F_100MB_HD:   return "100MB-HD";
     311                 :         30 :     case NETDEV_F_100MB_FD:   return "100MB-FD";
     312                 :          0 :     case NETDEV_F_1GB_HD:     return "1GB-HD";
     313                 :          0 :     case NETDEV_F_1GB_FD:     return "1GB-FD";
     314                 :         22 :     case NETDEV_F_10GB_FD:    return "10GB-FD";
     315                 :          0 :     case NETDEV_F_40GB_FD:    return "40GB-FD";
     316                 :          0 :     case NETDEV_F_100GB_FD:   return "100GB-FD";
     317                 :          0 :     case NETDEV_F_1TB_FD:     return "1TB-FD";
     318                 :          0 :     case NETDEV_F_OTHER:      return "OTHER";
     319                 :         42 :     case NETDEV_F_COPPER:     return "COPPER";
     320                 :          0 :     case NETDEV_F_FIBER:      return "FIBER";
     321                 :         30 :     case NETDEV_F_AUTONEG:    return "AUTO_NEG";
     322                 :          0 :     case NETDEV_F_PAUSE:      return "AUTO_PAUSE";
     323                 :          0 :     case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
     324                 :            :     }
     325                 :            : 
     326                 :          0 :     return NULL;
     327                 :            : }
     328                 :            : 
     329                 :            : static void
     330                 :         54 : ofp_print_port_features(struct ds *string, enum netdev_features features)
     331                 :            : {
     332                 :         54 :     ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
     333                 :         54 :     ds_put_char(string, '\n');
     334                 :         54 : }
     335                 :            : 
     336                 :            : static const char *
     337                 :        549 : ofputil_port_config_to_name(uint32_t bit)
     338                 :            : {
     339                 :        549 :     enum ofputil_port_config pc = bit;
     340                 :            : 
     341   [ +  -  +  -  :        549 :     switch (pc) {
             +  +  +  - ]
     342                 :        418 :     case OFPUTIL_PC_PORT_DOWN:    return "PORT_DOWN";
     343                 :          0 :     case OFPUTIL_PC_NO_STP:       return "NO_STP";
     344                 :         63 :     case OFPUTIL_PC_NO_RECV:      return "NO_RECV";
     345                 :          0 :     case OFPUTIL_PC_NO_RECV_STP:  return "NO_RECV_STP";
     346                 :         11 :     case OFPUTIL_PC_NO_FLOOD:     return "NO_FLOOD";
     347                 :         30 :     case OFPUTIL_PC_NO_FWD:       return "NO_FWD";
     348                 :         27 :     case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
     349                 :            :     }
     350                 :            : 
     351                 :          0 :     return NULL;
     352                 :            : }
     353                 :            : 
     354                 :            : static void
     355                 :        983 : ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
     356                 :            : {
     357                 :        983 :     ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
     358                 :        983 :     ds_put_char(string, '\n');
     359                 :        983 : }
     360                 :            : 
     361                 :            : static const char *
     362                 :        400 : ofputil_port_state_to_name(uint32_t bit)
     363                 :            : {
     364                 :        400 :     enum ofputil_port_state ps = bit;
     365                 :            : 
     366   [ +  -  -  -  :        400 :     switch (ps) {
                      - ]
     367                 :        400 :     case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
     368                 :          0 :     case OFPUTIL_PS_BLOCKED:   return "BLOCKED";
     369                 :          0 :     case OFPUTIL_PS_LIVE:      return "LIVE";
     370                 :            : 
     371                 :            :     case OFPUTIL_PS_STP_LISTEN:
     372                 :            :     case OFPUTIL_PS_STP_LEARN:
     373                 :            :     case OFPUTIL_PS_STP_FORWARD:
     374                 :            :     case OFPUTIL_PS_STP_BLOCK:
     375                 :            :         /* Handled elsewhere. */
     376                 :          0 :         return NULL;
     377                 :            :     }
     378                 :            : 
     379                 :          0 :     return NULL;
     380                 :            : }
     381                 :            : 
     382                 :            : static void
     383                 :        893 : ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
     384                 :            : {
     385                 :            :     enum ofputil_port_state stp_state;
     386                 :            : 
     387                 :            :     /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
     388                 :            :      * pattern.  We have to special case it.
     389                 :            :      *
     390                 :            :      * OVS doesn't support STP, so this field will always be 0 if we are
     391                 :            :      * talking to OVS, so we'd always print STP_LISTEN in that case.
     392                 :            :      * Therefore, we don't print anything at all if the value is STP_LISTEN, to
     393                 :            :      * avoid confusing users. */
     394                 :        893 :     stp_state = state & OFPUTIL_PS_STP_MASK;
     395         [ -  + ]:        893 :     if (stp_state) {
     396         [ #  # ]:          0 :         ds_put_cstr(string,
     397                 :            :                     (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
     398         [ #  # ]:          0 :                      : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
     399                 :            :                      : "STP_BLOCK"));
     400                 :          0 :         state &= ~OFPUTIL_PS_STP_MASK;
     401         [ #  # ]:          0 :         if (state) {
     402                 :          0 :             ofp_print_bit_names(string, state, ofputil_port_state_to_name,
     403                 :            :                                 ' ');
     404                 :            :         }
     405                 :            :     } else {
     406                 :        893 :         ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
     407                 :            :     }
     408                 :        893 :     ds_put_char(string, '\n');
     409                 :        893 : }
     410                 :            : 
     411                 :            : static void
     412                 :        893 : ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
     413                 :            : {
     414                 :            :     char name[sizeof port->name];
     415                 :            :     int j;
     416                 :            : 
     417                 :        893 :     memcpy(name, port->name, sizeof name);
     418         [ +  + ]:       8890 :     for (j = 0; j < sizeof name - 1; j++) {
     419         [ +  + ]:       8572 :         if (!isprint((unsigned char) name[j])) {
     420                 :        575 :             break;
     421                 :            :         }
     422                 :            :     }
     423                 :        893 :     name[j] = '\0';
     424                 :            : 
     425                 :        893 :     ds_put_char(string, ' ');
     426                 :        893 :     ofputil_format_port(port->port_no, string);
     427                 :        893 :     ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
     428                 :       5358 :                   name, ETH_ADDR_ARGS(port->hw_addr));
     429                 :            : 
     430                 :        893 :     ds_put_cstr(string, "     config:     ");
     431                 :        893 :     ofp_print_port_config(string, port->config);
     432                 :            : 
     433                 :        893 :     ds_put_cstr(string, "     state:      ");
     434                 :        893 :     ofp_print_port_state(string, port->state);
     435                 :            : 
     436         [ +  + ]:        893 :     if (port->curr) {
     437                 :         32 :         ds_put_format(string, "     current:    ");
     438                 :         32 :         ofp_print_port_features(string, port->curr);
     439                 :            :     }
     440         [ +  + ]:        893 :     if (port->advertised) {
     441                 :         10 :         ds_put_format(string, "     advertised: ");
     442                 :         10 :         ofp_print_port_features(string, port->advertised);
     443                 :            :     }
     444         [ +  + ]:        893 :     if (port->supported) {
     445                 :         10 :         ds_put_format(string, "     supported:  ");
     446                 :         10 :         ofp_print_port_features(string, port->supported);
     447                 :            :     }
     448         [ -  + ]:        893 :     if (port->peer) {
     449                 :          0 :         ds_put_format(string, "     peer:       ");
     450                 :          0 :         ofp_print_port_features(string, port->peer);
     451                 :            :     }
     452                 :        893 :     ds_put_format(string, "     speed: %"PRIu32" Mbps now, "
     453                 :            :                   "%"PRIu32" Mbps max\n",
     454                 :        893 :                   port->curr_speed / UINT32_C(1000),
     455                 :        893 :                   port->max_speed / UINT32_C(1000));
     456                 :        893 : }
     457                 :            : 
     458                 :            : /* Given a buffer 'b' that contains an array of OpenFlow ports of type
     459                 :            :  * 'ofp_version', writes a detailed description of each port into
     460                 :            :  * 'string'. */
     461                 :            : static void
     462                 :        145 : ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
     463                 :            :                     struct ofpbuf *b)
     464                 :            : {
     465                 :            :     struct ofputil_phy_port *ports;
     466                 :            :     size_t allocated_ports, n_ports;
     467                 :            :     int retval;
     468                 :            :     size_t i;
     469                 :            : 
     470                 :        145 :     ports = NULL;
     471                 :        145 :     allocated_ports = 0;
     472                 :        145 :     for (n_ports = 0; ; n_ports++) {
     473         [ +  + ]:        533 :         if (n_ports >= allocated_ports) {
     474                 :        385 :             ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
     475                 :            :         }
     476                 :            : 
     477                 :        533 :         retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
     478         [ +  + ]:        533 :         if (retval) {
     479                 :        145 :             break;
     480                 :            :         }
     481                 :        388 :     }
     482                 :            : 
     483                 :        145 :     qsort(ports, n_ports, sizeof *ports, compare_ports);
     484         [ +  + ]:        533 :     for (i = 0; i < n_ports; i++) {
     485                 :        388 :         ofp_print_phy_port(string, &ports[i]);
     486                 :            :     }
     487                 :        145 :     free(ports);
     488                 :            : 
     489         [ -  + ]:        145 :     if (retval != EOF) {
     490                 :          0 :         ofp_print_error(string, retval);
     491                 :            :     }
     492                 :        145 : }
     493                 :            : 
     494                 :            : static const char *
     495                 :        601 : ofputil_capabilities_to_name(uint32_t bit)
     496                 :            : {
     497                 :        601 :     enum ofputil_capabilities capabilities = bit;
     498                 :            : 
     499   [ +  +  +  +  :        601 :     switch (capabilities) {
          +  +  -  +  +  
                      - ]
     500                 :        120 :     case OFPUTIL_C_FLOW_STATS:   return "FLOW_STATS";
     501                 :        120 :     case OFPUTIL_C_TABLE_STATS:  return "TABLE_STATS";
     502                 :        120 :     case OFPUTIL_C_PORT_STATS:   return "PORT_STATS";
     503                 :          3 :     case OFPUTIL_C_IP_REASM:     return "IP_REASM";
     504                 :        118 :     case OFPUTIL_C_QUEUE_STATS:  return "QUEUE_STATS";
     505                 :         60 :     case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
     506                 :          0 :     case OFPUTIL_C_STP:          return "STP";
     507                 :         57 :     case OFPUTIL_C_GROUP_STATS:  return "GROUP_STATS";
     508                 :          3 :     case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
     509                 :            :     }
     510                 :            : 
     511                 :          0 :     return NULL;
     512                 :            : }
     513                 :            : 
     514                 :            : static void
     515                 :        120 : ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
     516                 :            : {
     517                 :            :     struct ofputil_switch_features features;
     518                 :        120 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
     519                 :        120 :     enum ofperr error = ofputil_pull_switch_features(&b, &features);
     520         [ -  + ]:        120 :     if (error) {
     521                 :          0 :         ofp_print_error(string, error);
     522                 :         32 :         return;
     523                 :            :     }
     524                 :            : 
     525                 :        120 :     ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
     526                 :            : 
     527                 :        120 :     ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
     528                 :        120 :                   features.n_tables, features.n_buffers);
     529         [ +  + ]:        120 :     if (features.auxiliary_id) {
     530                 :          1 :         ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
     531                 :            :     }
     532                 :        120 :     ds_put_char(string, '\n');
     533                 :            : 
     534                 :        120 :     ds_put_cstr(string, "capabilities: ");
     535                 :        120 :     ofp_print_bit_names(string, features.capabilities,
     536                 :            :                         ofputil_capabilities_to_name, ' ');
     537                 :        120 :     ds_put_char(string, '\n');
     538                 :            : 
     539   [ +  +  +  - ]:        120 :     switch ((enum ofp_version)oh->version) {
     540                 :            :     case OFP10_VERSION:
     541                 :         59 :         ds_put_cstr(string, "actions: ");
     542                 :         59 :         ofpact_bitmap_format(features.ofpacts, string);
     543                 :         59 :         ds_put_char(string, '\n');
     544                 :         59 :         break;
     545                 :            :     case OFP11_VERSION:
     546                 :            :     case OFP12_VERSION:
     547                 :         29 :         break;
     548                 :            :     case OFP13_VERSION:
     549                 :            :     case OFP14_VERSION:
     550                 :            :     case OFP15_VERSION:
     551                 :            :     case OFP16_VERSION:
     552                 :         32 :         return; /* no ports in ofp13_switch_features */
     553                 :            :     default:
     554                 :          0 :         OVS_NOT_REACHED();
     555                 :            :     }
     556                 :            : 
     557                 :         88 :     ofp_print_phy_ports(string, oh->version, &b);
     558                 :            : }
     559                 :            : 
     560                 :            : static void
     561                 :        509 : ofp_print_switch_config(struct ds *string,
     562                 :            :                         const struct ofputil_switch_config *config)
     563                 :            : {
     564                 :        509 :     ds_put_format(string, " frags=%s",
     565                 :            :                   ofputil_frag_handling_to_string(config->frag));
     566                 :            : 
     567         [ +  + ]:        509 :     if (config->invalid_ttl_to_controller > 0) {
     568                 :         40 :         ds_put_format(string, " invalid_ttl_to_controller");
     569                 :            :     }
     570                 :            : 
     571                 :        509 :     ds_put_format(string, " miss_send_len=%"PRIu16"\n", config->miss_send_len);
     572                 :        509 : }
     573                 :            : 
     574                 :            : static void
     575                 :        210 : ofp_print_set_config(struct ds *string, const struct ofp_header *oh)
     576                 :            : {
     577                 :            :     struct ofputil_switch_config config;
     578                 :            :     enum ofperr error;
     579                 :            : 
     580                 :        210 :     error = ofputil_decode_set_config(oh, &config);
     581         [ -  + ]:        210 :     if (error) {
     582                 :          0 :         ofp_print_error(string, error);
     583                 :          0 :         return;
     584                 :            :     }
     585                 :        210 :     ofp_print_switch_config(string, &config);
     586                 :            : }
     587                 :            : 
     588                 :            : static void
     589                 :        299 : ofp_print_get_config_reply(struct ds *string, const struct ofp_header *oh)
     590                 :            : {
     591                 :            :     struct ofputil_switch_config config;
     592                 :        299 :     ofputil_decode_get_config_reply(oh, &config);
     593                 :        299 :     ofp_print_switch_config(string, &config);
     594                 :        299 : }
     595                 :            : 
     596                 :            : static void print_wild(struct ds *string, const char *leader, int is_wild,
     597                 :            :             int verbosity, const char *format, ...)
     598                 :            :             OVS_PRINTF_FORMAT(5, 6);
     599                 :            : 
     600                 :          8 : static void print_wild(struct ds *string, const char *leader, int is_wild,
     601                 :            :                        int verbosity, const char *format, ...)
     602                 :            : {
     603 [ -  + ][ #  # ]:          8 :     if (is_wild && verbosity < 2) {
     604                 :          0 :         return;
     605                 :            :     }
     606                 :          8 :     ds_put_cstr(string, leader);
     607         [ +  - ]:          8 :     if (!is_wild) {
     608                 :            :         va_list args;
     609                 :            : 
     610                 :          8 :         va_start(args, format);
     611                 :          8 :         ds_put_format_valist(string, format, args);
     612                 :          8 :         va_end(args);
     613                 :            :     } else {
     614                 :          0 :         ds_put_char(string, '*');
     615                 :            :     }
     616                 :          8 :     ds_put_char(string, ',');
     617                 :            : }
     618                 :            : 
     619                 :            : static void
     620                 :          1 : print_wild_port(struct ds *string, const char *leader, int is_wild,
     621                 :            :                 int verbosity, ofp_port_t port)
     622                 :            : {
     623 [ -  + ][ #  # ]:          1 :     if (is_wild && verbosity < 2) {
     624                 :          0 :         return;
     625                 :            :     }
     626                 :          1 :     ds_put_cstr(string, leader);
     627         [ +  - ]:          1 :     if (!is_wild) {
     628                 :          1 :         ofputil_format_port(port, string);
     629                 :            :     } else {
     630                 :          0 :         ds_put_char(string, '*');
     631                 :            :     }
     632                 :          1 :     ds_put_char(string, ',');
     633                 :            : }
     634                 :            : 
     635                 :            : static void
     636                 :          2 : print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
     637                 :            :                  uint32_t wild_bits, int verbosity)
     638                 :            : {
     639 [ -  + ][ #  # ]:          2 :     if (wild_bits >= 32 && verbosity < 2) {
     640                 :          0 :         return;
     641                 :            :     }
     642                 :          2 :     ds_put_cstr(string, leader);
     643         [ +  - ]:          2 :     if (wild_bits < 32) {
     644                 :          2 :         ds_put_format(string, IP_FMT, IP_ARGS(ip));
     645         [ -  + ]:          2 :         if (wild_bits) {
     646                 :          2 :             ds_put_format(string, "/%d", 32 - wild_bits);
     647                 :            :         }
     648                 :            :     } else {
     649                 :          0 :         ds_put_char(string, '*');
     650                 :            :     }
     651                 :          2 :     ds_put_char(string, ',');
     652                 :            : }
     653                 :            : 
     654                 :            : void
     655                 :          1 : ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
     656                 :            : {
     657                 :          1 :     char *s = ofp10_match_to_string(om, verbosity);
     658                 :          1 :     ds_put_cstr(f, s);
     659                 :          1 :     free(s);
     660                 :          1 : }
     661                 :            : 
     662                 :            : char *
     663                 :          1 : ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
     664                 :            : {
     665                 :          1 :     struct ds f = DS_EMPTY_INITIALIZER;
     666                 :          1 :     uint32_t w = ntohl(om->wildcards);
     667                 :          1 :     bool skip_type = false;
     668                 :          1 :     bool skip_proto = false;
     669                 :            : 
     670         [ +  - ]:          1 :     if (!(w & OFPFW10_DL_TYPE)) {
     671                 :          1 :         skip_type = true;
     672         [ -  + ]:          1 :         if (om->dl_type == htons(ETH_TYPE_IP)) {
     673         [ #  # ]:          0 :             if (!(w & OFPFW10_NW_PROTO)) {
     674                 :          0 :                 skip_proto = true;
     675         [ #  # ]:          0 :                 if (om->nw_proto == IPPROTO_ICMP) {
     676                 :          0 :                     ds_put_cstr(&f, "icmp,");
     677         [ #  # ]:          0 :                 } else if (om->nw_proto == IPPROTO_TCP) {
     678                 :          0 :                     ds_put_cstr(&f, "tcp,");
     679         [ #  # ]:          0 :                 } else if (om->nw_proto == IPPROTO_UDP) {
     680                 :          0 :                     ds_put_cstr(&f, "udp,");
     681         [ #  # ]:          0 :                 } else if (om->nw_proto == IPPROTO_SCTP) {
     682                 :          0 :                     ds_put_cstr(&f, "sctp,");
     683                 :            :                 } else {
     684                 :          0 :                     ds_put_cstr(&f, "ip,");
     685                 :          0 :                     skip_proto = false;
     686                 :            :                 }
     687                 :            :             } else {
     688                 :          0 :                 ds_put_cstr(&f, "ip,");
     689                 :            :             }
     690         [ +  - ]:          1 :         } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
     691                 :          1 :             ds_put_cstr(&f, "arp,");
     692         [ #  # ]:          0 :         } else if (om->dl_type == htons(ETH_TYPE_RARP)){
     693                 :          0 :             ds_put_cstr(&f, "rarp,");
     694         [ #  # ]:          0 :         } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
     695                 :          0 :             ds_put_cstr(&f, "mpls,");
     696         [ #  # ]:          0 :         } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
     697                 :          0 :             ds_put_cstr(&f, "mplsm,");
     698                 :            :         } else {
     699                 :          0 :             skip_type = false;
     700                 :            :         }
     701                 :            :     }
     702                 :          1 :     print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
     703                 :          1 :                     u16_to_ofp(ntohs(om->in_port)));
     704                 :          1 :     print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
     705                 :          1 :                "%d", ntohs(om->dl_vlan));
     706                 :          1 :     print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
     707                 :          1 :                "%d", om->dl_vlan_pcp);
     708                 :          1 :     print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
     709                 :          6 :                ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
     710                 :          1 :     print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
     711                 :          6 :                ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
     712         [ -  + ]:          1 :     if (!skip_type) {
     713                 :          0 :         print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
     714                 :          0 :                    "0x%04x", ntohs(om->dl_type));
     715                 :            :     }
     716                 :          1 :     print_ip_netmask(&f, "nw_src=", om->nw_src,
     717                 :          1 :                      (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
     718                 :            :                      verbosity);
     719                 :          1 :     print_ip_netmask(&f, "nw_dst=", om->nw_dst,
     720                 :          1 :                      (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
     721                 :            :                      verbosity);
     722         [ +  - ]:          1 :     if (!skip_proto) {
     723   [ -  +  #  # ]:          1 :         if (om->dl_type == htons(ETH_TYPE_ARP) ||
     724                 :          0 :             om->dl_type == htons(ETH_TYPE_RARP)) {
     725                 :          1 :             print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
     726                 :          1 :                        "%u", om->nw_proto);
     727                 :            :         } else {
     728                 :          0 :             print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
     729                 :          0 :                        "%u", om->nw_proto);
     730                 :            :         }
     731                 :            :     }
     732                 :          1 :     print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
     733                 :          1 :                "%u", om->nw_tos);
     734         [ -  + ]:          1 :     if (om->nw_proto == IPPROTO_ICMP) {
     735                 :          0 :         print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
     736                 :          0 :                    "%d", ntohs(om->tp_src));
     737                 :          0 :         print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
     738                 :          0 :                    "%d", ntohs(om->tp_dst));
     739                 :            :     } else {
     740                 :          1 :         print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
     741                 :          1 :                    "%d", ntohs(om->tp_src));
     742                 :          1 :         print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
     743                 :          1 :                    "%d", ntohs(om->tp_dst));
     744                 :            :     }
     745                 :          1 :     ds_chomp(&f, ',');
     746                 :          1 :     return ds_cstr(&f);
     747                 :            : }
     748                 :            : 
     749                 :            : static void
     750                 :      33749 : ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
     751                 :            : {
     752         [ +  + ]:      33749 :     if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
     753                 :         41 :         ds_put_cstr(s, "send_flow_rem ");
     754                 :            :     }
     755         [ +  + ]:      33749 :     if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
     756                 :         10 :         ds_put_cstr(s, "check_overlap ");
     757                 :            :     }
     758         [ +  + ]:      33749 :     if (flags & OFPUTIL_FF_RESET_COUNTS) {
     759                 :         11 :         ds_put_cstr(s, "reset_counts ");
     760                 :            :     }
     761         [ +  + ]:      33749 :     if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
     762                 :          1 :         ds_put_cstr(s, "no_packet_counts ");
     763                 :            :     }
     764         [ +  + ]:      33749 :     if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
     765                 :          1 :         ds_put_cstr(s, "no_byte_counts ");
     766                 :            :     }
     767         [ -  + ]:      33749 :     if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
     768                 :          0 :         ds_put_cstr(s, "allow_hidden_fields ");
     769                 :            :     }
     770         [ -  + ]:      33749 :     if (flags & OFPUTIL_FF_NO_READONLY) {
     771                 :          0 :         ds_put_cstr(s, "no_readonly_table ");
     772                 :            :     }
     773                 :      33749 : }
     774                 :            : 
     775                 :            : static void
     776                 :      33739 : ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
     777                 :            : {
     778                 :            :     struct ofputil_flow_mod fm;
     779                 :            :     struct ofpbuf ofpacts;
     780                 :            :     bool need_priority;
     781                 :            :     enum ofperr error;
     782                 :            :     enum ofpraw raw;
     783                 :            :     enum ofputil_protocol protocol;
     784                 :            : 
     785                 :      33739 :     protocol = ofputil_protocol_from_ofp_version(oh->version);
     786                 :      33739 :     protocol = ofputil_protocol_set_tid(protocol, true);
     787                 :            : 
     788                 :      33739 :     ofpbuf_init(&ofpacts, 64);
     789                 :      33739 :     error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
     790                 :            :                                     OFPP_MAX, 255);
     791         [ -  + ]:      33739 :     if (error) {
     792                 :          0 :         ofpbuf_uninit(&ofpacts);
     793                 :          0 :         ofp_print_error(s, error);
     794                 :          0 :         return;
     795                 :            :     }
     796                 :            : 
     797                 :      33739 :     ds_put_char(s, ' ');
     798   [ +  +  +  +  :      33739 :     switch (fm.command) {
                   +  - ]
     799                 :            :     case OFPFC_ADD:
     800                 :      26952 :         ds_put_cstr(s, "ADD");
     801                 :      26952 :         break;
     802                 :            :     case OFPFC_MODIFY:
     803                 :         40 :         ds_put_cstr(s, "MOD");
     804                 :         40 :         break;
     805                 :            :     case OFPFC_MODIFY_STRICT:
     806                 :        340 :         ds_put_cstr(s, "MOD_STRICT");
     807                 :        340 :         break;
     808                 :            :     case OFPFC_DELETE:
     809                 :        732 :         ds_put_cstr(s, "DEL");
     810                 :        732 :         break;
     811                 :            :     case OFPFC_DELETE_STRICT:
     812                 :       5675 :         ds_put_cstr(s, "DEL_STRICT");
     813                 :       5675 :         break;
     814                 :            :     default:
     815                 :          0 :         ds_put_format(s, "cmd:%d", fm.command);
     816                 :            :     }
     817         [ +  + ]:      33739 :     if (fm.table_id != 0) {
     818                 :      21528 :         ds_put_format(s, " table:%d", fm.table_id);
     819                 :            :     }
     820                 :            : 
     821                 :      33739 :     ds_put_char(s, ' ');
     822                 :      33739 :     ofpraw_decode(&raw, oh);
     823 [ +  + ][ +  + ]:      33740 :     if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
     824                 :          1 :         const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
     825                 :          1 :         ofp10_match_print(s, &ofm->match, verbosity);
     826                 :            : 
     827                 :            :         /* ofp_print_match() doesn't print priority. */
     828                 :          1 :         need_priority = true;
     829 [ +  + ][ +  - ]:      33771 :     } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
     830                 :         33 :         const struct nx_flow_mod *nfm = ofpmsg_body(oh);
     831                 :         33 :         const void *nxm = nfm + 1;
     832                 :            :         char *nxm_s;
     833                 :            : 
     834                 :         33 :         nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
     835                 :         33 :         ds_put_cstr(s, nxm_s);
     836                 :         33 :         free(nxm_s);
     837                 :            : 
     838                 :            :         /* nx_match_to_string() doesn't print priority. */
     839                 :         33 :         need_priority = true;
     840                 :            :     } else {
     841                 :      33705 :         match_format(&fm.match, s, fm.priority);
     842                 :            : 
     843                 :            :         /* match_format() does print priority. */
     844                 :      33705 :         need_priority = false;
     845                 :            :     }
     846                 :            : 
     847         [ +  + ]:      33739 :     if (ds_last(s) != ' ') {
     848                 :      33113 :         ds_put_char(s, ' ');
     849                 :            :     }
     850 [ +  + ][ +  + ]:      33739 :     if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
     851                 :       7299 :         ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
     852                 :            :     }
     853         [ +  + ]:      33739 :     if (fm.cookie_mask != htonll(0)) {
     854                 :         11 :         ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
     855                 :            :                 ntohll(fm.cookie), ntohll(fm.cookie_mask));
     856                 :            :     }
     857         [ +  + ]:      33739 :     if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
     858                 :         80 :         ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
     859                 :            :     }
     860         [ +  + ]:      33739 :     if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
     861                 :         21 :         ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
     862                 :            :     }
     863         [ +  + ]:      33739 :     if (fm.importance != 0) {
     864                 :         33 :         ds_put_format(s, "importance:%"PRIu16" ", fm.importance);
     865                 :            :     }
     866 [ +  + ][ +  + ]:      33739 :     if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
     867                 :          2 :         ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
     868                 :            :     }
     869         [ +  + ]:      33739 :     if (fm.buffer_id != UINT32_MAX) {
     870                 :          2 :         ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
     871                 :            :     }
     872         [ +  + ]:      33739 :     if (fm.out_port != OFPP_ANY) {
     873                 :         10 :         ds_put_format(s, "out_port:");
     874                 :         10 :         ofputil_format_port(fm.out_port, s);
     875                 :         10 :         ds_put_char(s, ' ');
     876                 :            :     }
     877                 :            : 
     878 [ +  + ][ +  + ]:      33739 :     if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
     879                 :            :         /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
     880                 :            :          * versions don't really have such a flag and printing one is likely to
     881                 :            :          * confuse people. */
     882                 :      11039 :         fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
     883                 :            :     }
     884                 :      33739 :     ofp_print_flow_flags(s, fm.flags);
     885                 :            : 
     886                 :      33739 :     ds_put_cstr(s, "actions=");
     887                 :      33739 :     ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
     888                 :      33739 :     ofpbuf_uninit(&ofpacts);
     889                 :            : }
     890                 :            : 
     891                 :            : static void
     892                 :      28267 : ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
     893                 :            : {
     894                 :      28267 :     ds_put_format(string, "%u", sec);
     895                 :            : 
     896                 :            :     /* If there are no fractional seconds, don't print any decimals.
     897                 :            :      *
     898                 :            :      * If the fractional seconds can be expressed exactly as milliseconds,
     899                 :            :      * print 3 decimals.  Open vSwitch provides millisecond precision for most
     900                 :            :      * time measurements, so printing 3 decimals every time makes it easier to
     901                 :            :      * spot real changes in flow dumps that refresh themselves quickly.
     902                 :            :      *
     903                 :            :      * If the fractional seconds are more precise than milliseconds, print the
     904                 :            :      * number of decimals needed to express them exactly.
     905                 :            :      */
     906         [ +  + ]:      28267 :     if (nsec > 0) {
     907                 :      28104 :         unsigned int msec = nsec / 1000000;
     908         [ +  + ]:      28104 :         if (msec * 1000000 == nsec) {
     909                 :      28101 :             ds_put_format(string, ".%03u", msec);
     910                 :            :         } else {
     911                 :          3 :             ds_put_format(string, ".%09u", nsec);
     912         [ +  + ]:          8 :             while (string->string[string->length - 1] == '0') {
     913                 :          5 :                 string->length--;
     914                 :            :             }
     915                 :            :         }
     916                 :            :     }
     917                 :      28267 :     ds_put_char(string, 's');
     918                 :      28267 : }
     919                 :            : 
     920                 :            : /* Returns a string form of 'reason'.  The return value is either a statically
     921                 :            :  * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
     922                 :            :  * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
     923                 :            : #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
     924                 :            : static const char *
     925                 :       5370 : ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
     926                 :            :                                   char *reasonbuf, size_t bufsize)
     927                 :            : {
     928   [ +  +  +  +  :       5370 :     switch (reason) {
                +  +  - ]
     929                 :            :     case OFPRR_IDLE_TIMEOUT:
     930                 :         17 :         return "idle";
     931                 :            :     case OFPRR_HARD_TIMEOUT:
     932                 :         16 :         return "hard";
     933                 :            :     case OFPRR_DELETE:
     934                 :       5316 :         return "delete";
     935                 :            :     case OFPRR_GROUP_DELETE:
     936                 :         13 :         return "group_delete";
     937                 :            :     case OFPRR_EVICTION:
     938                 :          1 :         return "eviction";
     939                 :            :     case OFPRR_METER_DELETE:
     940                 :          7 :         return "meter_delete";
     941                 :            :     case OVS_OFPRR_NONE:
     942                 :            :     default:
     943                 :          0 :         snprintf(reasonbuf, bufsize, "%d", (int) reason);
     944                 :          0 :         return reasonbuf;
     945                 :            :     }
     946                 :            : }
     947                 :            : 
     948                 :            : static void
     949                 :         40 : ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
     950                 :            : {
     951                 :            :     char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
     952                 :            :     struct ofputil_flow_removed fr;
     953                 :            :     enum ofperr error;
     954                 :            : 
     955                 :         40 :     error = ofputil_decode_flow_removed(&fr, oh);
     956         [ -  + ]:         40 :     if (error) {
     957                 :          0 :         ofp_print_error(string, error);
     958                 :          0 :         return;
     959                 :            :     }
     960                 :            : 
     961                 :         40 :     ds_put_char(string, ' ');
     962                 :         40 :     match_format(&fr.match, string, fr.priority);
     963                 :            : 
     964                 :         40 :     ds_put_format(string, " reason=%s",
     965                 :         40 :                   ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
     966                 :            :                                                     sizeof reasonbuf));
     967                 :            : 
     968         [ +  + ]:         40 :     if (fr.table_id != 255) {
     969                 :         31 :         ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
     970                 :            :     }
     971                 :            : 
     972         [ +  + ]:         40 :     if (fr.cookie != htonll(0)) {
     973                 :          2 :         ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
     974                 :            :     }
     975                 :         40 :     ds_put_cstr(string, " duration");
     976                 :         40 :     ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
     977                 :         40 :     ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
     978         [ +  + ]:         40 :     if (fr.hard_timeout) {
     979                 :            :         /* The hard timeout was only added in OF1.2, so only print it if it is
     980                 :            :          * actually in use to avoid gratuitous change to the formatting. */
     981                 :          2 :         ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
     982                 :            :     }
     983                 :         40 :     ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
     984                 :            :                   fr.packet_count, fr.byte_count);
     985                 :            : }
     986                 :            : 
     987                 :            : static void
     988                 :         45 : ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
     989                 :            : {
     990                 :            :     struct ofputil_port_mod pm;
     991                 :            :     enum ofperr error;
     992                 :            : 
     993                 :         45 :     error = ofputil_decode_port_mod(oh, &pm, true);
     994         [ -  + ]:         45 :     if (error) {
     995                 :          0 :         ofp_print_error(string, error);
     996                 :          0 :         return;
     997                 :            :     }
     998                 :            : 
     999                 :         45 :     ds_put_cstr(string, " port: ");
    1000                 :         45 :     ofputil_format_port(pm.port_no, string);
    1001                 :         45 :     ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
    1002                 :        270 :                   ETH_ADDR_ARGS(pm.hw_addr));
    1003                 :            : 
    1004                 :         45 :     ds_put_cstr(string, "     config: ");
    1005                 :         45 :     ofp_print_port_config(string, pm.config);
    1006                 :            : 
    1007                 :         45 :     ds_put_cstr(string, "     mask:   ");
    1008                 :         45 :     ofp_print_port_config(string, pm.mask);
    1009                 :            : 
    1010                 :         45 :     ds_put_cstr(string, "     advertise: ");
    1011         [ +  + ]:         45 :     if (pm.advertise) {
    1012                 :          2 :         ofp_print_port_features(string, pm.advertise);
    1013                 :            :     } else {
    1014                 :         45 :         ds_put_cstr(string, "UNCHANGED\n");
    1015                 :            :     }
    1016                 :            : }
    1017                 :            : 
    1018                 :            : static const char *
    1019                 :         22 : ofputil_table_miss_to_string(enum ofputil_table_miss miss)
    1020                 :            : {
    1021   [ -  +  +  +  :         22 :     switch (miss) {
                      - ]
    1022                 :          0 :     case OFPUTIL_TABLE_MISS_DEFAULT: return "default";
    1023                 :         13 :     case OFPUTIL_TABLE_MISS_CONTROLLER: return "controller";
    1024                 :          5 :     case OFPUTIL_TABLE_MISS_CONTINUE: return "continue";
    1025                 :          4 :     case OFPUTIL_TABLE_MISS_DROP: return "drop";
    1026                 :          0 :     default: return "***error***";
    1027                 :            :     }
    1028                 :            : }
    1029                 :            : 
    1030                 :            : static const char *
    1031                 :       3316 : ofputil_table_eviction_to_string(enum ofputil_table_eviction eviction)
    1032                 :            : {
    1033   [ -  +  +  + ]:       3316 :     switch (eviction) {
    1034                 :          0 :     case OFPUTIL_TABLE_EVICTION_DEFAULT: return "default";
    1035                 :          8 :     case OFPUTIL_TABLE_EVICTION_ON: return "on";
    1036                 :       3304 :     case OFPUTIL_TABLE_EVICTION_OFF: return "off";
    1037                 :          4 :     default: return "***error***";
    1038                 :            :     }
    1039                 :            : 
    1040                 :            : }
    1041                 :            : 
    1042                 :            : static const char *
    1043                 :       9924 : ofputil_eviction_flag_to_string(uint32_t bit)
    1044                 :            : {
    1045                 :       9924 :     enum ofp14_table_mod_prop_eviction_flag eviction_flag = bit;
    1046                 :            : 
    1047   [ +  +  +  - ]:       9924 :     switch (eviction_flag) {
    1048                 :       3308 :     case OFPTMPEF14_OTHER:      return "OTHER";
    1049                 :       3308 :     case OFPTMPEF14_IMPORTANCE: return "IMPORTANCE";
    1050                 :       3308 :     case OFPTMPEF14_LIFETIME:   return "LIFETIME";
    1051                 :            :     }
    1052                 :            : 
    1053                 :          0 :     return NULL;
    1054                 :            : }
    1055                 :            : 
    1056                 :            : /* Appends to 'string' a description of the bitmap of OFPTMPEF14_* values in
    1057                 :            :  * 'eviction_flags'. */
    1058                 :            : static void
    1059                 :       3308 : ofputil_put_eviction_flags(struct ds *string, uint32_t eviction_flags)
    1060                 :            : {
    1061         [ +  - ]:       3308 :     if (eviction_flags != UINT32_MAX) {
    1062                 :       3308 :         ofp_print_bit_names(string, eviction_flags,
    1063                 :            :                             ofputil_eviction_flag_to_string, '|');
    1064                 :            :     } else {
    1065                 :          0 :         ds_put_cstr(string, "(default)");
    1066                 :            :     }
    1067                 :       3308 : }
    1068                 :            : 
    1069                 :            : static const char *
    1070                 :       3316 : ofputil_table_vacancy_to_string(enum ofputil_table_vacancy vacancy)
    1071                 :            : {
    1072   [ -  +  +  - ]:       3316 :     switch (vacancy) {
    1073                 :          0 :     case OFPUTIL_TABLE_VACANCY_DEFAULT: return "default";
    1074                 :         12 :     case OFPUTIL_TABLE_VACANCY_ON: return "on";
    1075                 :       3304 :     case OFPUTIL_TABLE_VACANCY_OFF: return "off";
    1076                 :          0 :     default: return "***error***";
    1077                 :            :     }
    1078                 :            : 
    1079                 :            : }
    1080                 :            : 
    1081                 :            : static void
    1082                 :         18 : ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
    1083                 :            : {
    1084                 :            :     struct ofputil_table_mod pm;
    1085                 :            :     enum ofperr error;
    1086                 :            : 
    1087                 :         18 :     error = ofputil_decode_table_mod(oh, &pm);
    1088         [ -  + ]:         18 :     if (error) {
    1089                 :          0 :         ofp_print_error(string, error);
    1090                 :          0 :         return;
    1091                 :            :     }
    1092                 :            : 
    1093         [ +  + ]:         18 :     if (pm.table_id == 0xff) {
    1094                 :          7 :         ds_put_cstr(string, " table_id: ALL_TABLES");
    1095                 :            :     } else {
    1096                 :         11 :         ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
    1097                 :            :     }
    1098                 :            : 
    1099         [ +  + ]:         18 :     if (pm.miss != OFPUTIL_TABLE_MISS_DEFAULT) {
    1100                 :          9 :         ds_put_format(string, ", flow_miss_config=%s",
    1101                 :            :                       ofputil_table_miss_to_string(pm.miss));
    1102                 :            :     }
    1103         [ +  + ]:         18 :     if (pm.eviction != OFPUTIL_TABLE_EVICTION_DEFAULT) {
    1104                 :          8 :         ds_put_format(string, ", eviction=%s",
    1105                 :            :                       ofputil_table_eviction_to_string(pm.eviction));
    1106                 :            :     }
    1107         [ -  + ]:         18 :     if (pm.eviction_flags != UINT32_MAX) {
    1108                 :          0 :         ds_put_cstr(string, "eviction_flags=");
    1109                 :          0 :         ofputil_put_eviction_flags(string, pm.eviction_flags);
    1110                 :            :     }
    1111         [ +  + ]:         18 :     if (pm.vacancy != OFPUTIL_TABLE_VACANCY_DEFAULT) {
    1112                 :          8 :         ds_put_format(string, ", vacancy=%s",
    1113                 :            :                       ofputil_table_vacancy_to_string(pm.vacancy));
    1114         [ +  + ]:          8 :         if (pm.vacancy == OFPUTIL_TABLE_VACANCY_ON) {
    1115                 :         18 :             ds_put_format(string, " vacancy:%"PRIu8""
    1116                 :          3 :                           ",%"PRIu8"", pm.table_vacancy.vacancy_down,
    1117                 :          3 :                           pm.table_vacancy.vacancy_up);
    1118                 :            :         }
    1119                 :            :     }
    1120                 :            : }
    1121                 :            : 
    1122                 :            : /* This function will print the Table description properties. */
    1123                 :            : static void
    1124                 :       3308 : ofp_print_table_desc(struct ds *string, const struct ofputil_table_desc *td)
    1125                 :            : {
    1126                 :       3308 :     ds_put_format(string, "\n  table %"PRIu8, td->table_id);
    1127                 :       3308 :     ds_put_cstr(string, ":\n");
    1128                 :       3308 :     ds_put_format(string, "   eviction=%s eviction_flags=",
    1129                 :            :                   ofputil_table_eviction_to_string(td->eviction));
    1130                 :       3308 :     ofputil_put_eviction_flags(string, td->eviction_flags);
    1131                 :       3308 :     ds_put_char(string, '\n');
    1132                 :       3308 :     ds_put_format(string, "   vacancy=%s",
    1133                 :            :                   ofputil_table_vacancy_to_string(td->vacancy));
    1134         [ +  + ]:       3308 :     if (td->vacancy == OFPUTIL_TABLE_VACANCY_ON) {
    1135                 :          9 :         ds_put_format(string, " vacancy_down=%"PRIu8"%%",
    1136                 :          9 :                       td->table_vacancy.vacancy_down);
    1137                 :          9 :         ds_put_format(string, " vacancy_up=%"PRIu8"%%",
    1138                 :          9 :                       td->table_vacancy.vacancy_up);
    1139                 :          9 :         ds_put_format(string, " vacancy=%"PRIu8"%%",
    1140                 :          9 :                       td->table_vacancy.vacancy);
    1141                 :            :     }
    1142                 :       3308 :     ds_put_char(string, '\n');
    1143                 :       3308 : }
    1144                 :            : 
    1145                 :            : static void
    1146                 :          6 : ofp_print_table_status_message(struct ds *string, const struct ofp_header *oh)
    1147                 :            : {
    1148                 :            :     struct ofputil_table_status ts;
    1149                 :            :     enum ofperr error;
    1150                 :            : 
    1151                 :          6 :     error = ofputil_decode_table_status(oh, &ts);
    1152         [ -  + ]:          6 :     if (error) {
    1153                 :          0 :         ofp_print_error(string, error);
    1154                 :          0 :         return;
    1155                 :            :     }
    1156                 :            : 
    1157         [ +  + ]:          6 :     if (ts.reason == OFPTR_VACANCY_DOWN) {
    1158                 :          2 :         ds_put_format(string, " reason=VACANCY_DOWN");
    1159         [ +  - ]:          4 :     } else if (ts.reason == OFPTR_VACANCY_UP) {
    1160                 :          4 :         ds_put_format(string, " reason=VACANCY_UP");
    1161                 :            :     }
    1162                 :            : 
    1163                 :          6 :     ds_put_format(string, "\ntable_desc:-");
    1164                 :          6 :     ofp_print_table_desc(string, &ts.desc);
    1165                 :            : }
    1166                 :            : 
    1167                 :            : static void
    1168                 :         26 : ofp_print_queue_get_config_request(struct ds *string,
    1169                 :            :                                    const struct ofp_header *oh)
    1170                 :            : {
    1171                 :            :     enum ofperr error;
    1172                 :            :     ofp_port_t port;
    1173                 :            :     uint32_t queue;
    1174                 :            : 
    1175                 :         26 :     error = ofputil_decode_queue_get_config_request(oh, &port, &queue);
    1176         [ -  + ]:         26 :     if (error) {
    1177                 :          0 :         ofp_print_error(string, error);
    1178                 :          0 :         return;
    1179                 :            :     }
    1180                 :            : 
    1181                 :         26 :     ds_put_cstr(string, " port=");
    1182                 :         26 :     ofputil_format_port(port, string);
    1183                 :            : 
    1184         [ +  + ]:         26 :     if (queue != OFPQ_ALL) {
    1185                 :          4 :         ds_put_cstr(string, " queue=");
    1186                 :         26 :         ofp_print_queue_name(string, queue);
    1187                 :            :     }
    1188                 :            : }
    1189                 :            : 
    1190                 :            : static void
    1191                 :         68 : print_queue_rate(struct ds *string, const char *name, unsigned int rate)
    1192                 :            : {
    1193         [ +  + ]:         68 :     if (rate <= 1000) {
    1194                 :         11 :         ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
    1195         [ -  + ]:         57 :     } else if (rate < UINT16_MAX) {
    1196                 :          0 :         ds_put_format(string, " %s:(disabled)", name);
    1197                 :            :     }
    1198                 :         68 : }
    1199                 :            : 
    1200                 :            : /* qsort comparison function. */
    1201                 :            : static int
    1202                 :         13 : compare_queues(const void *a_, const void *b_)
    1203                 :            : {
    1204                 :         13 :     const struct ofputil_queue_config *a = a_;
    1205                 :         13 :     const struct ofputil_queue_config *b = b_;
    1206                 :            : 
    1207                 :         13 :     uint16_t ap = ofp_to_u16(a->port);
    1208                 :         13 :     uint16_t bp = ofp_to_u16(b->port);
    1209         [ +  + ]:         13 :     if (ap != bp) {
    1210         [ +  + ]:          5 :         return ap < bp ? -1 : 1;
    1211                 :            :     }
    1212                 :            : 
    1213                 :          8 :     uint32_t aq = a->queue;
    1214                 :          8 :     uint32_t bq = b->queue;
    1215         [ +  - ]:          8 :     return aq < bq ? -1 : aq > bq;
    1216                 :            : }
    1217                 :            : 
    1218                 :            : static void
    1219                 :         21 : ofp_print_queue_get_config_reply(struct ds *string,
    1220                 :            :                                  const struct ofp_header *oh)
    1221                 :            : {
    1222                 :         21 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1223                 :            : 
    1224                 :         21 :     struct ofputil_queue_config *queues = NULL;
    1225                 :         21 :     size_t allocated_queues = 0;
    1226                 :         21 :     size_t n = 0;
    1227                 :            : 
    1228                 :         21 :     int retval = 0;
    1229                 :            :     for (;;) {
    1230         [ +  + ]:         55 :         if (n >= allocated_queues) {
    1231                 :         51 :             queues = x2nrealloc(queues, &allocated_queues, sizeof *queues);
    1232                 :            :         }
    1233                 :         55 :         retval = ofputil_pull_queue_get_config_reply(&b, &queues[n]);
    1234         [ +  + ]:         55 :         if (retval) {
    1235                 :         21 :             break;
    1236                 :            :         }
    1237                 :         34 :         n++;
    1238                 :         34 :     }
    1239                 :            : 
    1240                 :         21 :     qsort(queues, n, sizeof *queues, compare_queues);
    1241                 :            : 
    1242                 :         21 :     ds_put_char(string, ' ');
    1243                 :            : 
    1244                 :         21 :     ofp_port_t port = 0;
    1245         [ +  + ]:         55 :     for (const struct ofputil_queue_config *q = queues; q < &queues[n]; q++) {
    1246         [ +  + ]:         34 :         if (q->port != port) {
    1247                 :         26 :             port = q->port;
    1248                 :            : 
    1249                 :         26 :             ds_put_cstr(string, "port=");
    1250                 :         26 :             ofputil_format_port(port, string);
    1251                 :         26 :             ds_put_char(string, '\n');
    1252                 :            :         }
    1253                 :            : 
    1254                 :         34 :         ds_put_format(string, "queue %"PRIu32":", q->queue);
    1255                 :         34 :         print_queue_rate(string, "min_rate", q->min_rate);
    1256                 :         34 :         print_queue_rate(string, "max_rate", q->max_rate);
    1257                 :         34 :         ds_put_char(string, '\n');
    1258                 :            :     }
    1259                 :            : 
    1260         [ -  + ]:         21 :     if (retval != EOF) {
    1261                 :          0 :         ofp_print_error(string, retval);
    1262                 :            :     }
    1263                 :         21 :     ds_chomp(string, ' ');
    1264                 :         21 : }
    1265                 :            : 
    1266                 :            : static void
    1267                 :          5 : ofp_print_meter_flags(struct ds *s, uint16_t flags)
    1268                 :            : {
    1269         [ +  + ]:          5 :     if (flags & OFPMF13_KBPS) {
    1270                 :          3 :         ds_put_cstr(s, "kbps ");
    1271                 :            :     }
    1272         [ -  + ]:          5 :     if (flags & OFPMF13_PKTPS) {
    1273                 :          0 :         ds_put_cstr(s, "pktps ");
    1274                 :            :     }
    1275         [ +  + ]:          5 :     if (flags & OFPMF13_BURST) {
    1276                 :          2 :         ds_put_cstr(s, "burst ");
    1277                 :            :     }
    1278         [ +  + ]:          5 :     if (flags & OFPMF13_STATS) {
    1279                 :          2 :         ds_put_cstr(s, "stats ");
    1280                 :            :     }
    1281                 :            : 
    1282                 :          5 :     flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
    1283         [ +  + ]:          5 :     if (flags) {
    1284                 :          1 :         ds_put_format(s, "flags:0x%"PRIx16" ", flags);
    1285                 :            :     }
    1286                 :          5 : }
    1287                 :            : 
    1288                 :            : static void
    1289                 :          4 : ofp_print_meter_band(struct ds *s, uint16_t flags,
    1290                 :            :                      const struct ofputil_meter_band *mb)
    1291                 :            : {
    1292                 :          4 :     ds_put_cstr(s, "\ntype=");
    1293      [ +  +  - ]:          4 :     switch (mb->type) {
    1294                 :            :     case OFPMBT13_DROP:
    1295                 :          3 :         ds_put_cstr(s, "drop");
    1296                 :          3 :         break;
    1297                 :            :     case OFPMBT13_DSCP_REMARK:
    1298                 :          1 :         ds_put_cstr(s, "dscp_remark");
    1299                 :          1 :         break;
    1300                 :            :     default:
    1301                 :          0 :         ds_put_format(s, "%u", mb->type);
    1302                 :            :     }
    1303                 :            : 
    1304                 :          4 :     ds_put_format(s, " rate=%"PRIu32, mb->rate);
    1305                 :            : 
    1306         [ +  + ]:          4 :     if (flags & OFPMF13_BURST) {
    1307                 :          3 :         ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
    1308                 :            :     }
    1309         [ +  + ]:          4 :     if (mb->type == OFPMBT13_DSCP_REMARK) {
    1310                 :          1 :         ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
    1311                 :            :     }
    1312                 :          4 : }
    1313                 :            : 
    1314                 :            : static void
    1315                 :          2 : ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
    1316                 :            : {
    1317                 :            :     uint16_t i;
    1318                 :            : 
    1319                 :          2 :     ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
    1320                 :          2 :     ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
    1321                 :          2 :     ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
    1322                 :          2 :     ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
    1323                 :          2 :     ds_put_cstr(s, "duration:");
    1324                 :          2 :     ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
    1325                 :          2 :     ds_put_char(s, ' ');
    1326                 :            : 
    1327                 :          2 :     ds_put_cstr(s, "bands:\n");
    1328         [ +  + ]:          5 :     for (i = 0; i < ms->n_bands; ++i) {
    1329                 :          3 :         ds_put_format(s, "%d: ", i);
    1330                 :          3 :         ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
    1331                 :          3 :         ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
    1332                 :            :     }
    1333                 :          2 : }
    1334                 :            : 
    1335                 :            : static void
    1336                 :          5 : ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
    1337                 :            : {
    1338                 :            :     uint16_t i;
    1339                 :            : 
    1340                 :          5 :     ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
    1341                 :            : 
    1342                 :          5 :     ofp_print_meter_flags(s, mc->flags);
    1343                 :            : 
    1344                 :          5 :     ds_put_cstr(s, "bands=");
    1345         [ +  + ]:          9 :     for (i = 0; i < mc->n_bands; ++i) {
    1346                 :          4 :         ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
    1347                 :            :     }
    1348                 :          5 :     ds_put_char(s, '\n');
    1349                 :          5 : }
    1350                 :            : 
    1351                 :            : static void
    1352                 :          3 : ofp_print_meter_mod__(struct ds *s, const struct ofputil_meter_mod *mm)
    1353                 :            : {
    1354   [ +  +  -  - ]:          3 :     switch (mm->command) {
    1355                 :            :     case OFPMC13_ADD:
    1356                 :          2 :         ds_put_cstr(s, " ADD ");
    1357                 :          2 :         break;
    1358                 :            :     case OFPMC13_MODIFY:
    1359                 :          1 :         ds_put_cstr(s, " MOD ");
    1360                 :          1 :         break;
    1361                 :            :     case OFPMC13_DELETE:
    1362                 :          0 :         ds_put_cstr(s, " DEL ");
    1363                 :          0 :         break;
    1364                 :            :     default:
    1365                 :          0 :         ds_put_format(s, " cmd:%d ", mm->command);
    1366                 :            :     }
    1367                 :            : 
    1368                 :          3 :     ofp_print_meter_config(s, &mm->meter);
    1369                 :          3 : }
    1370                 :            : 
    1371                 :            : static void
    1372                 :          4 : ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
    1373                 :            : {
    1374                 :            :     struct ofputil_meter_mod mm;
    1375                 :            :     struct ofpbuf bands;
    1376                 :            :     enum ofperr error;
    1377                 :            : 
    1378                 :          4 :     ofpbuf_init(&bands, 64);
    1379                 :          4 :     error = ofputil_decode_meter_mod(oh, &mm, &bands);
    1380         [ +  + ]:          4 :     if (error) {
    1381                 :          3 :         ofp_print_error(s, error);
    1382                 :            :     } else {
    1383                 :          1 :         ofp_print_meter_mod__(s, &mm);
    1384                 :            :     }
    1385                 :          4 :     ofpbuf_uninit(&bands);
    1386                 :          4 : }
    1387                 :            : 
    1388                 :            : static void
    1389                 :          2 : ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
    1390                 :            : {
    1391                 :            :     uint32_t meter_id;
    1392                 :            : 
    1393                 :          2 :     ofputil_decode_meter_request(oh, &meter_id);
    1394                 :            : 
    1395                 :          2 :     ds_put_format(s, " meter=%"PRIu32, meter_id);
    1396                 :          2 : }
    1397                 :            : 
    1398                 :            : static const char *
    1399                 :          4 : ofputil_meter_capabilities_to_name(uint32_t bit)
    1400                 :            : {
    1401                 :          4 :     enum ofp13_meter_flags flag = bit;
    1402                 :            : 
    1403   [ +  +  +  +  :          4 :     switch (flag) {
                      - ]
    1404                 :          1 :     case OFPMF13_KBPS:    return "kbps";
    1405                 :          1 :     case OFPMF13_PKTPS:   return "pktps";
    1406                 :          1 :     case OFPMF13_BURST:   return "burst";
    1407                 :          1 :     case OFPMF13_STATS:   return "stats";
    1408                 :            :     }
    1409                 :            : 
    1410                 :          0 :     return NULL;
    1411                 :            : }
    1412                 :            : 
    1413                 :            : static const char *
    1414                 :          2 : ofputil_meter_band_types_to_name(uint32_t bit)
    1415                 :            : {
    1416      [ +  +  - ]:          2 :     switch (bit) {
    1417                 :          1 :     case 1 << OFPMBT13_DROP:          return "drop";
    1418                 :          1 :     case 1 << OFPMBT13_DSCP_REMARK:   return "dscp_remark";
    1419                 :            :     }
    1420                 :            : 
    1421                 :          0 :     return NULL;
    1422                 :            : }
    1423                 :            : 
    1424                 :            : static void
    1425                 :          1 : ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
    1426                 :            : {
    1427                 :            :     struct ofputil_meter_features mf;
    1428                 :            : 
    1429                 :          1 :     ofputil_decode_meter_features(oh, &mf);
    1430                 :            : 
    1431                 :          1 :     ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
    1432                 :          1 :     ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
    1433                 :          1 :     ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
    1434                 :            : 
    1435                 :          1 :     ds_put_cstr(s, "band_types: ");
    1436                 :          1 :     ofp_print_bit_names(s, mf.band_types,
    1437                 :            :                         ofputil_meter_band_types_to_name, ' ');
    1438                 :          1 :     ds_put_char(s, '\n');
    1439                 :            : 
    1440                 :          1 :     ds_put_cstr(s, "capabilities: ");
    1441                 :          1 :     ofp_print_bit_names(s, mf.capabilities,
    1442                 :            :                         ofputil_meter_capabilities_to_name, ' ');
    1443                 :          1 :     ds_put_char(s, '\n');
    1444                 :          1 : }
    1445                 :            : 
    1446                 :            : static void
    1447                 :          1 : ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
    1448                 :            : {
    1449                 :          1 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1450                 :            :     struct ofpbuf bands;
    1451                 :            : 
    1452                 :          1 :     ofpbuf_init(&bands, 64);
    1453                 :            :     for (;;) {
    1454                 :            :         struct ofputil_meter_config mc;
    1455                 :            :         int retval;
    1456                 :            : 
    1457                 :          3 :         retval = ofputil_decode_meter_config(&b, &mc, &bands);
    1458         [ +  + ]:          3 :         if (retval) {
    1459         [ -  + ]:          1 :             if (retval != EOF) {
    1460                 :          0 :                 ofp_print_error(s, retval);
    1461                 :            :             }
    1462                 :          1 :             break;
    1463                 :            :         }
    1464                 :          2 :         ds_put_char(s, '\n');
    1465                 :          2 :         ofp_print_meter_config(s, &mc);
    1466                 :          2 :     }
    1467                 :          1 :     ofpbuf_uninit(&bands);
    1468                 :          1 : }
    1469                 :            : 
    1470                 :            : static void
    1471                 :          1 : ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
    1472                 :            : {
    1473                 :          1 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1474                 :            :     struct ofpbuf bands;
    1475                 :            : 
    1476                 :          1 :     ofpbuf_init(&bands, 64);
    1477                 :            :     for (;;) {
    1478                 :            :         struct ofputil_meter_stats ms;
    1479                 :            :         int retval;
    1480                 :            : 
    1481                 :          3 :         retval = ofputil_decode_meter_stats(&b, &ms, &bands);
    1482         [ +  + ]:          3 :         if (retval) {
    1483         [ -  + ]:          1 :             if (retval != EOF) {
    1484                 :          0 :                 ofp_print_error(s, retval);
    1485                 :            :             }
    1486                 :          1 :             break;
    1487                 :            :         }
    1488                 :          2 :         ds_put_char(s, '\n');
    1489                 :          2 :         ofp_print_meter_stats(s, &ms);
    1490                 :          2 :     }
    1491                 :          1 :     ofpbuf_uninit(&bands);
    1492                 :          1 : }
    1493                 :            : 
    1494                 :            : static void
    1495                 :         22 : ofp_print_error(struct ds *string, enum ofperr error)
    1496                 :            : {
    1497         [ +  + ]:         22 :     if (string->length) {
    1498                 :         13 :         ds_put_char(string, ' ');
    1499                 :            :     }
    1500                 :         22 :     ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
    1501                 :         22 : }
    1502                 :            : 
    1503                 :            : static void
    1504                 :       6940 : ofp_print_hello(struct ds *string, const struct ofp_header *oh)
    1505                 :            : {
    1506                 :            :     uint32_t allowed_versions;
    1507                 :            :     bool ok;
    1508                 :            : 
    1509                 :       6940 :     ok = ofputil_decode_hello(oh, &allowed_versions);
    1510                 :            : 
    1511                 :       6940 :     ds_put_cstr(string, "\n version bitmap: ");
    1512                 :       6940 :     ofputil_format_version_bitmap(string, allowed_versions);
    1513                 :            : 
    1514         [ +  + ]:       6940 :     if (!ok) {
    1515                 :          9 :         ds_put_cstr(string, "\n unknown data in hello:\n");
    1516                 :          9 :         ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
    1517                 :            :     }
    1518                 :       6940 : }
    1519                 :            : 
    1520                 :            : static void
    1521                 :       1255 : ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
    1522                 :            : {
    1523                 :       1255 :     size_t len = ntohs(oh->length);
    1524                 :            :     struct ofpbuf payload;
    1525                 :            :     enum ofperr error;
    1526                 :            :     char *s;
    1527                 :            : 
    1528                 :       1255 :     error = ofperr_decode_msg(oh, &payload);
    1529         [ -  + ]:       1255 :     if (!error) {
    1530                 :          0 :         ds_put_cstr(string, "***decode error***");
    1531                 :          0 :         ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
    1532                 :          0 :         return;
    1533                 :            :     }
    1534                 :            : 
    1535                 :       1255 :     ds_put_format(string, " %s\n", ofperr_get_name(error));
    1536                 :            : 
    1537 [ +  - ][ +  + ]:       1255 :     if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
    1538                 :          2 :         ds_put_printable(string, payload.data, payload.size);
    1539                 :            :     } else {
    1540                 :       1253 :         s = ofp_to_string(payload.data, payload.size, 1);
    1541                 :       1253 :         ds_put_cstr(string, s);
    1542                 :       1253 :         free(s);
    1543                 :            :     }
    1544                 :       1255 :     ofpbuf_uninit(&payload);
    1545                 :            : }
    1546                 :            : 
    1547                 :            : static void
    1548                 :        505 : ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
    1549                 :            : {
    1550                 :            :     struct ofputil_port_status ps;
    1551                 :            :     enum ofperr error;
    1552                 :            : 
    1553                 :        505 :     error = ofputil_decode_port_status(oh, &ps);
    1554         [ -  + ]:        505 :     if (error) {
    1555                 :          0 :         ofp_print_error(string, error);
    1556                 :          0 :         return;
    1557                 :            :     }
    1558                 :            : 
    1559         [ +  + ]:        505 :     if (ps.reason == OFPPR_ADD) {
    1560                 :        345 :         ds_put_format(string, " ADD:");
    1561         [ +  + ]:        160 :     } else if (ps.reason == OFPPR_DELETE) {
    1562                 :        135 :         ds_put_format(string, " DEL:");
    1563         [ +  - ]:         25 :     } else if (ps.reason == OFPPR_MODIFY) {
    1564                 :         25 :         ds_put_format(string, " MOD:");
    1565                 :            :     }
    1566                 :            : 
    1567                 :        505 :     ofp_print_phy_port(string, &ps.desc);
    1568                 :            : }
    1569                 :            : 
    1570                 :            : static void
    1571                 :          1 : ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
    1572                 :            : {
    1573                 :          1 :     const struct ofp_desc_stats *ods = ofpmsg_body(oh);
    1574                 :            : 
    1575                 :          1 :     ds_put_char(string, '\n');
    1576                 :          1 :     ds_put_format(string, "Manufacturer: %.*s\n",
    1577                 :          1 :             (int) sizeof ods->mfr_desc, ods->mfr_desc);
    1578                 :          1 :     ds_put_format(string, "Hardware: %.*s\n",
    1579                 :          1 :             (int) sizeof ods->hw_desc, ods->hw_desc);
    1580                 :          1 :     ds_put_format(string, "Software: %.*s\n",
    1581                 :          1 :             (int) sizeof ods->sw_desc, ods->sw_desc);
    1582                 :          1 :     ds_put_format(string, "Serial Num: %.*s\n",
    1583                 :          1 :             (int) sizeof ods->serial_num, ods->serial_num);
    1584                 :          1 :     ds_put_format(string, "DP Description: %.*s\n",
    1585                 :          1 :             (int) sizeof ods->dp_desc, ods->dp_desc);
    1586                 :          1 : }
    1587                 :            : 
    1588                 :            : static void
    1589                 :        393 : ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
    1590                 :            : {
    1591                 :            :     struct ofputil_flow_stats_request fsr;
    1592                 :            :     enum ofperr error;
    1593                 :            : 
    1594                 :        393 :     error = ofputil_decode_flow_stats_request(&fsr, oh);
    1595         [ -  + ]:        393 :     if (error) {
    1596                 :          0 :         ofp_print_error(string, error);
    1597                 :          0 :         return;
    1598                 :            :     }
    1599                 :            : 
    1600         [ +  + ]:        393 :     if (fsr.table_id != 0xff) {
    1601                 :         60 :         ds_put_format(string, " table=%"PRIu8, fsr.table_id);
    1602                 :            :     }
    1603                 :            : 
    1604         [ +  + ]:        393 :     if (fsr.out_port != OFPP_ANY) {
    1605                 :          2 :         ds_put_cstr(string, " out_port=");
    1606                 :          2 :         ofputil_format_port(fsr.out_port, string);
    1607                 :            :     }
    1608                 :            : 
    1609                 :        393 :     ds_put_char(string, ' ');
    1610                 :        393 :     match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
    1611                 :            : }
    1612                 :            : 
    1613                 :            : void
    1614                 :      28186 : ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
    1615                 :            : {
    1616                 :      28186 :     ds_put_format(string, " %scookie=%s0x%"PRIx64", %sduration=%s",
    1617                 :            :                   colors.param, colors.end, ntohll(fs->cookie),
    1618                 :            :                   colors.param, colors.end);
    1619                 :            : 
    1620                 :      28186 :     ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
    1621                 :      28186 :     ds_put_format(string, ", %stable=%s%"PRIu8", ",
    1622                 :      28186 :                   colors.special, colors.end, fs->table_id);
    1623                 :      28186 :     ds_put_format(string, "%sn_packets=%s%"PRIu64", ",
    1624                 :            :                   colors.param, colors.end, fs->packet_count);
    1625                 :      28186 :     ds_put_format(string, "%sn_bytes=%s%"PRIu64", ",
    1626                 :            :                   colors.param, colors.end, fs->byte_count);
    1627         [ +  + ]:      28186 :     if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
    1628                 :        217 :         ds_put_format(string, "%sidle_timeout=%s%"PRIu16", ",
    1629                 :        217 :                       colors.param, colors.end, fs->idle_timeout);
    1630                 :            :     }
    1631         [ +  + ]:      28186 :     if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
    1632                 :        124 :         ds_put_format(string, "%shard_timeout=%s%"PRIu16", ",
    1633                 :        124 :                       colors.param, colors.end, fs->hard_timeout);
    1634                 :            :     }
    1635         [ +  + ]:      28186 :     if (fs->flags) {
    1636                 :         10 :         ofp_print_flow_flags(string, fs->flags);
    1637                 :            :     }
    1638         [ +  + ]:      28186 :     if (fs->importance != 0) {
    1639                 :         66 :         ds_put_format(string, "%simportance=%s%"PRIu16", ",
    1640                 :         66 :                       colors.param, colors.end, fs->importance);
    1641                 :            :     }
    1642         [ +  + ]:      28186 :     if (fs->idle_age >= 0) {
    1643                 :      23589 :         ds_put_format(string, "%sidle_age=%s%d, ",
    1644                 :            :                       colors.param, colors.end, fs->idle_age);
    1645                 :            :     }
    1646 [ +  + ][ +  + ]:      28186 :     if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
    1647                 :        124 :         ds_put_format(string, "%shard_age=%s%d, ",
    1648                 :            :                       colors.param, colors.end, fs->hard_age);
    1649                 :            :     }
    1650                 :            : 
    1651                 :      28186 :     match_format(&fs->match, string, fs->priority);
    1652         [ +  + ]:      28186 :     if (string->string[string->length - 1] != ' ') {
    1653                 :      28133 :         ds_put_char(string, ' ');
    1654                 :            :     }
    1655                 :            : 
    1656                 :      28186 :     ds_put_format(string, "%sactions=%s", colors.actions, colors.end);
    1657                 :      28186 :     ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
    1658                 :      28186 : }
    1659                 :            : 
    1660                 :            : static void
    1661                 :        774 : ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
    1662                 :            : {
    1663                 :        774 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1664                 :            :     struct ofpbuf ofpacts;
    1665                 :            : 
    1666                 :        774 :     ofpbuf_init(&ofpacts, 64);
    1667                 :            :     for (;;) {
    1668                 :            :         struct ofputil_flow_stats fs;
    1669                 :            :         int retval;
    1670                 :            : 
    1671                 :      28894 :         retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
    1672         [ +  + ]:      28894 :         if (retval) {
    1673         [ -  + ]:        774 :             if (retval != EOF) {
    1674                 :          0 :                 ds_put_cstr(string, " ***parse error***");
    1675                 :            :             }
    1676                 :        774 :             break;
    1677                 :            :         }
    1678                 :      28120 :         ds_put_char(string, '\n');
    1679                 :      28120 :         ofp_print_flow_stats(string, &fs);
    1680                 :      28120 :      }
    1681                 :        774 :     ofpbuf_uninit(&ofpacts);
    1682                 :        774 : }
    1683                 :            : 
    1684                 :            : static void
    1685                 :         14 : ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
    1686                 :            : {
    1687                 :            :     struct ofputil_aggregate_stats as;
    1688                 :            :     enum ofperr error;
    1689                 :            : 
    1690                 :         14 :     error = ofputil_decode_aggregate_stats_reply(&as, oh);
    1691         [ -  + ]:         14 :     if (error) {
    1692                 :          0 :         ofp_print_error(string, error);
    1693                 :          0 :         return;
    1694                 :            :     }
    1695                 :            : 
    1696                 :         14 :     ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
    1697                 :         14 :     ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
    1698                 :         14 :     ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
    1699                 :            : }
    1700                 :            : 
    1701                 :            : static void
    1702                 :       1446 : print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
    1703                 :            : {
    1704                 :       1446 :     ds_put_cstr(string, leader);
    1705         [ +  + ]:       1446 :     if (stat != UINT64_MAX) {
    1706                 :        590 :         ds_put_format(string, "%"PRIu64, stat);
    1707                 :            :     } else {
    1708                 :        856 :         ds_put_char(string, '?');
    1709                 :            :     }
    1710         [ +  + ]:       1446 :     if (more) {
    1711                 :       1240 :         ds_put_cstr(string, ", ");
    1712                 :            :     } else {
    1713                 :        206 :         ds_put_cstr(string, "\n");
    1714                 :            :     }
    1715                 :       1446 : }
    1716                 :            : 
    1717                 :            : static void
    1718                 :       2163 : print_port_stat_cond(struct ds *string, const char *leader, uint64_t stat)
    1719                 :            : {
    1720         [ -  + ]:       2163 :     if (stat != UINT64_MAX) {
    1721                 :          0 :         ds_put_format(string, "%s%"PRIu64", ", leader, stat);
    1722                 :            :     }
    1723                 :       2163 : }
    1724                 :            : 
    1725                 :            : static void
    1726                 :         23 : ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
    1727                 :            : {
    1728                 :            :     ofp_port_t ofp10_port;
    1729                 :            :     enum ofperr error;
    1730                 :            : 
    1731                 :         23 :     error = ofputil_decode_port_stats_request(oh, &ofp10_port);
    1732         [ -  + ]:         23 :     if (error) {
    1733                 :          0 :         ofp_print_error(string, error);
    1734                 :          0 :         return;
    1735                 :            :     }
    1736                 :            : 
    1737                 :         23 :     ds_put_cstr(string, " port_no=");
    1738                 :         23 :     ofputil_format_port(ofp10_port, string);
    1739                 :            : }
    1740                 :            : 
    1741                 :            : static void
    1742                 :         42 : ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
    1743                 :            :                            int verbosity)
    1744                 :            : {
    1745                 :         42 :     ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
    1746         [ -  + ]:         42 :     if (verbosity < 1) {
    1747                 :          0 :         return;
    1748                 :            :     }
    1749                 :            : 
    1750                 :         42 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1751                 :            :     for (;;) {
    1752                 :            :         struct ofputil_port_stats ps;
    1753                 :            :         int retval;
    1754                 :            : 
    1755                 :        145 :         retval = ofputil_decode_port_stats(&ps, &b);
    1756         [ +  + ]:        145 :         if (retval) {
    1757         [ -  + ]:         42 :             if (retval != EOF) {
    1758                 :          0 :                 ds_put_cstr(string, " ***parse error***");
    1759                 :            :             }
    1760                 :         42 :             return;
    1761                 :            :         }
    1762                 :            : 
    1763                 :        103 :         ds_put_cstr(string, "  port ");
    1764         [ +  + ]:        103 :         if (ofp_to_u16(ps.port_no) < 10) {
    1765                 :         78 :             ds_put_char(string, ' ');
    1766                 :            :         }
    1767                 :        103 :         ofputil_format_port(ps.port_no, string);
    1768                 :            : 
    1769                 :        103 :         ds_put_cstr(string, ": rx ");
    1770                 :        103 :         print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
    1771                 :        103 :         print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
    1772                 :        103 :         print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
    1773                 :        103 :         print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
    1774                 :        103 :         print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
    1775                 :        103 :         print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
    1776                 :        103 :         print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
    1777                 :            : 
    1778                 :        103 :         ds_put_cstr(string, "           tx ");
    1779                 :        103 :         print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
    1780                 :        103 :         print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
    1781                 :        103 :         print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
    1782                 :        103 :         print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
    1783                 :        103 :         print_port_stat(string, "coll=", ps.stats.collisions, 0);
    1784                 :            : 
    1785         [ +  + ]:        103 :         if (ps.duration_sec != UINT32_MAX) {
    1786                 :         11 :             ds_put_cstr(string, "           duration=");
    1787                 :         11 :             ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
    1788                 :         11 :             ds_put_char(string, '\n');
    1789                 :            :         }
    1790                 :        103 :         struct ds string_ext_stats = DS_EMPTY_INITIALIZER;
    1791                 :            : 
    1792                 :        103 :         ds_init(&string_ext_stats);
    1793                 :            : 
    1794                 :        103 :         print_port_stat_cond(&string_ext_stats, "1_to_64_packets=",
    1795                 :            :                              ps.stats.rx_1_to_64_packets);
    1796                 :        103 :         print_port_stat_cond(&string_ext_stats, "65_to_127_packets=",
    1797                 :            :                              ps.stats.rx_65_to_127_packets);
    1798                 :        103 :         print_port_stat_cond(&string_ext_stats, "128_to_255_packets=",
    1799                 :            :                              ps.stats.rx_128_to_255_packets);
    1800                 :        103 :         print_port_stat_cond(&string_ext_stats, "256_to_511_packets=",
    1801                 :            :                              ps.stats.rx_256_to_511_packets);
    1802                 :        103 :         print_port_stat_cond(&string_ext_stats, "512_to_1023_packets=",
    1803                 :            :                              ps.stats.rx_512_to_1023_packets);
    1804                 :        103 :         print_port_stat_cond(&string_ext_stats, "1024_to_1522_packets=",
    1805                 :            :                              ps.stats.rx_1024_to_1522_packets);
    1806                 :        103 :         print_port_stat_cond(&string_ext_stats, "1523_to_max_packets=",
    1807                 :            :                              ps.stats.rx_1523_to_max_packets);
    1808                 :        103 :         print_port_stat_cond(&string_ext_stats, "broadcast_packets=",
    1809                 :            :                              ps.stats.rx_broadcast_packets);
    1810                 :        103 :         print_port_stat_cond(&string_ext_stats, "undersized_errors=",
    1811                 :            :                              ps.stats.rx_undersized_errors);
    1812                 :        103 :         print_port_stat_cond(&string_ext_stats, "oversize_errors=",
    1813                 :            :                              ps.stats.rx_oversize_errors);
    1814                 :        103 :         print_port_stat_cond(&string_ext_stats, "rx_fragmented_errors=",
    1815                 :            :                              ps.stats.rx_fragmented_errors);
    1816                 :        103 :         print_port_stat_cond(&string_ext_stats, "rx_jabber_errors=",
    1817                 :            :                              ps.stats.rx_jabber_errors);
    1818                 :            : 
    1819         [ -  + ]:        103 :         if (string_ext_stats.length != 0) {
    1820                 :            :             /* If at least one statistics counter is reported: */
    1821                 :          0 :             ds_put_cstr(string, "           rx rfc2819 ");
    1822                 :          0 :             ds_put_buffer(string, string_ext_stats.string,
    1823                 :            :                           string_ext_stats.length);
    1824                 :          0 :             ds_put_cstr(string, "\n");
    1825                 :          0 :             ds_destroy(&string_ext_stats);
    1826                 :            :         }
    1827                 :            : 
    1828                 :        103 :         ds_init(&string_ext_stats);
    1829                 :            : 
    1830                 :        103 :         print_port_stat_cond(&string_ext_stats, "1_to_64_packets=",
    1831                 :            :                              ps.stats.tx_1_to_64_packets);
    1832                 :        103 :         print_port_stat_cond(&string_ext_stats, "65_to_127_packets=",
    1833                 :            :                              ps.stats.tx_65_to_127_packets);
    1834                 :        103 :         print_port_stat_cond(&string_ext_stats, "128_to_255_packets=",
    1835                 :            :                              ps.stats.tx_128_to_255_packets);
    1836                 :        103 :         print_port_stat_cond(&string_ext_stats, "256_to_511_packets=",
    1837                 :            :                              ps.stats.tx_256_to_511_packets);
    1838                 :        103 :         print_port_stat_cond(&string_ext_stats, "512_to_1023_packets=",
    1839                 :            :                              ps.stats.tx_512_to_1023_packets);
    1840                 :        103 :         print_port_stat_cond(&string_ext_stats, "1024_to_1522_packets=",
    1841                 :            :                              ps.stats.tx_1024_to_1522_packets);
    1842                 :        103 :         print_port_stat_cond(&string_ext_stats, "1523_to_max_packets=",
    1843                 :            :                              ps.stats.tx_1523_to_max_packets);
    1844                 :        103 :         print_port_stat_cond(&string_ext_stats, "multicast_packets=",
    1845                 :            :                              ps.stats.tx_multicast_packets);
    1846                 :        103 :         print_port_stat_cond(&string_ext_stats, "broadcast_packets=",
    1847                 :            :                              ps.stats.tx_broadcast_packets);
    1848                 :            : 
    1849         [ -  + ]:        103 :         if (string_ext_stats.length != 0) {
    1850                 :            :             /* If at least one statistics counter is reported: */
    1851                 :          0 :             ds_put_cstr(string, "           tx rfc2819 ");
    1852                 :          0 :             ds_put_buffer(string, string_ext_stats.string,
    1853                 :            :                           string_ext_stats.length);
    1854                 :          0 :             ds_put_cstr(string, "\n");
    1855                 :          0 :             ds_destroy(&string_ext_stats);
    1856                 :            :         }
    1857                 :        145 :     }
    1858                 :            : }
    1859                 :            : 
    1860                 :            : static void
    1861                 :         23 : ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh)
    1862                 :            : {
    1863                 :         23 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1864                 :         23 :     ofpraw_pull_assert(&b);
    1865                 :            : 
    1866                 :            :     struct ofputil_table_features prev_features;
    1867                 :            :     struct ofputil_table_stats prev_stats;
    1868                 :         23 :     for (int i = 0;; i++) {
    1869                 :            :         struct ofputil_table_features features;
    1870                 :            :         struct ofputil_table_stats stats;
    1871                 :            :         int retval;
    1872                 :            : 
    1873                 :       5361 :         retval = ofputil_decode_table_stats_reply(&b, &stats, &features);
    1874         [ +  + ]:       5361 :         if (retval) {
    1875         [ -  + ]:         23 :             if (retval != EOF) {
    1876                 :          0 :                 ofp_print_error(string, retval);
    1877                 :            :             }
    1878                 :         23 :             return;
    1879                 :            :         }
    1880                 :            : 
    1881                 :       5338 :         ds_put_char(string, '\n');
    1882 [ +  + ][ +  + ]:       5338 :         ofp_print_table_features(string,
    1883                 :            :                                  &features, i ? &prev_features : NULL,
    1884                 :            :                                  &stats, i ? &prev_stats : NULL);
    1885                 :       5338 :         prev_features = features;
    1886                 :       5338 :         prev_stats = stats;
    1887                 :       5338 :     }
    1888                 :            : }
    1889                 :            : 
    1890                 :            : static void
    1891                 :        143 : ofp_print_queue_name(struct ds *string, uint32_t queue_id)
    1892                 :            : {
    1893         [ +  + ]:        143 :     if (queue_id == OFPQ_ALL) {
    1894                 :         29 :         ds_put_cstr(string, "ALL");
    1895                 :            :     } else {
    1896                 :        114 :         ds_put_format(string, "%"PRIu32, queue_id);
    1897                 :            :     }
    1898                 :        143 : }
    1899                 :            : 
    1900                 :            : static void
    1901                 :         69 : ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
    1902                 :            : {
    1903                 :            :     struct ofputil_queue_stats_request oqsr;
    1904                 :            :     enum ofperr error;
    1905                 :            : 
    1906                 :         69 :     error = ofputil_decode_queue_stats_request(oh, &oqsr);
    1907         [ -  + ]:         69 :     if (error) {
    1908                 :          0 :         ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
    1909                 :          0 :         return;
    1910                 :            :     }
    1911                 :            : 
    1912                 :         69 :     ds_put_cstr(string, " port=");
    1913                 :         69 :     ofputil_format_port(oqsr.port_no, string);
    1914                 :            : 
    1915                 :         69 :     ds_put_cstr(string, " queue=");
    1916                 :         69 :     ofp_print_queue_name(string, oqsr.queue_id);
    1917                 :            : }
    1918                 :            : 
    1919                 :            : static void
    1920                 :         45 : ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
    1921                 :            :                             int verbosity)
    1922                 :            : {
    1923                 :         45 :     ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
    1924         [ -  + ]:         45 :     if (verbosity < 1) {
    1925                 :          0 :         return;
    1926                 :            :     }
    1927                 :            : 
    1928                 :         45 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1929                 :            :     for (;;) {
    1930                 :            :         struct ofputil_queue_stats qs;
    1931                 :            :         int retval;
    1932                 :            : 
    1933                 :        115 :         retval = ofputil_decode_queue_stats(&qs, &b);
    1934         [ +  + ]:        115 :         if (retval) {
    1935         [ -  + ]:         45 :             if (retval != EOF) {
    1936                 :          0 :                 ds_put_cstr(string, " ***parse error***");
    1937                 :            :             }
    1938                 :         45 :             return;
    1939                 :            :         }
    1940                 :            : 
    1941                 :         70 :         ds_put_cstr(string, "  port ");
    1942                 :         70 :         ofputil_format_port(qs.port_no, string);
    1943                 :         70 :         ds_put_cstr(string, " queue ");
    1944                 :         70 :         ofp_print_queue_name(string, qs.queue_id);
    1945                 :         70 :         ds_put_cstr(string, ": ");
    1946                 :            : 
    1947                 :         70 :         print_port_stat(string, "bytes=", qs.tx_bytes, 1);
    1948                 :         70 :         print_port_stat(string, "pkts=", qs.tx_packets, 1);
    1949                 :         70 :         print_port_stat(string, "errors=", qs.tx_errors, 1);
    1950                 :            : 
    1951                 :         70 :         ds_put_cstr(string, "duration=");
    1952         [ +  + ]:         70 :         if (qs.duration_sec != UINT32_MAX) {
    1953                 :         10 :             ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
    1954                 :            :         } else {
    1955                 :         60 :             ds_put_char(string, '?');
    1956                 :            :         }
    1957                 :         70 :         ds_put_char(string, '\n');
    1958                 :        115 :     }
    1959                 :            : }
    1960                 :            : 
    1961                 :            : static void
    1962                 :         38 : ofp_print_ofpst_port_desc_request(struct ds *string,
    1963                 :            :                                   const struct ofp_header *oh)
    1964                 :            : {
    1965                 :            :     enum ofperr error;
    1966                 :            :     ofp_port_t port;
    1967                 :            : 
    1968                 :         38 :     error = ofputil_decode_port_desc_stats_request(oh, &port);
    1969         [ -  + ]:         38 :     if (error) {
    1970                 :          0 :         ofp_print_error(string, error);
    1971                 :          0 :         return;
    1972                 :            :     }
    1973                 :            : 
    1974                 :         38 :     ds_put_cstr(string, " port=");
    1975                 :         38 :     ofputil_format_port(port, string);
    1976                 :            : }
    1977                 :            : 
    1978                 :            : static void
    1979                 :         57 : ofp_print_ofpst_port_desc_reply(struct ds *string,
    1980                 :            :                                 const struct ofp_header *oh)
    1981                 :            : {
    1982                 :         57 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    1983                 :         57 :     ofpraw_pull_assert(&b);
    1984                 :         57 :     ds_put_char(string, '\n');
    1985                 :         57 :     ofp_print_phy_ports(string, oh->version, &b);
    1986                 :         57 : }
    1987                 :            : 
    1988                 :            : static void
    1989                 :       1565 : ofp_print_stats(struct ds *string, const struct ofp_header *oh)
    1990                 :            : {
    1991                 :       1565 :     uint16_t flags = ofpmp_flags(oh);
    1992                 :            : 
    1993         [ +  + ]:       1565 :     if (flags) {
    1994                 :          8 :         ds_put_cstr(string, " flags=");
    1995 [ -  + ][ #  # ]:          8 :         if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION)
    1996         [ +  - ]:          8 :             && (flags & OFPSF_REPLY_MORE)) {
    1997                 :          8 :             ds_put_cstr(string, "[more]");
    1998                 :          8 :             flags &= ~OFPSF_REPLY_MORE;
    1999                 :            :         }
    2000         [ -  + ]:          8 :         if (flags) {
    2001                 :          0 :             ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
    2002                 :            :                           flags);
    2003                 :            :         }
    2004                 :            :     }
    2005                 :       1565 : }
    2006                 :            : 
    2007                 :            : static void
    2008                 :         47 : ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
    2009                 :            : {
    2010                 :         47 :     size_t len = ntohs(oh->length);
    2011                 :            : 
    2012                 :         47 :     ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
    2013         [ +  + ]:         47 :     if (verbosity > 1) {
    2014                 :          7 :         ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
    2015                 :            :     }
    2016                 :         47 : }
    2017                 :            : 
    2018                 :            : static void
    2019                 :        106 : ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
    2020                 :            :                        uint64_t generation_id)
    2021                 :            : {
    2022                 :        106 :     ds_put_cstr(string, " role=");
    2023                 :            : 
    2024   [ +  +  +  +  :        106 :     switch (role) {
                      - ]
    2025                 :            :     case OFPCR12_ROLE_NOCHANGE:
    2026                 :          9 :         ds_put_cstr(string, "nochange");
    2027                 :          9 :         break;
    2028                 :            :     case OFPCR12_ROLE_EQUAL:
    2029                 :          8 :         ds_put_cstr(string, "equal"); /* OF 1.2 wording */
    2030                 :          8 :         break;
    2031                 :            :     case OFPCR12_ROLE_MASTER:
    2032                 :         49 :         ds_put_cstr(string, "master");
    2033                 :         49 :         break;
    2034                 :            :     case OFPCR12_ROLE_SLAVE:
    2035                 :         40 :         ds_put_cstr(string, "slave");
    2036                 :         40 :         break;
    2037                 :            :     default:
    2038                 :          0 :         OVS_NOT_REACHED();
    2039                 :            :     }
    2040                 :            : 
    2041         [ +  + ]:        106 :     if (generation_id != UINT64_MAX) {
    2042                 :         77 :         ds_put_format(string, " generation_id=%"PRIu64, generation_id);
    2043                 :            :     }
    2044                 :        106 : }
    2045                 :            : 
    2046                 :            : static void
    2047                 :        101 : ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
    2048                 :            : {
    2049                 :            :     struct ofputil_role_request rr;
    2050                 :            :     enum ofperr error;
    2051                 :            : 
    2052                 :        101 :     error = ofputil_decode_role_message(oh, &rr);
    2053         [ -  + ]:        101 :     if (error) {
    2054                 :          0 :         ofp_print_error(string, error);
    2055                 :          0 :         return;
    2056                 :            :     }
    2057                 :            : 
    2058         [ +  + ]:        101 :     ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
    2059                 :            : }
    2060                 :            : 
    2061                 :            : static void
    2062                 :          5 : ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
    2063                 :            : {
    2064                 :            :     struct ofputil_role_status rs;
    2065                 :            :     enum ofperr error;
    2066                 :            : 
    2067                 :          5 :     error = ofputil_decode_role_status(oh, &rs);
    2068         [ -  + ]:          5 :     if (error) {
    2069                 :          0 :         ofp_print_error(string, error);
    2070                 :          0 :         return;
    2071                 :            :     }
    2072                 :            : 
    2073                 :          5 :     ofp_print_role_generic(string, rs.role, rs.generation_id);
    2074                 :            : 
    2075                 :          5 :     ds_put_cstr(string, " reason=");
    2076                 :            : 
    2077   [ +  +  +  - ]:          5 :     switch (rs.reason) {
    2078                 :            :     case OFPCRR_MASTER_REQUEST:
    2079                 :          2 :         ds_put_cstr(string, "master_request");
    2080                 :          5 :         break;
    2081                 :            :     case OFPCRR_CONFIG:
    2082                 :          2 :         ds_put_cstr(string, "configuration_changed");
    2083                 :          2 :         break;
    2084                 :            :     case OFPCRR_EXPERIMENTER:
    2085                 :          1 :         ds_put_cstr(string, "experimenter_data_changed");
    2086                 :          1 :         break;
    2087                 :            :     case OFPCRR_N_REASONS:
    2088                 :            :     default:
    2089                 :          0 :         OVS_NOT_REACHED();
    2090                 :            :     }
    2091                 :            : }
    2092                 :            : 
    2093                 :            : static void
    2094                 :         89 : ofp_print_nxt_flow_mod_table_id(struct ds *string,
    2095                 :            :                                 const struct nx_flow_mod_table_id *nfmti)
    2096                 :            : {
    2097         [ +  - ]:         89 :     ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
    2098                 :         89 : }
    2099                 :            : 
    2100                 :            : static void
    2101                 :        332 : ofp_print_nxt_set_flow_format(struct ds *string,
    2102                 :            :                               const struct nx_set_flow_format *nsff)
    2103                 :            : {
    2104                 :        332 :     uint32_t format = ntohl(nsff->format);
    2105                 :            : 
    2106                 :        332 :     ds_put_cstr(string, " format=");
    2107         [ +  - ]:        332 :     if (ofputil_nx_flow_format_is_valid(format)) {
    2108                 :        332 :         ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
    2109                 :            :     } else {
    2110                 :          0 :         ds_put_format(string, "%"PRIu32, format);
    2111                 :            :     }
    2112                 :        332 : }
    2113                 :            : 
    2114                 :            : static void
    2115                 :        202 : ofp_print_nxt_set_packet_in_format(struct ds *string,
    2116                 :            :                                    const struct nx_set_packet_in_format *nspf)
    2117                 :            : {
    2118                 :        202 :     uint32_t format = ntohl(nspf->format);
    2119                 :            : 
    2120                 :        202 :     ds_put_cstr(string, " format=");
    2121         [ +  - ]:        202 :     if (ofputil_packet_in_format_is_valid(format)) {
    2122                 :        202 :         ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
    2123                 :            :     } else {
    2124                 :          0 :         ds_put_format(string, "%"PRIu32, format);
    2125                 :            :     }
    2126                 :        202 : }
    2127                 :            : 
    2128                 :            : /* Returns a string form of 'reason'.  The return value is either a statically
    2129                 :            :  * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
    2130                 :            :  * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
    2131                 :            : #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
    2132                 :            : static const char *
    2133                 :         57 : ofp_port_reason_to_string(enum ofp_port_reason reason,
    2134                 :            :                           char *reasonbuf, size_t bufsize)
    2135                 :            : {
    2136   [ +  +  +  - ]:         57 :     switch (reason) {
    2137                 :            :     case OFPPR_ADD:
    2138                 :         19 :         return "add";
    2139                 :            : 
    2140                 :            :     case OFPPR_DELETE:
    2141                 :         21 :         return "delete";
    2142                 :            : 
    2143                 :            :     case OFPPR_MODIFY:
    2144                 :         17 :         return "modify";
    2145                 :            : 
    2146                 :            :     case OFPPR_N_REASONS:
    2147                 :            :     default:
    2148                 :          0 :         snprintf(reasonbuf, bufsize, "%d", (int) reason);
    2149                 :          0 :         return reasonbuf;
    2150                 :            :     }
    2151                 :            : }
    2152                 :            : 
    2153                 :            : /* Returns a string form of 'reason'.  The return value is either a statically
    2154                 :            :  * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
    2155                 :            :  * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
    2156                 :            : static const char*
    2157                 :          0 : ofp_role_reason_to_string(enum ofp14_controller_role_reason reason,
    2158                 :            :                           char *reasonbuf, size_t bufsize)
    2159                 :            : {
    2160   [ #  #  #  # ]:          0 :     switch (reason) {
    2161                 :            :     case OFPCRR_MASTER_REQUEST:
    2162                 :          0 :         return "master_request";
    2163                 :            : 
    2164                 :            :     case OFPCRR_CONFIG:
    2165                 :          0 :         return "configuration_changed";
    2166                 :            : 
    2167                 :            :     case OFPCRR_EXPERIMENTER:
    2168                 :          0 :         return "experimenter_data_changed";
    2169                 :            : 
    2170                 :            :     case OFPCRR_N_REASONS:
    2171                 :            :     default:
    2172                 :          0 :         snprintf(reasonbuf, bufsize, "%d", (int) reason);
    2173                 :          0 :         return reasonbuf;
    2174                 :            :     }
    2175                 :            : }
    2176                 :            : 
    2177                 :            : /* Returns a string form of 'reason'.  The return value is either a statically
    2178                 :            :  * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
    2179                 :            :  * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
    2180                 :            : static const char*
    2181                 :          4 : ofp_table_reason_to_string(enum ofp14_table_reason reason,
    2182                 :            :                            char *reasonbuf, size_t bufsize)
    2183                 :            : {
    2184      [ +  +  - ]:          4 :     switch (reason) {
    2185                 :            :     case OFPTR_VACANCY_DOWN:
    2186                 :          2 :         return "vacancy_down";
    2187                 :            : 
    2188                 :            :     case OFPTR_VACANCY_UP:
    2189                 :          2 :         return "vacancy_up";
    2190                 :            : 
    2191                 :            :     default:
    2192                 :          0 :         snprintf(reasonbuf, bufsize, "%d", (int) reason);
    2193                 :          0 :         return reasonbuf;
    2194                 :            :     }
    2195                 :            : }
    2196                 :            : 
    2197                 :            : /* Returns a string form of 'reason'.  The return value is either a statically
    2198                 :            :  * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
    2199                 :            :  * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
    2200                 :            : static const char*
    2201                 :         12 : ofp_requestforward_reason_to_string(enum ofp14_requestforward_reason reason,
    2202                 :            :                                     char *reasonbuf, size_t bufsize)
    2203                 :            : {
    2204      [ +  +  - ]:         12 :     switch (reason) {
    2205                 :            :     case OFPRFR_GROUP_MOD:
    2206                 :          6 :         return "group_mod_request";
    2207                 :            : 
    2208                 :            :     case OFPRFR_METER_MOD:
    2209                 :          6 :         return "meter_mod_request";
    2210                 :            : 
    2211                 :            :     case OFPRFR_N_REASONS:
    2212                 :            :     default:
    2213                 :          0 :         snprintf(reasonbuf, bufsize, "%d", (int) reason);
    2214                 :          0 :         return reasonbuf;
    2215                 :            :     }
    2216                 :            : }
    2217                 :            : 
    2218                 :            : static const char *
    2219                 :        212 : ofp_async_config_reason_to_string(uint32_t reason,
    2220                 :            :                                   enum ofputil_async_msg_type type,
    2221                 :            :                                   char *reasonbuf, size_t bufsize)
    2222                 :            : {
    2223   [ +  +  +  -  :        212 :     switch (type) {
                +  +  - ]
    2224                 :            :     case OAM_PACKET_IN:
    2225                 :         80 :         return ofputil_packet_in_reason_to_string(reason, reasonbuf, bufsize);
    2226                 :            : 
    2227                 :            :     case OAM_PORT_STATUS:
    2228                 :         57 :         return ofp_port_reason_to_string(reason, reasonbuf, bufsize);
    2229                 :            : 
    2230                 :            :     case OAM_FLOW_REMOVED:
    2231                 :         59 :         return ofp_flow_removed_reason_to_string(reason, reasonbuf, bufsize);
    2232                 :            : 
    2233                 :            :     case OAM_ROLE_STATUS:
    2234                 :          0 :         return ofp_role_reason_to_string(reason, reasonbuf, bufsize);
    2235                 :            : 
    2236                 :            :     case OAM_TABLE_STATUS:
    2237                 :          4 :         return ofp_table_reason_to_string(reason, reasonbuf, bufsize);
    2238                 :            : 
    2239                 :            :     case OAM_REQUESTFORWARD:
    2240                 :         12 :         return ofp_requestforward_reason_to_string(reason, reasonbuf, bufsize);
    2241                 :            : 
    2242                 :            :     case OAM_N_TYPES:
    2243                 :            :     default:
    2244                 :          0 :         return "Unknown asynchronous configuration message type";
    2245                 :            :     }
    2246                 :            : }
    2247                 :            : 
    2248                 :            : 
    2249                 :            : #define OFP_ASYNC_CONFIG_REASON_BUFSIZE (INT_STRLEN(int) + 1)
    2250                 :            : static void
    2251                 :         23 : ofp_print_set_async_config(struct ds *string, const struct ofp_header *oh,
    2252                 :            :                            enum ofptype type)
    2253                 :            : {
    2254                 :         23 :     struct ofputil_async_cfg basis = OFPUTIL_ASYNC_CFG_INIT;
    2255                 :            :     struct ofputil_async_cfg ac;
    2256                 :            : 
    2257                 :         23 :     bool is_reply = type == OFPTYPE_GET_ASYNC_REPLY;
    2258                 :         23 :     enum ofperr error = ofputil_decode_set_async_config(oh, is_reply,
    2259                 :            :                                                         &basis, &ac);
    2260         [ +  + ]:         23 :     if (error) {
    2261                 :          2 :         ofp_print_error(string, error);
    2262                 :          2 :         return;
    2263                 :            :     }
    2264                 :            : 
    2265         [ +  + ]:         63 :     for (int i = 0; i < 2; i++) {
    2266         [ +  + ]:         42 :         ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
    2267         [ +  + ]:        294 :         for (uint32_t type = 0; type < OAM_N_TYPES; type++) {
    2268                 :        252 :             ds_put_format(string, "%16s:",
    2269                 :            :                           ofputil_async_msg_type_to_string(type));
    2270                 :            : 
    2271         [ +  + ]:        252 :             uint32_t role = i == 0 ? ac.master[type] : ac.slave[type];
    2272         [ +  + ]:       8316 :             for (int j = 0; j < 32; j++) {
    2273         [ +  + ]:       8064 :                 if (role & (1u << j)) {
    2274                 :            :                     char reasonbuf[OFP_ASYNC_CONFIG_REASON_BUFSIZE];
    2275                 :            :                     const char *reason;
    2276                 :            : 
    2277                 :        212 :                     reason = ofp_async_config_reason_to_string(
    2278                 :            :                         j, type, reasonbuf, sizeof reasonbuf);
    2279         [ +  + ]:        212 :                     if (reason[0]) {
    2280                 :        212 :                         ds_put_format(string, " %s", reason);
    2281                 :            :                     }
    2282                 :            :                 }
    2283                 :            :             }
    2284         [ +  + ]:        252 :             if (!role) {
    2285                 :        152 :                 ds_put_cstr(string, " (off)");
    2286                 :            :             }
    2287                 :        252 :             ds_put_char(string, '\n');
    2288                 :            :         }
    2289                 :            :     }
    2290                 :            : }
    2291                 :            : 
    2292                 :            : static void
    2293                 :         17 : ofp_print_nxt_set_controller_id(struct ds *string,
    2294                 :            :                                 const struct nx_controller_id *nci)
    2295                 :            : {
    2296                 :         17 :     ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
    2297                 :         17 : }
    2298                 :            : 
    2299                 :            : static void
    2300                 :          1 : ofp_print_nxt_flow_monitor_cancel(struct ds *string,
    2301                 :            :                                   const struct ofp_header *oh)
    2302                 :            : {
    2303                 :          1 :     ds_put_format(string, " id=%"PRIu32,
    2304                 :            :                   ofputil_decode_flow_monitor_cancel(oh));
    2305                 :          1 : }
    2306                 :            : 
    2307                 :            : static const char *
    2308                 :         30 : nx_flow_monitor_flags_to_name(uint32_t bit)
    2309                 :            : {
    2310                 :         30 :     enum nx_flow_monitor_flags fmf = bit;
    2311                 :            : 
    2312   [ +  +  +  +  :         30 :     switch (fmf) {
                +  +  - ]
    2313                 :          5 :     case NXFMF_INITIAL: return "initial";
    2314                 :          5 :     case NXFMF_ADD: return "add";
    2315                 :          6 :     case NXFMF_DELETE: return "delete";
    2316                 :          5 :     case NXFMF_MODIFY: return "modify";
    2317                 :          5 :     case NXFMF_ACTIONS: return "actions";
    2318                 :          4 :     case NXFMF_OWN: return "own";
    2319                 :            :     }
    2320                 :            : 
    2321                 :          0 :     return NULL;
    2322                 :            : }
    2323                 :            : 
    2324                 :            : static void
    2325                 :          5 : ofp_print_nxst_flow_monitor_request(struct ds *string,
    2326                 :            :                                     const struct ofp_header *oh)
    2327                 :            : {
    2328                 :          5 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    2329                 :            :     for (;;) {
    2330                 :            :         struct ofputil_flow_monitor_request request;
    2331                 :            :         int retval;
    2332                 :            : 
    2333                 :         11 :         retval = ofputil_decode_flow_monitor_request(&request, &b);
    2334         [ +  + ]:         11 :         if (retval) {
    2335         [ -  + ]:          5 :             if (retval != EOF) {
    2336                 :          0 :                 ofp_print_error(string, retval);
    2337                 :            :             }
    2338                 :          5 :             return;
    2339                 :            :         }
    2340                 :            : 
    2341                 :          6 :         ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
    2342                 :          6 :         ofp_print_bit_names(string, request.flags,
    2343                 :            :                             nx_flow_monitor_flags_to_name, ',');
    2344                 :            : 
    2345         [ +  + ]:          6 :         if (request.out_port != OFPP_NONE) {
    2346                 :          2 :             ds_put_cstr(string, " out_port=");
    2347                 :          2 :             ofputil_format_port(request.out_port, string);
    2348                 :            :         }
    2349                 :            : 
    2350         [ +  + ]:          6 :         if (request.table_id != 0xff) {
    2351                 :          2 :             ds_put_format(string, " table=%"PRIu8, request.table_id);
    2352                 :            :         }
    2353                 :            : 
    2354                 :          6 :         ds_put_char(string, ' ');
    2355                 :          6 :         match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
    2356                 :          6 :         ds_chomp(string, ' ');
    2357                 :          6 :     }
    2358                 :            : }
    2359                 :            : 
    2360                 :            : static void
    2361                 :      17884 : ofp_print_nxst_flow_monitor_reply(struct ds *string,
    2362                 :            :                                   const struct ofp_header *oh)
    2363                 :            : {
    2364                 :            :     uint64_t ofpacts_stub[1024 / 8];
    2365                 :      17884 :     struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
    2366                 :      17884 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    2367                 :            : 
    2368                 :            :     for (;;) {
    2369                 :            :         char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
    2370                 :            :         struct ofputil_flow_update update;
    2371                 :            :         struct match match;
    2372                 :            :         int retval;
    2373                 :            : 
    2374                 :      41037 :         update.match = &match;
    2375                 :      41037 :         retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
    2376         [ +  + ]:      41037 :         if (retval) {
    2377         [ -  + ]:      17884 :             if (retval != EOF) {
    2378                 :          0 :                 ofp_print_error(string, retval);
    2379                 :            :             }
    2380                 :      17884 :             ofpbuf_uninit(&ofpacts);
    2381                 :      17884 :             return;
    2382                 :            :         }
    2383                 :            : 
    2384                 :      23153 :         ds_put_cstr(string, "\n event=");
    2385   [ +  +  +  +  :      23153 :         switch (update.event) {
                      - ]
    2386                 :            :         case NXFME_ADDED:
    2387                 :      17857 :             ds_put_cstr(string, "ADDED");
    2388                 :      17857 :             break;
    2389                 :            : 
    2390                 :            :         case NXFME_DELETED:
    2391                 :       5271 :             ds_put_format(string, "DELETED reason=%s",
    2392                 :            :                           ofp_flow_removed_reason_to_string(update.reason,
    2393                 :            :                                                             reasonbuf,
    2394                 :            :                                                             sizeof reasonbuf));
    2395                 :       5271 :             break;
    2396                 :            : 
    2397                 :            :         case NXFME_MODIFIED:
    2398                 :         22 :             ds_put_cstr(string, "MODIFIED");
    2399                 :         22 :             break;
    2400                 :            : 
    2401                 :            :         case NXFME_ABBREV:
    2402                 :          3 :             ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
    2403                 :          3 :             continue;
    2404                 :            :         }
    2405                 :            : 
    2406                 :      23150 :         ds_put_format(string, " table=%"PRIu8, update.table_id);
    2407         [ +  + ]:      23150 :         if (update.idle_timeout != OFP_FLOW_PERMANENT) {
    2408                 :          1 :             ds_put_format(string, " idle_timeout=%"PRIu16,
    2409                 :          1 :                           update.idle_timeout);
    2410                 :            :         }
    2411         [ +  + ]:      23150 :         if (update.hard_timeout != OFP_FLOW_PERMANENT) {
    2412                 :          1 :             ds_put_format(string, " hard_timeout=%"PRIu16,
    2413                 :          1 :                           update.hard_timeout);
    2414                 :            :         }
    2415                 :      23150 :         ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
    2416                 :            : 
    2417                 :      23150 :         ds_put_char(string, ' ');
    2418                 :      23150 :         match_format(update.match, string, OFP_DEFAULT_PRIORITY);
    2419                 :            : 
    2420         [ +  + ]:      23150 :         if (update.ofpacts_len) {
    2421         [ +  - ]:        110 :             if (string->string[string->length - 1] != ' ') {
    2422                 :        110 :                 ds_put_char(string, ' ');
    2423                 :            :             }
    2424                 :        110 :             ds_put_cstr(string, "actions=");
    2425                 :      23150 :             ofpacts_format(update.ofpacts, update.ofpacts_len, string);
    2426                 :            :         }
    2427                 :      23153 :     }
    2428                 :            : }
    2429                 :            : 
    2430                 :            : void
    2431                 :     100415 : ofp_print_version(const struct ofp_header *oh,
    2432                 :            :                   struct ds *string)
    2433                 :            : {
    2434   [ +  +  +  +  :     100415 :     switch (oh->version) {
             +  +  +  + ]
    2435                 :            :     case OFP10_VERSION:
    2436                 :      61310 :         break;
    2437                 :            :     case OFP11_VERSION:
    2438                 :        516 :         ds_put_cstr(string, " (OF1.1)");
    2439                 :        516 :         break;
    2440                 :            :     case OFP12_VERSION:
    2441                 :       1590 :         ds_put_cstr(string, " (OF1.2)");
    2442                 :       1590 :         break;
    2443                 :            :     case OFP13_VERSION:
    2444                 :      31209 :         ds_put_cstr(string, " (OF1.3)");
    2445                 :      31209 :         break;
    2446                 :            :     case OFP14_VERSION:
    2447                 :       3241 :         ds_put_cstr(string, " (OF1.4)");
    2448                 :       3241 :         break;
    2449                 :            :     case OFP15_VERSION:
    2450                 :        848 :         ds_put_cstr(string, " (OF1.5)");
    2451                 :        848 :         break;
    2452                 :            :     case OFP16_VERSION:
    2453                 :       1697 :         ds_put_cstr(string, " (OF1.6)");
    2454                 :       1697 :         break;
    2455                 :            :     default:
    2456                 :          4 :         ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
    2457                 :          4 :         break;
    2458                 :            :     }
    2459                 :     100415 :     ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
    2460                 :     100415 : }
    2461                 :            : 
    2462                 :            : static void
    2463                 :     100415 : ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
    2464                 :            :                        struct ds *string)
    2465                 :            : {
    2466                 :     100415 :     ds_put_cstr(string, ofpraw_get_name(raw));
    2467                 :     100415 :     ofp_print_version(oh, string);
    2468                 :     100415 : }
    2469                 :            : 
    2470                 :            : static void
    2471                 :        554 : ofp_print_bucket_id(struct ds *s, const char *label, uint32_t bucket_id,
    2472                 :            :                     enum ofp_version ofp_version)
    2473                 :            : {
    2474         [ +  + ]:        554 :     if (ofp_version < OFP15_VERSION) {
    2475                 :        149 :         return;
    2476                 :            :     }
    2477                 :            : 
    2478                 :        405 :     ds_put_cstr(s, label);
    2479                 :            : 
    2480   [ +  +  +  + ]:        405 :     switch (bucket_id) {
    2481                 :            :     case OFPG15_BUCKET_FIRST:
    2482                 :          9 :         ds_put_cstr(s, "first");
    2483                 :          9 :         break;
    2484                 :            :     case OFPG15_BUCKET_LAST:
    2485                 :         11 :         ds_put_cstr(s, "last");
    2486                 :         11 :         break;
    2487                 :            :     case OFPG15_BUCKET_ALL:
    2488                 :          4 :         ds_put_cstr(s, "all");
    2489                 :          4 :         break;
    2490                 :            :     default:
    2491                 :        381 :         ds_put_format(s, "%"PRIu32, bucket_id);
    2492                 :        381 :         break;
    2493                 :            :     }
    2494                 :            : 
    2495                 :        405 :     ds_put_char(s, ',');
    2496                 :            : }
    2497                 :            : 
    2498                 :            : static void
    2499                 :        321 : ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
    2500                 :            :                 const struct ovs_list *p_buckets,
    2501                 :            :                 const struct ofputil_group_props *props,
    2502                 :            :                 enum ofp_version ofp_version, bool suppress_type)
    2503                 :            : {
    2504                 :            :     struct ofputil_bucket *bucket;
    2505                 :            : 
    2506                 :        321 :     ds_put_format(s, "group_id=%"PRIu32, group_id);
    2507                 :            : 
    2508         [ +  + ]:        321 :     if (!suppress_type) {
    2509                 :            :         static const char *type_str[] = { "all", "select", "indirect",
    2510                 :            :                                           "ff", "unknown" };
    2511         [ +  - ]:        283 :         ds_put_format(s, ",type=%s", type_str[type > 4 ? 4 : type]);
    2512                 :            :     }
    2513                 :            : 
    2514         [ +  + ]:        321 :     if (props->selection_method[0]) {
    2515                 :         18 :         ds_put_format(s, ",selection_method=%s", props->selection_method);
    2516         [ +  + ]:         18 :         if (props->selection_method_param) {
    2517                 :          1 :             ds_put_format(s, ",selection_method_param=%"PRIu64,
    2518                 :            :                           props->selection_method_param);
    2519                 :            :         }
    2520                 :            : 
    2521                 :         18 :         size_t n = bitmap_count1(props->fields.used.bm, MFF_N_IDS);
    2522         [ -  + ]:         18 :         if (n == 1) {
    2523                 :          0 :             ds_put_cstr(s, ",fields=");
    2524                 :          0 :             oxm_format_field_array(s, &props->fields);
    2525         [ +  + ]:         18 :         } else if (n > 1) {
    2526                 :          7 :             ds_put_cstr(s, ",fields(");
    2527                 :          7 :             oxm_format_field_array(s, &props->fields);
    2528                 :          7 :             ds_put_char(s, ')');
    2529                 :            :         }
    2530                 :            :     }
    2531                 :            : 
    2532         [ -  + ]:        321 :     if (!p_buckets) {
    2533                 :          0 :         return;
    2534                 :            :     }
    2535                 :            : 
    2536                 :        321 :     ds_put_char(s, ',');
    2537                 :            : 
    2538         [ +  + ]:        837 :     LIST_FOR_EACH (bucket, list_node, p_buckets) {
    2539                 :        516 :         ds_put_cstr(s, "bucket=");
    2540                 :            : 
    2541                 :        516 :         ofp_print_bucket_id(s, "bucket_id:", bucket->bucket_id, ofp_version);
    2542         [ +  + ]:        516 :         if (bucket->weight != (type == OFPGT11_SELECT ? 1 : 0)) {
    2543                 :         77 :             ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
    2544                 :            :         }
    2545         [ +  + ]:        516 :         if (bucket->watch_port != OFPP_NONE) {
    2546                 :         15 :             ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
    2547                 :            :         }
    2548         [ -  + ]:        516 :         if (bucket->watch_group != OFPG_ANY) {
    2549                 :          0 :             ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
    2550                 :            :         }
    2551                 :            : 
    2552                 :        516 :         ds_put_cstr(s, "actions=");
    2553                 :        516 :         ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
    2554                 :        516 :         ds_put_char(s, ',');
    2555                 :            :     }
    2556                 :            : 
    2557                 :        321 :     ds_chomp(s, ',');
    2558                 :            : }
    2559                 :            : 
    2560                 :            : static void
    2561                 :         54 : ofp_print_ofpst_group_desc_request(struct ds *string,
    2562                 :            :                                    const struct ofp_header *oh)
    2563                 :            : {
    2564                 :         54 :     uint32_t group_id = ofputil_decode_group_desc_request(oh);
    2565                 :         54 :     ds_put_cstr(string, " group_id=");
    2566                 :         54 :     ofputil_format_group(group_id, string);
    2567                 :         54 : }
    2568                 :            : 
    2569                 :            : static void
    2570                 :        106 : ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
    2571                 :            : {
    2572                 :        106 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    2573                 :            :     for (;;) {
    2574                 :            :         struct ofputil_group_desc gd;
    2575                 :            :         int retval;
    2576                 :            : 
    2577                 :        220 :         retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
    2578         [ +  + ]:        220 :         if (retval) {
    2579         [ -  + ]:        106 :             if (retval != EOF) {
    2580                 :          0 :                 ds_put_cstr(s, " ***parse error***");
    2581                 :            :             }
    2582                 :        106 :             break;
    2583                 :            :         }
    2584                 :            : 
    2585                 :        114 :         ds_put_char(s, '\n');
    2586                 :        114 :         ds_put_char(s, ' ');
    2587                 :        114 :         ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, &gd.props,
    2588                 :        114 :                         oh->version, false);
    2589                 :        114 :         ofputil_uninit_group_desc(&gd);
    2590                 :        114 :      }
    2591                 :        106 : }
    2592                 :            : 
    2593                 :            : static void
    2594                 :          9 : ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
    2595                 :            : {
    2596                 :            :     enum ofperr error;
    2597                 :            :     uint32_t group_id;
    2598                 :            : 
    2599                 :          9 :     error = ofputil_decode_group_stats_request(oh, &group_id);
    2600         [ -  + ]:          9 :     if (error) {
    2601                 :          0 :         ofp_print_error(string, error);
    2602                 :          0 :         return;
    2603                 :            :     }
    2604                 :            : 
    2605                 :          9 :     ds_put_cstr(string, " group_id=");
    2606                 :          9 :     ofputil_format_group(group_id, string);
    2607                 :            : }
    2608                 :            : 
    2609                 :            : static void
    2610                 :         20 : ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
    2611                 :            : {
    2612                 :         20 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    2613                 :            :     for (;;) {
    2614                 :            :         struct ofputil_group_stats gs;
    2615                 :            :         int retval;
    2616                 :            : 
    2617                 :         48 :         retval = ofputil_decode_group_stats_reply(&b, &gs);
    2618         [ +  + ]:         48 :         if (retval) {
    2619         [ -  + ]:         20 :             if (retval != EOF) {
    2620                 :          0 :                 ds_put_cstr(s, " ***parse error***");
    2621                 :            :             }
    2622                 :         20 :             break;
    2623                 :            :         }
    2624                 :            : 
    2625                 :         28 :         ds_put_char(s, '\n');
    2626                 :            : 
    2627                 :         28 :         ds_put_char(s, ' ');
    2628                 :         28 :         ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
    2629                 :            : 
    2630         [ +  + ]:         28 :         if (gs.duration_sec != UINT32_MAX) {
    2631                 :         18 :             ds_put_cstr(s, "duration=");
    2632                 :         18 :             ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
    2633                 :         18 :             ds_put_char(s, ',');
    2634                 :            :         }
    2635                 :         28 :         ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
    2636                 :         28 :         ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
    2637                 :         28 :         ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
    2638                 :            : 
    2639         [ +  + ]:         72 :         for (uint32_t bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
    2640         [ +  - ]:         44 :             if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
    2641                 :         44 :                 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
    2642                 :         44 :                 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
    2643                 :         44 :                 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
    2644                 :            :             }
    2645                 :            :         }
    2646                 :            : 
    2647                 :         28 :         free(gs.bucket_stats);
    2648                 :         28 :      }
    2649                 :         20 : }
    2650                 :            : 
    2651                 :            : static const char *
    2652                 :         12 : group_type_to_string(enum ofp11_group_type type)
    2653                 :            : {
    2654   [ +  +  +  +  :         12 :     switch (type) {
                      - ]
    2655                 :          3 :     case OFPGT11_ALL: return "all";
    2656                 :          3 :     case OFPGT11_SELECT: return "select";
    2657                 :          3 :     case OFPGT11_INDIRECT: return "indirect";
    2658                 :          3 :     case OFPGT11_FF: return "fast failover";
    2659                 :          0 :     default: OVS_NOT_REACHED();
    2660                 :            :     }
    2661                 :            : }
    2662                 :            : 
    2663                 :            : static void
    2664                 :          3 : ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
    2665                 :            : {
    2666                 :            :     struct ofputil_group_features features;
    2667                 :            :     int i;
    2668                 :            : 
    2669                 :          3 :     ofputil_decode_group_features_reply(oh, &features);
    2670                 :            : 
    2671                 :          3 :     ds_put_format(string, "\n Group table:\n");
    2672                 :          3 :     ds_put_format(string, "    Types:  0x%"PRIx32"\n", features.types);
    2673                 :          3 :     ds_put_format(string, "    Capabilities:  0x%"PRIx32"\n",
    2674                 :            :                   features.capabilities);
    2675                 :            : 
    2676         [ +  + ]:         15 :     for (i = 0; i < OFPGT12_N_TYPES; i++) {
    2677         [ +  - ]:         12 :         if (features.types & (1u << i)) {
    2678                 :         12 :             ds_put_format(string, "    %s group:\n", group_type_to_string(i));
    2679                 :         12 :             ds_put_format(string, "       max_groups=%#"PRIx32"\n",
    2680                 :            :                           features.max_groups[i]);
    2681                 :         12 :             ds_put_format(string, "       actions: ");
    2682                 :         12 :             ofpact_bitmap_format(features.ofpacts[i], string);
    2683                 :         12 :             ds_put_char(string, '\n');
    2684                 :            :         }
    2685                 :            :     }
    2686                 :          3 : }
    2687                 :            : 
    2688                 :            : static void
    2689                 :        207 : ofp_print_group_mod__(struct ds *s, enum ofp_version ofp_version,
    2690                 :            :                       const struct ofputil_group_mod *gm)
    2691                 :            : {
    2692                 :        207 :     bool bucket_command = false;
    2693                 :            : 
    2694                 :        207 :     ds_put_char(s, '\n');
    2695                 :            : 
    2696                 :        207 :     ds_put_char(s, ' ');
    2697   [ +  +  +  +  :        207 :     switch (gm->command) {
                +  +  - ]
    2698                 :            :     case OFPGC11_ADD:
    2699                 :         74 :         ds_put_cstr(s, "ADD");
    2700                 :         74 :         break;
    2701                 :            : 
    2702                 :            :     case OFPGC11_MODIFY:
    2703                 :         13 :         ds_put_cstr(s, "MOD");
    2704                 :         13 :         break;
    2705                 :            : 
    2706                 :            :     case OFPGC11_ADD_OR_MOD:
    2707                 :          4 :         ds_put_cstr(s, "ADD_OR_MOD");
    2708                 :          4 :         break;
    2709                 :            : 
    2710                 :            :     case OFPGC11_DELETE:
    2711                 :         78 :         ds_put_cstr(s, "DEL");
    2712                 :         78 :         break;
    2713                 :            : 
    2714                 :            :     case OFPGC15_INSERT_BUCKET:
    2715                 :         18 :         ds_put_cstr(s, "INSERT_BUCKET");
    2716                 :         18 :         bucket_command = true;
    2717                 :         18 :         break;
    2718                 :            : 
    2719                 :            :     case OFPGC15_REMOVE_BUCKET:
    2720                 :         20 :         ds_put_cstr(s, "REMOVE_BUCKET");
    2721                 :         20 :         bucket_command = true;
    2722                 :         20 :         break;
    2723                 :            : 
    2724                 :            :     default:
    2725                 :          0 :         ds_put_format(s, "cmd:%"PRIu16"", gm->command);
    2726                 :            :     }
    2727                 :        207 :     ds_put_char(s, ' ');
    2728                 :            : 
    2729         [ +  + ]:        207 :     if (bucket_command) {
    2730                 :         38 :         ofp_print_bucket_id(s, "command_bucket_id:",
    2731                 :            :                             gm->command_bucket_id, ofp_version);
    2732                 :            :     }
    2733                 :            : 
    2734                 :        207 :     ofp_print_group(s, gm->group_id, gm->type, &gm->buckets, &gm->props,
    2735                 :            :                     ofp_version, bucket_command);
    2736                 :        207 : }
    2737                 :            : 
    2738                 :            : static void
    2739                 :        203 : ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
    2740                 :            : {
    2741                 :            :     struct ofputil_group_mod gm;
    2742                 :            :     int error;
    2743                 :            : 
    2744                 :        203 :     error = ofputil_decode_group_mod(oh, &gm);
    2745         [ +  + ]:        203 :     if (error) {
    2746                 :          6 :         ofp_print_error(s, error);
    2747                 :          6 :         return;
    2748                 :            :     }
    2749                 :        197 :     ofp_print_group_mod__(s, oh->version, &gm);
    2750                 :        197 :     ofputil_uninit_group_mod(&gm);
    2751                 :            : }
    2752                 :            : 
    2753                 :            : static void
    2754                 :         42 : print_table_action_features(struct ds *s,
    2755                 :            :                             const struct ofputil_table_action_features *taf)
    2756                 :            : {
    2757         [ +  + ]:         42 :     if (taf->ofpacts) {
    2758                 :         41 :         ds_put_cstr(s, "        actions: ");
    2759                 :         41 :         ofpact_bitmap_format(taf->ofpacts, s);
    2760                 :         41 :         ds_put_char(s, '\n');
    2761                 :            :     }
    2762                 :            : 
    2763         [ +  - ]:         42 :     if (!bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS)) {
    2764                 :            :         int i;
    2765                 :            : 
    2766                 :         42 :         ds_put_cstr(s, "        supported on Set-Field:");
    2767         [ +  + ]:       5326 :         BITMAP_FOR_EACH_1 (i, MFF_N_IDS, taf->set_fields.bm) {
    2768                 :       5284 :             ds_put_format(s, " %s", mf_from_id(i)->name);
    2769                 :            :         }
    2770                 :         42 :         ds_put_char(s, '\n');
    2771                 :            :     }
    2772                 :         42 : }
    2773                 :            : 
    2774                 :            : static bool
    2775                 :      25342 : table_action_features_equal(const struct ofputil_table_action_features *a,
    2776                 :            :                             const struct ofputil_table_action_features *b)
    2777                 :            : {
    2778                 :      25342 :     return (a->ofpacts == b->ofpacts
    2779 [ +  - ][ +  - ]:      25342 :             && bitmap_equal(a->set_fields.bm, b->set_fields.bm, MFF_N_IDS));
    2780                 :            : }
    2781                 :            : 
    2782                 :            : static bool
    2783                 :         88 : table_action_features_empty(const struct ofputil_table_action_features *taf)
    2784                 :            : {
    2785 [ +  - ][ +  - ]:         88 :     return !taf->ofpacts && bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS);
    2786                 :            : }
    2787                 :            : 
    2788                 :            : static void
    2789                 :       1026 : print_table_instruction_features(
    2790                 :            :     struct ds *s,
    2791                 :            :     const struct ofputil_table_instruction_features *tif,
    2792                 :            :     const struct ofputil_table_instruction_features *prev_tif)
    2793                 :            : {
    2794                 :            :     int start, end;
    2795                 :            : 
    2796         [ +  + ]:       1026 :     if (!bitmap_is_all_zeros(tif->next, 255)) {
    2797                 :       1013 :         ds_put_cstr(s, "      next tables: ");
    2798         [ +  + ]:       2026 :         for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
    2799                 :       1013 :              start = bitmap_scan(tif->next, 1, end, 255)) {
    2800                 :       1013 :             end = bitmap_scan(tif->next, 0, start + 1, 255);
    2801         [ +  + ]:       1013 :             if (end == start + 1) {
    2802                 :          4 :                 ds_put_format(s, "%d,", start);
    2803                 :            :             } else {
    2804                 :       1009 :                 ds_put_format(s, "%d-%d,", start, end - 1);
    2805                 :            :             }
    2806                 :            :         }
    2807                 :       1013 :         ds_chomp(s, ',');
    2808         [ -  + ]:       1013 :         if (ds_last(s) == ' ') {
    2809                 :          0 :             ds_put_cstr(s, "none");
    2810                 :            :         }
    2811                 :       1013 :         ds_put_char(s, '\n');
    2812                 :            :     }
    2813                 :            : 
    2814         [ +  - ]:       1026 :     if (tif->instructions) {
    2815 [ +  + ][ +  + ]:       1026 :         if (prev_tif && tif->instructions == prev_tif->instructions) {
    2816                 :        976 :             ds_put_cstr(s, "      (same instructions)\n");
    2817                 :            :         } else {
    2818                 :         50 :             ds_put_cstr(s, "      instructions: ");
    2819                 :            :             int i;
    2820                 :            : 
    2821         [ +  + ]:       1650 :             for (i = 0; i < 32; i++) {
    2822         [ +  + ]:       1600 :                 if (tif->instructions & (1u << i)) {
    2823                 :        279 :                     ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
    2824                 :            :                 }
    2825                 :            :             }
    2826                 :         50 :             ds_chomp(s, ',');
    2827                 :         50 :             ds_put_char(s, '\n');
    2828                 :            :         }
    2829                 :            :     }
    2830                 :            : 
    2831         [ +  + ]:       1026 :     if (prev_tif
    2832         [ +  - ]:        984 :         && table_action_features_equal(&tif->write, &prev_tif->write)
    2833         [ +  - ]:        984 :         && table_action_features_equal(&tif->apply, &prev_tif->apply)
    2834         [ +  - ]:        984 :         && !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
    2835                 :        984 :         ds_put_cstr(s, "      (same actions)\n");
    2836         [ -  + ]:         42 :     } else if (!table_action_features_equal(&tif->write, &tif->apply)) {
    2837                 :          0 :         ds_put_cstr(s, "      Write-Actions features:\n");
    2838                 :          0 :         print_table_action_features(s, &tif->write);
    2839                 :          0 :         ds_put_cstr(s, "      Apply-Actions features:\n");
    2840                 :          0 :         print_table_action_features(s, &tif->apply);
    2841         [ +  + ]:         42 :     } else if (tif->write.ofpacts
    2842         [ +  - ]:          1 :                || !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
    2843                 :         42 :         ds_put_cstr(s, "      Write-Actions and Apply-Actions features:\n");
    2844                 :         42 :         print_table_action_features(s, &tif->write);
    2845                 :            :     }
    2846                 :       1026 : }
    2847                 :            : 
    2848                 :            : static bool
    2849                 :      13630 : table_instruction_features_equal(
    2850                 :            :     const struct ofputil_table_instruction_features *a,
    2851                 :            :     const struct ofputil_table_instruction_features *b)
    2852                 :            : {
    2853                 :      27260 :     return (bitmap_equal(a->next, b->next, 255)
    2854         [ +  + ]:      11674 :             && a->instructions == b->instructions
    2855         [ +  - ]:      11666 :             && table_action_features_equal(&a->write, &b->write)
    2856 [ +  + ][ +  - ]:      25304 :             && table_action_features_equal(&a->apply, &b->apply));
    2857                 :            : }
    2858                 :            : 
    2859                 :            : static bool
    2860                 :       1074 : table_instruction_features_empty(
    2861                 :            :     const struct ofputil_table_instruction_features *tif)
    2862                 :            : {
    2863                 :       2148 :     return (bitmap_is_all_zeros(tif->next, 255)
    2864         [ +  + ]:         61 :             && !tif->instructions
    2865         [ +  - ]:         44 :             && table_action_features_empty(&tif->write)
    2866 [ +  + ][ +  - ]:       1135 :             && table_action_features_empty(&tif->apply));
    2867                 :            : }
    2868                 :            : 
    2869                 :            : static bool
    2870                 :       6295 : table_features_equal(const struct ofputil_table_features *a,
    2871                 :            :                      const struct ofputil_table_features *b)
    2872                 :            : {
    2873                 :       6295 :     return (a->metadata_match == b->metadata_match
    2874         [ +  - ]:       6295 :             && a->metadata_write == b->metadata_write
    2875         [ +  - ]:       6295 :             && a->miss_config == b->miss_config
    2876         [ +  - ]:       6295 :             && a->supports_eviction == b->supports_eviction
    2877         [ +  - ]:       6295 :             && a->supports_vacancy_events == b->supports_vacancy_events
    2878         [ +  + ]:       6295 :             && a->max_entries == b->max_entries
    2879         [ +  + ]:       6283 :             && table_instruction_features_equal(&a->nonmiss, &b->nonmiss)
    2880         [ +  - ]:       5303 :             && table_instruction_features_equal(&a->miss, &b->miss)
    2881 [ +  - ][ +  - ]:      12590 :             && bitmap_equal(a->match.bm, b->match.bm, MFF_N_IDS));
    2882                 :            : }
    2883                 :            : 
    2884                 :            : static bool
    2885                 :         13 : table_features_empty(const struct ofputil_table_features *tf)
    2886                 :            : {
    2887                 :         13 :     return (!tf->metadata_match
    2888         [ +  - ]:         13 :             && !tf->metadata_write
    2889         [ +  + ]:         13 :             && tf->miss_config == OFPUTIL_TABLE_MISS_DEFAULT
    2890         [ +  - ]:         11 :             && tf->supports_eviction < 0
    2891         [ +  - ]:         11 :             && tf->supports_vacancy_events < 0
    2892         [ +  - ]:         11 :             && !tf->max_entries
    2893         [ +  - ]:         11 :             && table_instruction_features_empty(&tf->nonmiss)
    2894         [ +  - ]:         11 :             && table_instruction_features_empty(&tf->miss)
    2895 [ +  - ][ +  - ]:         26 :             && bitmap_is_all_zeros(tf->match.bm, MFF_N_IDS));
    2896                 :            : }
    2897                 :            : 
    2898                 :            : static bool
    2899                 :       5315 : table_stats_equal(const struct ofputil_table_stats *a,
    2900                 :            :                   const struct ofputil_table_stats *b)
    2901                 :            : {
    2902                 :       5315 :     return (a->active_count == b->active_count
    2903         [ +  + ]:       5304 :             && a->lookup_count == b->lookup_count
    2904 [ +  + ][ +  - ]:      10619 :             && a->matched_count == b->matched_count);
    2905                 :            : }
    2906                 :            : 
    2907                 :            : void
    2908                 :       6355 : ofp_print_table_features(struct ds *s,
    2909                 :            :                          const struct ofputil_table_features *features,
    2910                 :            :                          const struct ofputil_table_features *prev_features,
    2911                 :            :                          const struct ofputil_table_stats *stats,
    2912                 :            :                          const struct ofputil_table_stats *prev_stats)
    2913                 :            : {
    2914                 :            :     int i;
    2915                 :            : 
    2916                 :       6355 :     ds_put_format(s, "  table %"PRIu8, features->table_id);
    2917         [ +  + ]:       6355 :     if (features->name[0]) {
    2918                 :       3813 :         ds_put_format(s, " (\"%s\")", features->name);
    2919                 :            :     }
    2920                 :       6355 :     ds_put_char(s, ':');
    2921                 :            : 
    2922 [ +  + ][ +  + ]:       6355 :     bool same_stats = prev_stats && table_stats_equal(stats, prev_stats);
    2923 [ +  + ][ +  + ]:       6355 :     bool same_features = prev_features && table_features_equal(features,
    2924                 :            :                                                                prev_features);
    2925 [ +  + ][ +  + ]:       6355 :     if ((!stats || same_stats) && same_features) {
                 [ +  + ]
    2926                 :       5290 :         ds_put_cstr(s, " ditto");
    2927                 :       5290 :         return;
    2928                 :            :     }
    2929                 :       1065 :     ds_put_char(s, '\n');
    2930         [ +  + ]:       1065 :     if (stats) {
    2931                 :         48 :         ds_put_format(s, "    active=%"PRIu32", ", stats->active_count);
    2932                 :         48 :         ds_put_format(s, "lookup=%"PRIu64", ", stats->lookup_count);
    2933                 :         48 :         ds_put_format(s, "matched=%"PRIu64"\n", stats->matched_count);
    2934                 :            :     }
    2935         [ +  + ]:       1065 :     if (same_features) {
    2936         [ +  + ]:         13 :         if (!table_features_empty(features)) {
    2937                 :          2 :             ds_put_cstr(s, "    (same features)\n");
    2938                 :            :         }
    2939                 :         13 :         return;
    2940                 :            :     }
    2941 [ +  + ][ -  + ]:       1052 :     if (features->metadata_match || features->metadata_write) {
    2942                 :       1029 :         ds_put_format(s, "    metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
    2943                 :            :                       ntohll(features->metadata_match),
    2944                 :            :                       ntohll(features->metadata_write));
    2945                 :            :     }
    2946                 :            : 
    2947         [ +  + ]:       1052 :     if (features->miss_config != OFPUTIL_TABLE_MISS_DEFAULT) {
    2948                 :         13 :         ds_put_format(s, "    config=%s\n",
    2949                 :            :                       ofputil_table_miss_to_string(features->miss_config));
    2950                 :            :     }
    2951                 :            : 
    2952         [ -  + ]:       1052 :     if (features->supports_eviction >= 0) {
    2953         [ #  # ]:          0 :         ds_put_format(s, "    eviction: %ssupported\n",
    2954                 :          0 :                       features->supports_eviction ? "" : "not ");
    2955                 :            : 
    2956                 :            :     }
    2957         [ -  + ]:       1052 :     if (features->supports_vacancy_events >= 0) {
    2958         [ #  # ]:          0 :         ds_put_format(s, "    vacancy events: %ssupported\n",
    2959                 :          0 :                       features->supports_vacancy_events ? "" : "not ");
    2960                 :            : 
    2961                 :            :     }
    2962                 :            : 
    2963         [ +  + ]:       1052 :     if (features->max_entries) {
    2964                 :       1041 :         ds_put_format(s, "    max_entries=%"PRIu32"\n", features->max_entries);
    2965                 :            :     }
    2966                 :            : 
    2967                 :       1052 :     const struct ofputil_table_instruction_features *prev_nonmiss
    2968         [ +  + ]:       1052 :         = prev_features ? &prev_features->nonmiss : NULL;
    2969                 :       1052 :     const struct ofputil_table_instruction_features *prev_miss
    2970         [ +  + ]:       1052 :         = prev_features ? &prev_features->miss : NULL;
    2971         [ +  + ]:       1052 :     if (prev_features
    2972         [ +  + ]:        992 :         && table_instruction_features_equal(&features->nonmiss, prev_nonmiss)
    2973         [ +  - ]:          8 :         && table_instruction_features_equal(&features->miss, prev_miss)) {
    2974         [ +  + ]:         12 :         if (!table_instruction_features_empty(&features->nonmiss)) {
    2975                 :          4 :             ds_put_cstr(s, "    (same instructions)\n");
    2976                 :            :         }
    2977         [ -  + ]:       1044 :     } else if (!table_instruction_features_equal(&features->nonmiss,
    2978                 :            :                                                  &features->miss)) {
    2979                 :          0 :         ds_put_cstr(s, "    instructions (other than table miss):\n");
    2980                 :          0 :         print_table_instruction_features(s, &features->nonmiss, prev_nonmiss);
    2981                 :          0 :         ds_put_cstr(s, "    instructions (table miss):\n");
    2982                 :          0 :         print_table_instruction_features(s, &features->miss, prev_miss);
    2983         [ +  + ]:       1044 :     } else if (!table_instruction_features_empty(&features->nonmiss)) {
    2984                 :       1026 :         ds_put_cstr(s, "    instructions (table miss and others):\n");
    2985                 :       1026 :         print_table_instruction_features(s, &features->nonmiss, prev_nonmiss);
    2986                 :            :     }
    2987                 :            : 
    2988         [ +  + ]:       1052 :     if (!bitmap_is_all_zeros(features->match.bm, MFF_N_IDS)) {
    2989         [ +  + ]:       1041 :         if (prev_features
    2990         [ +  - ]:        992 :             && bitmap_equal(features->match.bm, prev_features->match.bm,
    2991                 :            :                             MFF_N_IDS)) {
    2992                 :        992 :             ds_put_cstr(s, "    (same matching)\n");
    2993                 :            :         } else {
    2994                 :         49 :             ds_put_cstr(s, "    matching:\n");
    2995         [ +  + ]:       5834 :             BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) {
    2996                 :       5785 :                 const struct mf_field *f = mf_from_id(i);
    2997                 :       5785 :                 bool mask = bitmap_is_set(features->mask.bm, i);
    2998                 :       5785 :                 bool wildcard = bitmap_is_set(features->wildcard.bm, i);
    2999                 :            : 
    3000         [ +  + ]:       6890 :                 ds_put_format(s, "      %s: %s\n",
    3001                 :            :                               f->name,
    3002                 :            :                               (mask ? "arbitrary mask"
    3003                 :            :                                : wildcard ? "exact match or wildcard"
    3004         [ +  - ]:       1105 :                                : "must exact match"));
    3005                 :            :             }
    3006                 :            :         }
    3007                 :            :     }
    3008                 :            : }
    3009                 :            : 
    3010                 :            : static void
    3011                 :         37 : ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh)
    3012                 :            : {
    3013                 :         37 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    3014                 :            : 
    3015                 :            :     struct ofputil_table_features prev;
    3016                 :         37 :     for (int i = 0; ; i++) {
    3017                 :            :         struct ofputil_table_features tf;
    3018                 :            :         int retval;
    3019                 :            : 
    3020                 :        546 :         retval = ofputil_decode_table_features(&b, &tf, true);
    3021         [ +  + ]:        546 :         if (retval) {
    3022         [ -  + ]:         37 :             if (retval != EOF) {
    3023                 :          0 :                 ofp_print_error(s, retval);
    3024                 :            :             }
    3025                 :         37 :             return;
    3026                 :            :         }
    3027                 :            : 
    3028                 :        509 :         ds_put_char(s, '\n');
    3029         [ +  + ]:        509 :         ofp_print_table_features(s, &tf, i ? &prev : NULL, NULL, NULL);
    3030                 :        509 :         prev = tf;
    3031                 :        509 :     }
    3032                 :            : }
    3033                 :            : 
    3034                 :            : static void
    3035                 :         23 : ofp_print_table_desc_reply(struct ds *s, const struct ofp_header *oh)
    3036                 :            : {
    3037                 :         23 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    3038                 :            :     for (;;) {
    3039                 :            :         struct ofputil_table_desc td;
    3040                 :            :         int retval;
    3041                 :            : 
    3042                 :       3325 :         retval = ofputil_decode_table_desc(&b, &td, oh->version);
    3043         [ +  + ]:       3325 :         if (retval) {
    3044         [ -  + ]:         23 :             if (retval != EOF) {
    3045                 :          0 :                 ofp_print_error(s, retval);
    3046                 :            :             }
    3047                 :         23 :             return;
    3048                 :            :         }
    3049                 :       3302 :         ofp_print_table_desc(s, &td);
    3050                 :       3302 :     }
    3051                 :            : }
    3052                 :            : 
    3053                 :            : static const char *
    3054                 :       2005 : bundle_flags_to_name(uint32_t bit)
    3055                 :            : {
    3056      [ +  +  - ]:       2005 :     switch (bit) {
    3057                 :            :     case OFPBF_ATOMIC:
    3058                 :        983 :         return "atomic";
    3059                 :            :     case OFPBF_ORDERED:
    3060                 :       1022 :         return "ordered";
    3061                 :            :     default:
    3062                 :          0 :         return NULL;
    3063                 :            :     }
    3064                 :            : }
    3065                 :            : 
    3066                 :            : static void
    3067                 :        587 : ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh)
    3068                 :            : {
    3069                 :            :     int error;
    3070                 :            :     struct ofputil_bundle_ctrl_msg bctrl;
    3071                 :            : 
    3072                 :        587 :     error = ofputil_decode_bundle_ctrl(oh, &bctrl);
    3073         [ -  + ]:        587 :     if (error) {
    3074                 :          0 :         ofp_print_error(s, error);
    3075                 :          0 :         return;
    3076                 :            :     }
    3077                 :            : 
    3078                 :        587 :     ds_put_char(s, '\n');
    3079                 :            : 
    3080                 :        587 :     ds_put_format(s, " bundle_id=%#"PRIx32" type=",  bctrl.bundle_id);
    3081   [ +  +  +  +  :        587 :     switch (bctrl.type) {
             +  +  +  +  
                      - ]
    3082                 :            :     case OFPBCT_OPEN_REQUEST:
    3083                 :        148 :         ds_put_cstr(s, "OPEN_REQUEST");
    3084                 :        148 :         break;
    3085                 :            :     case OFPBCT_OPEN_REPLY:
    3086                 :        138 :         ds_put_cstr(s, "OPEN_REPLY");
    3087                 :        138 :         break;
    3088                 :            :     case OFPBCT_CLOSE_REQUEST:
    3089                 :         29 :         ds_put_cstr(s, "CLOSE_REQUEST");
    3090                 :         29 :         break;
    3091                 :            :     case OFPBCT_CLOSE_REPLY:
    3092                 :          5 :         ds_put_cstr(s, "CLOSE_REPLY");
    3093                 :          5 :         break;
    3094                 :            :     case OFPBCT_COMMIT_REQUEST:
    3095                 :        141 :         ds_put_cstr(s, "COMMIT_REQUEST");
    3096                 :        141 :         break;
    3097                 :            :     case OFPBCT_COMMIT_REPLY:
    3098                 :        110 :         ds_put_cstr(s, "COMMIT_REPLY");
    3099                 :        110 :         break;
    3100                 :            :     case OFPBCT_DISCARD_REQUEST:
    3101                 :         12 :         ds_put_cstr(s, "DISCARD_REQUEST");
    3102                 :         12 :         break;
    3103                 :            :     case OFPBCT_DISCARD_REPLY:
    3104                 :          4 :         ds_put_cstr(s, "DISCARD_REPLY");
    3105                 :          4 :         break;
    3106                 :            :     }
    3107                 :            : 
    3108                 :        587 :     ds_put_cstr(s, " flags=");
    3109                 :        587 :     ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' ');
    3110                 :            : }
    3111                 :            : 
    3112                 :            : static void
    3113                 :        716 : ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
    3114                 :            : {
    3115                 :            :     int error;
    3116                 :            :     struct ofputil_bundle_add_msg badd;
    3117                 :            : 
    3118                 :        716 :     error = ofputil_decode_bundle_add(oh, &badd, NULL);
    3119         [ +  + ]:        716 :     if (error) {
    3120                 :          2 :         ofp_print_error(s, error);
    3121                 :          2 :         return;
    3122                 :            :     }
    3123                 :            : 
    3124                 :        714 :     ds_put_char(s, '\n');
    3125                 :        714 :     ds_put_format(s, " bundle_id=%#"PRIx32,  badd.bundle_id);
    3126                 :        714 :     ds_put_cstr(s, " flags=");
    3127                 :        714 :     ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
    3128                 :            : 
    3129                 :        714 :     ds_put_char(s, '\n');
    3130                 :        714 :     char *msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
    3131                 :        714 :     ds_put_and_free_cstr(s, msg);
    3132                 :            : }
    3133                 :            : 
    3134                 :            : static void
    3135                 :        106 : print_tlv_table(struct ds *s, struct ovs_list *mappings)
    3136                 :            : {
    3137                 :            :     struct ofputil_tlv_map *map;
    3138                 :            : 
    3139                 :        106 :     ds_put_cstr(s, " mapping table:\n");
    3140                 :        106 :     ds_put_cstr(s, " class\ttype\tlength\tmatch field\n");
    3141                 :        106 :     ds_put_cstr(s, " -----\t----\t------\t-----------");
    3142                 :            : 
    3143         [ +  + ]:        173 :     LIST_FOR_EACH (map, list_node, mappings) {
    3144                 :         67 :         ds_put_char(s, '\n');
    3145                 :         67 :         ds_put_format(s, " 0x%"PRIx16"\t0x%"PRIx8"\t%"PRIu8"\ttun_metadata%"PRIu16,
    3146                 :        201 :                       map->option_class, map->option_type, map->option_len,
    3147                 :         67 :                       map->index);
    3148                 :            :     }
    3149                 :        106 : }
    3150                 :            : 
    3151                 :            : static void
    3152                 :         61 : ofp_print_tlv_table_mod(struct ds *s, const struct ofp_header *oh)
    3153                 :            : {
    3154                 :            :     int error;
    3155                 :            :     struct ofputil_tlv_table_mod ttm;
    3156                 :            : 
    3157                 :         61 :     error = ofputil_decode_tlv_table_mod(oh, &ttm);
    3158         [ -  + ]:         61 :     if (error) {
    3159                 :          0 :         ofp_print_error(s, error);
    3160                 :          0 :         return;
    3161                 :            :     }
    3162                 :            : 
    3163                 :         61 :     ds_put_cstr(s, "\n ");
    3164                 :            : 
    3165   [ +  +  +  - ]:         61 :     switch (ttm.command) {
    3166                 :            :     case NXTTMC_ADD:
    3167                 :         59 :         ds_put_cstr(s, "ADD");
    3168                 :         59 :         break;
    3169                 :            :     case NXTTMC_DELETE:
    3170                 :          1 :         ds_put_cstr(s, "DEL");
    3171                 :          1 :         break;
    3172                 :            :     case NXTTMC_CLEAR:
    3173                 :          1 :         ds_put_cstr(s, "CLEAR");
    3174                 :          1 :         break;
    3175                 :            :     }
    3176                 :            : 
    3177         [ +  + ]:         61 :     if (ttm.command != NXTTMC_CLEAR) {
    3178                 :         60 :         print_tlv_table(s, &ttm.mappings);
    3179                 :            :     }
    3180                 :            : 
    3181                 :         61 :     ofputil_uninit_tlv_table(&ttm.mappings);
    3182                 :            : }
    3183                 :            : 
    3184                 :            : static void
    3185                 :         46 : ofp_print_tlv_table_reply(struct ds *s, const struct ofp_header *oh)
    3186                 :            : {
    3187                 :            :     int error;
    3188                 :            :     struct ofputil_tlv_table_reply ttr;
    3189                 :            :     struct ofputil_tlv_map *map;
    3190                 :         46 :     int allocated_space = 0;
    3191                 :            : 
    3192                 :         46 :     error = ofputil_decode_tlv_table_reply(oh, &ttr);
    3193         [ -  + ]:         46 :     if (error) {
    3194                 :          0 :         ofp_print_error(s, error);
    3195                 :          0 :         return;
    3196                 :            :     }
    3197                 :            : 
    3198                 :         46 :     ds_put_char(s, '\n');
    3199                 :            : 
    3200         [ -  + ]:         46 :     LIST_FOR_EACH (map, list_node, &ttr.mappings) {
    3201                 :          0 :         allocated_space += map->option_len;
    3202                 :            :     }
    3203                 :            : 
    3204                 :         46 :     ds_put_format(s, " max option space=%"PRIu32" max fields=%"PRIu16"\n",
    3205                 :         46 :                   ttr.max_option_space, ttr.max_fields);
    3206                 :         46 :     ds_put_format(s, " allocated option space=%d\n", allocated_space);
    3207                 :         46 :     ds_put_char(s, '\n');
    3208                 :         46 :     print_tlv_table(s, &ttr.mappings);
    3209                 :            : 
    3210                 :         46 :     ofputil_uninit_tlv_table(&ttr.mappings);
    3211                 :            : }
    3212                 :            : 
    3213                 :            : /* This function will print the request forward message. The reason for
    3214                 :            :  * request forward is taken from rf.request.type */
    3215                 :            : static void
    3216                 :         12 : ofp_print_requestforward(struct ds *string, const struct ofp_header *oh)
    3217                 :            : {
    3218                 :            :     struct ofputil_requestforward rf;
    3219                 :            :     enum ofperr error;
    3220                 :            : 
    3221                 :         12 :     error = ofputil_decode_requestforward(oh, &rf);
    3222         [ -  + ]:         12 :     if (error) {
    3223                 :          0 :         ofp_print_error(string, error);
    3224                 :          0 :         return;
    3225                 :            :     }
    3226                 :            : 
    3227                 :         12 :     ds_put_cstr(string, " reason=");
    3228                 :            : 
    3229   [ +  +  -  - ]:         12 :     switch (rf.reason) {
    3230                 :            :     case OFPRFR_GROUP_MOD:
    3231                 :         10 :         ds_put_cstr(string, "group_mod");
    3232                 :         10 :         ofp_print_group_mod__(string, oh->version, rf.group_mod);
    3233                 :         10 :         break;
    3234                 :            : 
    3235                 :            :     case OFPRFR_METER_MOD:
    3236                 :          2 :         ds_put_cstr(string, "meter_mod");
    3237                 :          2 :         ofp_print_meter_mod__(string, rf.meter_mod);
    3238                 :          2 :         break;
    3239                 :            : 
    3240                 :            :     case OFPRFR_N_REASONS:
    3241                 :          0 :         OVS_NOT_REACHED();
    3242                 :            :     }
    3243                 :         12 :     ofputil_destroy_requestforward(&rf);
    3244                 :            : }
    3245                 :            : 
    3246                 :            : static void
    3247                 :         70 : print_ipfix_stat(struct ds *string, const char *leader, uint64_t stat, int more)
    3248                 :            : {
    3249                 :         70 :     ds_put_cstr(string, leader);
    3250         [ +  - ]:         70 :     if (stat != UINT64_MAX) {
    3251                 :         70 :         ds_put_format(string, "%"PRIu64, stat);
    3252                 :            :     } else {
    3253                 :          0 :         ds_put_char(string, '?');
    3254                 :            :     }
    3255         [ +  + ]:         70 :     if (more) {
    3256                 :         56 :         ds_put_cstr(string, ", ");
    3257                 :            :     } else {
    3258                 :         14 :         ds_put_cstr(string, "\n");
    3259                 :            :     }
    3260                 :         70 : }
    3261                 :            : 
    3262                 :            : static void
    3263                 :          3 : ofp_print_nxst_ipfix_bridge_reply(struct ds *string, const struct ofp_header *oh)
    3264                 :            : {
    3265                 :          3 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    3266                 :            :     for (;;) {
    3267                 :            :         struct ofputil_ipfix_stats is;
    3268                 :            :         int retval;
    3269                 :            : 
    3270                 :          6 :         retval = ofputil_pull_ipfix_stats(&is, &b);
    3271         [ +  + ]:          6 :         if (retval) {
    3272         [ -  + ]:          3 :             if (retval != EOF) {
    3273                 :          0 :                 ds_put_cstr(string, " ***parse error***");
    3274                 :            :             }
    3275                 :          3 :             return;
    3276                 :            :         }
    3277                 :            : 
    3278                 :          3 :         ds_put_cstr(string, "\n  bridge ipfix: ");
    3279                 :          3 :         print_ipfix_stat(string, "flows=", is.total_flows, 1);
    3280                 :          3 :         print_ipfix_stat(string, "current flows=", is.current_flows, 1);
    3281                 :          3 :         print_ipfix_stat(string, "sampled pkts=", is.pkts, 1);
    3282                 :          3 :         print_ipfix_stat(string, "ipv4 ok=", is.ipv4_pkts, 1);
    3283                 :          3 :         print_ipfix_stat(string, "ipv6 ok=", is.ipv6_pkts, 1);
    3284                 :          3 :         print_ipfix_stat(string, "tx pkts=", is.tx_pkts, 0);
    3285                 :          3 :         ds_put_cstr(string, "                ");
    3286                 :          3 :         print_ipfix_stat(string, "pkts errs=", is.error_pkts, 1);
    3287                 :          3 :         print_ipfix_stat(string, "ipv4 errs=", is.ipv4_error_pkts, 1);
    3288                 :          3 :         print_ipfix_stat(string, "ipv6 errs=", is.ipv6_error_pkts, 1);
    3289                 :          3 :         print_ipfix_stat(string, "tx errs=", is.tx_errors, 0);
    3290                 :          3 :     }
    3291                 :            : }
    3292                 :            : 
    3293                 :            : static void
    3294                 :          3 : ofp_print_nxst_ipfix_flow_reply(struct ds *string, const struct ofp_header *oh)
    3295                 :            : {
    3296                 :          3 :     ds_put_format(string, " %"PRIuSIZE" ids\n", ofputil_count_ipfix_stats(oh));
    3297                 :            : 
    3298                 :          3 :     struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
    3299                 :            :     for (;;) {
    3300                 :            :         struct ofputil_ipfix_stats is;
    3301                 :            :         int retval;
    3302                 :            : 
    3303                 :          7 :         retval = ofputil_pull_ipfix_stats(&is, &b);
    3304         [ +  + ]:          7 :         if (retval) {
    3305         [ -  + ]:          3 :             if (retval != EOF) {
    3306                 :          0 :                 ds_put_cstr(string, " ***parse error***");
    3307                 :            :             }
    3308                 :          3 :             return;
    3309                 :            :         }
    3310                 :            : 
    3311                 :          4 :         ds_put_cstr(string, "  id");
    3312                 :          4 :         ds_put_format(string, " %3"PRIuSIZE": ", (size_t) is.collector_set_id);
    3313                 :          4 :         print_ipfix_stat(string, "flows=", is.total_flows, 1);
    3314                 :          4 :         print_ipfix_stat(string, "current flows=", is.current_flows, 1);
    3315                 :          4 :         print_ipfix_stat(string, "sampled pkts=", is.pkts, 1);
    3316                 :          4 :         print_ipfix_stat(string, "ipv4 ok=", is.ipv4_pkts, 1);
    3317                 :          4 :         print_ipfix_stat(string, "ipv6 ok=", is.ipv6_pkts, 1);
    3318                 :          4 :         print_ipfix_stat(string, "tx pkts=", is.tx_pkts, 0);
    3319                 :          4 :         ds_put_cstr(string, "          ");
    3320                 :          4 :         print_ipfix_stat(string, "pkts errs=", is.error_pkts, 1);
    3321                 :          4 :         print_ipfix_stat(string, "ipv4 errs=", is.ipv4_error_pkts, 1);
    3322                 :          4 :         print_ipfix_stat(string, "ipv6 errs=", is.ipv6_error_pkts, 1);
    3323                 :          4 :         print_ipfix_stat(string, "tx errs=", is.tx_errors, 0);
    3324                 :          4 :     }
    3325                 :            : }
    3326                 :            : 
    3327                 :            : 
    3328                 :            : static void
    3329                 :      99276 : ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
    3330                 :            :                 struct ds *string, int verbosity)
    3331                 :            : {
    3332                 :      99276 :     const void *msg = oh;
    3333                 :            : 
    3334                 :      99276 :     ofp_header_to_string__(oh, raw, string);
    3335                 :            : 
    3336                 :      99276 :     enum ofptype type = ofptype_from_ofpraw(raw);
    3337   [ +  +  +  +  :      99276 :     switch (type) {
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  -  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
                   +  - ]
    3338                 :            :     case OFPTYPE_GROUP_STATS_REQUEST:
    3339                 :          9 :         ofp_print_stats(string, oh);
    3340                 :          9 :         ofp_print_ofpst_group_request(string, oh);
    3341                 :          9 :         break;
    3342                 :            : 
    3343                 :            :     case OFPTYPE_GROUP_STATS_REPLY:
    3344                 :         20 :         ofp_print_group_stats(string, oh);
    3345                 :         20 :         break;
    3346                 :            : 
    3347                 :            :     case OFPTYPE_GROUP_DESC_STATS_REQUEST:
    3348                 :         54 :         ofp_print_stats(string, oh);
    3349                 :         54 :         ofp_print_ofpst_group_desc_request(string, oh);
    3350                 :         54 :         break;
    3351                 :            : 
    3352                 :            :     case OFPTYPE_GROUP_DESC_STATS_REPLY:
    3353                 :        106 :         ofp_print_group_desc(string, oh);
    3354                 :        106 :         break;
    3355                 :            : 
    3356                 :            :     case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
    3357                 :          2 :         ofp_print_stats(string, oh);
    3358                 :          2 :         break;
    3359                 :            : 
    3360                 :            :     case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
    3361                 :          3 :         ofp_print_group_features(string, oh);
    3362                 :          3 :         break;
    3363                 :            : 
    3364                 :            :     case OFPTYPE_GROUP_MOD:
    3365                 :        203 :         ofp_print_group_mod(string, oh);
    3366                 :        203 :         break;
    3367                 :            : 
    3368                 :            :     case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
    3369                 :            :     case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
    3370                 :         37 :         ofp_print_table_features_reply(string, oh);
    3371                 :         37 :         break;
    3372                 :            : 
    3373                 :            :     case OFPTYPE_TABLE_DESC_REQUEST:
    3374                 :            :     case OFPTYPE_TABLE_DESC_REPLY:
    3375                 :         23 :         ofp_print_table_desc_reply(string, oh);
    3376                 :         23 :         break;
    3377                 :            : 
    3378                 :            :     case OFPTYPE_HELLO:
    3379                 :       6940 :         ofp_print_hello(string, oh);
    3380                 :       6940 :         break;
    3381                 :            : 
    3382                 :            :     case OFPTYPE_ERROR:
    3383                 :       1255 :         ofp_print_error_msg(string, oh);
    3384                 :       1255 :         break;
    3385                 :            : 
    3386                 :            :     case OFPTYPE_ECHO_REQUEST:
    3387                 :            :     case OFPTYPE_ECHO_REPLY:
    3388                 :         47 :         ofp_print_echo(string, oh, verbosity);
    3389                 :         47 :         break;
    3390                 :            : 
    3391                 :            :     case OFPTYPE_FEATURES_REQUEST:
    3392                 :         75 :         break;
    3393                 :            : 
    3394                 :            :     case OFPTYPE_FEATURES_REPLY:
    3395                 :        120 :         ofp_print_switch_features(string, oh);
    3396                 :        120 :         break;
    3397                 :            : 
    3398                 :            :     case OFPTYPE_GET_CONFIG_REQUEST:
    3399                 :        253 :         break;
    3400                 :            : 
    3401                 :            :     case OFPTYPE_GET_CONFIG_REPLY:
    3402                 :        299 :         ofp_print_get_config_reply(string, oh);
    3403                 :        299 :         break;
    3404                 :            : 
    3405                 :            :     case OFPTYPE_SET_CONFIG:
    3406                 :        210 :         ofp_print_set_config(string, oh);
    3407                 :        210 :         break;
    3408                 :            : 
    3409                 :            :     case OFPTYPE_PACKET_IN:
    3410                 :       1520 :         ofp_print_packet_in(string, oh, verbosity);
    3411                 :       1520 :         break;
    3412                 :            : 
    3413                 :            :     case OFPTYPE_FLOW_REMOVED:
    3414                 :         40 :         ofp_print_flow_removed(string, oh);
    3415                 :         40 :         break;
    3416                 :            : 
    3417                 :            :     case OFPTYPE_PORT_STATUS:
    3418                 :        505 :         ofp_print_port_status(string, oh);
    3419                 :        505 :         break;
    3420                 :            : 
    3421                 :            :     case OFPTYPE_PACKET_OUT:
    3422                 :       1619 :         ofp_print_packet_out(string, oh, verbosity);
    3423                 :       1619 :         break;
    3424                 :            : 
    3425                 :            :     case OFPTYPE_FLOW_MOD:
    3426                 :      33739 :         ofp_print_flow_mod(string, oh, verbosity);
    3427                 :      33739 :         break;
    3428                 :            : 
    3429                 :            :     case OFPTYPE_PORT_MOD:
    3430                 :         45 :         ofp_print_port_mod(string, oh);
    3431                 :         45 :         break;
    3432                 :            : 
    3433                 :            :     case OFPTYPE_TABLE_MOD:
    3434                 :         18 :         ofp_print_table_mod(string, oh);
    3435                 :         18 :         break;
    3436                 :            : 
    3437                 :            :     case OFPTYPE_METER_MOD:
    3438                 :          4 :         ofp_print_meter_mod(string, oh);
    3439                 :          4 :         break;
    3440                 :            : 
    3441                 :            :     case OFPTYPE_BARRIER_REQUEST:
    3442                 :            :     case OFPTYPE_BARRIER_REPLY:
    3443                 :      30026 :         break;
    3444                 :            : 
    3445                 :            :     case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
    3446                 :         26 :         ofp_print_queue_get_config_request(string, oh);
    3447                 :         26 :         break;
    3448                 :            : 
    3449                 :            :     case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
    3450                 :         21 :         ofp_print_queue_get_config_reply(string, oh);
    3451                 :         21 :         break;
    3452                 :            : 
    3453                 :            :     case OFPTYPE_ROLE_REQUEST:
    3454                 :            :     case OFPTYPE_ROLE_REPLY:
    3455                 :        101 :         ofp_print_role_message(string, oh);
    3456                 :        101 :         break;
    3457                 :            :     case OFPTYPE_ROLE_STATUS:
    3458                 :          5 :         ofp_print_role_status_message(string, oh);
    3459                 :          5 :         break;
    3460                 :            : 
    3461                 :            :     case OFPTYPE_REQUESTFORWARD:
    3462                 :         12 :         ofp_print_requestforward(string, oh);
    3463                 :         12 :         break;
    3464                 :            : 
    3465                 :            :     case OFPTYPE_TABLE_STATUS:
    3466                 :          6 :         ofp_print_table_status_message(string, oh);
    3467                 :          6 :         break;
    3468                 :            : 
    3469                 :            :     case OFPTYPE_METER_STATS_REQUEST:
    3470                 :            :     case OFPTYPE_METER_CONFIG_STATS_REQUEST:
    3471                 :          2 :         ofp_print_stats(string, oh);
    3472                 :          2 :         ofp_print_meter_stats_request(string, oh);
    3473                 :          2 :         break;
    3474                 :            : 
    3475                 :            :     case OFPTYPE_METER_STATS_REPLY:
    3476                 :          1 :         ofp_print_stats(string, oh);
    3477                 :          1 :         ofp_print_meter_stats_reply(string, oh);
    3478                 :          1 :         break;
    3479                 :            : 
    3480                 :            :     case OFPTYPE_METER_CONFIG_STATS_REPLY:
    3481                 :          1 :         ofp_print_stats(string, oh);
    3482                 :          1 :         ofp_print_meter_config_reply(string, oh);
    3483                 :          1 :         break;
    3484                 :            : 
    3485                 :            :     case OFPTYPE_METER_FEATURES_STATS_REPLY:
    3486                 :          1 :         ofp_print_stats(string, oh);
    3487                 :          1 :         ofp_print_meter_features_reply(string, oh);
    3488                 :          1 :         break;
    3489                 :            : 
    3490                 :            :     case OFPTYPE_DESC_STATS_REQUEST:
    3491                 :            :     case OFPTYPE_METER_FEATURES_STATS_REQUEST:
    3492                 :          2 :         ofp_print_stats(string, oh);
    3493                 :          2 :         break;
    3494                 :            : 
    3495                 :            :     case OFPTYPE_FLOW_STATS_REQUEST:
    3496                 :            :     case OFPTYPE_AGGREGATE_STATS_REQUEST:
    3497                 :        393 :         ofp_print_stats(string, oh);
    3498                 :        393 :         ofp_print_flow_stats_request(string, oh);
    3499                 :        393 :         break;
    3500                 :            : 
    3501                 :            :     case OFPTYPE_TABLE_STATS_REQUEST:
    3502                 :         14 :         ofp_print_stats(string, oh);
    3503                 :         14 :         break;
    3504                 :            : 
    3505                 :            :     case OFPTYPE_PORT_STATS_REQUEST:
    3506                 :         23 :         ofp_print_stats(string, oh);
    3507                 :         23 :         ofp_print_ofpst_port_request(string, oh);
    3508                 :         23 :         break;
    3509                 :            : 
    3510                 :            :     case OFPTYPE_QUEUE_STATS_REQUEST:
    3511                 :         69 :         ofp_print_stats(string, oh);
    3512                 :         69 :         ofp_print_ofpst_queue_request(string, oh);
    3513                 :         69 :         break;
    3514                 :            : 
    3515                 :            :     case OFPTYPE_DESC_STATS_REPLY:
    3516                 :          1 :         ofp_print_stats(string, oh);
    3517                 :          1 :         ofp_print_ofpst_desc_reply(string, oh);
    3518                 :          1 :         break;
    3519                 :            : 
    3520                 :            :     case OFPTYPE_FLOW_STATS_REPLY:
    3521                 :        774 :         ofp_print_stats(string, oh);
    3522                 :        774 :         ofp_print_flow_stats_reply(string, oh);
    3523                 :        774 :         break;
    3524                 :            : 
    3525                 :            :     case OFPTYPE_QUEUE_STATS_REPLY:
    3526                 :         45 :         ofp_print_stats(string, oh);
    3527                 :         45 :         ofp_print_ofpst_queue_reply(string, oh, verbosity);
    3528                 :         45 :         break;
    3529                 :            : 
    3530                 :            :     case OFPTYPE_PORT_STATS_REPLY:
    3531                 :         42 :         ofp_print_stats(string, oh);
    3532                 :         42 :         ofp_print_ofpst_port_reply(string, oh, verbosity);
    3533                 :         42 :         break;
    3534                 :            : 
    3535                 :            :     case OFPTYPE_TABLE_STATS_REPLY:
    3536                 :         23 :         ofp_print_stats(string, oh);
    3537                 :         23 :         ofp_print_table_stats_reply(string, oh);
    3538                 :         23 :         break;
    3539                 :            : 
    3540                 :            :     case OFPTYPE_AGGREGATE_STATS_REPLY:
    3541                 :         14 :         ofp_print_stats(string, oh);
    3542                 :         14 :         ofp_print_aggregate_stats_reply(string, oh);
    3543                 :         14 :         break;
    3544                 :            : 
    3545                 :            :     case OFPTYPE_PORT_DESC_STATS_REQUEST:
    3546                 :         38 :         ofp_print_stats(string, oh);
    3547                 :         38 :         ofp_print_ofpst_port_desc_request(string, oh);
    3548                 :         38 :         break;
    3549                 :            : 
    3550                 :            :     case OFPTYPE_PORT_DESC_STATS_REPLY:
    3551                 :         57 :         ofp_print_stats(string, oh);
    3552                 :         57 :         ofp_print_ofpst_port_desc_reply(string, oh);
    3553                 :         57 :         break;
    3554                 :            : 
    3555                 :            :     case OFPTYPE_FLOW_MOD_TABLE_ID:
    3556                 :         89 :         ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
    3557                 :         89 :         break;
    3558                 :            : 
    3559                 :            :     case OFPTYPE_SET_FLOW_FORMAT:
    3560                 :        332 :         ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
    3561                 :        332 :         break;
    3562                 :            : 
    3563                 :            :     case OFPTYPE_SET_PACKET_IN_FORMAT:
    3564                 :        202 :         ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
    3565                 :        202 :         break;
    3566                 :            : 
    3567                 :            :     case OFPTYPE_FLOW_AGE:
    3568                 :          0 :         break;
    3569                 :            : 
    3570                 :            :     case OFPTYPE_SET_CONTROLLER_ID:
    3571                 :         17 :         ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
    3572                 :         17 :         break;
    3573                 :            : 
    3574                 :            :     case OFPTYPE_GET_ASYNC_REPLY:
    3575                 :            :     case OFPTYPE_SET_ASYNC_CONFIG:
    3576                 :         23 :         ofp_print_set_async_config(string, oh, type);
    3577                 :         23 :         break;
    3578                 :            :     case OFPTYPE_GET_ASYNC_REQUEST:
    3579                 :          2 :         break;
    3580                 :            :     case OFPTYPE_FLOW_MONITOR_CANCEL:
    3581                 :          1 :         ofp_print_nxt_flow_monitor_cancel(string, msg);
    3582                 :          1 :         break;
    3583                 :            : 
    3584                 :            :     case OFPTYPE_FLOW_MONITOR_PAUSED:
    3585                 :            :     case OFPTYPE_FLOW_MONITOR_RESUMED:
    3586                 :          6 :         break;
    3587                 :            : 
    3588                 :            :     case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
    3589                 :          5 :         ofp_print_nxst_flow_monitor_request(string, msg);
    3590                 :          5 :         break;
    3591                 :            : 
    3592                 :            :     case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
    3593                 :      17884 :         ofp_print_nxst_flow_monitor_reply(string, msg);
    3594                 :      17884 :         break;
    3595                 :            : 
    3596                 :            :     case OFPTYPE_BUNDLE_CONTROL:
    3597                 :        587 :         ofp_print_bundle_ctrl(string, msg);
    3598                 :        587 :         break;
    3599                 :            : 
    3600                 :            :     case OFPTYPE_BUNDLE_ADD_MESSAGE:
    3601                 :        716 :         ofp_print_bundle_add(string, msg, verbosity);
    3602                 :        716 :         break;
    3603                 :            : 
    3604                 :            :     case OFPTYPE_NXT_TLV_TABLE_MOD:
    3605                 :         61 :         ofp_print_tlv_table_mod(string, msg);
    3606                 :         61 :         break;
    3607                 :            : 
    3608                 :            :     case OFPTYPE_NXT_TLV_TABLE_REQUEST:
    3609                 :         46 :         break;
    3610                 :            : 
    3611                 :            :     case OFPTYPE_NXT_TLV_TABLE_REPLY:
    3612                 :         46 :         ofp_print_tlv_table_reply(string, msg);
    3613                 :         46 :         break;
    3614                 :            : 
    3615                 :            :     case OFPTYPE_NXT_RESUME:
    3616                 :        394 :         ofp_print_packet_in(string, msg, verbosity);
    3617                 :        394 :         break;
    3618                 :            :     case OFPTYPE_IPFIX_BRIDGE_STATS_REQUEST:
    3619                 :          8 :         break;
    3620                 :            :     case OFPTYPE_IPFIX_BRIDGE_STATS_REPLY:
    3621                 :          3 :         ofp_print_nxst_ipfix_bridge_reply(string, oh);
    3622                 :          3 :         break;
    3623                 :            :     case OFPTYPE_IPFIX_FLOW_STATS_REQUEST:
    3624                 :          8 :         break;
    3625                 :            :     case OFPTYPE_IPFIX_FLOW_STATS_REPLY:
    3626                 :          3 :         ofp_print_nxst_ipfix_flow_reply(string, oh);
    3627                 :          3 :         break;
    3628                 :            :     }
    3629                 :      99276 : }
    3630                 :            : 
    3631                 :            : /* Composes and returns a string representing the OpenFlow packet of 'len'
    3632                 :            :  * bytes at 'oh' at the given 'verbosity' level.  0 is a minimal amount of
    3633                 :            :  * verbosity and higher numbers increase verbosity.  The caller is responsible
    3634                 :            :  * for freeing the string. */
    3635                 :            : char *
    3636                 :     100428 : ofp_to_string(const void *oh_, size_t len, int verbosity)
    3637                 :            : {
    3638                 :     100428 :     struct ds string = DS_EMPTY_INITIALIZER;
    3639                 :     100428 :     const struct ofp_header *oh = oh_;
    3640                 :            : 
    3641         [ +  + ]:     100428 :     if (!len) {
    3642                 :          1 :         ds_put_cstr(&string, "OpenFlow message is empty\n");
    3643         [ +  + ]:     100427 :     } else if (len < sizeof(struct ofp_header)) {
    3644                 :          1 :         ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
    3645                 :            :                       len);
    3646         [ +  + ]:     100426 :     } else if (ntohs(oh->length) > len) {
    3647                 :            :         enum ofperr error;
    3648                 :            :         enum ofpraw raw;
    3649                 :            : 
    3650                 :       1140 :         error = ofpraw_decode_partial(&raw, oh, len);
    3651         [ +  + ]:       1140 :         if (!error) {
    3652                 :       1139 :             ofp_header_to_string__(oh, raw, &string);
    3653                 :       1139 :             ds_put_char(&string, '\n');
    3654                 :            :         }
    3655                 :            : 
    3656                 :       1140 :         ds_put_format(&string,
    3657                 :            :                       "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
    3658                 :       1140 :                       len, ntohs(oh->length));
    3659         [ +  + ]:      99286 :     } else if (ntohs(oh->length) < len) {
    3660                 :          1 :         ds_put_format(&string,
    3661                 :            :                       "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
    3662                 :          1 :                       ntohs(oh->length), len);
    3663                 :            :     } else {
    3664                 :            :         enum ofperr error;
    3665                 :            :         enum ofpraw raw;
    3666                 :            : 
    3667                 :      99285 :         error = ofpraw_decode(&raw, oh);
    3668         [ +  + ]:      99285 :         if (!error) {
    3669                 :      99276 :             ofp_to_string__(oh, raw, &string, verbosity);
    3670         [ -  + ]:      99276 :             if (verbosity >= 5) {
    3671         [ #  # ]:          0 :                 if (ds_last(&string) != '\n') {
    3672                 :          0 :                     ds_put_char(&string, '\n');
    3673                 :            :                 }
    3674                 :          0 :                 ds_put_hex_dump(&string, oh, len, 0, true);
    3675                 :            :             }
    3676         [ +  + ]:      99276 :             if (ds_last(&string) != '\n') {
    3677                 :      92227 :                 ds_put_char(&string, '\n');
    3678                 :            :             }
    3679                 :      99276 :             return ds_steal_cstr(&string);
    3680                 :            :         }
    3681                 :            : 
    3682                 :          9 :         ofp_print_error(&string, error);
    3683                 :            :     }
    3684                 :       1152 :     ds_put_hex_dump(&string, oh, len, 0, true);
    3685                 :     100428 :     return ds_steal_cstr(&string);
    3686                 :            : }
    3687                 :            : 
    3688                 :            : static void
    3689                 :       4962 : print_and_free(FILE *stream, char *string)
    3690                 :            : {
    3691                 :       4962 :     fputs(string, stream);
    3692                 :       4962 :     free(string);
    3693                 :       4962 : }
    3694                 :            : 
    3695                 :            : /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
    3696                 :            :  * given 'verbosity' level.  0 is a minimal amount of verbosity and higher
    3697                 :            :  * numbers increase verbosity. */
    3698                 :            : void
    3699                 :       4962 : ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
    3700                 :            : {
    3701                 :       4962 :     print_and_free(stream, ofp_to_string(oh, len, verbosity));
    3702                 :       4962 : }
    3703                 :            : 
    3704                 :            : /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
    3705                 :            :  * 'data' to 'stream'. */
    3706                 :            : void
    3707                 :          0 : ofp_print_packet(FILE *stream, const void *data, size_t len)
    3708                 :            : {
    3709                 :          0 :     print_and_free(stream, ofp_packet_to_string(data, len));
    3710                 :          0 : }

Generated by: LCOV version 1.12