OpenFlow v1.4 消息和结构

控制器到交换机消息

握手

class os_ken.ofproto.ofproto_v1_4_parser.OFPFeaturesRequest(datapath)

功能请求消息

控制器在会话建立后向交换机发送功能请求。

此消息由 OSKen 框架处理,因此 OSKen 应用程序通常不需要处理此消息。

示例

def send_features_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPFeaturesRequest(datapath)
    datapath.send_msg(req)

JSON 示例

{
   "OFPFeaturesRequest": {}
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPSwitchFeatures(datapath, datapath_id=None, n_buffers=None, n_tables=None, auxiliary_id=None, capabilities=None)

功能回复消息

交换机响应功能请求,发送功能回复消息。

此消息由 OSKen 框架处理,因此 OSKen 应用程序通常不需要处理此消息。

示例

@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev):
    msg = ev.msg

    self.logger.debug('OFPSwitchFeatures received: '
                      'datapath_id=0x%016x n_buffers=%d '
                      'n_tables=%d auxiliary_id=%d '
                      'capabilities=0x%08x',
                      msg.datapath_id, msg.n_buffers, msg.n_tables,
                      msg.auxiliary_id, msg.capabilities)

JSON 示例

{
   "OFPSwitchFeatures": {
      "auxiliary_id": 99,
      "capabilities": 79,
      "datapath_id": 9210263729383,
      "n_buffers": 0,
      "n_tables": 255
   }
}

交换机配置

class os_ken.ofproto.ofproto_v1_4_parser.OFPSetConfig(datapath, flags=0, miss_send_len=0)

设置配置请求消息

控制器发送设置配置请求消息以设置配置参数。

属性

描述

flags

以下标志的位图。

OFPC_FRAG_NORMAL
OFPC_FRAG_DROP
OFPC_FRAG_REASM

miss_send_len

数据路径应发送到控制器的最大新流字节数

示例

def send_set_config(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPSetConfig(datapath, ofp.OFPC_FRAG_NORMAL, 256)
    datapath.send_msg(req)

JSON 示例

{
   "OFPSetConfig": {
      "flags": 0,
      "miss_send_len": 128
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGetConfigRequest(datapath)

获取配置请求消息

控制器发送获取配置请求以查询交换机中的配置参数。

示例

def send_get_config_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPGetConfigRequest(datapath)
    datapath.send_msg(req)

JSON 示例

{
   "OFPGetConfigRequest": {}
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGetConfigReply(datapath, flags=None, miss_send_len=None)

获取配置回复消息

交换机响应配置请求,发送获取配置回复消息。

属性

描述

flags

以下标志的位图。

OFPC_FRAG_NORMAL
OFPC_FRAG_DROP
OFPC_FRAG_REASM

miss_send_len

数据路径应发送到控制器的最大新流字节数

示例

@set_ev_cls(ofp_event.EventOFPGetConfigReply, MAIN_DISPATCHER)
def get_config_reply_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto
    flags = []

    if msg.flags & ofp.OFPC_FRAG_NORMAL:
        flags.append('NORMAL')
    if msg.flags & ofp.OFPC_FRAG_DROP:
        flags.append('DROP')
    if msg.flags & ofp.OFPC_FRAG_REASM:
        flags.append('REASM')
    self.logger.debug('OFPGetConfigReply received: '
                      'flags=%s miss_send_len=%d',
                      ','.join(flags), msg.miss_send_len)

JSON 示例

{
   "OFPGetConfigReply": {
      "flags": 0,
      "miss_send_len": 128
   }
}

修改状态消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPTableMod(datapath, table_id, config, properties)

流表配置消息

控制器发送此消息以配置表状态。

属性

描述

table_id

表的 ID(OFPTT_ALL 表示所有表)

config

配置标志的位图。

OFPTC_EVICTION
OFPTC_VACANCY_EVENTS

properties

OFPTableModProp 子类实例列表

示例

def send_table_mod(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPTableMod(datapath, 1, 3)
    flags = ofp.OFPTC_VACANCY_EVENTS
    properties = [ofp_parser.OFPTableModPropEviction(flags)]
    req = ofp_parser.OFPTableMod(datapath, 1, 3, properties)
    datapath.send_msg(req)

JSON 示例

{
   "OFPTableMod": {
      "config": 0,
      "properties": [
         {
            "OFPTableModPropEviction": {
               "flags": 0,
               "length": 8,
               "type": 2
            }
         },
         {
            "OFPTableModPropVacancy": {
               "length": 8,
               "type": 3,
               "vacancy": 0,
               "vacancy_down": 0,
               "vacancy_up": 0
            }
         },
         {
            "OFPTableModPropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65535
            }
         },
         {
            "OFPTableModPropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPTableModPropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ],
      "table_id": 255
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPFlowMod(datapath, cookie=0, cookie_mask=0, table_id=0, command=0, idle_timeout=0, hard_timeout=0, priority=32768, buffer_id=4294967295, out_port=0, out_group=0, flags=0, importance=0, match=None, instructions=None)

修改流条目消息

控制器发送此消息以修改流表。

属性

描述

cookie

不透明的控制器颁发的标识符

cookie_mask

用于限制在命令为 OPFFC_MODIFY*OFPFC_DELETE* 时必须匹配的 cookie 位的掩码

table_id

要将流放入的表的 ID

command

以下值之一。

OFPFC_ADD
OFPFC_MODIFY
OFPFC_MODIFY_STRICT
OFPFC_DELETE
OFPFC_DELETE_STRICT

idle_timeout

丢弃前的空闲时间(秒)

hard_timeout

丢弃前的最大时间(秒)

priority

流条目的优先级

buffer_id

要应用的缓冲数据包(或 OFP_NO_BUFFER)

out_port

对于 OFPFC_DELETE* 命令,要求匹配的条目包含此作为输出端口

out_group

对于 OFPFC_DELETE* 命令,要求匹配的条目包含此作为输出组

flags

以下标志的位图。

OFPFF_SEND_FLOW_REM
OFPFF_CHECK_OVERLAP
OFPFF_RESET_COUNTS
OFPFF_NO_PKT_COUNTS
OFPFF_NO_BYT_COUNTS

importance

驱逐优先级

match

OFPMatch 的实例

instructions

OFPInstruction* 实例列表

示例

def send_flow_mod(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    cookie = cookie_mask = 0
    table_id = 0
    idle_timeout = hard_timeout = 0
    priority = 32768
    buffer_id = ofp.OFP_NO_BUFFER
    importance = 0
    match = ofp_parser.OFPMatch(in_port=1, eth_dst='ff:ff:ff:ff:ff:ff')
    actions = [ofp_parser.OFPActionOutput(ofp.OFPP_NORMAL, 0)]
    inst = [ofp_parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS,
                                             actions)]
    req = ofp_parser.OFPFlowMod(datapath, cookie, cookie_mask,
                                table_id, ofp.OFPFC_ADD,
                                idle_timeout, hard_timeout,
                                priority, buffer_id,
                                ofp.OFPP_ANY, ofp.OFPG_ANY,
                                ofp.OFPFF_SEND_FLOW_REM,
                                importance,
                                match, inst)
    datapath.send_msg(req)

JSON 示例

{
   "OFPFlowMod": {
      "buffer_id": 65535,
      "command": 0,
      "cookie": 0,
      "cookie_mask": 0,
      "flags": 0,
      "hard_timeout": 0,
      "idle_timeout": 0,
      "importance": 0,
      "instructions": [
         {
            "OFPInstructionActions": {
               "actions": [
                  {
                     "OFPActionSetField": {
                        "field": {
                           "OXMTlv": {
                              "field": "vlan_vid",
                              "mask": null,
                              "value": 258
                           }
                        },
                        "len": 16,
                        "type": 25
                     }
                  },
                  {
                     "OFPActionCopyTtlOut": {
                        "len": 8,
                        "type": 11
                     }
                  },
                  {
                     "OFPActionCopyTtlIn": {
                        "len": 8,
                        "type": 12
                     }
                  },
                  {
                     "OFPActionCopyTtlIn": {
                        "len": 8,
                        "type": 12
                     }
                  },
                  {
                     "OFPActionPopPbb": {
                        "len": 8,
                        "type": 27
                     }
                  },
                  {
                     "OFPActionPushPbb": {
                        "ethertype": 4660,
                        "len": 8,
                        "type": 26
                     }
                  },
                  {
                     "OFPActionPopMpls": {
                        "ethertype": 39030,
                        "len": 8,
                        "type": 20
                     }
                  },
                  {
                     "OFPActionPushMpls": {
                        "ethertype": 34887,
                        "len": 8,
                        "type": 19
                     }
                  },
                  {
                     "OFPActionPopVlan": {
                        "len": 8,
                        "type": 18
                     }
                  },
                  {
                     "OFPActionPushVlan": {
                        "ethertype": 33024,
                        "len": 8,
                        "type": 17
                     }
                  },
                  {
                     "OFPActionDecMplsTtl": {
                        "len": 8,
                        "type": 16
                     }
                  },
                  {
                     "OFPActionSetMplsTtl": {
                        "len": 8,
                        "mpls_ttl": 10,
                        "type": 15
                     }
                  },
                  {
                     "OFPActionDecNwTtl": {
                        "len": 8,
                        "type": 24
                     }
                  },
                  {
                     "OFPActionSetNwTtl": {
                        "len": 8,
                        "nw_ttl": 10,
                        "type": 23
                     }
                  },
                  {
                     "OFPActionExperimenterUnknown": {
                        "data": "AAECAwQFBgc=",
                        "experimenter": 101,
                        "len": 16,
                        "type": 65535
                     }
                  },
                  {
                     "OFPActionSetQueue": {
                        "len": 8,
                        "queue_id": 3,
                        "type": 21
                     }
                  },
                  {
                     "OFPActionGroup": {
                        "group_id": 99,
                        "len": 8,
                        "type": 22
                     }
                  },
                  {
                     "OFPActionOutput": {
                        "len": 16,
                        "max_len": 65535,
                        "port": 6,
                        "type": 0
                     }
                  }
               ],
               "len": 176,
               "type": 3
            }
         },
         {
            "OFPInstructionActions": {
               "actions": [
                  {
                     "OFPActionSetField": {
                        "field": {
                           "OXMTlv": {
                              "field": "eth_src",
                              "mask": null,
                              "value": "01:02:03:04:05:06"
                           }
                        },
                        "len": 16,
                        "type": 25
                     }
                  },
                  {
                     "OFPActionSetField": {
                        "field": {
                           "OXMTlv": {
                              "field": "pbb_uca",
                              "mask": null,
                              "value": 1
                           }
                        },
                        "len": 16,
                        "type": 25
                     }
                  }
               ],
               "len": 40,
               "type": 4
            }
         }
      ],
      "match": {
         "OFPMatch": {
            "length": 14,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               }
            ],
            "type": 1
         }
      },
      "out_group": 4294967295,
      "out_port": 4294967295,
      "priority": 123,
      "table_id": 1
   }
}
{
   "OFPFlowMod": {
      "buffer_id": 65535,
      "command": 0,
      "cookie": 0,
      "cookie_mask": 0,
      "flags": 0,
      "hard_timeout": 0,
      "idle_timeout": 0,
      "importance": 0,
      "instructions": [
         {
            "OFPInstructionGotoTable": {
               "len": 8,
               "table_id": 1,
               "type": 1
            }
         }
      ],
      "match": {
         "OFPMatch": {
            "length": 22,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "in_port",
                     "mask": null,
                     "value": 6
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_src",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               }
            ],
            "type": 1
         }
      },
      "out_group": 4294967295,
      "out_port": 4294967295,
      "priority": 123,
      "table_id": 0
   }
}
{
   "OFPFlowMod": {
      "buffer_id": 65535,
      "command": 0,
      "cookie": 0,
      "cookie_mask": 0,
      "flags": 0,
      "hard_timeout": 0,
      "idle_timeout": 0,
      "importance": 0,
      "instructions": [
         {
            "OFPInstructionMeter": {
               "len": 8,
               "meter_id": 1,
               "type": 6
            }
         },
         {
            "OFPInstructionActions": {
               "actions": [
                  {
                     "OFPActionOutput": {
                        "len": 16,
                        "max_len": 65535,
                        "port": 6,
                        "type": 0
                     }
                  }
               ],
               "len": 24,
               "type": 3
            }
         }
      ],
      "match": {
         "OFPMatch": {
            "length": 14,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               }
            ],
            "type": 1
         }
      },
      "out_group": 4294967295,
      "out_port": 4294967295,
      "priority": 123,
      "table_id": 1
   }
}
{
   "OFPFlowMod": {
      "buffer_id": 65535,
      "command": 0,
      "cookie": 0,
      "cookie_mask": 0,
      "flags": 0,
      "hard_timeout": 0,
      "idle_timeout": 0,
      "importance": 0,
      "instructions": [],
      "match": {
         "OFPMatch": {
            "length": 329,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "in_port",
                     "mask": null,
                     "value": 84281096
                  }
               },
               {
                  "OXMTlv": {
                     "field": "in_phy_port",
                     "mask": null,
                     "value": 16909060
                  }
               },
               {
                  "OXMTlv": {
                     "field": "metadata",
                     "mask": null,
                     "value": 283686952306183
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_type",
                     "mask": null,
                     "value": 2054
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "ff:ff:ff:ff:ff:ff"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_src",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "vlan_vid",
                     "mask": null,
                     "value": 999
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ip_dscp",
                     "mask": null,
                     "value": 9
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ip_ecn",
                     "mask": null,
                     "value": 3
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ip_proto",
                     "mask": null,
                     "value": 99
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv4_src",
                     "mask": null,
                     "value": "1.2.3.4"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv4_dst",
                     "mask": null,
                     "value": "1.2.3.4"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "tcp_src",
                     "mask": null,
                     "value": 8080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "tcp_dst",
                     "mask": null,
                     "value": 18080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "udp_src",
                     "mask": null,
                     "value": 28080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "udp_dst",
                     "mask": null,
                     "value": 55936
                  }
               },
               {
                  "OXMTlv": {
                     "field": "sctp_src",
                     "mask": null,
                     "value": 48080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "sctp_dst",
                     "mask": null,
                     "value": 59328
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv4_type",
                     "mask": null,
                     "value": 100
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv4_code",
                     "mask": null,
                     "value": 101
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_op",
                     "mask": null,
                     "value": 1
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_spa",
                     "mask": null,
                     "value": "10.0.0.1"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_tpa",
                     "mask": null,
                     "value": "10.0.0.3"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_sha",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_tha",
                     "mask": null,
                     "value": "00:00:00:00:00:00"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_src",
                     "mask": null,
                     "value": "fe80::f00b:a4ff:fe48:28a5"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_dst",
                     "mask": null,
                     "value": "fe80::f00b:a4ff:fe05:b7dc"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_flabel",
                     "mask": null,
                     "value": 541473
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv6_type",
                     "mask": null,
                     "value": 200
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv6_code",
                     "mask": null,
                     "value": 201
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_nd_target",
                     "mask": null,
                     "value": "fe80::a60:6eff:fe7f:74e7"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_nd_sll",
                     "mask": null,
                     "value": "00:00:00:00:02:9a"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_nd_tll",
                     "mask": null,
                     "value": "00:00:00:00:02:2b"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "mpls_label",
                     "mask": null,
                     "value": 624485
                  }
               },
               {
                  "OXMTlv": {
                     "field": "mpls_tc",
                     "mask": null,
                     "value": 5
                  }
               },
               {
                  "OXMTlv": {
                     "field": "mpls_bos",
                     "mask": null,
                     "value": 1
                  }
               },
               {
                  "OXMTlv": {
                     "field": "pbb_isid",
                     "mask": null,
                     "value": 11259375
                  }
               },
               {
                  "OXMTlv": {
                     "field": "tunnel_id",
                     "mask": null,
                     "value": 651061555542690057
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_exthdr",
                     "mask": null,
                     "value": 500
                  }
               },
               {
                  "OXMTlv": {
                     "field": "pbb_uca",
                     "mask": null,
                     "value": 1
                  }
               }
            ],
            "type": 1
         }
      },
      "out_group": 4294967295,
      "out_port": 4294967295,
      "priority": 123,
      "table_id": 1
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupMod(datapath, command=0, type_=0, group_id=0, buckets=None)

修改组条目消息

控制器发送此消息以修改组表。

属性

描述

command

以下值之一。

OFPGC_ADD
OFPGC_MODIFY
OFPGC_DELETE

type

以下值之一。

OFPGT_ALL
OFPGT_SELECT
OFPGT_INDIRECT
OFPGT_FF

group_id

组标识符

buckets

OFPBucket 列表

type 属性对应于 __init__ 的 type_ 参数。

示例

def send_group_mod(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    port = 1
    max_len = 2000
    actions = [ofp_parser.OFPActionOutput(port, max_len)]

    weight = 100
    watch_port = 0
    watch_group = 0
    buckets = [ofp_parser.OFPBucket(weight, watch_port, watch_group,
                                    actions)]

    group_id = 1
    req = ofp_parser.OFPGroupMod(datapath, ofp.OFPGC_ADD,
                                 ofp.OFPGT_SELECT, group_id, buckets)
    datapath.send_msg(req)

JSON 示例

{
   "OFPGroupMod": {
      "buckets": [
         {
            "OFPBucket": {
               "actions": [
                  {
                     "OFPActionOutput": {
                        "len": 16,
                        "max_len": 65535,
                        "port": 2,
                        "type": 0
                     }
                  }
               ],
               "len": 32,
               "watch_group": 1,
               "watch_port": 1,
               "weight": 1
            }
         }
      ],
      "command": 0,
      "group_id": 1,
      "type": 0
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPPortMod(datapath, port_no=0, hw_addr='00:00:00:00:00:00', config=0, mask=0, properties=None)

端口修改消息

控制器发送此消息以修改端口的行为。

属性

描述

port_no

要修改的端口号

hw_addr

必须与 OFPSwitchFeaturesOFPPort 的 hw_addr 相同的硬件地址

config

配置标志的位图。

OFPPC_PORT_DOWN
OFPPC_NO_RECV
OFPPC_NO_FWD
OFPPC_NO_PACKET_IN

mask

要更改的上述配置标志的位图

properties

OFPPortModProp 子类实例列表

示例

def send_port_mod(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    port_no = 3
    hw_addr = 'fa:c8:e8:76:1d:7e'
    config = 0
    mask = (ofp.OFPPC_PORT_DOWN | ofp.OFPPC_NO_RECV |
            ofp.OFPPC_NO_FWD | ofp.OFPPC_NO_PACKET_IN)
    advertise = (ofp.OFPPF_10MB_HD | ofp.OFPPF_100MB_FD |
                 ofp.OFPPF_1GB_FD | ofp.OFPPF_COPPER |
                 ofp.OFPPF_AUTONEG | ofp.OFPPF_PAUSE |
                 ofp.OFPPF_PAUSE_ASYM)
    properties = [ofp_parser.OFPPortModPropEthernet(advertise)]
    req = ofp_parser.OFPPortMod(datapath, port_no, hw_addr, config,
                                mask, properties)
    datapath.send_msg(req)

JSON 示例

{
   "OFPPortMod": {
      "config": 0,
      "hw_addr": "00:11:00:00:11:11",
      "mask": 0,
      "port_no": 1,
      "properties": [
         {
            "OFPPortModPropEthernet": {
               "advertise": 4096,
               "length": 8,
               "type": 0
            }
         },
         {
            "OFPPortModPropOptical": {
               "configure": 3,
               "fl_offset": 2000,
               "freq_lmda": 1500,
               "grid_span": 3000,
               "length": 24,
               "tx_pwr": 300,
               "type": 1
            }
         },
         {
            "OFPPortModPropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65535
            }
         },
         {
            "OFPPortModPropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPPortModPropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ]
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterMod(datapath, command=0, flags=1, meter_id=1, bands=None)

计量器修改消息

控制器发送此消息以修改计量器。

属性

描述

command

以下值之一。

OFPMC_ADD
OFPMC_MODIFY
OFPMC_DELETE

flags

以下标志的位图。

OFPMF_KBPS
OFPMF_PKTPS
OFPMF_BURST
OFPMF_STATS

meter_id

计量器实例

bands

以下类实例列表。

OFPMeterBandDrop
OFPMeterBandDscpRemark
OFPMeterBandExperimenter

JSON 示例

{
   "OFPMeterMod": {
      "bands": [
         {
            "OFPMeterBandDrop": {
               "burst_size": 10,
               "len": 16,
               "rate": 1000,
               "type": 1
            }
         },
         {
            "OFPMeterBandDscpRemark": {
               "burst_size": 10,
               "len": 16,
               "prec_level": 1,
               "rate": 1000,
               "type": 2
            }
         },
         {
            "OFPMeterBandExperimenter": {
               "burst_size": 10,
               "experimenter": 999,
               "len": 16,
               "rate": 1000,
               "type": 65535
            }
         }
      ],
      "command": 0,
      "flags": 14,
      "meter_id": 100
   }
}

多部分消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPDescStatsRequest(datapath, flags=0, type_=None)

描述统计请求消息

控制器使用此消息查询交换机的描述。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_desc_stats_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPDescStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPDescStatsRequest": {
      "flags": 0,
      "type": 0
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPDescStatsReply(datapath, type_=None, **kwargs)

描述统计回复消息

交换机响应描述统计请求,发送此消息。

属性

描述

body

OFPDescStats 的实例

示例

@set_ev_cls(ofp_event.EventOFPDescStatsReply, MAIN_DISPATCHER)
def desc_stats_reply_handler(self, ev):
    body = ev.msg.body

    self.logger.debug('DescStats: mfr_desc=%s hw_desc=%s sw_desc=%s '
                      'serial_num=%s dp_desc=%s',
                      body.mfr_desc, body.hw_desc, body.sw_desc,
                      body.serial_num, body.dp_desc)

JSON 示例

{
   "OFPDescStatsReply": {
      "body": {
         "OFPDescStats": {
            "dp_desc": "dp",
            "hw_desc": "hw",
            "mfr_desc": "mfr",
            "serial_num": "serial",
            "sw_desc": "sw"
         }
      },
      "flags": 0,
      "type": 0
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPFlowStatsRequest(datapath, flags=0, table_id=255, out_port=4294967295, out_group=4294967295, cookie=0, cookie_mask=0, match=None, type_=None)

单个流统计请求消息

控制器使用此消息查询单个流统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

table_id

要读取的表 ID

out_port

要求匹配的条目将此作为输出端口包含在内

out_group

要求匹配的条目将此作为输出组包含在内

cookie

要求匹配的条目包含此 cookie 值

cookie_mask

用于限制必须匹配的 cookie 位的掩码

match

OFPMatch 的实例

示例

def send_flow_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    cookie = cookie_mask = 0
    match = ofp_parser.OFPMatch(in_port=1)
    req = ofp_parser.OFPFlowStatsRequest(datapath, 0,
                                         ofp.OFPTT_ALL,
                                         ofp.OFPP_ANY, ofp.OFPG_ANY,
                                         cookie, cookie_mask,
                                         match)
    datapath.send_msg(req)

JSON 示例

{
   "OFPFlowStatsRequest": {
      "cookie": 0,
      "cookie_mask": 0,
      "flags": 0,
      "match": {
         "OFPMatch": {
            "length": 4,
            "oxm_fields": [],
            "type": 1
         }
      },
      "out_group": 4294967295,
      "out_port": 4294967295,
      "table_id": 0,
      "type": 1
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPFlowStatsReply(datapath, type_=None, **kwargs)

单个流统计回复消息

交换机使用此消息响应单个流统计请求。

属性

描述

body

OFPFlowStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPFlowStatsReply, MAIN_DISPATCHER)
def flow_stats_reply_handler(self, ev):
    flows = []
    for stat in ev.msg.body:
        flows.append('table_id=%s '
                     'duration_sec=%d duration_nsec=%d '
                     'priority=%d '
                     'idle_timeout=%d hard_timeout=%d flags=0x%04x '
                     'importance=%d cookie=%d packet_count=%d '
                     'byte_count=%d match=%s instructions=%s' %
                     (stat.table_id,
                      stat.duration_sec, stat.duration_nsec,
                      stat.priority,
                      stat.idle_timeout, stat.hard_timeout,
                      stat.flags, stat.importance,
                      stat.cookie, stat.packet_count, stat.byte_count,
                      stat.match, stat.instructions))
    self.logger.debug('FlowStats: %s', flows)

JSON 示例

{
   "OFPFlowStatsReply": {
      "body": [
         {
            "OFPFlowStats": {
               "byte_count": 0,
               "cookie": 0,
               "duration_nsec": 115277000,
               "duration_sec": 358,
               "flags": 0,
               "hard_timeout": 0,
               "idle_timeout": 0,
               "importance": 0,
               "instructions": [],
               "length": 56,
               "match": {
                  "OFPMatch": {
                     "length": 4,
                     "oxm_fields": [],
                     "type": 1
                  }
               },
               "packet_count": 0,
               "priority": 65535,
               "table_id": 0
            }
         },
         {
            "OFPFlowStats": {
               "byte_count": 0,
               "cookie": 0,
               "duration_nsec": 115055000,
               "duration_sec": 358,
               "flags": 0,
               "hard_timeout": 0,
               "idle_timeout": 0,
               "importance": 0,
               "instructions": [
                  {
                     "OFPInstructionActions": {
                        "actions": [
                           {
                              "OFPActionOutput": {
                                 "len": 16,
                                 "max_len": 0,
                                 "port": 4294967290,
                                 "type": 0
                              }
                           }
                        ],
                        "len": 24,
                        "type": 4
                     }
                  }
               ],
               "length": 88,
               "match": {
                  "OFPMatch": {
                     "length": 10,
                     "oxm_fields": [
                        {
                           "OXMTlv": {
                              "field": "eth_type",
                              "mask": null,
                              "value": 2054
                           }
                        }
                     ],
                     "type": 1
                  }
               },
               "packet_count": 0,
               "priority": 65534,
               "table_id": 0
            }
         },
         {
            "OFPFlowStats": {
               "byte_count": 238,
               "cookie": 0,
               "duration_nsec": 511582000,
               "duration_sec": 316220,
               "flags": 0,
               "hard_timeout": 0,
               "idle_timeout": 0,
               "importance": 0,
               "instructions": [
                  {
                     "OFPInstructionGotoTable": {
                        "len": 8,
                        "table_id": 1,
                        "type": 1
                     }
                  }
               ],
               "length": 80,
               "match": {
                  "OFPMatch": {
                     "length": 22,
                     "oxm_fields": [
                        {
                           "OXMTlv": {
                              "field": "in_port",
                              "mask": null,
                              "value": 6
                           }
                        },
                        {
                           "OXMTlv": {
                              "field": "eth_src",
                              "mask": null,
                              "value": "f2:0b:a4:7d:f8:ea"
                           }
                        }
                     ],
                     "type": 1
                  }
               },
               "packet_count": 3,
               "priority": 123,
               "table_id": 0
            }
         },
         {
            "OFPFlowStats": {
               "byte_count": 98,
               "cookie": 0,
               "duration_nsec": 980901000,
               "duration_sec": 313499,
               "flags": 0,
               "hard_timeout": 0,
               "idle_timeout": 0,
               "importance": 0,
               "instructions": [
                  {
                     "OFPInstructionActions": {
                        "actions": [
                           {
                              "OFPActionSetField": {
                                 "field": {
                                    "OXMTlv": {
                                       "field": "vlan_vid",
                                       "mask": null,
                                       "value": 258
                                    }
                                 },
                                 "len": 16,
                                 "type": 25
                              }
                           },
                           {
                              "OFPActionCopyTtlOut": {
                                 "len": 8,
                                 "type": 11
                              }
                           },
                           {
                              "OFPActionCopyTtlIn": {
                                 "len": 8,
                                 "type": 12
                              }
                           },
                           {
                              "OFPActionCopyTtlIn": {
                                 "len": 8,
                                 "type": 12
                              }
                           },
                           {
                              "OFPActionPopPbb": {
                                 "len": 8,
                                 "type": 27
                              }
                           },
                           {
                              "OFPActionPushPbb": {
                                 "ethertype": 4660,
                                 "len": 8,
                                 "type": 26
                              }
                           },
                           {
                              "OFPActionPopMpls": {
                                 "ethertype": 39030,
                                 "len": 8,
                                 "type": 20
                              }
                           },
                           {
                              "OFPActionPushMpls": {
                                 "ethertype": 34887,
                                 "len": 8,
                                 "type": 19
                              }
                           },
                           {
                              "OFPActionPopVlan": {
                                 "len": 8,
                                 "type": 18
                              }
                           },
                           {
                              "OFPActionPushVlan": {
                                 "ethertype": 33024,
                                 "len": 8,
                                 "type": 17
                              }
                           },
                           {
                              "OFPActionDecMplsTtl": {
                                 "len": 8,
                                 "type": 16
                              }
                           },
                           {
                              "OFPActionSetMplsTtl": {
                                 "len": 8,
                                 "mpls_ttl": 10,
                                 "type": 15
                              }
                           },
                           {
                              "OFPActionDecNwTtl": {
                                 "len": 8,
                                 "type": 24
                              }
                           },
                           {
                              "OFPActionSetNwTtl": {
                                 "len": 8,
                                 "nw_ttl": 10,
                                 "type": 23
                              }
                           },
                           {
                              "OFPActionSetQueue": {
                                 "len": 8,
                                 "queue_id": 3,
                                 "type": 21
                              }
                           },
                           {
                              "OFPActionGroup": {
                                 "group_id": 99,
                                 "len": 8,
                                 "type": 22
                              }
                           },
                           {
                              "OFPActionOutput": {
                                 "len": 16,
                                 "max_len": 65535,
                                 "port": 6,
                                 "type": 0
                              }
                           },
                           {
                              "OFPActionExperimenterUnknown": {
                                 "len": 16,
                                 "data": "ZXhwX2RhdGE=",
                                 "experimenter": 98765432,
                                 "type": 65535
                              }
                           },
                           {
                              "NXActionUnknown": {
                                 "len": 16,
                                 "data": "cF9kYXRh",
                                 "experimenter": 8992,
                                 "type": 65535,
                                 "subtype": 25976
                              }
                           }
                        ],
                        "len": 192,
                        "type": 3
                     }
                  },
                  {
                     "OFPInstructionActions": {
                        "actions": [
                           {
                              "OFPActionSetField": {
                                 "field": {
                                    "OXMTlv": {
                                       "field": "eth_src",
                                       "mask": null,
                                       "value": "01:02:03:04:05:06"
                                    }
                                 },
                                 "len": 16,
                                 "type": 25
                              }
                           },
                           {
                              "OFPActionSetField": {
                                 "field": {
                                    "OXMTlv": {
                                       "field": "pbb_uca",
                                       "mask": null,
                                       "value": 1
                                    }
                                 },
                                 "len": 16,
                                 "type": 25
                              }
                           }
                        ],
                        "len": 40,
                        "type": 4
                     }
                  },
                  {
                     "OFPInstructionActions": {
                        "actions": [
                           {
                              "OFPActionOutput": {
                                 "len": 16,
                                 "max_len": 65535,
                                 "port": 4294967293,
                                 "type": 0
                              }
                           }
                        ],
                        "len": 24,
                        "type": 3
                     }
                  }
               ],
               "length": 312,
               "match": {
                  "OFPMatch": {
                     "length": 4,
                     "oxm_fields": [],
                     "type": 1
                  }
               },
               "packet_count": 1,
               "priority": 0,
               "table_id": 0
            }
         }
      ],
      "flags": 0,
      "type": 1
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPAggregateStatsRequest(datapath, flags, table_id, out_port, out_group, cookie, cookie_mask, match, type_=None)

聚合流统计请求消息

控制器使用此消息查询聚合流统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

table_id

要读取的表 ID

out_port

要求匹配的条目将此作为输出端口包含在内

out_group

要求匹配的条目将此作为输出组包含在内

cookie

要求匹配的条目包含此 cookie 值

cookie_mask

用于限制必须匹配的 cookie 位的掩码

match

OFPMatch 的实例

示例

def send_aggregate_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    cookie = cookie_mask = 0
    match = ofp_parser.OFPMatch(in_port=1)
    req = ofp_parser.OFPAggregateStatsRequest(datapath, 0,
                                              ofp.OFPTT_ALL,
                                              ofp.OFPP_ANY,
                                              ofp.OFPG_ANY,
                                              cookie, cookie_mask,
                                              match)
    datapath.send_msg(req)

JSON 示例

{
   "OFPAggregateStatsRequest": {
      "cookie": 0,
      "cookie_mask": 0,
      "flags": 0,
      "match": {
         "OFPMatch": {
            "length": 4,
            "oxm_fields": [],
            "type": 1
         }
      },
      "out_group": 4294967295,
      "out_port": 4294967295,
      "table_id": 255,
      "type": 2
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPAggregateStatsReply(datapath, type_=None, **kwargs)

聚合流统计回复消息

交换机使用此消息响应聚合流统计请求。

属性

描述

body

OFPAggregateStats 实例

示例

@set_ev_cls(ofp_event.EventOFPAggregateStatsReply, MAIN_DISPATCHER)
def aggregate_stats_reply_handler(self, ev):
    body = ev.msg.body

    self.logger.debug('AggregateStats: packet_count=%d byte_count=%d '
                      'flow_count=%d',
                      body.packet_count, body.byte_count,
                      body.flow_count)

JSON 示例

{
   "OFPAggregateStatsReply": {
      "body": {
         "OFPAggregateStats": {
            "byte_count": 574,
            "flow_count": 6,
            "packet_count": 7
         }
      },
      "flags": 0,
      "type": 2
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPTableStatsRequest(datapath, flags, type_=None)

表统计请求消息

控制器使用此消息查询流表统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_table_stats_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPTableStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPTableStatsRequest": {
      "flags": 0,
      "type": 3
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPTableStatsReply(datapath, type_=None, **kwargs)

表统计回复消息

交换机使用此消息响应表统计请求。

属性

描述

body

OFPTableStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPTableStatsReply, MAIN_DISPATCHER)
def table_stats_reply_handler(self, ev):
    tables = []
    for stat in ev.msg.body:
        tables.append('table_id=%d active_count=%d lookup_count=%d '
                      ' matched_count=%d' %
                      (stat.table_id, stat.active_count,
                       stat.lookup_count, stat.matched_count))
    self.logger.debug('TableStats: %s', tables)

JSON 示例

{
   "OFPTableStatsReply": {
      "body": [
         {
            "OFPTableStats": {
               "active_count": 4,
               "lookup_count": 4,
               "matched_count": 4,
               "table_id": 0
            }
         },
         {
            "OFPTableStats": {
               "active_count": 4,
               "lookup_count": 4,
               "matched_count": 4,
               "table_id": 1
            }
         }
      ],
      "flags": 0,
      "type": 3
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPTableDescStatsRequest(datapath, flags=0, type_=None)

表描述请求消息

控制器使用此消息查询所有表的描述。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_table_desc_stats_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPTableDescStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPTableDescStatsRequest": {
      "flags": 0,
      "type": 14
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPTableDescStatsReply(datapath, type_=None, **kwargs)

表描述回复消息

交换机使用此消息响应表描述请求。

属性

描述

body

OFPTableDesc 实例列表

示例

@set_ev_cls(ofp_event.EventOFPTableDescStatsReply, MAIN_DISPATCHER)
def table_desc_stats_reply_handler(self, ev):
    tables = []
    for p in ev.msg.body:
        tables.append('table_id=%d config=0x%08x properties=%s' %
                     (p.table_id, p.config, repr(p.properties)))
    self.logger.debug('OFPTableDescStatsReply received: %s', tables)

JSON 示例

{
   "OFPTableDescStatsReply": {
      "body": [
         {
            "OFPTableDesc": {
               "config": 0,
               "length": 24,
               "properties": [
                  {
                     "OFPTableModPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  }
               ],
               "table_id": 7
            }
         },
         {
            "OFPTableDesc": {
               "config": 0,
               "length": 80,
               "properties": [
                  {
                     "OFPTableModPropEviction": {
                        "flags": 0,
                        "length": 8,
                        "type": 2
                     }
                  },
                  {
                     "OFPTableModPropVacancy": {
                        "length": 8,
                        "type": 3,
                        "vacancy": 0,
                        "vacancy_down": 0,
                        "vacancy_up": 0
                     }
                  },
                  {
                     "OFPTableModPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  },
                  {
                     "OFPTableModPropExperimenter": {
                        "data": [
                           1
                        ],
                        "exp_type": 1,
                        "experimenter": 101,
                        "length": 16,
                        "type": 65535
                     }
                  },
                  {
                     "OFPTableModPropExperimenter": {
                        "data": [
                           1,
                           2
                        ],
                        "exp_type": 2,
                        "experimenter": 101,
                        "length": 20,
                        "type": 65535
                     }
                  }
               ],
               "table_id": 8
            }
         }
      ],
      "flags": 0,
      "type": 14
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPTableFeaturesStatsRequest(datapath, flags=0, body=None, type_=None)

表功能统计请求消息

控制器使用此消息查询表功能。

属性

描述

body

OFPTableFeaturesStats 实例列表。默认值为 []。

JSON 示例

请参阅示例:

os_ken/tests/unit/ofproto/json/of14/5-53-ofp_table_features_request.packet.json

class os_ken.ofproto.ofproto_v1_4_parser.OFPTableFeaturesStatsReply(datapath, type_=None, **kwargs)

表功能统计回复消息

交换机使用此消息响应表功能统计请求。

属性

描述

body

OFPTableFeaturesStats 实例列表

JSON 示例

请参阅示例:

os_ken/tests/unit/ofproto/json/of14/5-54-ofp_table_features_reply.packet.json

class os_ken.ofproto.ofproto_v1_4_parser.OFPPortStatsRequest(datapath, flags, port_no, type_=None)

端口统计请求消息

控制器使用此消息查询端口统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

port_no

要读取的端口号(OFPP_ANY 表示所有端口)

示例

def send_port_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPPortStatsRequest(datapath, 0, ofp.OFPP_ANY)
    datapath.send_msg(req)

JSON 示例

{
   "OFPPortStatsRequest": {
      "flags": 0,
      "port_no": 4294967295,
      "type": 4
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPPortStatsReply(datapath, type_=None, **kwargs)

端口统计回复消息

交换机使用此消息响应端口统计请求。

属性

描述

body

OFPPortStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPPortStatsReply, MAIN_DISPATCHER)
def port_stats_reply_handler(self, ev):
    ports = []
    for stat in ev.msg.body:
        ports.append(stat.length, stat.port_no,
                     stat.duration_sec, stat.duration_nsec,
                     stat.rx_packets, stat.tx_packets,
                     stat.rx_bytes, stat.tx_bytes,
                     stat.rx_dropped, stat.tx_dropped,
                     stat.rx_errors, stat.tx_errors,
                     repr(stat.properties))
    self.logger.debug('PortStats: %s', ports)

JSON 示例

{
   "OFPPortStatsReply": {
      "body": [
         {
            "OFPPortStats": {
               "duration_nsec": 0,
               "duration_sec": 0,
               "length": 224,
               "port_no": 7,
               "properties": [
                  {
                     "OFPPortStatsPropEthernet": {
                        "collisions": 0,
                        "length": 40,
                        "rx_crc_err": 0,
                        "rx_frame_err": 0,
                        "rx_over_err": 0,
                        "type": 0
                     }
                  },
                  {
                     "OFPPortStatsPropOptical": {
                        "bias_current": 300,
                        "flags": 3,
                        "length": 44,
                        "rx_freq_lmda": 1500,
                        "rx_grid_span": 500,
                        "rx_offset": 700,
                        "rx_pwr": 2000,
                        "temperature": 273,
                        "tx_freq_lmda": 1500,
                        "tx_grid_span": 500,
                        "tx_offset": 700,
                        "tx_pwr": 2000,
                        "type": 1
                     }
                  },
                  {
                     "OFPPortStatsPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  },
                  {
                     "OFPPortStatsPropExperimenter": {
                        "data": [
                           1
                        ],
                        "exp_type": 1,
                        "experimenter": 101,
                        "length": 16,
                        "type": 65535
                     }
                  },
                  {
                     "OFPPortStatsPropExperimenter": {
                        "data": [
                           1,
                           2
                        ],
                        "exp_type": 2,
                        "experimenter": 101,
                        "length": 20,
                        "type": 65535
                     }
                  }
               ],
               "rx_bytes": 0,
               "rx_dropped": 0,
               "rx_errors": 0,
               "rx_packets": 0,
               "tx_bytes": 336,
               "tx_dropped": 0,
               "tx_errors": 0,
               "tx_packets": 4
            }
         },
         {
            "OFPPortStats": {
               "duration_nsec": 0,
               "duration_sec": 0,
               "length": 120,
               "port_no": 6,
               "properties": [
                  {
                     "OFPPortStatsPropEthernet": {
                        "collisions": 0,
                        "length": 40,
                        "rx_crc_err": 0,
                        "rx_frame_err": 0,
                        "rx_over_err": 0,
                        "type": 0
                     }
                  }
               ],
               "rx_bytes": 336,
               "rx_dropped": 0,
               "rx_errors": 0,
               "rx_packets": 4,
               "tx_bytes": 336,
               "tx_dropped": 0,
               "tx_errors": 0,
               "tx_packets": 4
            }
         }
      ],
      "flags": 0,
      "type": 4
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPPortDescStatsRequest(datapath, flags=0, type_=None)

端口描述请求消息

控制器使用此消息查询所有端口的描述。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_port_desc_stats_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPPortDescStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPPortDescStatsRequest": {
      "flags": 0,
      "type": 13
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPPortDescStatsReply(datapath, type_=None, **kwargs)

端口描述回复消息

交换机使用此消息响应端口描述请求。

属性

描述

body

OFPPort 实例列表

示例

@set_ev_cls(ofp_event.EventOFPPortDescStatsReply, MAIN_DISPATCHER)
def port_desc_stats_reply_handler(self, ev):
    ports = []
    for p in ev.msg.body:
        ports.append('port_no=%d hw_addr=%s name=%s config=0x%08x '
                     'state=0x%08x properties=%s' %
                     (p.port_no, p.hw_addr,
                      p.name, p.config, p.state, repr(p.properties)))
    self.logger.debug('OFPPortDescStatsReply received: %s', ports)

JSON 示例

{
   "OFPPortDescStatsReply": {
      "body": [
         {
            "OFPPort": {
               "config": 0,
               "hw_addr": "f2:0b:a4:d0:3f:70",
               "length": 168,
               "name": "Port7",
               "port_no": 7,
               "properties": [
                  {
                     "OFPPortDescPropEthernet": {
                        "advertised": 10240,
                        "curr": 10248,
                        "curr_speed": 5000,
                        "length": 32,
                        "max_speed": 5000,
                        "peer": 10248,
                        "supported": 10248,
                        "type": 0
                     }
                  },
                  {
                     "OFPPortDescPropOptical": {
                        "length": 40,
                        "rx_grid_freq_lmda": 1500,
                        "rx_max_freq_lmda": 2000,
                        "rx_min_freq_lmda": 1000,
                        "supported": 1,
                        "tx_grid_freq_lmda": 1500,
                        "tx_max_freq_lmda": 2000,
                        "tx_min_freq_lmda": 1000,
                        "tx_pwr_max": 2000,
                        "tx_pwr_min": 1000,
                        "type": 1
                     }
                  },
                  {
                     "OFPPortDescPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  },
                  {
                     "OFPPortDescPropExperimenter": {
                        "data": [
                           1
                        ],
                        "exp_type": 1,
                        "experimenter": 101,
                        "length": 16,
                        "type": 65535
                     }
                  },
                  {
                     "OFPPortDescPropExperimenter": {
                        "data": [
                           1,
                           2
                        ],
                        "exp_type": 2,
                        "experimenter": 101,
                        "length": 20,
                        "type": 65535
                     }
                  }
               ],
               "state": 4
            }
         },
         {
            "OFPPort": {
               "config": 0,
               "hw_addr": "f2:0b:a4:7d:f8:ea",
               "length": 72,
               "name": "Port6",
               "port_no": 6,
               "properties": [
                  {
                     "OFPPortDescPropEthernet": {
                        "advertised": 10240,
                        "curr": 10248,
                        "curr_speed": 5000,
                        "length": 32,
                        "max_speed": 5000,
                        "peer": 10248,
                        "supported": 10248,
                        "type": 0
                     }
                  }
               ],
               "state": 4
            }
         }
      ],
      "flags": 0,
      "type": 13
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPQueueStatsRequest(datapath, flags=0, port_no=4294967295, queue_id=4294967295, type_=None)

队列统计请求消息

控制器使用此消息查询队列统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

port_no

要读取的端口号

queue_id

要读取的队列 ID

示例

def send_queue_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPQueueStatsRequest(datapath, 0, ofp.OFPP_ANY,
                                          ofp.OFPQ_ALL)
    datapath.send_msg(req)

JSON 示例

{
   "OFPQueueStatsRequest": {
      "flags": 0,
      "port_no": 4294967295,
      "queue_id": 4294967295,
      "type": 5
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPQueueStatsReply(datapath, type_=None, **kwargs)

队列统计回复消息

交换机使用此消息响应聚合流统计请求。

属性

描述

body

OFPQueueStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPQueueStatsReply, MAIN_DISPATCHER)
def queue_stats_reply_handler(self, ev):
    queues = []
    for stat in ev.msg.body:
        queues.append('port_no=%d queue_id=%d '
                      'tx_bytes=%d tx_packets=%d tx_errors=%d '
                      'duration_sec=%d duration_nsec=%d'
                      'properties=%s' %
                      (stat.port_no, stat.queue_id,
                       stat.tx_bytes, stat.tx_packets, stat.tx_errors,
                       stat.duration_sec, stat.duration_nsec,
                       repr(stat.properties)))
    self.logger.debug('QueueStats: %s', queues)

JSON 示例

{
   "OFPQueueStatsReply": {
      "body": [
         {
            "OFPQueueStats": {
               "duration_nsec": 0,
               "duration_sec": 0,
               "length": 104,
               "port_no": 7,
               "properties": [
                  {
                     "OFPQueueStatsPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  },
                  {
                     "OFPQueueStatsPropExperimenter": {
                        "data": [
                           1
                        ],
                        "exp_type": 1,
                        "experimenter": 101,
                        "length": 16,
                        "type": 65535
                     }
                  },
                  {
                     "OFPQueueStatsPropExperimenter": {
                        "data": [
                           1,
                           2
                        ],
                        "exp_type": 2,
                        "experimenter": 101,
                        "length": 20,
                        "type": 65535
                     }
                  }
               ],
               "queue_id": 1,
               "tx_bytes": 0,
               "tx_errors": 0,
               "tx_packets": 0
            }
         },
         {
            "OFPQueueStats": {
               "duration_nsec": 0,
               "duration_sec": 0,
               "length": 48,
               "port_no": 6,
               "properties": [],
               "queue_id": 1,
               "tx_bytes": 0,
               "tx_errors": 0,
               "tx_packets": 0
            }
         },
         {
            "OFPQueueStats": {
               "duration_nsec": 0,
               "duration_sec": 0,
               "length": 48,
               "port_no": 7,
               "properties": [],
               "queue_id": 2,
               "tx_bytes": 0,
               "tx_errors": 0,
               "tx_packets": 0
            }
         }
      ],
      "flags": 0,
      "type": 5
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPQueueDescStatsRequest(datapath, flags=0, port_no=4294967295, queue_id=4294967295, type_=None)

队列描述请求消息

控制器使用此消息查询所有队列的描述。

属性

描述

flags

零或 OFPMPF_REQ_MORE

port_no

要读取的端口号(对于所有端口使用OFPP_ANY)

queue_id

要读取的队列ID(对于所有队列使用OFPQ_ALL)

示例

def send_queue_desc_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser
    req = ofp_parser.OFPQueueDescStatsRequest(datapath, 0,
                                              ofp.OFPP_ANY,
                                              ofp.OFPQ_ALL)
    datapath.send_msg(req)

JSON 示例

{
   "OFPQueueDescStatsRequest": {
      "flags": 0,
      "port_no": 7,
      "queue_id": 4294967295,
      "type": 15
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPQueueDescStatsReply(datapath, type_=None, **kwargs)

队列描述回复消息

交换机使用此消息响应队列描述请求。

属性

描述

body

OFPQueueDesc 实例列表

示例

@set_ev_cls(ofp_event.EventOFPQueueDescStatsReply, MAIN_DISPATCHER)
def queue_desc_stats_reply_handler(self, ev):
    queues = []
    for q in ev.msg.body:
        queues.append('port_no=%d queue_id=0x%08x properties=%s' %
                     (q.port_no, q.queue_id, repr(q.properties)))
    self.logger.debug('OFPQueueDescStatsReply received: %s', queues)

JSON 示例

{
   "OFPQueueDescStatsReply": {
      "body": [
         {
            "OFPQueueDesc": {
               "len": 32,
               "port_no": 7,
               "properties": [
                  {
                     "OFPQueueDescPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  }
               ],
               "queue_id": 0
            }
         },
         {
            "OFPQueueDesc": {
               "len": 88,
               "port_no": 8,
               "properties": [
                  {
                     "OFPQueueDescPropMinRate": {
                        "length": 8,
                        "rate": 300,
                        "type": 1
                     }
                  },
                  {
                     "OFPQueueDescPropMaxRate": {
                        "length": 8,
                        "rate": 900,
                        "type": 2
                     }
                  },
                  {
                     "OFPQueueDescPropExperimenter": {
                        "data": [],
                        "exp_type": 0,
                        "experimenter": 101,
                        "length": 12,
                        "type": 65535
                     }
                  },
                  {
                     "OFPQueueDescPropExperimenter": {
                        "data": [
                           1
                        ],
                        "exp_type": 1,
                        "experimenter": 101,
                        "length": 16,
                        "type": 65535
                     }
                  },
                  {
                     "OFPQueueDescPropExperimenter": {
                        "data": [
                           1,
                           2
                        ],
                        "exp_type": 2,
                        "experimenter": 101,
                        "length": 20,
                        "type": 65535
                     }
                  }
               ],
               "queue_id": 1
            }
         }
      ],
      "flags": 0,
      "type": 15
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupStatsRequest(datapath, flags=0, group_id=4294967292, type_=None)

组统计请求消息

控制器使用此消息查询一个或多个组的统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

group_id

要读取的组ID(使用OFPG_ALL表示所有组)

示例

def send_group_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPGroupStatsRequest(datapath, 0, ofp.OFPG_ALL)
    datapath.send_msg(req)

JSON 示例

{
   "OFPGroupStatsRequest": {
      "flags": 0,
      "group_id": 4294967292,
      "type": 6
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupStatsReply(datapath, type_=None, **kwargs)

组统计回复消息

交换机使用此消息响应组统计请求。

属性

描述

body

OFPGroupStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPGroupStatsReply, MAIN_DISPATCHER)
def group_stats_reply_handler(self, ev):
    groups = []
    for stat in ev.msg.body:
        groups.append('length=%d group_id=%d '
                      'ref_count=%d packet_count=%d byte_count=%d '
                      'duration_sec=%d duration_nsec=%d' %
                      (stat.length, stat.group_id,
                       stat.ref_count, stat.packet_count,
                       stat.byte_count, stat.duration_sec,
                       stat.duration_nsec))
    self.logger.debug('GroupStats: %s', groups)

JSON 示例

{
   "OFPGroupStatsReply": {
      "body": [
         {
            "OFPGroupStats": {
               "bucket_stats": [
                  {
                     "OFPBucketCounter": {
                        "byte_count": 2345,
                        "packet_count": 234
                     }
                  }
               ],
               "byte_count": 12345,
               "duration_nsec": 609036000,
               "duration_sec": 9,
               "group_id": 1,
               "length": 56,
               "packet_count": 123,
               "ref_count": 2
            }
         }
      ],
      "flags": 0,
      "type": 6
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupDescStatsRequest(datapath, flags=0, type_=None)

组描述请求消息

控制器使用此消息列出交换机上的组集合。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_group_desc_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPGroupDescStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPGroupDescStatsRequest": {
      "flags": 0,
      "type": 7
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupDescStatsReply(datapath, type_=None, **kwargs)

组描述回复消息

交换机使用此消息响应组描述请求。

属性

描述

body

OFPGroupDescStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPGroupDescStatsReply, MAIN_DISPATCHER)
def group_desc_stats_reply_handler(self, ev):
    descs = []
    for stat in ev.msg.body:
        descs.append('length=%d type=%d group_id=%d '
                     'buckets=%s' %
                     (stat.length, stat.type, stat.group_id,
                      stat.bucket))
    self.logger.debug('GroupDescStats: %s', descs)

JSON 示例

{
   "OFPGroupDescStatsReply": {
      "body": [
         {
            "OFPGroupDescStats": {
               "buckets": [
                  {
                     "OFPBucket": {
                        "actions": [
                           {
                              "OFPActionOutput": {
                                 "len": 16,
                                 "max_len": 65535,
                                 "port": 2,
                                 "type": 0
                              }
                           }
                        ],
                        "len": 32,
                        "watch_group": 1,
                        "watch_port": 1,
                        "weight": 1
                     }
                  }
               ],
               "group_id": 1,
               "length": 40,
               "type": 0
            }
         }
      ],
      "flags": 0,
      "type": 7
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupFeaturesStatsRequest(datapath, flags=0, type_=None)

组功能请求消息

控制器使用此消息查询交换机上组的功能。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_group_features_stats_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPGroupFeaturesStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPGroupFeaturesStatsRequest": {
      "flags": 0,
      "type": 8
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGroupFeaturesStatsReply(datapath, type_=None, **kwargs)

组功能回复消息

交换机使用此消息响应组功能请求。

属性

描述

body

OFPGroupFeaturesStats 实例

示例

@set_ev_cls(ofp_event.EventOFPGroupFeaturesStatsReply, MAIN_DISPATCHER)
def group_features_stats_reply_handler(self, ev):
    body = ev.msg.body

    self.logger.debug('GroupFeaturesStats: types=%d '
                      'capabilities=0x%08x max_groups=%s '
                      'actions=%s',
                      body.types, body.capabilities,
                      body.max_groups, body.actions)

JSON 示例

{
   "OFPGroupFeaturesStatsReply": {
      "body": {
         "OFPGroupFeaturesStats": {
            "actions": [
               67082241,
               67082241,
               67082241,
               67082241
            ],
            "capabilities": 5,
            "max_groups": [
               16777216,
               16777216,
               16777216,
               16777216
            ],
            "types": 15
         }
      },
      "flags": 0,
      "type": 8
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterStatsRequest(datapath, flags=0, meter_id=4294967295, type_=None)

计量统计请求消息

控制器使用此消息查询一个或多个计量的统计信息。

属性

描述

flags

零或 OFPMPF_REQ_MORE

meter_id

要读取的计量ID(使用OFPM_ALL表示所有计量)

示例

def send_meter_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPMeterStatsRequest(datapath, 0, ofp.OFPM_ALL)
    datapath.send_msg(req)

JSON 示例

{
   "OFPMeterStatsRequest": {
      "flags": 0,
      "meter_id": 4294967295,
      "type": 9
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterStatsReply(datapath, type_=None, **kwargs)

计量统计回复消息

交换机使用此消息响应计量统计请求。

属性

描述

body

OFPMeterStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPMeterStatsReply, MAIN_DISPATCHER)
def meter_stats_reply_handler(self, ev):
    meters = []
    for stat in ev.msg.body:
        meters.append('meter_id=0x%08x len=%d flow_count=%d '
                      'packet_in_count=%d byte_in_count=%d '
                      'duration_sec=%d duration_nsec=%d '
                      'band_stats=%s' %
                      (stat.meter_id, stat.len, stat.flow_count,
                       stat.packet_in_count, stat.byte_in_count,
                       stat.duration_sec, stat.duration_nsec,
                       stat.band_stats))
    self.logger.debug('MeterStats: %s', meters)

JSON 示例

{
   "OFPMeterStatsReply": {
      "body": [
         {
            "OFPMeterStats": {
               "band_stats": [
                  {
                     "OFPMeterBandStats": {
                        "byte_band_count": 0,
                        "packet_band_count": 0
                     }
                  }
               ],
               "byte_in_count": 0,
               "duration_nsec": 480000,
               "duration_sec": 0,
               "flow_count": 0,
               "len": 56,
               "meter_id": 100,
               "packet_in_count": 0
            }
         }
      ],
      "flags": 0,
      "type": 9
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterConfigStatsRequest(datapath, flags=0, meter_id=4294967295, type_=None)

计量配置统计请求消息

控制器使用此消息查询一个或多个计量的配置。

属性

描述

flags

零或 OFPMPF_REQ_MORE

meter_id

要读取的计量ID(使用OFPM_ALL表示所有计量)

示例

def send_meter_config_stats_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPMeterConfigStatsRequest(datapath, 0,
                                                ofp.OFPM_ALL)
    datapath.send_msg(req)

JSON 示例

{
   "OFPMeterConfigStatsRequest": {
      "flags": 0,
      "meter_id": 4294967295,
      "type": 10
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterConfigStatsReply(datapath, type_=None, **kwargs)

计量配置统计回复消息

交换机使用此消息响应计量配置统计请求。

属性

描述

body

OFPMeterConfigStats 实例列表

示例

@set_ev_cls(ofp_event.EventOFPMeterConfigStatsReply, MAIN_DISPATCHER)
def meter_config_stats_reply_handler(self, ev):
    configs = []
    for stat in ev.msg.body:
        configs.append('length=%d flags=0x%04x meter_id=0x%08x '
                       'bands=%s' %
                       (stat.length, stat.flags, stat.meter_id,
                        stat.bands))
    self.logger.debug('MeterConfigStats: %s', configs)

JSON 示例

{
   "OFPMeterConfigStatsReply": {
      "body": [
         {
            "OFPMeterConfigStats": {
               "bands": [
                  {
                     "OFPMeterBandDrop": {
                        "burst_size": 10,
                        "len": 16,
                        "rate": 1000,
                        "type": 1
                     }
                  }
               ],
               "flags": 14,
               "length": 24,
               "meter_id": 100
            }
         }
      ],
      "flags": 0,
      "type": 10
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterFeaturesStatsRequest(datapath, flags=0, type_=None)

计量功能统计请求消息

控制器使用此消息查询交换机上计量的功能集。

属性

描述

flags

零或 OFPMPF_REQ_MORE

示例

def send_meter_features_stats_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPMeterFeaturesStatsRequest(datapath, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPMeterFeaturesStatsRequest": {
      "flags": 0,
      "type": 11
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPMeterFeaturesStatsReply(datapath, type_=None, **kwargs)

计量功能统计回复消息

交换机使用此消息响应计量功能统计请求。

属性

描述

body

OFPMeterFeaturesStats 实例

示例

@set_ev_cls(ofp_event.EventOFPMeterFeaturesStatsReply, MAIN_DISPATCHER)
def meter_features_stats_reply_handler(self, ev):
    features = []
    for stat in ev.msg.body:
        features.append('max_meter=%d band_types=0x%08x '
                        'capabilities=0x%08x max_bands=%d '
                        'max_color=%d' %
                        (stat.max_meter, stat.band_types,
                         stat.capabilities, stat.max_bands,
                         stat.max_color))
    self.logger.debug('MeterFeaturesStats: %s', features)

JSON 示例

{
   "OFPMeterFeaturesStatsReply": {
      "body": [
         {
            "OFPMeterFeaturesStats": {
               "band_types": 2147483654,
               "capabilities": 15,
               "max_bands": 255,
               "max_color": 0,
               "max_meter": 16777216
            }
         }
      ],
      "flags": 0,
      "type": 11
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPFlowMonitorRequest(datapath, flags=0, monitor_id=0, out_port=4294967295, out_group=4294967295, monitor_flags=0, table_id=255, command=0, match=None, type_=None)

流监控请求消息

控制器使用此消息查询流监控。

属性

描述

flags

零或 OFPMPF_REQ_MORE

monitor_id

控制器分配给此监控的ID

out_port

要求匹配的条目将此作为输出端口包含在内

out_group

要求匹配的条目将此作为输出组包含在内

monitor_flags

以下标志的位图。

OFPFMF_INITIAL
OFPFMF_ADD
OFPFMF_REMOVED
OFPFMF_MODIFY
OFPFMF_INSTRUCTIONS
OFPFMF_NO_ABBREV
OFPFMF_ONLY_OWN

table_id

要监控的表ID

command

以下值之一。

OFPFMC_ADD
OFPFMC_MODIFY
OFPFMC_DELETE

match

OFPMatch 的实例

示例

def send_flow_monitor_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    monitor_flags = [ofp.OFPFMF_INITIAL, ofp.OFPFMF_ONLY_OWN]
    match = ofp_parser.OFPMatch(in_port=1)
    req = ofp_parser.OFPFlowMonitorRequest(datapath, 0, 10000,
                                           ofp.OFPP_ANY, ofp.OFPG_ANY,
                                           monitor_flags,
                                           ofp.OFPTT_ALL,
                                           ofp.OFPFMC_ADD, match)
    datapath.send_msg(req)

JSON 示例

{
   "OFPFlowMonitorRequest": {
      "command": 0,
      "flags": 0,
      "match": {
         "OFPMatch": {
            "length": 14,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               }
            ],
            "type": 1
         }
      },
      "monitor_flags": 15,
      "monitor_id": 100000000,
      "out_group": 4294967295,
      "out_port": 22,
      "table_id": 33,
      "type": 16
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPFlowMonitorReply(datapath, type_=None, **kwargs)

流监控回复消息

交换机使用此消息响应流监控请求。

属性

描述

body

以下类实例的列表

OFPFlowMonitorFull
OFPFlowMonitorAbbrev
OFPFlowMonitorPaused

示例

@set_ev_cls(ofp_event.EventOFPFlowMonitorReply, MAIN_DISPATCHER)
def flow_monitor_reply_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto
    flow_updates = []

    for update in msg.body:
        update_str = 'length=%d event=%d' %
                     (update.length, update.event)
        if (update.event == ofp.OFPFME_INITIAL or
            update.event == ofp.OFPFME_ADDED or
            update.event == ofp.OFPFME_REMOVED or
            update.event == ofp.OFPFME_MODIFIED):
            update_str += 'table_id=%d reason=%d idle_timeout=%d '
                          'hard_timeout=%d priority=%d cookie=%d '
                          'match=%d instructions=%s' %
                          (update.table_id, update.reason,
                           update.idle_timeout, update.hard_timeout,
                           update.priority, update.cookie,
                           update.match, update.instructions)
        elif update.event == ofp.OFPFME_ABBREV:
            update_str += 'xid=%d' % (update.xid)
        flow_updates.append(update_str)
    self.logger.debug('FlowUpdates: %s', flow_updates)

JSON 示例

{
   "OFPFlowMonitorReply": {
      "body": [
         {
            "OFPFlowUpdateFull": {
               "cookie": 0,
               "event": 0,
               "hard_timeout": 700,
               "idle_timeout": 600,
               "instructions": [
                  {
                     "OFPInstructionActions": {
                        "actions": [
                           {
                              "OFPActionOutput": {
                                 "len": 16,
                                 "max_len": 0,
                                 "port": 4294967290,
                                 "type": 0
                              }
                           }
                        ],
                        "len": 24,
                        "type": 4
                     }
                  }
               ],
               "length": 64,
               "match": {
                  "OFPMatch": {
                     "length": 10,
                     "oxm_fields": [
                        {
                           "OXMTlv": {
                              "field": "eth_type",
                              "mask": null,
                              "value": 2054
                           }
                        }
                     ],
                     "type": 1
                  }
               },
               "priority": 3,
               "reason": 0,
               "table_id": 0
            }
         },
         {
            "OFPFlowUpdateAbbrev": {
               "event": 4,
               "length": 8,
               "xid": 1234
            }
         },
         {
            "OFPFlowUpdatePaused": {
               "event": 5,
               "length": 8
            }
         }
      ],
      "flags": 0,
      "type": 16
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPExperimenterStatsRequest(datapath, flags, experimenter, exp_type, data, type_=None)

实验者多部分请求消息

属性

描述

flags

零或 OFPMPF_REQ_MORE

experimenter

实验者ID

exp_type

实验者定义

data

实验者定义的附加数据

JSON 示例

{
   "OFPExperimenterStatsRequest": {
      "data": "aG9nZWhvZ2U=",
      "exp_type": 3405678728,
      "experimenter": 3735928495,
      "flags": 0,
      "type": 65535
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPExperimenterStatsReply(datapath, type_=None, **kwargs)

实验者多部分回复消息

属性

描述

body

一个 OFPExperimenterMultipart 实例

JSON 示例

{
   "OFPExperimenterStatsReply": {
      "body": {
         "OFPExperimenterMultipart": {
            "data": "dGVzdGRhdGE5OTk5OTk5OQ==",
            "exp_type": 3405674359,
            "experimenter": 3735928495
         }
      },
      "flags": 0,
      "type": 65535
   }
}

报文输出消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPPacketOut(datapath, buffer_id=None, in_port=None, actions=None, data=None, actions_len=None)

报文输出消息

控制器使用此消息通过交换机发送一个报文。

属性

描述

buffer_id

由数据路径分配的ID (如果没有则为 OFP_NO_BUFFER)

in_port

报文的输入端口或 OFPP_CONTROLLER

动作

OpenFlow动作类的列表

data

二进制类型值的报文数据或 packet.Packet 的实例。

示例

def send_packet_out(self, datapath, buffer_id, in_port):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD, 0)]
    req = ofp_parser.OFPPacketOut(datapath, buffer_id,
                                  in_port, actions)
    datapath.send_msg(req)

JSON 示例

{
   "OFPPacketOut": {
      "actions": [
         {
            "OFPActionOutput": {
               "len": 16,
               "max_len": 65535,
               "port": 4294967292,
               "type": 0
            }
         }
      ],
      "actions_len": 16,
      "buffer_id": 4294967295,
      "data": "8guk0D9w8gukffjqCABFAABU+BoAAP8Br4sKAAABCgAAAggAAgj3YAAAMdYCAAAAAACrjS0xAAAAABAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vAAAAAAAAAAA=",
      "in_port": 4294967293
   }
}

屏障消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPBarrierRequest(datapath)

屏障请求消息

控制器发送此消息以确保已满足消息依赖关系或接收已完成操作的通知。

示例

def send_barrier_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPBarrierRequest(datapath)
    datapath.send_msg(req)

JSON 示例

{
   "OFPBarrierRequest": {}
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPBarrierReply(datapath)

屏障回复消息

交换机用此消息响应屏障请求。

示例

@set_ev_cls(ofp_event.EventOFPBarrierReply, MAIN_DISPATCHER)
def barrier_reply_handler(self, ev):
    self.logger.debug('OFPBarrierReply received')

JSON 示例

{
   "OFPBarrierReply": {}
}

角色请求消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPRoleRequest(datapath, role=None, generation_id=None)

角色请求消息

控制器使用此消息来更改其角色。

属性

描述

role

以下值之一。

OFPCR_ROLE_NOCHANGE
OFPCR_ROLE_EQUAL
OFPCR_ROLE_MASTER
OFPCR_ROLE_SLAVE

generation_id

主选举生成ID

示例

def send_role_request(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPRoleRequest(datapath, ofp.OFPCR_ROLE_EQUAL, 0)
    datapath.send_msg(req)

JSON 示例

{
   "OFPRoleRequest": {
      "generation_id": 17294086455919964160,
      "role": 2
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPRoleReply(datapath, role=None, generation_id=None)

角色回复消息

交换机用此消息响应角色请求。

属性

描述

role

以下值之一。

OFPCR_ROLE_NOCHANGE
OFPCR_ROLE_EQUAL
OFPCR_ROLE_MASTER
OFPCR_ROLE_SLAVE

generation_id

主选举生成ID

示例

@set_ev_cls(ofp_event.EventOFPRoleReply, MAIN_DISPATCHER)
def role_reply_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.role == ofp.OFPCR_ROLE_NOCHANGE:
        role = 'NOCHANGE'
    elif msg.role == ofp.OFPCR_ROLE_EQUAL:
        role = 'EQUAL'
    elif msg.role == ofp.OFPCR_ROLE_MASTER:
        role = 'MASTER'
    elif msg.role == ofp.OFPCR_ROLE_SLAVE:
        role = 'SLAVE'
    else:
        role = 'unknown'

    self.logger.debug('OFPRoleReply received: '
                      'role=%s generation_id=%d',
                      role, msg.generation_id)

JSON 示例

{
   "OFPRoleReply": {
      "generation_id": 17294086455919964160,
      "role": 3
   }
}

捆绑消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPBundleCtrlMsg(datapath, bundle_id=None, type_=None, flags=None, properties=None)

捆绑控制消息

控制器使用此消息来创建、销毁和提交捆绑包

属性

描述

bundle_id

捆绑包的ID

type

以下值之一。

OFPBCT_OPEN_REQUEST
OFPBCT_OPEN_REPLY
OFPBCT_CLOSE_REQUEST
OFPBCT_CLOSE_REPLY
OFPBCT_COMMIT_REQUEST
OFPBCT_COMMIT_REPLY
OFPBCT_DISCARD_REQUEST
OFPBCT_DISCARD_REPLY

flags

以下标志的位图。

OFPBF_ATOMIC
OFPBF_ORDERED

properties

OFPBundleProp 子类的列表实例

示例

def send_bundle_control(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPBundleCtrlMsg(datapath, 7,
                                      ofp.OFPBCT_OPEN_REQUEST,
                                      ofp.OFPBF_ATOMIC, [])
    datapath.send_msg(req)

JSON 示例

{
   "OFPBundleCtrlMsg": {
      "bundle_id": 1234,
      "flags": 1,
      "properties": [
         {
            "OFPBundlePropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65535
            }
         },
         {
            "OFPBundlePropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPBundlePropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ],
      "type": 0
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPBundleAddMsg(datapath, bundle_id, flags, message, properties)

捆绑添加消息

控制器使用此消息将消息添加到捆绑包

属性

描述

bundle_id

捆绑包的ID

flags

以下标志的位图。

OFPBF_ATOMIC
OFPBF_ORDERED

message

MsgBase 子类实例

properties

OFPBundleProp 子类的列表实例

示例

def send_bundle_add_message(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    msg = ofp_parser.OFPRoleRequest(datapath, ofp.OFPCR_ROLE_EQUAL, 0)

    req = ofp_parser.OFPBundleAddMsg(datapath, 7, ofp.OFPBF_ATOMIC,
                                     msg, [])
    datapath.send_msg(req)

JSON 示例

{
   "OFPBundleAddMsg": {
      "bundle_id": 1234,
      "flags": 1,
      "message": {
         "OFPEchoRequest": {
            "data": null
         }
      },
      "properties": [
         {
            "OFPBundlePropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65535
            }
         },
         {
            "OFPBundlePropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPBundlePropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ]
   }
}

设置异步配置消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPSetAsync(datapath, properties=None)

设置异步配置消息

控制器发送此消息以设置要在给定 OpenFlow 通道上接收的异步消息。

属性

描述

properties

OFPAsyncConfigProp 子类的列表实例

示例

def send_set_async(self, datapath):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    properties = [
        ofp_parser.OFPAsyncConfigPropReasons(
            ofp.OFPACPT_PACKET_IN_SLAVE, 8,
            (1 << ofp.OFPR_APPLY_ACTION
             | 1 << ofp.OFPR_INVALID_TTL))]
    req = ofp_parser.OFPSetAsync(datapath, properties)
    datapath.send_msg(req)

JSON 示例

{
   "OFPSetAsync": {
      "properties": [
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 0
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 1
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 2
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 3
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 4
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 5
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 6
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 7
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 24,
               "type": 8
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 24,
               "type": 9
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 10
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 11
            }
         },
         {
            "OFPAsyncConfigPropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65534
            }
         },
         {
            "OFPAsyncConfigPropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPAsyncConfigPropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ]
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGetAsyncRequest(datapath)

获取异步配置请求消息

控制器使用此消息来查询异步消息。

示例

def send_get_async_request(self, datapath):
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPGetAsyncRequest(datapath)
    datapath.send_msg(req)

JSON 示例

{
   "OFPGetAsyncRequest": {}
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPGetAsyncReply(datapath, properties=None)

获取异步配置回复消息

交换机用此消息响应获取异步配置请求。

属性

描述

properties

OFPAsyncConfigProp 子类的列表实例

示例

@set_ev_cls(ofp_event.EventOFPGetAsyncReply, MAIN_DISPATCHER)
def get_async_reply_handler(self, ev):
    msg = ev.msg

    self.logger.debug('OFPGetAsyncReply received: '
                      'properties=%s', repr(msg.properties))

JSON 示例

{
   "OFPGetAsyncReply": {
      "properties": [
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 0
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 1
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 2
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 3
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 4
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 5
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 6
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 7
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 24,
               "type": 8
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 24,
               "type": 9
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 10
            }
         },
         {
            "OFPAsyncConfigPropReasons": {
               "length": 8,
               "mask": 3,
               "type": 11
            }
         },
         {
            "OFPAsyncConfigPropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65534
            }
         },
         {
            "OFPAsyncConfigPropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPAsyncConfigPropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ]
   }
}

异步消息

报文输入消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPPacketIn(datapath, buffer_id=None, total_len=None, reason=None, table_id=None, cookie=None, match=None, data=None)

报文输入消息

交换机通过此消息将接收到的报文发送给控制器。

属性

描述

buffer_id

由数据路径分配的ID

total_len

帧的完整长度

reason

发送报文的原因。

OFPR_TABLE_MISS
OFPR_APPLY_ACTION
OFPR_INVALID_TTL
OFPR_ACTION_SET
OFPR_GROUP
OFPR_PACKET_OUT

table_id

查找表的ID

cookie

查找的流条目的 Cookie

match

OFPMatch 的实例

data

以太网帧

示例

@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def packet_in_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.reason == ofp.TABLE_MISS:
        reason = 'TABLE MISS'
    elif msg.reason == ofp.OFPR_APPLY_ACTION:
        reason = 'APPLY ACTION'
    elif msg.reason == ofp.OFPR_INVALID_TTL:
        reason = 'INVALID TTL'
    elif msg.reason == ofp.OFPR_ACTION_SET:
        reason = 'ACTION SET'
    elif msg.reason == ofp.OFPR_GROUP:
        reason = 'GROUP'
    elif msg.reason == ofp.OFPR_PACKET_OUT:
        reason = 'PACKET OUT'
    else:
        reason = 'unknown'

    self.logger.debug('OFPPacketIn received: '
                      'buffer_id=%x total_len=%d reason=%s '
                      'table_id=%d cookie=%d match=%s data=%s',
                      msg.buffer_id, msg.total_len, reason,
                      msg.table_id, msg.cookie, msg.match,
                      utils.hex_array(msg.data))

JSON 示例

{
   "OFPPacketIn": {
      "buffer_id": 2,
      "cookie": 283686884868096,
      "data": "////////8gukffjqCAYAAQgABgQAAfILpH346goAAAEAAAAAAAAKAAAD",
      "match": {
         "OFPMatch": {
            "length": 80,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "in_port",
                     "mask": null,
                     "value": 6
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_type",
                     "mask": null,
                     "value": 2054
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "ff:ff:ff:ff:ff:ff"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_src",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_op",
                     "mask": null,
                     "value": 1
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_spa",
                     "mask": null,
                     "value": "10.0.0.1"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_tpa",
                     "mask": null,
                     "value": "10.0.0.3"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_sha",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_tha",
                     "mask": null,
                     "value": "00:00:00:00:00:00"
                  }
               }
            ],
            "type": 1
         }
      },
      "reason": 3,
      "table_id": 1,
      "total_len": 42
   }
}
{
   "OFPPacketIn": {
      "buffer_id": 4026531840,
      "cookie": 283686884868096,
      "data": "",
      "match": {
         "OFPMatch": {
            "length": 329,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "in_port",
                     "mask": null,
                     "value": 84281096
                  }
               },
               {
                  "OXMTlv": {
                     "field": "in_phy_port",
                     "mask": null,
                     "value": 16909060
                  }
               },
               {
                  "OXMTlv": {
                     "field": "metadata",
                     "mask": null,
                     "value": 283686952306183
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_type",
                     "mask": null,
                     "value": 2054
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "ff:ff:ff:ff:ff:ff"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "eth_src",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "vlan_vid",
                     "mask": null,
                     "value": 999
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ip_dscp",
                     "mask": null,
                     "value": 9
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ip_ecn",
                     "mask": null,
                     "value": 3
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ip_proto",
                     "mask": null,
                     "value": 99
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv4_src",
                     "mask": null,
                     "value": "1.2.3.4"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv4_dst",
                     "mask": null,
                     "value": "1.2.3.4"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "tcp_src",
                     "mask": null,
                     "value": 8080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "tcp_dst",
                     "mask": null,
                     "value": 18080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "udp_src",
                     "mask": null,
                     "value": 28080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "udp_dst",
                     "mask": null,
                     "value": 55936
                  }
               },
               {
                  "OXMTlv": {
                     "field": "sctp_src",
                     "mask": null,
                     "value": 48080
                  }
               },
               {
                  "OXMTlv": {
                     "field": "sctp_dst",
                     "mask": null,
                     "value": 59328
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv4_type",
                     "mask": null,
                     "value": 100
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv4_code",
                     "mask": null,
                     "value": 101
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_op",
                     "mask": null,
                     "value": 1
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_spa",
                     "mask": null,
                     "value": "10.0.0.1"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_tpa",
                     "mask": null,
                     "value": "10.0.0.3"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_sha",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "arp_tha",
                     "mask": null,
                     "value": "00:00:00:00:00:00"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_src",
                     "mask": null,
                     "value": "fe80::f00b:a4ff:fe48:28a5"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_dst",
                     "mask": null,
                     "value": "fe80::f00b:a4ff:fe05:b7dc"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_flabel",
                     "mask": null,
                     "value": 541473
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv6_type",
                     "mask": null,
                     "value": 200
                  }
               },
               {
                  "OXMTlv": {
                     "field": "icmpv6_code",
                     "mask": null,
                     "value": 201
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_nd_target",
                     "mask": null,
                     "value": "fe80::a60:6eff:fe7f:74e7"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_nd_sll",
                     "mask": null,
                     "value": "00:00:00:00:02:9a"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_nd_tll",
                     "mask": null,
                     "value": "00:00:00:00:02:2b"
                  }
               },
               {
                  "OXMTlv": {
                     "field": "mpls_label",
                     "mask": null,
                     "value": 624485
                  }
               },
               {
                  "OXMTlv": {
                     "field": "mpls_tc",
                     "mask": null,
                     "value": 5
                  }
               },
               {
                  "OXMTlv": {
                     "field": "mpls_bos",
                     "mask": null,
                     "value": 1
                  }
               },
               {
                  "OXMTlv": {
                     "field": "pbb_isid",
                     "mask": null,
                     "value": 11259375
                  }
               },
               {
                  "OXMTlv": {
                     "field": "tunnel_id",
                     "mask": null,
                     "value": 651061555542690057
                  }
               },
               {
                  "OXMTlv": {
                     "field": "ipv6_exthdr",
                     "mask": null,
                     "value": 500
                  }
               },
               {
                  "OXMTlv": {
                     "field": "pbb_uca",
                     "mask": null,
                     "value": 1
                  }
               }
            ],
            "type": 1
         }
      },
      "reason": 0,
      "table_id": 200,
      "total_len": 0
   }
}

流移除消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPFlowRemoved(datapath, cookie=None, priority=None, reason=None, table_id=None, duration_sec=None, duration_nsec=None, idle_timeout=None, hard_timeout=None, packet_count=None, byte_count=None, match=None)

流移除消息

当流条目超时或被删除时,交换机通过此消息通知控制器。

属性

描述

cookie

不透明的控制器颁发的标识符

priority

流条目的优先级

reason

以下值之一。

OFPRR_IDLE_TIMEOUT
OFPRR_HARD_TIMEOUT
OFPRR_DELETE
OFPRR_GROUP_DELETE
OFPRR_METER_DELETE
OFPRR_EVICTION

table_id

表的ID

duration_sec

流存活的时间,以秒为单位

duration_nsec

超出 duration_sec 的流存活时间,以纳秒为单位

idle_timeout

原始流 mod 中的空闲超时

hard_timeout

原始流 mod 中的硬超时

packet_count

与流关联的数据包数量

byte_count

与流关联的字节数

match

OFPMatch 的实例

示例

@set_ev_cls(ofp_event.EventOFPFlowRemoved, MAIN_DISPATCHER)
def flow_removed_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.reason == ofp.OFPRR_IDLE_TIMEOUT:
        reason = 'IDLE TIMEOUT'
    elif msg.reason == ofp.OFPRR_HARD_TIMEOUT:
        reason = 'HARD TIMEOUT'
    elif msg.reason == ofp.OFPRR_DELETE:
        reason = 'DELETE'
    elif msg.reason == ofp.OFPRR_GROUP_DELETE:
        reason = 'GROUP DELETE'
    else:
        reason = 'unknown'

    self.logger.debug('OFPFlowRemoved received: '
                      'cookie=%d priority=%d reason=%s table_id=%d '
                      'duration_sec=%d duration_nsec=%d '
                      'idle_timeout=%d hard_timeout=%d '
                      'packet_count=%d byte_count=%d match.fields=%s',
                      msg.cookie, msg.priority, reason, msg.table_id,
                      msg.duration_sec, msg.duration_nsec,
                      msg.idle_timeout, msg.hard_timeout,
                      msg.packet_count, msg.byte_count, msg.match)

JSON 示例

{
   "OFPFlowRemoved": {
      "byte_count": 86,
      "cookie": 0,
      "duration_nsec": 48825000,
      "duration_sec": 3,
      "hard_timeout": 0,
      "idle_timeout": 3,
      "match": {
         "OFPMatch": {
            "length": 14,
            "oxm_fields": [
               {
                  "OXMTlv": {
                     "field": "eth_dst",
                     "mask": null,
                     "value": "f2:0b:a4:7d:f8:ea"
                  }
               }
            ],
            "type": 1
         }
      },
      "packet_count": 1,
      "priority": 65535,
      "reason": 0,
      "table_id": 0
   }
}

端口状态消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPPortStatus(datapath, reason=None, desc=None)

端口状态消息

交换机通知控制器端口的变化。

属性

描述

reason

以下值之一。

OFPPR_ADD
OFPPR_DELETE
OFPPR_MODIFY

desc

OFPPort 的实例

示例

@set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
def port_status_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.reason == ofp.OFPPR_ADD:
        reason = 'ADD'
    elif msg.reason == ofp.OFPPR_DELETE:
        reason = 'DELETE'
    elif msg.reason == ofp.OFPPR_MODIFY:
        reason = 'MODIFY'
    else:
        reason = 'unknown'

    self.logger.debug('OFPPortStatus received: reason=%s desc=%s',
                      reason, msg.desc)

JSON 示例

{
   "OFPPortStatus": {
      "desc": {
         "OFPPort": {
            "config": 0,
            "hw_addr": "f2:0b:a4:d0:3f:70",
            "length": 168,
            "name": "\u79c1\u306e\u30dd\u30fc\u30c8",
            "port_no": 7,
            "properties": [
               {
                  "OFPPortDescPropEthernet": {
                     "advertised": 10240,
                     "curr": 10248,
                     "curr_speed": 5000,
                     "length": 32,
                     "max_speed": 5000,
                     "peer": 10248,
                     "supported": 10248,
                     "type": 0
                  }
               },
               {
                  "OFPPortDescPropOptical": {
                     "length": 40,
                     "rx_grid_freq_lmda": 1500,
                     "rx_max_freq_lmda": 2000,
                     "rx_min_freq_lmda": 1000,
                     "supported": 1,
                     "tx_grid_freq_lmda": 1500,
                     "tx_max_freq_lmda": 2000,
                     "tx_min_freq_lmda": 1000,
                     "tx_pwr_max": 2000,
                     "tx_pwr_min": 1000,
                     "type": 1
                  }
               },
               {
                  "OFPPortDescPropExperimenter": {
                     "data": [],
                     "exp_type": 0,
                     "experimenter": 101,
                     "length": 12,
                     "type": 65535
                  }
               },
               {
                  "OFPPortDescPropExperimenter": {
                     "data": [
                        1
                     ],
                     "exp_type": 1,
                     "experimenter": 101,
                     "length": 16,
                     "type": 65535
                  }
               },
               {
                  "OFPPortDescPropExperimenter": {
                     "data": [
                        1,
                        2
                     ],
                     "exp_type": 2,
                     "experimenter": 101,
                     "length": 20,
                     "type": 65535
                  }
               }
            ],
            "state": 4
         }
      },
      "reason": 0
   }
}

控制器角色状态消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPRoleStatus(datapath, role=None, reason=None, generation_id=None, properties=None)

角色状态消息

交换机通知控制器角色变更。

属性

描述

role

以下值之一。

OFPCR_ROLE_NOCHANGE
OFPCR_ROLE_EQUAL
OFPCR_ROLE_MASTER

reason

以下值之一。

OFPCRR_MASTER_REQUEST
OFPCRR_CONFIG
OFPCRR_EXPERIMENTER

generation_id

主选举生成ID

properties

OFPRoleProp 子类实例列表

示例

@set_ev_cls(ofp_event.EventOFPRoleStatus, MAIN_DISPATCHER)
def role_status_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.role == ofp.OFPCR_ROLE_NOCHANGE:
        role = 'ROLE NOCHANGE'
    elif msg.role == ofp.OFPCR_ROLE_EQUAL:
        role = 'ROLE EQUAL'
    elif msg.role == ofp.OFPCR_ROLE_MASTER:
        role = 'ROLE MASTER'
    else:
        role = 'unknown'

    if msg.reason == ofp.OFPCRR_MASTER_REQUEST:
        reason = 'MASTER REQUEST'
    elif msg.reason == ofp.OFPCRR_CONFIG:
        reason = 'CONFIG'
    elif msg.reason == ofp.OFPCRR_EXPERIMENTER:
        reason = 'EXPERIMENTER'
    else:
        reason = 'unknown'

    self.logger.debug('OFPRoleStatus received: role=%s reason=%s '
                      'generation_id=%d properties=%s', role, reason,
                      msg.generation_id, repr(msg.properties))

JSON 示例

{
   "OFPRoleStatus": {
      "generation_id": 7,
      "properties": [
         {
            "OFPRolePropExperimenter": {
               "data": [],
               "exp_type": 0,
               "experimenter": 101,
               "length": 12,
               "type": 65535
            }
         },
         {
            "OFPRolePropExperimenter": {
               "data": [
                  1
               ],
               "exp_type": 1,
               "experimenter": 101,
               "length": 16,
               "type": 65535
            }
         },
         {
            "OFPRolePropExperimenter": {
               "data": [
                  1,
                  2
               ],
               "exp_type": 2,
               "experimenter": 101,
               "length": 20,
               "type": 65535
            }
         }
      ],
      "reason": 0,
      "role": 2
   }
}

表状态消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPTableStatus(datapath, reason=None, table=None)

表状态消息

交换机通知控制器表状态变更。

属性

描述

reason

以下值之一。

OFPTR_VACANCY_DOWN
OFPTR_VACANCY_UP

表格

OFPTableDesc 实例

示例

@set_ev_cls(ofp_event.EventOFPTableStatus, MAIN_DISPATCHER)
def table(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.reason == ofp.OFPTR_VACANCY_DOWN:
        reason = 'VACANCY_DOWN'
    elif msg.reason == ofp.OFPTR_VACANCY_UP:
        reason = 'VACANCY_UP'
    else:
        reason = 'unknown'

    self.logger.debug('OFPTableStatus received: reason=%s '
                      'table_id=%d config=0x%08x properties=%s',
                      reason, msg.table.table_id, msg.table.config,
                      repr(msg.table.properties))

JSON 示例

{
   "OFPTableStatus": {
      "reason": 3,
      "table": {
         "OFPTableDesc": {
            "config": 0,
            "length": 80,
            "properties": [
               {
                  "OFPTableModPropEviction": {
                     "flags": 0,
                     "length": 8,
                     "type": 2
                  }
               },
               {
                  "OFPTableModPropVacancy": {
                     "length": 8,
                     "type": 3,
                     "vacancy": 0,
                     "vacancy_down": 0,
                     "vacancy_up": 0
                  }
               },
               {
                  "OFPTableModPropExperimenter": {
                     "data": [],
                     "exp_type": 0,
                     "experimenter": 101,
                     "length": 12,
                     "type": 65535
                  }
               },
               {
                  "OFPTableModPropExperimenter": {
                     "data": [
                        1
                     ],
                     "exp_type": 1,
                     "experimenter": 101,
                     "length": 16,
                     "type": 65535
                  }
               },
               {
                  "OFPTableModPropExperimenter": {
                     "data": [
                        1,
                        2
                     ],
                     "exp_type": 2,
                     "experimenter": 101,
                     "length": 20,
                     "type": 65535
                  }
               }
            ],
            "table_id": 8
         }
      }
   }
}

请求转发消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPRequestForward(datapath, request=None)

转发的请求消息

交换机将请求消息从一个控制器转发到其他控制器。

属性

描述

请求

OFPGroupModOFPMeterMod 实例

示例

@set_ev_cls(ofp_event.EventOFPRequestForward, MAIN_DISPATCHER)
def request_forward_handler(self, ev):
    msg = ev.msg
    dp = msg.datapath
    ofp = dp.ofproto

    if msg.request.msg_type == ofp.OFPT_GROUP_MOD:
        self.logger.debug(
            'OFPRequestForward received: request=OFPGroupMod('
            'command=%d, type=%d, group_id=%d, buckets=%s)',
            msg.request.command, msg.request.type,
            msg.request.group_id, msg.request.buckets)
    elif msg.request.msg_type == ofp.OFPT_METER_MOD:
        self.logger.debug(
            'OFPRequestForward received: request=OFPMeterMod('
            'command=%d, flags=%d, meter_id=%d, bands=%s)',
            msg.request.command, msg.request.flags,
            msg.request.meter_id, msg.request.bands)
    else:
        self.logger.debug(
            'OFPRequestForward received: request=Unknown')

JSON 示例

{
   "OFPRequestForward": {
      "request": {
         "OFPGroupMod": {
            "buckets": [
               {
                  "OFPBucket": {
                     "actions": [
                        {
                           "OFPActionOutput": {
                              "len": 16,
                              "max_len": 65535,
                              "port": 2,
                              "type": 0
                           }
                        }
                     ],
                     "len": 32,
                     "watch_group": 1,
                     "watch_port": 1,
                     "weight": 1
                  }
               }
            ],
            "command": 0,
            "group_id": 1,
            "type": 0
         }
      }
   }
}

对称消息

Hello

class os_ken.ofproto.ofproto_v1_4_parser.OFPHello(datapath, elements=None)

Hello 消息

当连接启动时,Hello 消息在交换机和控制器之间交换。

此消息由 OSKen 框架处理,因此 OSKen 应用程序通常不需要处理此消息。

属性

描述

元素

OFPHelloElemVersionBitmap 实例列表

JSON 示例

{
   "OFPHello": {
      "elements": [
         {
            "OFPHelloElemVersionBitmap": {
               "length": 8,
               "type": 1,
               "versions": [
                  1,
                  2,
                  3,
                  9,
                  10,
                  30
               ]
            }
         }
      ]
   }
}
class os_ken.ofproto.ofproto_v1_4_parser.OFPHelloElemVersionBitmap(versions, type_=None, length=None)

版本位图 Hello 元素

属性

描述

versions

设备支持的 OpenFlow 协议版本列表

Echo 请求

class os_ken.ofproto.ofproto_v1_4_parser.OFPEchoRequest(datapath, data=None)

Echo 请求消息

此消息由 OSKen 框架处理,因此 OSKen 应用程序通常不需要处理此消息。

属性

描述

data

任意长度的数据

示例

def send_echo_request(self, datapath, data):
    ofp = datapath.ofproto
    ofp_parser = datapath.ofproto_parser

    req = ofp_parser.OFPEchoRequest(datapath, data)
    datapath.send_msg(req)

@set_ev_cls(ofp_event.EventOFPEchoRequest,
            [HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
def echo_request_handler(self, ev):
    self.logger.debug('OFPEchoRequest received: data=%s',
                      utils.hex_array(ev.msg.data))

JSON 示例

{
   "OFPEchoRequest": {
      "data": "aG9nZQ=="
   }
}

Echo 响应

class os_ken.ofproto.ofproto_v1_4_parser.OFPEchoReply(datapath, data=None)

Echo 响应消息

此消息由 OSKen 框架处理,因此 OSKen 应用程序通常不需要处理此消息。

属性

描述

data

任意长度的数据

示例

def send_echo_reply(self, datapath, data):
    ofp_parser = datapath.ofproto_parser

    reply = ofp_parser.OFPEchoReply(datapath, data)
    datapath.send_msg(reply)

@set_ev_cls(ofp_event.EventOFPEchoReply,
            [HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
def echo_reply_handler(self, ev):
    self.logger.debug('OFPEchoReply received: data=%s',
                      utils.hex_array(ev.msg.data))

JSON 示例

{
   "OFPEchoReply": {
      "data": "aG9nZQ=="
   }
}

错误消息

class os_ken.ofproto.ofproto_v1_4_parser.OFPErrorMsg(datapath, type_=None, code=None, data=None, **kwargs)

错误消息

交换机通过此消息通知控制器问题。

属性

描述

type

错误的高级类型

code

根据类型而定的详细信息

data

根据类型和代码而定的变长数据

type 属性对应于 __init__ 的 type_ 参数。

类型和代码在 os_ken.ofproto.ofproto 中定义。

类型

代码

OFPET_HELLO_FAILED

OFPHFC_*

OFPET_BAD_REQUEST

OFPBRC_*

OFPET_BAD_ACTION

OFPBAC_*

OFPET_BAD_INSTRUCTION

OFPBIC_*

OFPET_BAD_MATCH

OFPBMC_*

OFPET_FLOW_MOD_FAILED

OFPFMFC_*

OFPET_GROUP_MOD_FAILED

OFPGMFC_*

OFPET_PORT_MOD_FAILED

OFPPMFC_*

OFPET_TABLE_MOD_FAILED

OFPTMFC_*

OFPET_QUEUE_OP_FAILED

OFPQOFC_*

OFPET_SWITCH_CONFIG_FAILED

OFPSCFC_*

OFPET_ROLE_REQUEST_FAILED

OFPRRFC_*

OFPET_METER_MOD_FAILED

OFPMMFC_*

OFPET_TABLE_FEATURES_FAILED

OFPTFFC_*

OFPET_EXPERIMENTER

不适用

如果 type == OFPET_EXPERIMENTER,此消息还具有以下属性。

属性

描述

exp_type

实验者定义的类型

experimenter

实验者ID

示例

@set_ev_cls(ofp_event.EventOFPErrorMsg,
            [HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
def error_msg_handler(self, ev):
    msg = ev.msg

    self.logger.debug('OFPErrorMsg received: type=0x%02x code=0x%02x '
                      'message=%s',
                      msg.type, msg.code, utils.hex_array(msg.data))

JSON 示例

{
   "OFPErrorMsg": {
      "code": 11,
      "data": "ZnVnYWZ1Z2E=",
      "type": 2
   }
}

实验者

class os_ken.ofproto.ofproto_v1_4_parser.OFPExperimenter(datapath, experimenter=None, exp_type=None, data=None)

实验者扩展消息

属性

描述

experimenter

实验者ID

exp_type

实验者定义

data

实验者定义的任意附加数据

JSON 示例

{
   "OFPExperimenter": {
      "data": "bmF6bw==",
      "exp_type": 123456789,
      "experimenter": 98765432
   }
}

端口结构

class os_ken.ofproto.ofproto_v1_4_parser.OFPPort(port_no=None, length=None, hw_addr=None, name=None, config=None, state=None, properties=None)

端口的描述

属性

描述

port_no

端口号,它在交换机内唯一标识一个端口。

长度

ofp_port 的长度(不包括填充)。

hw_addr

端口的 MAC 地址。

name

以 null 结尾的字符串,包含接口的可读名称。

config

端口配置标志的位图。

OFPPC_PORT_DOWN
OFPPC_NO_RECV
OFPPC_NO_FWD
OFPPC_NO_PACKET_IN

state

端口状态标志的位图。

OFPPS_LINK_DOWN
OFPPS_BLOCKED
OFPPS_LIVE

properties

OFPPortDescProp 子类实例列表

流匹配结构

class os_ken.ofproto.ofproto_v1_4_parser.OFPMatch(type_=None, length=None, _ordered_fields=None, **kwargs)

流匹配结构

此类是具有 compose/query API 的流匹配结构的实现。

您可以通过关键字参数定义流匹配。以下参数可用:

参数

描述

in_port

整数 32 位

交换机输入端口

in_phy_port

整数 32 位

交换机物理输入端口

metadata

整数 64 位

在表之间传递的元数据

eth_dst

MAC 地址

以太网目标地址

eth_src

MAC 地址

以太网源地址

eth_type

整数 16 位

以太网帧类型

vlan_vid

整数 16 位

VLAN ID

vlan_pcp

整数 8 位

VLAN 优先级

ip_dscp

整数 8 位

IP DSCP(ToS 字段中的 6 位)

ip_ecn

整数 8 位

IP ECN(ToS 字段中的 2 位)

ip_proto

整数 8 位

IP 协议

ipv4_src

IPv4 地址

IPv4 源地址

ipv4_dst

IPv4 地址

IPv4 目标地址

tcp_src

整数 16 位

TCP 源端口

tcp_dst

整数 16 位

TCP 目标端口

udp_src

整数 16 位

UDP 源端口

udp_dst

整数 16 位

UDP 目标端口

sctp_src

整数 16 位

SCTP 源端口

sctp_dst

整数 16 位

SCTP 目标端口

icmpv4_type

整数 8 位

ICMP 类型

icmpv4_code

整数 8 位

ICMP 代码

arp_op

整数 16 位

ARP 操作码

arp_spa

IPv4 地址

ARP 源 IPv4 地址

arp_tpa

IPv4 地址

ARP 目标 IPv4 地址

arp_sha

MAC 地址

ARP 源硬件地址

arp_tha

MAC 地址

ARP 目标硬件地址

ipv6_src

IPv6 地址

IPv6 源地址

ipv6_dst

IPv6 地址

IPv6 目标地址

ipv6_flabel

整数 32 位

IPv6 流标签

icmpv6_type

整数 8 位

ICMPv6 类型

icmpv6_code

整数 8 位

ICMPv6 代码

ipv6_nd_target

IPv6 地址

ND 的目标地址

ipv6_nd_sll

MAC 地址

ND 的源链路层

ipv6_nd_tll

MAC 地址

ND 的目标链路层

mpls_label

整数 32 位

MPLS 标签

mpls_tc

整数 8 位

MPLS TC

mpls_bos

整数 8 位

MPLS BoS 位

pbb_isid

整数 24 位

PBB I-SID

tunnel_id

整数 64 位

逻辑端口元数据

ipv6_exthdr

整数 16 位

IPv6 扩展标头伪字段

pbb_uca

整数 8 位

PBB UCA 标头字段

tcp_flags

整数 16 位

TCP 标志(EXT-109 ONF 扩展)

actset_output

整数 32 位

动作集元数据中的输出端口(EXT-233 ONF 扩展)

示例

>>> # compose
>>> match = parser.OFPMatch(
...     in_port=1,
...     eth_type=0x86dd,
...     ipv6_src=('2001:db8:bd05:1d2:288a:1fc0:1:10ee',
...               'ffff:ffff:ffff:ffff::'),
...     ipv6_dst='2001:db8:bd05:1d2:288a:1fc0:1:10ee')
>>> # query
>>> if 'ipv6_src' in match:
...     print match['ipv6_src']
...
('2001:db8:bd05:1d2:288a:1fc0:1:10ee', 'ffff:ffff:ffff:ffff::')

注意

有关受支持的 Nicira 实验者匹配的列表,请参阅 os_ken.ofproto.nx_match

注意

对于 VLAN ID 匹配字段,OpenFlow 规范中定义了特殊值。

  1. 带有和不带有 VLAN 标签的数据包

    • 示例

      match = parser.OFPMatch()
      
    • 数据包匹配

      非 VLAN 标记

      MATCH

      VLAN 标记(vlan_id=3)

      MATCH

      VLAN 标记(vlan_id=5)

      MATCH

  2. 仅不带 VLAN 标签的数据包

    • 示例

      match = parser.OFPMatch(vlan_vid=0x0000)
      
    • 数据包匹配

      非 VLAN 标记

      MATCH

      VLAN 标记(vlan_id=3)

      x

      VLAN 标记(vlan_id=5)

      x

  3. 仅带有 VLAN 标签的数据包,无论其值如何

    • 示例

      match = parser.OFPMatch(vlan_vid=(0x1000, 0x1000))
      
    • 数据包匹配

      非 VLAN 标记

      x

      VLAN 标记(vlan_id=3)

      MATCH

      VLAN 标记(vlan_id=5)

      MATCH

  4. 仅带有 VLAN 标签且 VID 等于的数据包

    • 示例

      match = parser.OFPMatch(vlan_vid=(0x1000 | 3))
      
    • 数据包匹配

      非 VLAN 标记

      x

      VLAN 标记(vlan_id=3)

      MATCH

      VLAN 标记(vlan_id=5)

      x

流指令结构

class os_ken.ofproto.ofproto_v1_4_parser.OFPInstructionGotoTable(table_id, type_=None, len_=None)

转到表指令

此指令指示处理流水线中的下一个表。

属性

描述

table_id

下一个表

class os_ken.ofproto.ofproto_v1_4_parser.OFPInstructionWriteMetadata(metadata, metadata_mask, type_=None, len_=None)

写入元数据指令

此指令将掩码后的元数据值写入元数据字段。

属性

描述

metadata

要写入的元数据值

metadata_mask

元数据写入位掩码

class os_ken.ofproto.ofproto_v1_4_parser.OFPInstructionActions(type_, actions=None, len_=None)

动作指令

此指令写入/应用/清除动作。

属性

描述

type

以下值之一。

OFPIT_WRITE_ACTIONS
OFPIT_APPLY_ACTIONS
OFPIT_CLEAR_ACTIONS

动作

OpenFlow动作类的列表

type 属性对应于 __init__ 的 type_ 参数。

class os_ken.ofproto.ofproto_v1_4_parser.OFPInstructionMeter(meter_id=1, type_=None, len_=None)

计量指令

此指令应用计量器。

属性

描述

meter_id

计量器实例

动作结构

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionOutput(port, max_len=65509, type_=None, len_=None)

输出动作

此动作指示将数据包输出到交换机端口。

属性

描述

port

输出端口

max_len

发送到控制器的最大长度

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionCopyTtlOut(type_=None, len_=None)

复制 TTL Out 动作

此动作将从外层倒数第二个头部复制 TTL 到最外层头部。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionCopyTtlIn(type_=None, len_=None)

复制 TTL In 动作

此动作将从最外层头部复制 TTL 到外层倒数第二个头部。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionSetMplsTtl(mpls_ttl, type_=None, len_=None)

设置 MPLS TTL 动作

此动作设置 MPLS TTL。

属性

描述

mpls_ttl

MPLS TTL

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionDecMplsTtl(type_=None, len_=None)

减少 MPLS TTL 动作

此动作减少 MPLS TTL。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionPushVlan(ethertype=33024, type_=None, len_=None)

推送 VLAN 动作

此动作将新的 VLAN 标签推送到数据包。

属性

描述

ethertype

以太类型。默认值为 802.1Q (0x8100)

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionPopVlan(type_=None, len_=None)

弹出 VLAN 动作

此动作从数据包中弹出最外层的 VLAN 标签。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionPushMpls(ethertype, type_=None, len_=None)

推送 MPLS 动作

此动作将新的 MPLS 头部推送到数据包。

属性

描述

ethertype

以太类型

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionPopMpls(ethertype=2048, type_=None, len_=None)

弹出 MPLS 动作

此动作从数据包中弹出 MPLS 头部。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionSetQueue(queue_id, type_=None, len_=None)

设置队列动作

此动作设置将用于将流映射到端口上已配置队列的队列 ID。

属性

描述

queue_id

数据包的队列 ID

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionGroup(group_id=0, type_=None, len_=None)

组动作

此动作指示用于处理数据包的组。

属性

描述

group_id

组标识符

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionSetNwTtl(nw_ttl, type_=None, len_=None)

设置 IP TTL 动作

此动作设置 IP TTL。

属性

描述

nw_ttl

IP TTL

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionDecNwTtl(type_=None, len_=None)

减少 IP TTL 动作

此动作减少 IP TTL。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionSetField(field=None, **kwargs)

设置字段动作

此动作修改数据包中的头部字段。

可用的关键字集合与 OFPMatch 相同。

示例

set_field = OFPActionSetField(eth_src="00:00:00:00:00:00")
class os_ken.ofproto.ofproto_v1_4_parser.OFPActionPushPbb(ethertype, type_=None, len_=None)

推送 PBB 动作

此动作将新的 PBB 头部推送到数据包。

属性

描述

ethertype

以太类型

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionPopPbb(type_=None, len_=None)

弹出 PBB 动作

此动作从数据包中弹出最外层的 PBB 服务实例头部。

class os_ken.ofproto.ofproto_v1_4_parser.OFPActionExperimenter(experimenter)

实验者动作

此动作是实验者的可扩展动作。

属性

描述

experimenter

实验者ID

注意

有关受支持的 Nicira 实验者动作列表,请参阅 os_ken.ofproto.nx_actions