From patchwork Fri Nov 27 12:27:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 549450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2780414031B for ; Fri, 27 Nov 2015 23:35:37 +1100 (AEDT) Received: from localhost ([::1]:56339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2IFM-00048x-B6 for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2015 07:35:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I6i-0007PM-3R for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2I6h-0002xB-6l for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:32 -0500 Received: from [59.151.112.132] (port=43907 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I6g-0002gO-I3 for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:31 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="918285" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Nov 2015 20:26:10 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 112984066D31; Fri, 27 Nov 2015 20:26:01 +0800 (CST) Received: from G08FNSTD140215.g08.fujitsu.local (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 27 Nov 2015 20:26:00 +0800 From: Zhang Chen To: qemu devel , Jason Wang , Stefan Hajnoczi Date: Fri, 27 Nov 2015 20:27:31 +0800 Message-ID: <1448627251-11186-10-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448627251-11186-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1448627251-11186-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner-ID: 112984066D31.A9E83 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Li Zhijian , Gui jianfeng , "eddie.dong" , "Dr. David Alan Gilbert" , Huang peng , Gong lei , jan.kiszka@siemens.com, Zhang Chen , zhanghailiang Subject: [Qemu-devel] [RFC PATCH 9/9] net/colo-proxy: add packet compare and notify checkpoint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: zhangchen Lookup same connection's primary and secondary packet to compare,if same we will send primary packet and drop secondary packet,else send all of primary packets be queued,drop secondary queue and notify colo to do checkpoint Signed-off-by: zhangchen --- net/colo-proxy.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/net/colo-proxy.c b/net/colo-proxy.c index 5f1852a..847f7f2 100644 --- a/net/colo-proxy.c +++ b/net/colo-proxy.c @@ -70,6 +70,41 @@ static Connection *connection_new(void) return connection; } +static void colo_send_primary_packet(void *opaque, void *user_data) +{ + Packet *pkt = opaque; + qemu_net_queue_send(pkt->s->incoming_queue, pkt->sender, 0, + (const uint8_t *)pkt->data, pkt->size, NULL); +} + +static void colo_flush_connection(void *opaque, void *user_data) +{ + Connection *connection = opaque; + g_queue_foreach(&connection->primary_list, colo_send_primary_packet, NULL); + g_queue_foreach(&connection->secondary_list, packet_destroy, NULL); +} + +static void colo_proxy_notify_checkpoint(void) +{ + DEBUG("colo_proxy_notify_checkpoint\n"); +} + +static void colo_proxy_do_checkpoint(NetFilterState *nf) +{ + ColoProxyState *s = FILTER_COLO_PROXY(nf); + + g_queue_foreach(&s->unprocessed_connections, colo_flush_connection, NULL); +} + +/* + * colo failover flag + */ +static ssize_t colo_has_failover(NetFilterState *nf) +{ + ColoProxyState *s = FILTER_COLO_PROXY(nf); + return s->has_failover; +} + /* Return 0 on success, or return -1 if the pkt is corrpted */ static int parse_packet_early(Packet *pkt, Connection_key *key) { @@ -136,6 +171,45 @@ static void packet_destroy(void *opaque, void *user_data) g_slice_free(Packet, pkt); } +/* + * The sent IP packets comparison between primary + * and secondary + * TODOļ¼š support ip fragment + * return: true means packet same + * false means packet different + */ +static bool colo_packet_compare(Packet *ppkt, Packet *spkt) +{ + int i; + DEBUG("colo_packet_compare lens ppkt %d,spkt %d\n", ppkt->size, + spkt->size); + DEBUG("primary pkt data=%s, pkt->ip->ipsrc=%x,pkt->ip->ipdst=%x\n", + (char *)ppkt->data, ppkt->ip->ip_src, ppkt->ip->ip_dst); + DEBUG("seconda pkt data=%s, pkt->ip->ipsrc=%x,pkt->ip->ipdst=%x\n", + (char *)spkt->data, spkt->ip->ip_src, spkt->ip->ip_dst); + if (ppkt->size == spkt->size) { + DEBUG("colo_packet_compare data ppkt\n"); + for (i = 0; i < spkt->size; i++) { + DEBUG("%x", ((char *)ppkt->data)[i]); + DEBUG("|"); + } + DEBUG("\ncolo_packet_compare data spkt\n"); + for (i = 0; i < spkt->size; i++) { + DEBUG("%x", ((char *)spkt->data)[i]); + DEBUG("|"); + } + DEBUG("\ncolo_packet_compare data ppkt %s\n", (char *)ppkt->data); + DEBUG("colo_packet_compare data spkt %s\n", (char *)spkt->data); + if (!memcmp(ppkt->data, spkt->data, spkt->size)) { + return true; + } else { + return false; + } + } else { + return false; + } +} + static Connection *colo_proxy_enqueue_packet(GHashTable *unprocessed_packets, Connection_key *key, Packet *pkt, packet_type type)