本文整理汇总了Python中ryu.topology.api.get_link函数的典型用法代码示例。如果您正苦于以下问题:Python get_link函数的具体用法?Python get_link怎么用?Python get_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_link函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _route
def _route(self, req, **kwargs):
srcdpid=dpid_lib.str_to_dpid(kwargs['srcdpid'])
srcport=port_no_lib.str_to_port_no(kwargs['srcport'])
dstdpid=dpid_lib.str_to_dpid(kwargs['dstdpid'])
dstport=port_no_lib.str_to_port_no(kwargs['dstport'])
links = get_link(self.topology_api_app, None)
topology = nx.MultiDiGraph()
for link in links:
print link
topology.add_edge(link.src.dpid, link.dst.dpid, src_port=link.src.port_no, dst_port=link.dst.port_no)
try:
shortest_path = nx.shortest_path(topology, srcdpid, dstdpid)
except (nx.NetworkXError, nx.NetworkXNoPath):
body = json.dumps([])
print "Error"
return Response(content_type='application/json', body=body)
ingressPort = NodePortTuple(srcdpid, srcport)
egressPort = NodePortTuple(dstdpid, dstport)
route = []
route.append(ingressPort)
for i in range(0, len(shortest_path)-1):
link = topology[shortest_path[i]][shortest_path[i+1]]
index = randrange(len(link))
dstPort = NodePortTuple(shortest_path[i], link[index]['src_port'])
srcPort = NodePortTuple(shortest_path[i+1], link[index]['dst_port'])
route.append(dstPort)
route.append(srcPort)
route.append(egressPort)
body = json.dumps([hop.to_dict() for hop in route])
return Response(content_type='application/json', body=body)
开发者ID:netgroup,项目名称:dreamer-ryu,代码行数:35,代码来源:rest_topology.py
示例2: get_topology_data
def get_topology_data(self,ev):
switch_list = get_switch(self.topology_api_app, None)
switches = [switch.dp.id for switch in switch_list]
links_list = get_link(self.topology_api_app, None)
links = [(link.src.dpid, link.dst.dpid, {'port':(link.src.hw_addr,link.dst.hw_addr)}) for link in links_list]
print len(switches)
print "total links",len(links)
开发者ID:cotyb,项目名称:enhancement-ryu,代码行数:7,代码来源:topo_learner.py
示例3: get_topology_data
def get_topology_data(self, ev):
self.logger.info("get_topology_data()")
self._update_switch_dpid_list()
switch_list = get_switch(self.topology_data_app, None)
switches = [switch.dp.id for switch in switch_list]
# print "switches: ", switches
self.net.add_nodes_from(switches)
# print "~~~~~ FRONT ~~~~~~~"
# print "switches:", [self._hostname_Check(s) for s in switches]
# print "self.link_port: ", self.link_port
# print "self.net.nodes():", self.net.nodes()
# print "self.net.edges():", self.net.edges()
# print "net nodes: ", self.net.nodes()
for node in self.net.nodes():
self.link_port.setdefault(node, {})
# with open(OFP_LINK_PORT, 'w') as outp:
# src_dpid dst_dpid src_dpid_output_port dst_dpid_input_port
links_list = get_link(self.topology_data_app, None)
# print "links_list: ", links_list
# add link from one direction
links = [(link.src.dpid, link.dst.dpid,
{'out_port': link.src.port_no}) for link in links_list]
# print "links:", links
self.net.add_edges_from(links)
for link in links:
# self.logger.info("%s %s %s\n" % (self._hostname_Check(link[0]),
# self._hostname_Check(link[1]), link[2]['out_port']))
# self.logger.info("%s %s %s\n" % (link[0], link[1], link[2]['out_port']))
# outp.write("%s %s %s\n" % (link[0], link[1], link[2]['out_port']))
self.link_port[link[0]][link[1]] = link[2]['out_port']
开发者ID:ShuaiZhao,项目名称:Ryu-SDN-Codes,代码行数:34,代码来源:my_switch_13_v10_topo_2.py
示例4: _packet_in_handler
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
in_port = msg.match['in_port']
dpid = datapath.id
ports = [int(link.to_dict()['src']['port_no'], 16)
for link in get_link(self, dpid)]
pkt = packet.Packet(msg.data)
eth = pkt.get_protocol(ethernet.ethernet)
src = eth.src
dst = eth.dst
time_now = time.time()
if in_port not in ports:
self.hosts[src] = {'dpid': dpid, 'time': time_now}
if eth.ethertype == 0x0806: # ARP packet
arp_p = pkt.get_protocol(arp.arp)
if arp_p.src_mac != '00:00:00:00:00:00':
self.arp[arp_p.src_mac] = {'dpid': dpid, 'ip': arp_p.src_ip,
'time': time_now}
if arp_p.dst_mac != '00:00:00:00:00:00':
self.arp[arp_p.dst_mac] = {'dpid': dpid, 'ip': arp_p.dst_ip,
'time': time_now}
elif eth.ethertype == 0x0800: # IPv4 packet
ip_p = pkt.get_protocol(ipv4.ipv4)
if ip_p.proto == 17:
udp_p = pkt.get_protocol(udp.udp)
if udp_p.dst_port == 67 and udp_p.src_port == 68: # DHCP
return
self.arp[src] = {'dpid': dpid, 'ip': ip_p.src, 'time': time_now}
self.arp[dst] = {'dpid': dpid, 'ip': ip_p.dst, 'time': time_now}
开发者ID:cubarco,项目名称:SDN-2015,代码行数:33,代码来源:rest_topology.py
示例5: get_topology_data
def get_topology_data(self, ev):
switch_list = get_switch(self.topology_api_app, None)
switches=[switch.dp.id for switch in switch_list]
self.net.add_nodes_from(switches)
#print "**********List of switches"
#for switch in switch_list:
#self.ls(switch)
#print switch
# self.nodes[self.no_of_nodes] = switch
# self.no_of_nodes += 1
links_list = get_link(self.topology_api_app, None)
#print links_list
#links=[(link.src.dpid,link.dst.dpid,port=link.src.port_no) for link in links_list]
#print links
#self.net.add_edges_from(links)
#links=[(link.dst.dpid,link.src.dpid,port=link.dst.port_no) for link in links_list]
#print links
#self.net.add_edges_from(links)
for link in links_list:
if (link.src.dpid,link.dst.dpid,link.src.port_no) not in list(self.net.edges_iter(data='port')):
self.net.add_edge(link.src.dpid,link.dst.dpid,port=link.src.port_no)
if (link.dst.dpid,link.src.dpid,link.dst.port_no) not in list(self.net.edges_iter(data='port')):
self.net.add_edge(link.dst.dpid,link.src.dpid,port=link.dst.port_no)
print "List of links"
print self.net.edges(data=True, keys=True)
开发者ID:nicolaskagami,项目名称:RedesTF,代码行数:27,代码来源:spSFCbak.py
示例6: _links
def _links(self, req, **kwargs):
dpid = None
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
links = get_link(self.topology_api_app, dpid)
body = json.dumps([link.to_dict() for link in links])
return Response(content_type='application/json', body=body)
开发者ID:zewei,项目名称:SDN101,代码行数:7,代码来源:rest_topology.py
示例7: get_topology_data
def get_topology_data(self):
if not self.topo_stable:
return
self.topo_stable = False
print 'get_topoloty_data'
self.switch_list = get_switch(self.topology_api_app, None)
self.mSwitches = [switch.dp.id for switch in self.switch_list] # switch.dp.id
self.mDataPaths = [switch.dp for switch in self.switch_list]
print type(self.mDataPaths[0])
self.links_list = get_link(self.topology_api_app, None)
self.links = [(1, link.src.dpid, link.dst.dpid, link.src.port_no, link.dst.port_no) for link in self.links_list]
self.links.sort()
# print 'links : ', self.links
print '\n\nlinks:'
for lk in self.links:
print 'switch ', lk[1], ', port ', lk[3], '--> switch ', lk[2], ', port', lk[4]
print 'switches : ', self.mSwitches
self.constructing_stp_krustal()
# Delete all flows in all datapaths
for dpid in self.mSwitches:
self.delete_flow(dpid)
# Install new flows
for block in self.ports_to_block:
if block in self.ports_to_enable:
continue
dpid = block[0]
port = block[1]
self.block_port(dpid, port)
# for enable in self.ports_to_enable:
# pass
self.start_learning = True
开发者ID:SDN-comments,项目名称:RyuApps,代码行数:32,代码来源:simple_spanning_tree_12.py
示例8: _switch_enter_handler
def _switch_enter_handler(self, ev):
# get_switch(self, None) outputs the list of switches object.
self.topo_switches = get_switch(self, None)
# get_link(self, None) outputs the list of links object.
self.topo_links = get_link(self, None)
"""
Now you have saved the links and switches of the topo. But they are object, we need to use to_dict() to trans them
"""
# print '*'*40,"Switch_set",'*'*40
for switch in self.topo_switches:
dp = switch.dp
dp_no = dpid_to_str(dp.id)
if (Switch_set.has_key(dp_no) == False):
ports = switch.ports
Switch_set[dp_no] = [port.to_dict() for port in ports]
# pprint.pprint(Switch_set)
Switch_set_json = json.dumps(Switch_set, indent=4)
Ssj_file = open('./Info/Static/Switch_json.json','w+')
Ssj_file.write(Switch_set_json)
Ssj_file.close()
# print '*'*40,"Link_set",'*'*40
Link_set = [ link.to_dict() for link in self.topo_links ]
# pprint.pprint(Link_set)
Link_set_json = json.dumps(Link_set, indent=4)
Lsj_file = open('./Info/Static/Link_json.json','w+')
Lsj_file.write(Link_set_json)
Lsj_file.close()
self.logger.info("******_switch_enter_handler, Switch_set & Link_set******")
开发者ID:xuan63,项目名称:TopoInfoLearner_Monitor,代码行数:30,代码来源:TopoInfoLearner.py
示例9: get_topology_data
def get_topology_data(self, ev):
switch_list = get_switch(self.topology_api_app, None)
switches=[switch.dp.id for switch in switch_list]
links_list = get_link(self.topology_api_app, None)
links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no}) for link in links_list]
print links
print switches
开发者ID:nicolaskagami,项目名称:RedesTF,代码行数:7,代码来源:shortest_path.py
示例10: get_topology_data
def get_topology_data(self, ev):
switch_list = get_switch(self.topology_data_app, None)
switches = [switch.dp.id for switch in switch_list]
self.net.add_nodes_from(switches)
with open(OFP_LINK_PORT, 'w') as outp:
# src_dpid dst_dpid src_dpid_output_port dst_dpid_input_port
links_list = get_link(self.topology_data_app, None)
# print links_list
# add link from one direction
links = [(self._hostname_Check(link.src.dpid), self._hostname_Check(link.dst.dpid),
{'out_port': link.src.port_no})
for link in links_list]
# print links
self.net.add_edges_from(links)
for link in links:
outp.write("%s %s %s\n" % (self._hostname_Check(link[0]),
self._hostname_Check(link[1]), link[2]['out_port']))
# add links from oppsite direction
links = [(link.dst.dpid, link.src.dpid,
{'out_port': link.dst.port_no}) for link in links_list]
# print links
self.net.add_edges_from(links)
for link in links:
outp.write("%s %s %s\n" % (self._hostname_Check(link[0]),
self._hostname_Check(link[1]), link[2]['out_port']))
开发者ID:ShuaiZhao,项目名称:Ryu-SDN-Codes,代码行数:28,代码来源:my_switch_13_v3.py
示例11: get_topology
def get_topology(self, ev):
switch_list = get_switch(self.topology_api_app, None)
self.create_port_map(switch_list)
self.switches = self.switch_port_table.keys()
links = get_link(self.topology_api_app, None)
self.create_inter_links(links)
self.create_access_ports()
self.get_graph(self.link_to_port.keys())
开发者ID:Jasonlyt,项目名称:ryu,代码行数:8,代码来源:shortest_switch.py
示例12: topology
def topology(self):
#TODO add the topology collecting periodically
self.edgenum=0
start = time.time()
print start
self.switches = get_switch(self)
self.links = get_link(self)
self.topo_col_num = self.topo_col_num + 1
end = time.time()
print end
print 'topology collecting time:'
print end-start
self.topo_col_period = self.topo_col_period + end-start
#n=len(self.switches)
#m=len(self.links)
## self.startnum=0
## self.dpids_to_nums={}
## self.nums_to_dpids={}
print 'dpids nums:'
for switch in self.switches:#TODO this may has error
if self.dpids_to_nums.get(switch.dp.id)==None:
self.nums_to_dpids[self.startnum] = switch.dp.id
self.dpids_to_nums[switch.dp.id] = self.startnum
print str(switch.dp.id)+' '+str(self.startnum)
self.startnum = self.startnum + 1
print self.dpids_to_nums
self.n=self.startnum
print 'edges:'
self.linkgraph=[]
for i in xrange(self.switch_num):
self.linkgraph.append([])
for j in xrange(self.switch_num):
self.linkgraph[i].append(0)
for link in self.links:
self.edgenum=self.edgenum+1
srcnum = self.dpids_to_nums[link.src.dpid]
dstnum = self.dpids_to_nums[link.dst.dpid]
self.linkgraph[srcnum][dstnum]=1
if self.graph[srcnum][dstnum]==0 and self.graph[dstnum][srcnum]==0:
print str(srcnum)+' '+str(dstnum)
self.dpid_to_port[(link.src.dpid, link.dst.dpid)] = (link.src.port_no, link.dst.port_no)
self.dpid_to_port[(link.dst.dpid, link.src.dpid)]=(link.dst.port_no, link.src.port_no)
#print>>devicegraph, str(srcnum)+' '+str(dstnum)
self.graph[srcnum][dstnum] = 1
self.graph[dstnum][srcnum] = 1
self.undirected[srcnum][dstnum] = 1
self.m=self.m+1
self.G={}
for i in xrange(self.switch_num):
self.G[i]={}
for j in xrange(self.switch_num):
if self.linkgraph[i][j]==1 and self.linkgraph[j][i]==1:#TODO if only one way is ok then regard it as not ok
self.G[i][j]=1
print self.G
print self.linkgraph
print self.graph
print self.undirected
开发者ID:shenerguang,项目名称:ryu,代码行数:58,代码来源:shortest8.py
示例13: get_topology_data
def get_topology_data(self, ev):
switch_list = get_switch(self.my_topology_api_app, None)
all_switches = [switch.dp.id for switch in switch_list]
# links_list = get_link(self.topology_api_app, None)
links_list = get_link(self.my_topology_api_app)
links = [(link.src.dpid, link.dst.dpid,
{'port': link.src.port_no}) for link in links_list]
print ">> switches: ", all_switches
print ">> links: ", links
开发者ID:ShuaiZhao,项目名称:Ryu-SDN-Codes,代码行数:9,代码来源:my_ryu_application.py
示例14: linkDeleteHandler
def linkDeleteHandler(self, ev):
link_list = get_link(self.topology_api_app, None)
self.debugfile.write("linkdelete events happened"+"\n")
self.debugfile.flush()
for link in link_list:
self.debugfile.write(str(link)+"\n")
self.debugfile.flush()
self.debugfile.write("the time is: "+str(time.time())+"\n")
self.debugfile.flush()
开发者ID:zhiqiangguo0727,项目名称:MPLS_Based_SFC_Deployment,代码行数:9,代码来源:network_aware.py
示例15: get_topology
def get_topology(self, ev):
print("HELLOOOOOO WORLD")
switch_list = copy.copy(get_switch(self, None))
links = copy.copy(get_link(self, None))
edges_list=[]
for link in links:
src = link.src
dst = link.src
edges_list.append((src.dpid, dst.dpid, {'port': link.src.port_no}))
print(links)
开发者ID:zimola,项目名称:sdn_a2,代码行数:10,代码来源:switch.py
示例16: _new_link_event
def _new_link_event(self, ev):
LOG.info('TOPO_EVENT: New link detected %s -> %s', ev.link.src.dpid, ev.link.dst.dpid)
link_list = get_link(self.topology_api_app, None)
links = [(link.src.dpid, link.dst.dpid, {'port':link.src.port_no, 'weight':self.DEF_EDGE_WEIGHT}) for link in link_list]
self.net.add_edges_from(links)
print '****List of links:'
print links
开发者ID:enriDev,项目名称:trusted-sdn,代码行数:10,代码来源:trust_based_forwarder.py
示例17: get_topology
def get_topology(self, ev):
switch_list = get_switch(self.topology_api_app, None)
self.create_port_map(switch_list)
self.switches = self.switch_port_table.keys()
links = get_link(self.topology_api_app, None)
self.create_interior_links(links)
self.create_access_ports()
self.get_graph(self.link_to_port.keys())
self.shortest_paths = self.all_k_shortest_paths(
self.graph, weight='weight', k=CONF.k_paths)
开发者ID:neuzhangxu,项目名称:ryu,代码行数:10,代码来源:network_awareness.py
示例18: get_topology_data
def get_topology_data(self, ev):
switch_list = get_switch(self.topology_api_app, None)
switches = [switch.dp.id for switch in switch_list]
link_list = get_link(self.topology_api_app, None)
self.net.add_nodes_from(switches)
links=[(link.src.dpid,link.dst.dpid,
{'port':link.src.port_no}) for link in links_list]
self.ned_add_edges_from(links)
self.logger.info('******************************** List of links')
self.logger.info(self.net.edges())
开发者ID:revolverXD,项目名称:ospf_git,代码行数:10,代码来源:OSPF_switch_v2.py
示例19: get_topology_data
def get_topology_data(self, ev):
print "Beep!"
switch_list = get_switch(self.topology_api_app, None)
switches = [switch.dp.id for switch in switch_list]
links_list = get_link(self.topology_api_app, None)
links = [(link.src.dpid, link.dst.dpid, {'port': link.src.port_no}) for link in links_list]
# host_list = get_host(self.topology_api_app, None)
# hosts = [host.dp.id for host in host_list]
# print i
print switches
print links
开发者ID:nguyenngocduy20,项目名称:vlan-ryu,代码行数:11,代码来源:vlan_lui.py
示例20: get_topology_data
def get_topology_data(self, ev):
switch_list = get_switch(self.topology_api_app, None)
self.switches=[switch.dp.id for switch in switch_list]
print '************Switch List*********************'
# print self.switches
links_list = get_link(self.topology_api_app, None)
self.links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no}) for link in links_list]
self.switches_nodes=[switch.dp for switch in switch_list]
self.net.add_nodes_from(self.switches)
self.net.add_edges_from(self.links)
开发者ID:yaphone,项目名称:ryu_topo,代码行数:11,代码来源:load_balance.py
注:本文中的ryu.topology.api.get_link函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论