2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 01:51:26 +00:00
ovs/ofproto/ofproto-dpif-xlate-cache.h
Dumitru Ceara 600125b2c3 ofproto: Add ofproto/detrace command to map UFIDs to OpenFlow.
It improves the debugging experience if we can easily get a list of
OpenFlow rules and groups that contribute to the creation of a datapath
flow.

The suggested workflow is:
a. dump datapath flows (along with UUIDs), this also prints the core IDs
(PMD IDs) when applicable.

  $ ovs-appctl dpctl/dump-flows -m
  flow-dump from pmd on cpu core: 7
  ufid:7460db8f..., recirc_id(0), ....

b. dump related OpenFlow rules and groups:
  $ ovs-appctl ofproto/detrace ufid:7460db8f... pmd=7
  cookie=0x12345678, table=0 priority=100,ip,in_port=2,nw_dst=10.0.0.2,actions=resubmit(,1)
  cookie=0x0, table=1 priority=200,actions=group:1
  group_id=1,bucket=bucket_id:0,actions=ct(commit,table=2,nat(dst=20.0.0.2))
  cookie=0x0, table=2 actions=output:1

The new command only shows rules and groups attached to ukeys that are
in states UKEY_VISIBLE or UKEY_OPERATIONAL.  That should be fine as all
other ukeys should not be relevant for the use case presented above.

This commit tries to mimic the output format of the ovs-ofctl
dump-flows/dump-groups commands.

Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2024-07-15 19:12:52 +02:00

157 lines
4.5 KiB
C

/* Copyright (c) 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
#ifndef OFPROTO_DPIF_XLATE_CACHE_H
#define OFPROTO_DPIF_XLATE_CACHE_H 1
#include <net/if.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include "openvswitch/types.h"
#include "dp-packet.h"
#include "odp-util.h"
#include "ofproto/ofproto-dpif-mirror.h"
#include "openvswitch/ofpbuf.h"
struct bfd;
struct bond;
struct dpif_flow_stats;
struct flow;
struct group_dpif;
struct mbridge;
struct netdev;
struct netflow;
struct ofpbuf;
struct ofproto_dpif;
struct ofputil_bucket;
struct ofputil_flow_mod;
struct rule_dpif;
enum xc_type {
XC_TABLE,
XC_RULE,
XC_BOND,
XC_NETDEV,
XC_NETFLOW,
XC_MIRROR,
XC_LEARN, /* Calls back to ofproto. */
XC_NORMAL,
XC_FIN_TIMEOUT, /* Calls back to ofproto. */
XC_GROUP,
XC_TNL_NEIGH,
XC_TUNNEL_HEADER,
};
/* xlate_cache entries hold enough information to perform the side effects of
* xlate_actions() for a rule, without needing to perform rule translation
* from scratch. The primary usage of these is to submit statistics to objects
* that a flow relates to, although they may be used for other effects as well
* (for instance, refreshing hard timeouts for learned flows).
*
* An explicit reference is taken to all pointers.
*/
struct xc_entry {
enum xc_type type;
union {
struct {
struct ofproto_dpif *ofproto;
uint8_t id;
bool match; /* or miss. */
} table;
struct rule_dpif *rule;
struct {
struct netdev *tx;
struct netdev *rx;
struct bfd *bfd;
} dev;
struct {
struct netflow *netflow;
struct flow *flow;
ofp_port_t iface;
} nf;
struct {
struct mbridge *mbridge;
mirror_mask_t mirrors;
} mirror;
struct {
struct bond *bond;
struct flow *flow;
uint16_t vid;
} bond;
struct {
struct ofproto_flow_mod *ofm;
unsigned limit;
} learn;
struct {
struct ofproto_dpif *ofproto;
ofp_port_t in_port;
struct eth_addr dl_src;
int vlan;
bool is_gratuitous_arp;
} normal;
struct {
struct rule_dpif *rule;
uint16_t idle;
uint16_t hard;
} fin;
struct {
struct group_dpif *group;
struct ofputil_bucket *bucket;
} group;
struct {
char br_name[IFNAMSIZ];
struct in6_addr d_ipv6;
} tnl_neigh_cache;
struct {
struct ofproto_dpif *ofproto;
struct ofproto_async_msg *am;
} controller;
struct {
enum {
ADD,
REMOVE,
} operation;
uint16_t hdr_size;
} tunnel_hdr;
};
};
#define XC_ENTRY_FOR_EACH(ENTRY, ENTRIES) \
for (ENTRY = ofpbuf_try_pull(ENTRIES, sizeof *ENTRY); \
ENTRY; \
ENTRY = ofpbuf_try_pull(ENTRIES, sizeof *ENTRY))
struct xlate_cache {
struct ofpbuf entries;
};
void xlate_cache_init(struct xlate_cache *);
struct xlate_cache *xlate_cache_new(void);
struct xc_entry *xlate_cache_add_entry(struct xlate_cache *, enum xc_type);
void xlate_push_stats_entry(struct xc_entry *, struct dpif_flow_stats *,
bool);
void xlate_push_stats(struct xlate_cache *, struct dpif_flow_stats *,
bool);
void xlate_cache_clear_entry(struct xc_entry *);
void xlate_cache_clear(struct xlate_cache *);
void xlate_cache_uninit(struct xlate_cache *);
void xlate_cache_delete(struct xlate_cache *);
void xlate_cache_steal_entries(struct xlate_cache *, struct xlate_cache *);
void xlate_xcache_format(struct ds *, const struct xlate_cache *);
#endif /* ofproto-dpif-xlate-cache.h */