本文整理汇总了Python中ryu.lib.ofctl_utils.send_stats_request函数的典型用法代码示例。如果您正苦于以下问题:Python send_stats_request函数的具体用法?Python send_stats_request怎么用?Python send_stats_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_stats_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_queue_config
def get_queue_config(dp, port, waiters):
port = UTIL.ofp_port_from_user(port)
stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
prop_type = {dp.ofproto.OFPQT_MIN_RATE: 'MIN_RATE',
dp.ofproto.OFPQT_MAX_RATE: 'MAX_RATE',
dp.ofproto.OFPQT_EXPERIMENTER: 'EXPERIMENTER',
}
configs = []
for config in msgs:
queue_list = []
for queue in config.queues:
prop_list = []
for prop in queue.properties:
p = {'property': prop_type.get(prop.property, 'UNKNOWN')}
if prop.property == dp.ofproto.OFPQT_MIN_RATE or \
prop.property == dp.ofproto.OFPQT_MAX_RATE:
p['rate'] = prop.rate
elif prop.property == dp.ofproto.OFPQT_EXPERIMENTER:
p['experimenter'] = prop.experimenter
p['data'] = prop.data
prop_list.append(p)
q = {'port': UTIL.ofp_port_to_user(queue.port),
'properties': prop_list,
'queue_id': UTIL.ofp_queue_to_user(queue.queue_id)}
queue_list.append(q)
c = {'port': UTIL.ofp_port_to_user(config.port),
'queues': queue_list}
configs.append(c)
configs = {str(dp.id): configs}
return configs
示例2: get_flow_stats
def get_flow_stats(dp, waiters, flow=None):
flow = flow if flow else {}
match = to_match(dp, flow.get('match', {}))
table_id = UTIL.ofp_table_from_user(
flow.get('table_id', 0xff))
out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_NONE))
stats = dp.ofproto_parser.OFPFlowStatsRequest(
dp, 0, match, table_id, out_port)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
flows = []
for msg in msgs:
for stats in msg.body:
actions = actions_to_str(stats.actions)
match = match_to_str(stats.match)
s = {'priority': stats.priority,
'cookie': stats.cookie,
'idle_timeout': stats.idle_timeout,
'hard_timeout': stats.hard_timeout,
'actions': actions,
'match': match,
'byte_count': stats.byte_count,
'duration_sec': stats.duration_sec,
'duration_nsec': stats.duration_nsec,
'packet_count': stats.packet_count,
'table_id': UTIL.ofp_table_to_user(stats.table_id)}
flows.append(s)
return {str(dp.id): flows}
示例3: get_queue_desc
def get_queue_desc(dp, waiters, port_no=None, queue_id=None, to_user=True):
if port_no is None:
port_no = dp.ofproto.OFPP_ANY
else:
port_no = UTIL.ofp_port_from_user(port_no)
if queue_id is None:
queue_id = dp.ofproto.OFPQ_ALL
else:
queue_id = UTIL.ofp_queue_from_user(queue_id)
stats = dp.ofproto_parser.OFPQueueDescStatsRequest(
dp, 0, port_no, queue_id)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
configs = []
for msg in msgs:
for queue in msg.body:
q = queue.to_jsondict()[queue.__class__.__name__]
prop_list = []
for prop in queue.properties:
p = prop.to_jsondict()[prop.__class__.__name__]
if to_user:
t = UTIL.ofp_queue_desc_prop_type_to_user(prop.type)
p['type'] = t if t != prop.type else 'UNKNOWN'
prop_list.append(p)
q['properties'] = prop_list
configs.append(q)
return wrap_dpid_dict(dp, configs, to_user)
示例4: get_meter_config
def get_meter_config(dp, waiters):
flags = {
dp.ofproto.OFPMF_KBPS: "KBPS",
dp.ofproto.OFPMF_PKTPS: "PKTPS",
dp.ofproto.OFPMF_BURST: "BURST",
dp.ofproto.OFPMF_STATS: "STATS",
}
stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(dp, 0, dp.ofproto.OFPM_ALL)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
configs = []
for msg in msgs:
for config in msg.body:
c = config.to_jsondict()[config.__class__.__name__]
bands = []
for band in config.bands:
b = band.to_jsondict()[band.__class__.__name__]
t = UTIL.ofp_meter_band_type_to_user(band.type)
b["type"] = t if t != band.type else "UNKNOWN"
bands.append(b)
c_flags = []
for k, v in sorted(flags.items()):
if k & config.flags:
c_flags.append(v)
c["flags"] = c_flags
c["bands"] = bands
configs.append(c)
configs = {str(dp.id): configs}
return configs
示例5: get_group_stats
def get_group_stats(dp, waiters, group_id=None):
if group_id is None:
group_id = dp.ofproto.OFPG_ALL
else:
group_id = str_to_int(group_id)
stats = dp.ofproto_parser.OFPGroupStatsRequest(
dp, group_id, 0)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
groups = []
for msg in msgs:
for stats in msg.body:
bucket_counters = []
for bucket_counter in stats.bucket_counters:
c = {'packet_count': bucket_counter.packet_count,
'byte_count': bucket_counter.byte_count}
bucket_counters.append(c)
g = {'length': stats.length,
'group_id': UTIL.ofp_group_to_user(stats.group_id),
'ref_count': stats.ref_count,
'packet_count': stats.packet_count,
'byte_count': stats.byte_count,
'bucket_stats': bucket_counters}
groups.append(g)
return {str(dp.id): groups}
示例6: get_aggregate_flow_stats
def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True):
flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL))
flags = str_to_int(flow.get('flags', 0))
out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {}))
stats = dp.ofproto_parser.OFPAggregateStatsRequest(
dp, flags, table_id, out_port, out_group, cookie, cookie_mask,
match)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
flows = []
for msg in msgs:
stats = msg.body
s = stats.to_jsondict()[stats.__class__.__name__]
s['stats'] = stats_to_str(stats.stats)
flows.append(s)
return wrap_dpid_dict(dp, flows, to_user)
示例7: get_port_stats
def get_port_stats(dp, waiters, port_no=None, to_user=True):
if port_no is None:
port_no = dp.ofproto.OFPP_ANY
else:
port_no = UTIL.ofp_port_from_user(port_no)
stats = dp.ofproto_parser.OFPPortStatsRequest(dp, 0, port_no)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
ports = []
for msg in msgs:
for stats in msg.body:
s = stats.to_jsondict()[stats.__class__.__name__]
properties = []
for prop in stats.properties:
p = prop.to_jsondict()[prop.__class__.__name__]
t = UTIL.ofp_port_stats_prop_type_to_user(prop.type)
p['type'] = t if t != prop.type else 'UNKNOWN'
properties.append(p)
s['properties'] = properties
if to_user:
s['port_no'] = UTIL.ofp_port_to_user(stats.port_no)
ports.append(s)
return wrap_dpid_dict(dp, ports, to_user)
示例8: get_aggregate_flow_stats
def get_aggregate_flow_stats(dp, waiters, flow=None):
flow = flow if flow else {}
match = to_match(dp, flow.get('match', {}))
table_id = UTIL.ofp_table_from_user(
flow.get('table_id', 0xff))
out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_NONE))
stats = dp.ofproto_parser.OFPAggregateStatsRequest(
dp, 0, match, table_id, out_port)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
flows = []
for msg in msgs:
stats = msg.body
for st in stats:
s = {'packet_count': st.packet_count,
'byte_count': st.byte_count,
'flow_count': st.flow_count}
flows.append(s)
flows = {str(dp.id): flows}
return flows
示例9: get_port_desc
def get_port_desc(dp, waiters, to_user=True):
stats = dp.ofproto_parser.OFPPortDescStatsRequest(dp, 0)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
descs = []
for msg in msgs:
stats = msg.body
for stat in stats:
d = {'hw_addr': stat.hw_addr,
'name': stat.name.decode('utf-8'),
'config': stat.config,
'state': stat.state,
'curr': stat.curr,
'advertised': stat.advertised,
'supported': stat.supported,
'peer': stat.peer,
'curr_speed': stat.curr_speed,
'max_speed': stat.max_speed}
if to_user:
d['port_no'] = UTIL.ofp_port_to_user(stat.port_no)
else:
d['port_no'] = stat.port_no
descs.append(d)
return wrap_dpid_dict(dp, descs, to_user)
示例10: get_queue_stats
def get_queue_stats(dp, waiters, port=None, queue_id=None, to_user=True):
ofp = dp.ofproto
if port is None:
port = ofp.OFPP_ANY
else:
port = int(str(port), 0)
if queue_id is None:
queue_id = ofp.OFPQ_ALL
else:
queue_id = int(str(queue_id), 0)
stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
queue_id)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
s = []
for msg in msgs:
stats = msg.body
for stat in stats:
s.append({'duration_nsec': stat.duration_nsec,
'duration_sec': stat.duration_sec,
'port_no': stat.port_no,
'queue_id': stat.queue_id,
'tx_bytes': stat.tx_bytes,
'tx_errors': stat.tx_errors,
'tx_packets': stat.tx_packets})
return wrap_dpid_dict(dp, s, to_user)
示例11: get_group_desc
def get_group_desc(dp, waiters):
type_convert = {dp.ofproto.OFPGT_ALL: 'ALL',
dp.ofproto.OFPGT_SELECT: 'SELECT',
dp.ofproto.OFPGT_INDIRECT: 'INDIRECT',
dp.ofproto.OFPGT_FF: 'FF'}
stats = dp.ofproto_parser.OFPGroupDescStatsRequest(dp, 0)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
descs = []
for msg in msgs:
for stats in msg.body:
buckets = []
for bucket in stats.buckets:
actions = []
for action in bucket.actions:
actions.append(action_to_str(action))
b = {'weight': bucket.weight,
'watch_port': bucket.watch_port,
'watch_group': bucket.watch_group,
'actions': actions}
buckets.append(b)
d = {'type': type_convert.get(stats.type),
'group_id': UTIL.ofp_group_to_user(stats.group_id),
'buckets': buckets}
descs.append(d)
return {str(dp.id): descs}
示例12: get_port_desc
def get_port_desc(dp, waiters, port_no=None, to_user=True):
if port_no is None:
port_no = dp.ofproto.OFPP_ANY
else:
port_no = UTIL.ofp_port_from_user(port_no)
stats = dp.ofproto_parser.OFPPortDescStatsRequest(dp, 0, port_no)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
descs = []
for msg in msgs:
stats = msg.body
for stat in stats:
d = stat.to_jsondict()[stat.__class__.__name__]
properties = []
for prop in stat.properties:
p = prop.to_jsondict()[prop.__class__.__name__]
if to_user:
t = UTIL.ofp_port_desc_prop_type_to_user(prop.type)
p['type'] = t if t != prop.type else 'UNKNOWN'
properties.append(p)
d['name'] = stat.name.decode('utf-8')
d['properties'] = properties
if to_user:
d['port_no'] = UTIL.ofp_port_to_user(stat.port_no)
descs.append(d)
return wrap_dpid_dict(dp, descs, to_user)
示例13: get_group_desc
def get_group_desc(dp, waiters, to_user=True):
stats = dp.ofproto_parser.OFPGroupDescStatsRequest(dp, 0)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
descs = []
for msg in msgs:
for stats in msg.body:
d = stats.to_jsondict()[stats.__class__.__name__]
buckets = []
for bucket in stats.buckets:
b = bucket.to_jsondict()[bucket.__class__.__name__]
actions = []
for action in bucket.actions:
if to_user:
actions.append(action_to_str(action))
else:
actions.append(action)
b['actions'] = actions
buckets.append(b)
d['buckets'] = buckets
if to_user:
d['group_id'] = UTIL.ofp_group_to_user(stats.group_id)
t = UTIL.ofp_group_type_to_user(stats.type)
d['type'] = t if t != stats.type else 'UNKNOWN'
descs.append(d)
return wrap_dpid_dict(dp, descs, to_user)
示例14: get_meter_stats
def get_meter_stats(dp, waiters, meter_id=None, to_user=True):
if meter_id is None:
meter_id = dp.ofproto.OFPM_ALL
else:
meter_id = UTIL.ofp_meter_from_user(meter_id)
stats = dp.ofproto_parser.OFPMeterStatsRequest(
dp, 0, meter_id)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
meters = []
for msg in msgs:
for stats in msg.body:
s = stats.to_jsondict()[stats.__class__.__name__]
bands = []
for band in stats.band_stats:
b = band.to_jsondict()[band.__class__.__name__]
bands.append(b)
s['band_stats'] = bands
if to_user:
s['meter_id'] = UTIL.ofp_meter_to_user(stats.meter_id)
meters.append(s)
return wrap_dpid_dict(dp, meters, to_user)
示例15: get_meter_config
def get_meter_config(dp, waiters, meter_id=None, to_user=True):
flags = {dp.ofproto.OFPMF_KBPS: 'KBPS',
dp.ofproto.OFPMF_PKTPS: 'PKTPS',
dp.ofproto.OFPMF_BURST: 'BURST',
dp.ofproto.OFPMF_STATS: 'STATS'}
band_type = {dp.ofproto.OFPMBT_DROP: 'DROP',
dp.ofproto.OFPMBT_DSCP_REMARK: 'DSCP_REMARK',
dp.ofproto.OFPMBT_EXPERIMENTER: 'EXPERIMENTER'}
if meter_id is None:
meter_id = dp.ofproto.OFPM_ALL
else:
meter_id = int(str(meter_id), 0)
stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(
dp, 0, meter_id)
msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
configs = []
for msg in msgs:
for config in msg.body:
bands = []
for band in config.bands:
b = {'rate': band.rate,
'burst_size': band.burst_size}
if to_user:
b['type'] = band_type.get(band.type, '')
else:
b['type'] = band.type
if band.type == dp.ofproto.OFPMBT_DSCP_REMARK:
b['prec_level'] = band.prec_level
elif band.type == dp.ofproto.OFPMBT_EXPERIMENTER:
b['experimenter'] = band.experimenter
bands.append(b)
c_flags = []
for k, v in sorted(flags.items()):
if k & config.flags:
if to_user:
c_flags.append(v)
else:
c_flags.append(k)
c = {'flags': c_flags,
'bands': bands}
if to_user:
c['meter_id'] = UTIL.ofp_meter_to_user(config.meter_id)
else:
c['meter_id'] = config.meter_id
configs.append(c)
return wrap_dpid_dict(dp, configs, to_user)