colo-proxy.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. COLO-proxy
  2. ----------
  3. Copyright (c) 2016 Intel Corporation
  4. Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
  5. Copyright (c) 2016 Fujitsu, Corp.
  6. This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. See the COPYING file in the top-level directory.
  8. This document gives an overview of COLO proxy's design.
  9. == Background ==
  10. COLO-proxy is a part of COLO project. It is used
  11. to compare the network package to help COLO decide
  12. whether to do checkpoint. With COLO-proxy's help,
  13. COLO greatly improves the performance.
  14. The filter-redirector, filter-mirror, colo-compare
  15. and filter-rewriter compose the COLO-proxy.
  16. == Architecture ==
  17. COLO-Proxy is based on qemu netfilter and it's a plugin for qemu netfilter
  18. (except colo-compare). It keep Secondary VM connect normally to
  19. client and compare packets sent by PVM with sent by SVM.
  20. If the packet difference, notify COLO-frame to do checkpoint and send
  21. all primary packet has queued. Otherwise just send the queued primary
  22. packet and drop the queued secondary packet.
  23. Below is a COLO proxy ascii figure:
  24. Primary qemu Secondary qemu
  25. +--------------------------------------------------------------+ +----------------------------------------------------------------+
  26. | +----------------------------------------------------------+ | | +-----------------------------------------------------------+ |
  27. | | | | | | | |
  28. | | guest | | | | guest | |
  29. | | | | | | | |
  30. | +-------^--------------------------+-----------------------+ | | +---------------------+--------+----------------------------+ |
  31. | | | | | ^ | |
  32. | | | | | | | |
  33. | | +------------------------------------------------------+ | | | |
  34. |netfilter| | | | | | netfilter | | |
  35. | +----------+ +----------------------------+ | | | +-----------------------------------------------------------+ |
  36. | | | | | | out | | | | | | filter execute order | |
  37. | | | | +-----------------------------+ | | | | | | +-------------------> | |
  38. | | | | | | | | | | | | | | TCP | |
  39. | | +-----+--+-+ +-----v----+ +-----v----+ |pri +----+----+sec| | | | +------------+ +---+----+---v+rewriter++ +------------+ | |
  40. | | | | | | | | |in | |in | | | | | | | | | | | | |
  41. | | | filter | | filter | | filter +------> colo <------+ +--------> filter +--> adjust | adjust +--> filter | | |
  42. | | | mirror | |redirector| |redirector| | | compare | | | | | | redirector | | ack | seq | | redirector | | |
  43. | | | | | | | | | | | | | | | | | | | | | | | |
  44. | | +----^-----+ +----+-----+ +----------+ | +---------+ | | | | +------------+ +--------+--------------+ +---+--------+ | |
  45. | | | tx | rx rx | | | | | tx all | rx | |
  46. | | | | | | | | +-----------------------------------------------------------+ |
  47. | | | +--------------+ | | | | | |
  48. | | | filter execute order | | | | | | |
  49. | | | +----------------> | | | +--------------------------------------------------------+ |
  50. | +-----------------------------------------+ | | |
  51. | | | | | |
  52. +--------------------------------------------------------------+ +----------------------------------------------------------------+
  53. |guest receive | guest send
  54. | |
  55. +--------+----------------------------v------------------------+
  56. | | NOTE: filter direction is rx/tx/all
  57. | tap | rx:receive packets sent to the netdev
  58. | | tx:receive packets sent by the netdev
  59. +--------------------------------------------------------------+
  60. 1.Guest receive packet route:
  61. Primary:
  62. Tap --> Mirror Client Filter
  63. Mirror client will send packet to guest,at the
  64. same time, copy and forward packet to secondary
  65. mirror server.
  66. Secondary:
  67. Mirror Server Filter --> TCP Rewriter
  68. If receive packet is TCP packet,we will adjust ack
  69. and update TCP checksum, then send to secondary
  70. guest. Otherwise directly send to guest.
  71. 2.Guest send packet route:
  72. Primary:
  73. Guest --> Redirect Server Filter
  74. Redirect server filter receive primary guest packet
  75. but do nothing, just pass to next filter.
  76. Redirect Server Filter --> COLO-Compare
  77. COLO-compare receive primary guest packet then
  78. waiting secondary redirect packet to compare it.
  79. If packet same,send queued primary packet and clear
  80. queued secondary packet, Otherwise send primary packet
  81. and do checkpoint.
  82. COLO-Compare --> Another Redirector Filter
  83. The redirector get packet from colo-compare by use
  84. chardev socket.
  85. Redirector Filter --> Tap
  86. Send the packet.
  87. Secondary:
  88. Guest --> TCP Rewriter Filter
  89. If the packet is TCP packet,we will adjust seq
  90. and update TCP checksum. Then send it to
  91. redirect client filter. Otherwise directly send to
  92. redirect client filter.
  93. Redirect Client Filter --> Redirect Server Filter
  94. Forward packet to primary.
  95. == Components introduction ==
  96. Filter-mirror is a netfilter plugin.
  97. It gives qemu the ability to mirror
  98. packets to a chardev.
  99. Filter-redirector is a netfilter plugin.
  100. It gives qemu the ability to redirect net packet.
  101. Redirector can redirect filter's net packet to outdev,
  102. and redirect indev's packet to filter.
  103. filter
  104. +
  105. redirector |
  106. +--------------+
  107. | | |
  108. | | |
  109. | | |
  110. indev +---------+ +----------> outdev
  111. | | |
  112. | | |
  113. | | |
  114. +--------------+
  115. |
  116. v
  117. filter
  118. COLO-compare, we do packet comparing job.
  119. Packets coming from the primary char indev will be sent to outdev.
  120. Packets coming from the secondary char dev will be dropped after comparing.
  121. COLO-compare needs two input chardevs and one output chardev:
  122. primary_in=chardev1-id (source: primary send packet)
  123. secondary_in=chardev2-id (source: secondary send packet)
  124. outdev=chardev3-id
  125. Filter-rewriter will rewrite some of secondary packet to make
  126. secondary guest's tcp connection established successfully.
  127. In this module we will rewrite tcp packet's ack to the secondary
  128. from primary,and rewrite tcp packet's seq to the primary from
  129. secondary.
  130. == Usage ==
  131. Here is an example using demonstration IP and port addresses to more
  132. clearly describe the usage.
  133. Primary(ip:3.3.3.3):
  134. -netdev tap,id=hn0,vhost=off
  135. -device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
  136. -chardev socket,id=mirror0,host=3.3.3.3,port=9003,server=on,wait=off
  137. -chardev socket,id=compare1,host=3.3.3.3,port=9004,server=on,wait=off
  138. -chardev socket,id=compare0,host=3.3.3.3,port=9001,server=on,wait=off
  139. -chardev socket,id=compare0-0,host=3.3.3.3,port=9001
  140. -chardev socket,id=compare_out,host=3.3.3.3,port=9005,server=on,wait=off
  141. -chardev socket,id=compare_out0,host=3.3.3.3,port=9005
  142. -object iothread,id=iothread1
  143. -object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0
  144. -object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out
  145. -object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0
  146. -object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,iothread=iothread1
  147. Secondary(ip:3.3.3.8):
  148. -netdev tap,id=hn0,vhost=off
  149. -device e1000,netdev=hn0,mac=52:a4:00:12:78:66
  150. -chardev socket,id=red0,host=3.3.3.3,port=9003
  151. -chardev socket,id=red1,host=3.3.3.3,port=9004
  152. -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0
  153. -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1
  154. -object filter-rewriter,id=f3,netdev=hn0,queue=all
  155. If you want to use virtio-net-pci or other driver with vnet_header:
  156. Primary(ip:3.3.3.3):
  157. -netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown
  158. -device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
  159. -chardev socket,id=mirror0,host=3.3.3.3,port=9003,server=on,wait=off
  160. -chardev socket,id=compare1,host=3.3.3.3,port=9004,server=on,wait=off
  161. -chardev socket,id=compare0,host=3.3.3.3,port=9001,server=on,wait=off
  162. -chardev socket,id=compare0-0,host=3.3.3.3,port=9001
  163. -chardev socket,id=compare_out,host=3.3.3.3,port=9005,server=on,wait=off
  164. -chardev socket,id=compare_out0,host=3.3.3.3,port=9005
  165. -object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support
  166. -object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out,vnet_hdr_support
  167. -object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0,vnet_hdr_support
  168. -object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support
  169. Secondary(ip:3.3.3.8):
  170. -netdev tap,id=hn0,vhost=off
  171. -device e1000,netdev=hn0,mac=52:a4:00:12:78:66
  172. -chardev socket,id=red0,host=3.3.3.3,port=9003
  173. -chardev socket,id=red1,host=3.3.3.3,port=9004
  174. -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0,vnet_hdr_support
  175. -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1,vnet_hdr_support
  176. -object filter-rewriter,id=f3,netdev=hn0,queue=all,vnet_hdr_support
  177. Note:
  178. a.COLO-proxy must work with COLO-frame and Block-replication.
  179. b.Primary COLO must be started firstly, because COLO-proxy needs
  180. chardev socket server running before secondary started.
  181. c.Filter-rewriter only rewrite tcp packet.