本文整理汇总了Python中ryu.lib.dpid.dpid_to_str函数的典型用法代码示例。如果您正苦于以下问题:Python dpid_to_str函数的具体用法?Python dpid_to_str怎么用?Python dpid_to_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dpid_to_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
super(OfTester, self).__init__()
self._set_logger()
self.target_dpid = self._convert_dpid(CONF['test-switch']['target'])
self.tester_dpid = self._convert_dpid(CONF['test-switch']['tester'])
self.logger.info('target_dpid=%s',
dpid_lib.dpid_to_str(self.target_dpid))
self.logger.info('tester_dpid=%s',
dpid_lib.dpid_to_str(self.tester_dpid))
test_dir = CONF['test-switch']['dir']
self.logger.info('Test files directory = %s', test_dir)
self.target_sw = OpenFlowSw(DummyDatapath(), self.logger)
self.tester_sw = OpenFlowSw(DummyDatapath(), self.logger)
self.state = STATE_INIT_FLOW
self.sw_waiter = None
self.waiter = None
self.send_msg_xids = []
self.rcv_msgs = []
self.ingress_event = None
self.ingress_threads = []
self.thread_msg = None
self.test_thread = hub.spawn(
self._test_sequential_execute, test_dir)
示例2: switch_desc_handler
def switch_desc_handler(self, ev):
switch_str = ""
stats = ev.msg.body
dp_desc = stats.dp_desc
hw_desc = stats.hw_desc
mfr_desc = stats.mfr_desc
serial_num = stats.serial_num
sw_desc = stats.sw_desc
switch_str = "\n\n==========================================\n"
switch_str += " Switch Description: \n"
switch_str += "==========================================\n"
switch_str += "* Manufacturer description: \t" + mfr_desc + "\n"
switch_str += "* Hardware description: \t" + hw_desc + "\n"
switch_str += "* Software description: \t" + sw_desc + "\n"
switch_str += "* Serial number: \t" + serial_num + "\n"
switch_str += "* Datapath description: \t" + dp_desc + "\n"
switch_str += "==========================================\n\n"
# Save
fd = open("./results/switch_" + dpidlib.dpid_to_str(ev.msg.datapath.id) + "_v10_extra.txt", 'a+')
fd.write(switch_str)
fd.close()
# Combined
self.combined_str += (switch_str)
# Last handle.. So save combined string
fd = open("./results/switch_" + dpidlib.dpid_to_str(ev.msg.datapath.id) + "_v10_combined.txt", 'a+')
fd.write(self.combined_str)
fd.close()
示例3: __str__
def __str__(self):
return "EventTunnelPort<dpid %s port_no %d remote_dpid %s " "add_del %s>" % (
dpid_lib.dpid_to_str(self.dpid),
self.port_no,
dpid_lib.dpid_to_str(self.remote_dpid),
self.add_del,
)
示例4: packet_in_handler
def packet_in_handler(self, ev):
self.logger.debug('packet_in_handler')
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
# TODO: subscribe only the designated datapath
dpid = datapath.id
if dpid != self.interface.dpid:
self.logger.debug('packet_in_handler dpid %s %s',
dpid_lib.dpid_to_str(dpid),
dpid_lib.dpid_to_str(self.interface.dpid))
return
in_port = None
for field in msg.match.fields:
if field.header == ofproto.OXM_OF_IN_PORT:
in_port = field.value
break
if in_port != self.interface.port_no:
self.logger.debug('packet_in_handler in_port %s %s',
in_port, self.interface.port_no)
return
self._send_vrrp_packet_received(msg.data)
示例5: to_dict
def to_dict(self):
return {'dpid': dpid_to_str(self.dp.id),
'name': self.name,
'neighbors': [dpid_to_str(switch.dp.id) for switch in self.neighbors],
'ports': [port.to_dict() for (port_no, port) in self.ports.items()],
'arp_table': self.get_arp_list(),
'routing_table': self.get_routing_table()}
示例6: _hosts
def _hosts(self, req, **kwargs):
body = None
db = database(DB_PATH)
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
rcd_dpid = selectDPID(dpid=dpid)
host_of_dpid = []
tmp = {'mac':'a', 'port':0,'ip':'a', 'slave':1}
for x in rcd_dpid:
tmp['mac'], tmp['port'], tmp['ip'], tmp['slave'] = x[0].encode('utf-8'), x[1], x[2].encode('utf-8'), x[3]
hosts_of_dpid.append(dict(tmp))
body = json.dumps(hosts_of_dpid)
else:
rcd_dev = db.selectDEVICE()
hosts = []
tmp = {'user_id':0, 'dpid':0,'mac':'a', 'vlan':0, 'ip': 'a', 'port':0}
#add gateway
tmp['mac'] = db.selectGATEWAY()[0][0].encode('utf-8')
tmp['ip'] = db.selectGATEWAY()[0][1].encode('utf-8')
gw_dpid = db.getDPIDBySlave(mac_addr=tmp['mac'])
if None != gw_dpid:
tmp['port'] = db.findDPIDByX(gw_dpid,'MAC_ADDR',tmp['mac'])[0][0]
tmp['dpid'] = dpid_lib.dpid_to_str(gw_dpid)
hosts.append(dict(tmp))
#add host
for dev in rcd_dev:
tmp['mac'], tmp['vlan'], tmp['user_id'] = dev[0].encode('utf-8'), dev[1], dev[2]
dpid = db.getDPIDBySlave(mac_addr=tmp['mac'])
tmp['dpid'] = dpid_lib.dpid_to_str(dpid)
rcd_host = db.findDPIDByX(dpid,'MAC_ADDR',tmp['mac'])
tmp['port'], tmp['ip'] = rcd_host[0][0], rcd_host[0][1].encode('utf-8')
hosts.append(dict(tmp))
body = json.dumps(hosts)
return Response(content_type='application/json', body=body)
示例7: port_status_handler
def port_status_handler(self, ev):
msg = ev.msg
reason = msg.reason
datapath = msg.datapath
port = msg.desc
ofproto = datapath.ofproto
if reason == ofproto.OFPPR_ADD:
LOG.debug('DPSET: A port was added.' +
'(datapath id = %s, port number = %s)',
dpid_to_str(datapath.id), port.port_no)
self._port_added(datapath, port)
self.send_event_to_observers(EventPortAdd(datapath, port))
elif reason == ofproto.OFPPR_DELETE:
LOG.debug('DPSET: A port was deleted.' +
'(datapath id = %s, port number = %s)',
dpid_to_str(datapath.id), port.port_no)
self._port_deleted(datapath, port)
self.send_event_to_observers(EventPortDelete(datapath, port))
else:
assert reason == ofproto.OFPPR_MODIFY
LOG.debug('DPSET: A port was modified.' +
'(datapath id = %s, port number = %s)',
dpid_to_str(datapath.id), port.port_no)
self.port_state[datapath.id].modify(port.port_no, port)
self.send_event_to_observers(EventPortModify(datapath, port))
示例8: _setup_data_fwd_flows
def _setup_data_fwd_flows(self, src_mac, dst_mac):
"""
Given two MAC addresses, set up flows on their connected switches
towards each other, so that they can forward packets between each other
"""
(src_dpid, src_port) = (self.inception.
mac_to_dpid_port[src_mac])
(dst_dpid, dst_port) = (self.inception.
mac_to_dpid_port[dst_mac])
# If src_dpid == dst_dpid, no need to set up flows
if src_dpid == dst_dpid:
return
src_ip = self.inception.dpid_to_ip[src_dpid]
dst_ip = self.inception.dpid_to_ip[dst_dpid]
src_fwd_port = self.inception.dpid_to_conns[src_dpid][dst_ip]
dst_fwd_port = self.inception.dpid_to_conns[dst_dpid][src_ip]
src_datapath = self.inception.dpset.get(src_dpid)
dst_datapath = self.inception.dpset.get(dst_dpid)
src_ofproto = src_datapath.ofproto
dst_ofproto = dst_datapath.ofproto
src_ofproto_parser = src_datapath.ofproto_parser
dst_ofproto_parser = dst_datapath.ofproto_parser
if (src_dpid, dst_mac) not in self.inception.unicast_rules:
actions_fwd = [src_ofproto_parser.OFPActionOutput(src_fwd_port)]
instructions_fwd = [src_datapath.ofproto_parser.
OFPInstructionActions(
src_ofproto.OFPIT_APPLY_ACTIONS, actions_fwd)]
src_datapath.send_msg(src_ofproto_parser.OFPFlowMod(
datapath=src_datapath,
match=src_ofproto_parser.OFPMatch(eth_dst=dst_mac),
cookie=0, command=src_ofproto.OFPFC_ADD,
priority=priority.DATA_FWD,
flags=src_ofproto.OFPFF_SEND_FLOW_REM,
instructions=instructions_fwd
))
self.inception.unicast_rules.append((src_dpid, dst_mac))
LOGGER.info("Setup forward flow on switch=%s"
"towards mac=%s", dpid_to_str(src_dpid), dst_mac)
if (dst_dpid, src_mac) not in self.inception.unicast_rules:
actions_dst = [dst_ofproto_parser.OFPActionOutput(dst_fwd_port)]
instructions_dst = [dst_datapath.ofproto_parser.
OFPInstructionActions(
dst_ofproto.OFPIT_APPLY_ACTIONS, actions_dst)]
dst_datapath.send_msg(dst_ofproto_parser.OFPFlowMod(
datapath=dst_datapath,
match=dst_ofproto_parser.OFPMatch(eth_dst=src_mac),
cookie=0, command=dst_ofproto.OFPFC_ADD,
priority=priority.DATA_FWD,
flags=dst_ofproto.OFPFF_SEND_FLOW_REM,
instructions=instructions_dst
))
self.inception.unicast_rules.append((dst_dpid, src_mac))
LOGGER.info("Setup forward flow on switch=%s"
"towards mac=%s", dpid_to_str(dst_dpid), src_mac)
示例9: _do_lacp
def _do_lacp(self, req_lacp, src, msg):
"""packet-in process when the received packet is LACP."""
datapath = msg.datapath
dpid = datapath.id
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
if ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
port = msg.in_port
else:
port = msg.match['in_port']
self.logger.info("SW=%s PORT=%d LACP received.",
dpid_to_str(dpid), port)
self.logger.debug(str(req_lacp))
# when LACP arrived at disabled port, update the status of
# the slave i/f to enabled, and send a event.
if not self._get_slave_enabled(dpid, port):
self.logger.info(
"SW=%s PORT=%d the slave i/f has just been up.",
dpid_to_str(dpid), port)
self._set_slave_enabled(dpid, port, True)
self.send_event_to_observers(
EventSlaveStateChanged(datapath, port, True))
# set the idle_timeout time using the actor state of the
# received packet.
if req_lacp.LACP_STATE_SHORT_TIMEOUT == \
req_lacp.actor_state_timeout:
idle_timeout = req_lacp.SHORT_TIMEOUT_TIME
else:
idle_timeout = req_lacp.LONG_TIMEOUT_TIME
# when the timeout time has changed, update the timeout time of
# the slave i/f and re-enter a flow entry for the packet from
# the slave i/f with idle_timeout.
if idle_timeout != self._get_slave_timeout(dpid, port):
self.logger.info(
"SW=%s PORT=%d the timeout time has changed.",
dpid_to_str(dpid), port)
self._set_slave_timeout(dpid, port, idle_timeout)
func = self._add_flow.get(ofproto.OFP_VERSION)
assert func
func(src, port, idle_timeout, datapath)
# create a response packet.
res_pkt = self._create_response(datapath, port, req_lacp)
# packet-out the response packet.
out_port = ofproto.OFPP_IN_PORT
actions = [parser.OFPActionOutput(out_port)]
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=ofproto.OFP_NO_BUFFER,
data=res_pkt.data, in_port=port, actions=actions)
datapath.send_msg(out)
示例10: create_switch_to_switch_links
def create_switch_to_switch_links(self):
for link in self.links:
src_port = link.src.port_no
dst_port = link.dst.port_no
src_dpid = format_dpid_str(dpid_to_str(link.src.dpid))
dst_dpid = format_dpid_str(dpid_to_str(link.dst.dpid))
src_port_id = src_dpid + str(src_port)
dst_port_id = dst_dpid + str(dst_port)
src_port_vertex = self.get_unique_port_vertex(src_port_id)
dst_port_vertex = self.get_unique_port_vertex(dst_port_id)
self.create_link_edge(src_port_vertex,dst_port_vertex)
示例11: _get_bridge_name
def _get_bridge_name(self):
""" get Bridge name of a given 'datapath_id' """
command = ovs_vsctl.VSCtlCommand(
'find',
('Bridge',
'datapath_id=%s' % dpid_lib.dpid_to_str(self.datapath_id)))
self.run_command([command])
if not isinstance(command.result, list) or len(command.result) != 1:
raise OVSBridgeNotFound(
datapath_id=dpid_lib.dpid_to_str(self.datapath_id))
return command.result[0].name
示例12: _get_bridge_name
def _get_bridge_name(self):
""" get Bridge name of a given 'datapath_id' """
command = ovs_vsctl.VSCtlCommand(
'find',
('Bridge',
'datapath_id=%s' % dpid_lib.dpid_to_str(self.datapath_id)))
self.run_command([command])
result = command.result
if len(result) == 0 or len(result) > 1:
raise OVSBridgeNotFound(
datapath_id=dpid_lib.dpid_to_str(self.datapath_id))
return result[0].name
示例13: unregist_ofs
def unregist_ofs(dp):
if dp.id in FirewallController._OFS_LIST:
del FirewallController._OFS_LIST[dp.id]
dpid_str = dpid_lib.dpid_to_str(dp.id)
try:
http_request_test(dpid_str, 'leave')
except:
print "DrawBridge controller is not enabled"
#http_request_test(dpid_str, 'leave')
# again, make a POST request to the DrawBridge controller.
FirewallController._LOGGER.info('dpid=%s: Leave firewall.',
dpid_lib.dpid_to_str(dp.id))
示例14: table_features_handler
def table_features_handler(self, ev):
feature_str = ""
prop_str = ""
## Fields
print ev.msg.datapath
table_list = ev.msg.body
for t in table_list:
table_id = t.table_id
name = t.name
metadata_match = t.metadata_match
metadata_write = t.metadata_write
# config = t.config ## Bitmap that is provided for backward compability in OF.
max_entries = t.max_entries
properties = t.properties
#
feature_str = "\n\n==========================================\n"
feature_str += " Table Feature: " + str(table_id) + "\n"
feature_str += "==========================================\n"
feature_str += (
"Table Id: "
+ str(table_id)
+ "\n"
+ "Name: "
+ str(name)
+ "\n"
+ "Metadata_match: "
+ str(hex(metadata_match))
+ "\n"
+ "Metadata_write: "
+ str(hex(metadata_write))
+ "\n"
+ "Max entries: "
+ str(max_entries)
+ "\n"
)
prop_str = self.property_parser(properties)
# Save
fd = open("./results/switch_" + dpidlib.dpid_to_str(ev.msg.datapath.id) + "_v13_table.txt", "a+")
fd.write(feature_str + prop_str)
fd.close()
# Combined
# self.combined_str += (feature_str + prop_str)
self.combined_str_map[dpidlib.dpid_to_str(ev.msg.datapath.id)] += feature_str + prop_str
示例15: port_stats_reply_handler
def port_stats_reply_handler(self, ev):
dpid = dpidlib.dpid_to_str(ev.msg.datapath.id)
if self.looped[dpid] is True:
# Last handle.. So save combined string
fd = open("./results/switch_" + dpidlib.dpid_to_str(ev.msg.datapath.id) + "_v13_combined.txt", "a+")
fd.write(self.combined_str_map[dpidlib.dpid_to_str(ev.msg.datapath.id)])
fd.close()
return
ports = []
port_num_list = []
for stat in ev.msg.body:
ports.append(
"port_no=%d "
"rx_packets=%d tx_packets=%d "
"rx_bytes=%d tx_bytes=%d "
"rx_dropped=%d tx_dropped=%d "
"rx_errors=%d tx_errors=%d "
"rx_frame_err=%d rx_over_err=%d rx_crc_err=%d "
"collisions=%d duration_sec=%d duration_nsec=%d"
% (
stat.port_no,
stat.rx_packets,
stat.tx_packets,
stat.rx_bytes,
stat.tx_bytes,
stat.rx_dropped,
stat.tx_dropped,
stat.rx_errors,
stat.tx_errors,
stat.rx_frame_err,
stat.rx_over_err,
stat.rx_crc_err,
stat.collisions,
stat.duration_sec,
stat.duration_nsec,
)
)
# print stat.port_no
port_num_list.append(stat.port_no)
# Add to Overview
fd = open("./results/switch_" + dpid + "_v13_overview.txt", "a")
fd.write("\n\n" + "Port number list (shown to controller): " + str(port_num_list) + "\n")
fd.close()
# Add to combined
self.combined_str_map[dpid] += "\n\n" + "Port number list (shown to controller): " + str(port_num_list) + "\n"
self.looped[dpid] = True