qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Yang Hongyang <yanghy@cn.fujitsu.com>
Cc: thuth@redhat.com, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com, jasowang@redhat.com,
	qemu-devel@nongnu.org, armbru@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v10 09/10] netfilter: add a netbuffer filter
Date: Mon, 14 Sep 2015 10:04:06 +0100	[thread overview]
Message-ID: <20150914090406.GC7611@redhat.com> (raw)
In-Reply-To: <1441783481-17698-10-git-send-email-yanghy@cn.fujitsu.com>

On Wed, Sep 09, 2015 at 03:24:40PM +0800, Yang Hongyang wrote:
> This filter is to buffer/release packets, this feature can be used
> when using MicroCheckpointing, or other Remus like VM FT solutions, you
> can also use it to simulate the network delay.
> It has an interval option, if supplied, this filter will release
> packets by interval.
> 
> Usage:
>  -netdev tap,id=bn0
>  -object filter-buffer,id=f0,netdev=bn0,chain=in,interval=1000
> 
> NOTE:
>  the scale of interval is microsecond.
> 
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>

> diff --git a/net/filter-buffer.c b/net/filter-buffer.c
> new file mode 100644
> index 0000000..26698d9
> --- /dev/null
> +++ b/net/filter-buffer.c
> @@ -0,0 +1,169 @@
> +/*
> + * Copyright (c) 2015 FUJITSU LIMITED
> + * Author: Yang Hongyang <yanghy@cn.fujitsu.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * later.  See the COPYING file in the top-level directory.
> + */
> +
> +#include "net/filter.h"
> +#include "net/queue.h"
> +#include "qemu-common.h"
> +#include "qemu/timer.h"
> +#include "qemu/iov.h"
> +#include "qapi/qmp/qerror.h"
> +#include "qapi-visit.h"
> +#include "qom/object.h"
> +
> +#define TYPE_FILTER_BUFFER "filter-buffer"
> +
> +#define FILTER_BUFFER(obj) \
> +    OBJECT_CHECK(FilterBufferState, (obj), TYPE_FILTER_BUFFER)
> +
> +typedef struct FilterBufferState {
> +    NetFilterState parent_obj;
> +
> +    NetQueue *incoming_queue;
> +    uint32_t interval;
> +    QEMUTimer release_timer;
> +} FilterBufferState;
> +
> +static void filter_buffer_flush(NetFilterState *nf)
> +{
> +    FilterBufferState *s = FILTER_BUFFER(nf);
> +
> +    if (!qemu_net_queue_flush(s->incoming_queue)) {
> +        /* Unable to empty the queue, purge remaining packets */
> +        qemu_net_queue_purge(s->incoming_queue, nf->netdev);
> +    }
> +}
> +
> +static void filter_buffer_release_timer(void *opaque)
> +{
> +    NetFilterState *nf = opaque;
> +    FilterBufferState *s = FILTER_BUFFER(nf);
> +    filter_buffer_flush(nf);
> +    timer_mod(&s->release_timer,
> +              qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + s->interval);
> +}
> +
> +/* filter APIs */
> +static ssize_t filter_buffer_receive_iov(NetFilterState *nf,
> +                                         NetClientState *sender,
> +                                         unsigned flags,
> +                                         const struct iovec *iov,
> +                                         int iovcnt,
> +                                         NetPacketSent *sent_cb)
> +{
> +    FilterBufferState *s = FILTER_BUFFER(nf);
> +
> +    /*
> +     * we return size when buffer a packet, the sender will take it as
> +     * a already sent packet, so sent_cb should not be called later
> +     */
> +    qemu_net_queue_append_iov(s->incoming_queue, sender, flags,
> +                              iov, iovcnt, NULL);
> +    return iov_size(iov, iovcnt);
> +}
> +
> +static void filter_buffer_cleanup(NetFilterState *nf)

Same comment about s/cleanup/finalize/

> +{
> +    FilterBufferState *s = FILTER_BUFFER(nf);
> +
> +    if (s->interval) {
> +        timer_del(&s->release_timer);
> +    }
> +
> +    /* flush packets */
> +    if (s->incoming_queue) {
> +        filter_buffer_flush(nf);
> +        g_free(s->incoming_queue);
> +    }
> +}

> diff --git a/vl.c b/vl.c
> index 672f8b2..30196e4 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2783,7 +2783,12 @@ static bool object_create_initial(const char *type)
>      if (g_str_equal(type, "rng-egd")) {
>          return false;
>      }
> -    /* TODO: reture false for concrete netfilters */

Oh, I missed the typo in your earlier patch - s/reture/return/

> +
> +    /* reture false for concrete netfilters */

And again in the line you changed here.

> +    if (g_str_equal(type, "filter-buffer")) {
> +        return false;
> +    }
> +


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2015-09-14  9:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09  7:24 [Qemu-devel] [PATCH v10 00/10] Add a netfilter object and netbuffer filter Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 01/10] qmp: delete qemu opts when delete an object Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 02/10] init/cleanup of netfilter object Yang Hongyang
2015-09-14  8:54   ` Daniel P. Berrange
2015-09-14  8:56     ` Daniel P. Berrange
2015-09-14  9:05     ` Yang Hongyang
2015-09-16  9:28   ` Jason Wang
2015-09-16 11:11     ` Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 03/10] netfilter: hook packets before net queue send Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 04/10] net: merge qemu_deliver_packet and qemu_deliver_packet_iov Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 05/10] net/queue: introduce NetQueueDeliverFunc Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 06/10] netfilter: add an API to pass the packet to next filter Yang Hongyang
2015-09-16  9:29   ` Jason Wang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 07/10] netfilter: print filter info associate with the netdev Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 08/10] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 09/10] netfilter: add a netbuffer filter Yang Hongyang
2015-09-14  9:04   ` Daniel P. Berrange [this message]
2015-09-14  9:53     ` Yang Hongyang
2015-09-16  9:42   ` Jason Wang
2015-09-16 11:19     ` Yang Hongyang
2015-09-09  7:24 ` [Qemu-devel] [PATCH v10 10/10] tests: add test cases for netfilter object Yang Hongyang
2015-09-14  5:09 ` [Qemu-devel] [PATCH v10 00/10] Add a netfilter object and netbuffer filter Yang Hongyang
2015-09-14  5:22   ` Jason Wang
2015-09-14  5:36     ` Yang Hongyang
2015-09-16  9:48       ` Jason Wang
2015-09-16 11:22         ` Yang Hongyang
2015-09-14  9:05   ` Daniel P. Berrange
2015-09-14  9:14     ` Yang Hongyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150914090406.GC7611@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=yanghy@cn.fujitsu.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).