2 * Copyright (c) 2008-2017 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "openvswitch/ofp-ipfix.h"
20 #include "byte-order.h"
21 #include "openflow/nicira-ext.h"
22 #include "openvswitch/ofp-errors.h"
23 #include "openvswitch/ofp-msgs.h"
24 #include "openvswitch/ofpbuf.h"
28 ofputil_ipfix_stats_to_reply(const struct ofputil_ipfix_stats
*ois
,
29 struct nx_ipfix_stats_reply
*reply
)
31 reply
->collector_set_id
= htonl(ois
->collector_set_id
);
32 reply
->total_flows
= htonll(ois
->total_flows
);
33 reply
->current_flows
= htonll(ois
->current_flows
);
34 reply
->pkts
= htonll(ois
->pkts
);
35 reply
->ipv4_pkts
= htonll(ois
->ipv4_pkts
);
36 reply
->ipv6_pkts
= htonll(ois
->ipv6_pkts
);
37 reply
->error_pkts
= htonll(ois
->error_pkts
);
38 reply
->ipv4_error_pkts
= htonll(ois
->ipv4_error_pkts
);
39 reply
->ipv6_error_pkts
= htonll(ois
->ipv6_error_pkts
);
40 reply
->tx_pkts
= htonll(ois
->tx_pkts
);
41 reply
->tx_errors
= htonll(ois
->tx_errors
);
42 memset(reply
->pad
, 0, sizeof reply
->pad
);
45 /* Encode a ipfix stat for 'ois' and append it to 'replies'. */
47 ofputil_append_ipfix_stat(struct ovs_list
*replies
,
48 const struct ofputil_ipfix_stats
*ois
)
50 struct nx_ipfix_stats_reply
*reply
= ofpmp_append(replies
, sizeof *reply
);
51 ofputil_ipfix_stats_to_reply(ois
, reply
);
55 ofputil_ipfix_stats_from_nx(struct ofputil_ipfix_stats
*is
,
56 const struct nx_ipfix_stats_reply
*reply
)
58 is
->collector_set_id
= ntohl(reply
->collector_set_id
);
59 is
->total_flows
= ntohll(reply
->total_flows
);
60 is
->current_flows
= ntohll(reply
->current_flows
);
61 is
->pkts
= ntohll(reply
->pkts
);
62 is
->ipv4_pkts
= ntohll(reply
->ipv4_pkts
);
63 is
->ipv6_pkts
= ntohll(reply
->ipv6_pkts
);
64 is
->error_pkts
= ntohll(reply
->error_pkts
);
65 is
->ipv4_error_pkts
= ntohll(reply
->ipv4_error_pkts
);
66 is
->ipv6_error_pkts
= ntohll(reply
->ipv6_error_pkts
);
67 is
->tx_pkts
= ntohll(reply
->tx_pkts
);
68 is
->tx_errors
= ntohll(reply
->tx_errors
);
74 ofputil_pull_ipfix_stats(struct ofputil_ipfix_stats
*is
, struct ofpbuf
*msg
)
79 memset(is
, 0xFF, sizeof (*is
));
81 error
= (msg
->header
? ofpraw_decode(&raw
, msg
->header
)
82 : ofpraw_pull(&raw
, msg
));
89 } else if (raw
== OFPRAW_NXST_IPFIX_BRIDGE_REPLY
||
90 raw
== OFPRAW_NXST_IPFIX_FLOW_REPLY
) {
91 struct nx_ipfix_stats_reply
*reply
;
93 reply
= ofpbuf_try_pull(msg
, sizeof *reply
);
94 return ofputil_ipfix_stats_from_nx(is
, reply
);
101 /* Returns the number of ipfix stats elements in
102 * OFPTYPE_IPFIX_BRIDGE_STATS_REPLY or OFPTYPE_IPFIX_FLOW_STATS_REPLY
105 ofputil_count_ipfix_stats(const struct ofp_header
*oh
)
107 struct ofpbuf b
= ofpbuf_const_initializer(oh
, ntohs(oh
->length
));
108 ofpraw_pull_assert(&b
);
110 return b
.size
/ sizeof(struct ofputil_ipfix_stats
);
114 print_ipfix_stat(struct ds
*string
, const char *leader
, uint64_t stat
,
117 ds_put_cstr(string
, leader
);
118 if (stat
!= UINT64_MAX
) {
119 ds_put_format(string
, "%"PRIu64
, stat
);
121 ds_put_char(string
, '?');
124 ds_put_cstr(string
, ", ");
126 ds_put_cstr(string
, "\n");
131 format_ipfix_stats(struct ds
*string
, const struct ofputil_ipfix_stats
*is
,
134 print_ipfix_stat(string
, "flows=", is
->total_flows
, 1);
135 print_ipfix_stat(string
, "current flows=", is
->current_flows
, 1);
136 print_ipfix_stat(string
, "sampled pkts=", is
->pkts
, 1);
137 print_ipfix_stat(string
, "ipv4 ok=", is
->ipv4_pkts
, 1);
138 print_ipfix_stat(string
, "ipv6 ok=", is
->ipv6_pkts
, 1);
139 print_ipfix_stat(string
, "tx pkts=", is
->tx_pkts
, 0);
140 ds_put_char_multiple(string
, ' ', indent
);
141 print_ipfix_stat(string
, "pkts errs=", is
->error_pkts
, 1);
142 print_ipfix_stat(string
, "ipv4 errs=", is
->ipv4_error_pkts
, 1);
143 print_ipfix_stat(string
, "ipv6 errs=", is
->ipv6_error_pkts
, 1);
144 print_ipfix_stat(string
, "tx errs=", is
->tx_errors
, 0);
148 ofputil_format_ipfix_stats_bridge(struct ds
*string
,
149 const struct ofputil_ipfix_stats
*is
)
151 ds_put_cstr(string
, "\n bridge ipfix: ");
152 format_ipfix_stats(string
, is
, 16);
156 ofputil_format_ipfix_stats_flow(struct ds
*string
,
157 const struct ofputil_ipfix_stats
*is
)
159 ds_put_cstr(string
, " id");
160 ds_put_format(string
, " %3"PRIuSIZE
": ", (size_t) is
->collector_set_id
);
161 format_ipfix_stats(string
, is
, 10);