Skip to content

Commit

Permalink
mirror: Support "both" direction in the same mirror object.
Browse files Browse the repository at this point in the history
It is more convenient to support "both" as a keyword to indicate both
directions instead of having to create two mirror objects to mirror both
directions.

Signed-off-by: Han Zhou <hzhou@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
  • Loading branch information
hzhou8 committed May 10, 2023
1 parent fccb35a commit c3d328d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 16 deletions.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Post v23.03.0
Listener Discovery protocols, regardless of ACLs defined.
- Add IPv6 iPXE support introducing "bootfile_name" (59) and
"bootfile_name_alt" (254) options to ovn dhcpv6 server.
- Support using local OVS port as port-mirroring target.
- Support using local OVS port as port-mirroring target, and also support
'both' directions for the 'filter' field.

OVN v23.03.0 - 03 Mar 2023
--------------------------
Expand Down
14 changes: 10 additions & 4 deletions controller/mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,17 @@ ovn_mirror_delete(struct ovn_mirror *m)
static void
ovn_mirror_add_lport(struct ovn_mirror *m, struct local_binding *lbinding)
{
struct mirror_lport *m_lport = xzalloc(sizeof *m_lport);
m_lport->lbinding = lbinding;
if (!strcmp(m->sb_mirror->filter, "from-lport")) {
if (!strcmp(m->sb_mirror->filter, "from-lport") ||
!strcmp(m->sb_mirror->filter, "both")) {
struct mirror_lport *m_lport = xzalloc(sizeof *m_lport);
m_lport->lbinding = lbinding;
ovs_list_push_back(&m->mirror_src_lports, &m_lport->list_node);
} else {
}

if (!strcmp(m->sb_mirror->filter, "to-lport") ||
!strcmp(m->sb_mirror->filter, "both")) {
struct mirror_lport *m_lport = xzalloc(sizeof *m_lport);
m_lport->lbinding = lbinding;
ovs_list_push_back(&m->mirror_dst_lports, &m_lport->list_node);
}
}
Expand Down
7 changes: 4 additions & 3 deletions ovn-nb.ovsschema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "OVN_Northbound",
"version": "7.0.1",
"cksum": "441625132 33536",
"version": "7.0.2",
"cksum": "190109735 33605",
"tables": {
"NB_Global": {
"columns": {
Expand Down Expand Up @@ -311,7 +311,8 @@
"name": {"type": "string"},
"filter": {"type": {"key": {"type": "string",
"enum": ["set", ["from-lport",
"to-lport"]]}}},
"to-lport",
"both"]]}}},
"sink":{"type": "string"},
"type": {"type": {"key": {"type": "string",
"enum": ["set", ["gre",
Expand Down
1 change: 1 addition & 0 deletions ovn-nb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,7 @@ or
The value of this field represents selection criteria of the mirror.
<code>to-lport</code> mirrors the packets coming into logical port.
<code>from-lport</code> mirrors the packets going out of logical port.
<code>both</code> mirrors for both directions.
</p>
</column>

Expand Down
7 changes: 4 additions & 3 deletions ovn-sb.ovsschema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "OVN_Southbound",
"version": "20.27.1",
"cksum": "1439763681 30400",
"version": "20.27.2",
"cksum": "1291808617 30462",
"tables": {
"SB_Global": {
"columns": {
Expand Down Expand Up @@ -148,7 +148,8 @@
"filter": {"type": {"key": {"type": "string",
"enum": ["set",
["from-lport",
"to-lport"]]}}},
"to-lport",
"both"]]}}},
"sink":{"type": "string"},
"type": {"type": {"key": {"type": "string",
"enum": ["set", ["gre",
Expand Down
3 changes: 3 additions & 0 deletions ovn-sb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2900,6 +2900,9 @@ tcp.flags = RST;
<column name="filter">
<p>
The value of this field represents selection criteria of the mirror.
<code>to-lport</code> mirrors the packets coming into logical port.
<code>from-lport</code> mirrors the packets going out of logical port.
<code>both</code> mirrors for both directions.
</p>
</column>

Expand Down
9 changes: 8 additions & 1 deletion tests/ovn.at
Original file line number Diff line number Diff line change
Expand Up @@ -16787,7 +16787,7 @@ mirror-to-lp2
# Send a packet from lp1 to lp2, should be mirrored to both mirror ports.
packet="inport==\"ls1-lp1\" && eth.src==00:00:00:01:01:02 && eth.dst==00:00:00:01:01:03 &&
ip4 && ip.ttl==64 && ip4.src==10.0.0.2 && ip4.dst==10.0.0.3 && icmp"
AT_CHECK([as hv1 ovs-appctl -t ovn-controller inject-pkt "$packet"])
OVS_WAIT_UNTIL([as hv1 ovs-appctl -t ovn-controller inject-pkt "$packet"])

exp_packet="eth.src==00:00:00:01:01:02 && eth.dst==00:00:00:01:01:03 && ip4 &&
ip.ttl==64 && ip4.src==10.0.0.2 && ip4.dst==10.0.0.3 && icmp"
Expand All @@ -16802,6 +16802,13 @@ OVS_WAIT_UNTIL([
AT_CHECK([cat mirror1.packets | sort], [0], [expout])
AT_CHECK([cat mirror2.packets | sort], [0], [expout])

port_src_old=$(ovs-vsctl get mirror mirror-from-lp1 select_src_port)
check ovn-nbctl set mirror $uuid1 filter=both
port_src_new=$(ovs-vsctl get mirror mirror-from-lp1 select_src_port)
port_dst_new=$(ovs-vsctl get mirror mirror-from-lp1 select_dst_port)
AT_CHECK([test $port_src_old = $port_src_new], [0], [])
AT_CHECK([test $port_src_old = $port_dst_new], [0], [])

OVN_CLEANUP([hv1])
AT_CLEANUP
])
Expand Down
3 changes: 2 additions & 1 deletion utilities/ovn-nbctl.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,8 @@

<p>
<var>filter</var> specifies the mirror source selection.
Can be <code>from-lport</code> or <code>to-lport</code>.
Can be <code>from-lport</code>, <code>to-lport</code> or
<code>both</code>.
</p>

<p>
Expand Down
8 changes: 5 additions & 3 deletions utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Mirror commands:\n\
(indicates key if GRE\n\
erpsan_idx if ERSPAN)\n\
specify FILTER for mirroring selection\n\
'to-lport' / 'from-lport'\n\
'to-lport' / 'from-lport' / 'both'\n\
specify Sink / Destination i.e. Remote IP, or a\n\
local interface with external-ids:mirror-id\n\
matching MIRROR-ID\n\
Expand Down Expand Up @@ -7399,10 +7399,12 @@ parse_mirror_filter(const char *arg, const char **selection_p)
*selection_p = "to-lport";
} else if (arg[0] == 'f') {
*selection_p = "from-lport";
} else if (arg[0] == 'b') {
*selection_p = "both";
} else {
*selection_p = NULL;
return xasprintf("%s: selection must be \"to-lport\" or "
"\"from-lport\"", arg);
return xasprintf("%s: selection must be \"to-lport\", "
"\"from-lport\", or \"both\"", arg);
}
return NULL;
}
Expand Down

0 comments on commit c3d328d

Please sign in to comment.