2016年1月25日 星期一

[POX] Controller安裝Flow entry到Switch

本篇是筆記當Controller要安裝flow entry到Switch上時 
所需使用的字串以及部分字串的使用範例
尚無完整範例


若要安裝Flow entry到Switch上
Controller必須編輯 ofp_flow_mod 訊息並傳送給Switch
訊息中有些必要參數需要設定


ofp_flow_mod message fields:

  • ofp_flow_mod() : 編輯Entry訊息所用的函數,包含command參數,分別代表不同編輯規則,預設為0(新增),設定方式與相關數值如下:
    msg = of.opf_flow_mod(command=x) #creat a new flow_message, x∈0~4
    
    • 0: Add Flow entry
    • 1: Modify Flow entry
    • 2: Modify_Strict Flow entry
    • 3: Delete Flow entry
    • 4: Delete_Strict Flow entry
  • priority : Flow entry的優先權,範圍在1-65535,Openflow標準中曾提到當優先權相同時的處置方式尚未被定義,未確定1.5版本後是否完成定義 

  • match : ofp_match 物件,預設會match所有packet,要match特定封包時,其相關參數如下
    • ofp_match fields:

      • in_port : (short)封包進入的switch port,值為Switch上的port index
      • dl_src : (byte[])Match的src_address (MAC)
      • dl_dst : (byte[])Match的dst_address (MAC)
      • dl_type : (short)Match的Ethernet Type
      • dl_vlan : (short)Match的vlan id (必須是Switch上存在的vlan)
      • nw_src : (int)Match的src ip address
      • nw_dst : (int)Match的dst ip address
      • nw_proto : (byte)Match的protocol type
      • tcp_src : (short)Match TCP src port
      • tcp_dst : (short)Match TCP dst port
      • idle_timeout : Flow entry的閒置時間(N秒後沒有處理flow就刪除該entry),單位為秒(sec),預設沒有閒置時間
      • hard_timeout : Flow entry的存活時間(N秒後不論有無動作,entry一定會被移除),單位為秒(sec),預設沒有存活限制
      • dl_vlan_pcp : Match vlan的優先權 (range 0-7)
      • nw_tos Match的服務類型(Type of Service)
  • actions : 對於match的packet要執行的處理動作清單 (e.g., ofp_action_output),預設為丟棄(Drop)封包,action中的執行命令主要使用append()附加,因此增加action時須使用以下方式:
     msg.actions.append(....) 
    
    其中可用的相關參數包含
    • of.ofp_action_output() : 指定output port,參數為port=x,port為openflow vlan中的port,另外包含部分特殊值如下 
      • 0xfff8 : 從IN_PORT送出
      • 0xfffb : Flood,除了In_port以及STP不允許的port之外廣播
      • 0xfffc : All,除了In_port之外的廣播
      • 0xfffd : Controller,轉送到Controller
      • 0xffff : None
    • of.ofp_action_enqueue():轉送到特定的Port和queue,參數包含port與queue_id
    • of.ofp_action_dl_addr.set_src(“”):變更src MAC address為("")中指定的MAC address,形式為aa:bb:cc:dd:ee:ff
    • of.ofp_action_dl_addr.set_dst(“”):變更dst MAC address為("")中指定的MAC address,形式為aa:bb:cc:dd:ee:ff
    • of.ofp_action_nw_tos():設定Type of Service值,參數為nw_tos
    • of.ofp_action_vlan_vid():設定vlan id,參數為vlan_vid
    • of.ofp_action_vlan_pcp():設定vlan的Class of Service,參數為vlan_pcp,需要先設置vid
相關設置範例
msg = of.opf_flow_mod(command=0) #creat a new flow_message (0-4)
msg.priority=x #range(1-65535)

msg.match.dl_src=EthAddr(“src_Mac address”) #set src MAC address
msg.match.dl_dst=EthAddr(“dst_Mac address”) #set dst MAC address
msg.match.dl_type=0x0800 #match Ethernet type
msg.match.dl_vlan= #match vlan
msg.match.dl_vlan_pcp=x #match vlan priority (0-7)
#Before set src IP address, dst IP address, Type of Service and protocol, you have to set the dl_type first
msg.match.nw_src=“A.B.C.D/X” #src ip address
msg.match.nw_dst=“A.B.C.D/X” #dst ip address
msg.match.nw_proto=x #protocal
msg.match.nw_tos=x #type of service

#Before set TCP src port ,TCP dst port,you have to set the dl_type and nw_proto first
msg.match.tp_src=X 
msg.match.tp_dst=X 

msg.idle_timeout=X 
msg.hard_timeout=X 

msg.actions.append(of.ofp_action_output(port=X))
msg.actions.append(of.ofp_action_enqueue(port=x,queue_id=y))
msg.actions.append(of.ofp_action_dl_addr.set_dst(“”))
msg.actions.append(of.ofp_action_dl_addr.set_src(“”))
msg.actions.append(of.ofp_action_nw_tos(nw_tos=x))


#Before set vlan CoS, you have to set the vlan id first
msg.actions.append(of.ofp_action_vlan_vid(vlan_vid=x))
msg.actions.append(of.ofp_action_vlan_pcp(vlan_pcp=x))
self.connection.send(msg) #send the message

Reference:
[1] http://www.control.lth.se/Education/DoctorateProgram/introduction-to-cloud-computing/homework-assignment-3.html (Available:2016/01/26)
[2] http://www.lai18.com/content/1138662.html (Available:2016/02/18)
[3] http://www.muzixing.com/pages/2013/12/12/yuan-chuang-openflowtong-xin-liu-cheng-jie-du.html (Available:2016/02/18)

沒有留言:

張貼留言