POX设置packet-in的miss_send_len

POX设置packet-in的miss_send_len


在of_01.py中可以看到交换机和Controller建立连接时的信息流交互,互问hello,然后得到Switch的feature信息,而后Controller可以发送ofp_switch_cofig消息配置交换机,这个消息很简单,就是我们需要的 miss_send_len。这些初始化的过程在任何SDN控制器中都有对应的逻辑,之前也看过Floodlight中的流程

openflow 1.0协议中对应结构体:
这里写图片描述

POX中处理来自交换机的ofp_switch_features消息的过程如下:

def handle_FEATURES_REPLY (con, msg):
  connecting = con.connect_time == None
  con.features = msg
  con.original_ports._ports = set(msg.ports)
  con.ports._reset()
  con.dpid = msg.datapath_id

  nexus = core.OpenFlowConnectionArbiter.getNexus(con)
  con.ofnexus = nexus
  con.ofnexus._connect(con)

  barrier = of.ofp_barrier_request()

  listeners = []

  def finish_connecting (event):
    if event.xid != barrier.xid:
      con.dpid = None
      con.err("failed connect")
      con.disconnect()
    else:
      con.info("connected")
      con.connect_time = time.time()
      e = con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
      if e is None or e.halt != True:
        con.raiseEventNoErrors(ConnectionUp, con, msg)
      e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
      if e is None or e.halt != True:
        con.raiseEventNoErrors(FeaturesReceived, con, msg)
    con.removeListeners(listeners)
  listeners.append(con.addListener(BarrierIn, finish_connecting))

  def also_finish_connecting (event):
    if event.xid != barrier.xid: return
    if event.ofp.type != of.OFPET_BAD_REQUEST: return
    if event.ofp.code != of.OFPBRC_BAD_TYPE: return
    # Okay, so this is probably an HP switch that doesn't support barriers
    # (ugh).  We'll just assume that things are okay.
    finish_connecting(event)
  listeners.append(con.addListener(ErrorIn, also_finish_connecting))

  # 在这里设置的miss_send_len
  if con.ofnexus.miss_send_len is not None:
    con.send(of.ofp_set_config(miss_send_len =
                                  con.ofnexus.miss_send_len))
  if con.ofnexus.clear_flows_on_connect:
    con.send(of.ofp_flow_mod(match=of.ofp_match(),command=of.OFPFC_DELETE))

  con.send(barrier)

在这里看到设置的默认值是128,需要写一个简单的模块收取所有的packet-in,然后flood,这样才会看packet-in miss_send_len的日志。

我使用netcat来在两个mininet主机之间发送UDP数据包。

默认情况下效果:
这里写图片描述
(长度为42的是ARP包,长度为203的是我们发送的UDP包)

可以自己设置miss_send_len,然后效果如下:

if con.ofnexus.miss_send_len is not None:
    log.debug('[*] miss_send_len = 1500')
    con.send(of.ofp_set_config(miss_send_len = 1500))

这里写图片描述

猜你喜欢

转载自blog.csdn.net/vonzhoufz/article/details/50241407
今日推荐