資源簡介
Open vSwitch源代碼詳細的分析與指導,非常值得一看!
COPYING 許可說明 DESIGN 設計原則,處理 openflow協議相關細節和考慮 FAQ NEWS NOTICE README README-gCOV REPORTING-BUGS WHY-OVS 注:1.8.90版本,所有C源碼行數為189964,其中 datapath模塊28131, vswitchd模 塊5888, ovsdb模塊10549,ib為101592, ofproto為18571。 find openvswitch -name"*[ch]"I xargs cat Wc - 15.其他文件 debian/ Integration Guide 集成到其他 hypervisor PORTING 移植說明 python/ Submitting Patches 補丁提交 tests 測試代碼 third-party/ 支持第三方的插件,包括讓 tcpdump支持解析of協議的補丁。 utilities/ 小工具,包括用戶操作命令,例如ovs-dpct、ovs- ofctl、 OVS-controller、 oVS-vsctl等 等。其中 ovs-vsctl是主要的對配置數據庫進行交互的接口。 xenserver/ xenserver集成信息 1.6.整體功能邏輯 ovid pace ovS-dpctl controller + ovs-vswitchd etc Kerne datapath data path datapath pace 2. datapath模塊 2.1.整體分析 datapath模塊的代碼主要包括如下幾個關鍵子模塊:主文件 datapath.hc, vport的實 現 vport( generIc/gre/ capwap/ netdev/ internal/ρatch),gen子模塊。 2.1.1 tion模塊 action.c中定義了對網包執行操仵的各個接口。 包括對van頭的處理,對skb執行一系列給定的操作,發出網包,發skb給用戶態 ovsd),采樣,設置包頭各個域的屬性等。 2.1.2.flow模塊 包括fowh和 flow. c。 定義維護交換機本地流表相關的數據結構和操作,包括流表結構的創建、更新、刪除, 對每條流的管理等。 21.3.genl模塊 gen|- exec. h中定義了對gen的相關操作,包括 typedef int genl exec func t)void*data) int genl exec(genl exec func t func, void*data); int genl exec init(void; void genl exec exit(void) genl_ exec_ family的定義為 static struct genl family genl exec family =i id= GENL ID GENERATE, / channel number: will be assigned by the controller name=ovs genl exec version =1 genl exec ops的定義為 static struct genl ops genl exec opsl cmd= GENL EXEC RUN, // reference the operation doit= genl exec cmd, //the callback function flags =CAP NET ADMIN, 2.14. vport和 vport ops 關鍵的邏輯實現在 vport子模塊中。在 vport. h/c中定義了抽象的 vport結構。對外的 對 vport進行操作的接山如下 int ovs vport init(void); void ovs vport exit/void) struct vport ovs vport add(const struct vport parms*): void ovs vport del(struct vport*); struct vport ovs vport locate(struct net*net, const char *name) int ovs vport set addr struct vport * const unsigned char void ovs vport set stats(struct vport struct ovs vport stats ) void ovs vport get stats struct vport struct ovs vport stats " int ovs _vport set options(struct vport *, struct nlattr *options) int ovs vport_ _ get options(const struct vport*, struct sk buff *) int ovs vport send(struct vport * struct sk buff 這些接口對外提供統一的用戶操作界面。部分并沒有立刻定義,即使定義的接口中, 大部分依次或者單獨調用某種類型的 vport上綁定的 vport_ops中提供的接口,對所有支 持的 vport進行操作。例如,初始化過程中,實際上是初始化了一個 vport_ ops list,依 次初始化不同類型的 vport,并放到該ist中。再比如 ovs vport add接山實際上先進行查 找,找到給定的類型之后,進行對應的操作 而具體到某個 vport,其能進行操作的接口在 vport ops結構體中聲眀,為 struct vport ops i enum ovs vport type type 32 fla / Called at module in it and exit respectively int (init)(void); (exit)(void); / Called with RTNL lock * port**create)(const struct vport_ parms *) yoid(destroy (struct vport * ) int set options)(struct vport*, struct nlattr * int( get options)(const stru 0● t sk buff ) int set addr (struct sports, const unsigned char * / Called with rcu read lock or rtL lock const char *get name)const struct vport*) const unsigned char *(get _addr(const struct vport void get_config(const struct vport * void*); struct kobject*( get kobe(const struct vport ) unsigned get dev flags)(const struct vport ) int ( *is running)(const struct vport unsigned char get operstate)(const struct vport *) int *get ifindex (const struct vport*) int (get mtu)(const struct vport*) int(send)(struct vport struct sk buff * 日前, vport ops支持5種類型,分別為 static const struct vport ops *base vport ops list[=i &ovs netdev vport ops &ovs internal vport ops, &ovs patch vport ops, &ovs gre vport ops #if LINUX VERSION CODE >=KERNEL VERSION(2, 6, 26) &ovs capwap vport ops, fendi 以 ovs netdev vport ops為例,定義了一系列的函數指針。 const struct vport ops ovs netdev vport ops =t tvpe E OVS VPORT TYPE NETDEV flags VPORT F REQUIRED netdev init exit netdev exit create netdev create, destroy netdev destroy set addr ovs netdev set addr, get name =ovs netdev_get name, et addr =ovs_ netdev _get_ addr get kob ovs netdev get obj get dev flags =ovs netdev get dev flags, is running =ovs netdev is running get operstate ovs netdev get operstate, get_ifindex =ovs_ netdev_get ifindex, get_ mtu ovs netdev get mtu sen netdev send 2.1.5. netdev vport 綁定到具體網終設備上的vpot的結構 該結構的定義十分簡單,封裝了一個 net device結構,定義如下。 struct netdev vport struct net device dev 2.2 datapath. c 模塊的主文件。實現了一個簡單的交換機。 2.2.1.注冊和回收 module_ init(dp init); call when this module is loaded into kernel module exit(dp cleanup); //call when the module is removed from kernel 注冊后,調用dρ_init來完成各項初始化工作,dpρ_init也是模塊的主函數。 當模垬被卸載時,調用dp_ cleanup完成清理工作,凹收各項數據結構 dp init主要過程為 genl exec inito ovs workqueues init( ovs flow inito ovs vport init() register_pernet device(&ovs_ _net ops) register netdevice notifier(&ovs dp device notifier) dp register geno schedule delayed work &rehash flow wa, REHASH FLOW INTERVAL 22.2. GENL EXEC RUN初始化 genl exec_init(,完成 genl exec run的相關注冊,僅在 KERNEL VERSION<2.635時生 效。主要代碼為 err= genl register family with ops(&genl exec family genl_ exec ops, ARRAY SIZE(genl_ exec ops) 注冊的 generic netlink family:gen|_ exec family。 static struct genl family genl exec family = i id=GENL ID GENERATE, / new family will be assigned by the controller ame=ovs_genl exec version =1 對應操作的結構為 static struct genl ops genl exec ops[=i cmd= gENL EXEC RUN doit genl exec cmd, flags= CAP NET_ ADMIN 22.3.工作隊列初始化 ovs workqueues init( 創建 worker thread,初始化 more work工作隊列,輪詢檢測執行隊列中的任務 主要代碼為 work_ thread = kthread create worker thread, NULL, "ovs work ) ;//just create wake up_ process work thread); //run the created thread 224. port_ table初始化 ovs_tnl_init),初始化 port_ table數據結構 主要代碼為 port table kmalloc(PORT TABLE_ SIZE *sizeof(struct hist head*), GFP KERNEL) fori=0; i< PORT TABLE SIZE; i++) INIT HLIST HEAD (&port table[il) 22.5. flow cache初始化 ovs flow init(),申請 flow cache,主要代碼為
代碼片段和文件信息
評論
共有 條評論