本文整理汇总了Python中ryu.topology.api.get_switch函数的典型用法代码示例。如果您正苦于以下问题:Python get_switch函数的具体用法?Python get_switch怎么用?Python get_switch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_switch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _alert_to_block
def _alert_to_block(self, ev):
msg = ev.msg
# Get all dpid from switches
sw_dpid = [s.dp.id for s in get_switch(self.topology_api_app, None)]
# Get datapath by dpid
datapath = ryu.app.ofctl.api.get_datapath(self.topology_api_app,
sw_dpid[0])
# Use datapath to do OFPFlowMod DROP action here
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
pkt = packet.Packet(array.array('B', msg.pkt))
_ipv4 = pkt.get_protocol(ipv4.ipv4)
_tcp = pkt.get_protocol(tcp.tcp)
if _ipv4:
c_and_c_IP = _ipv4.src
c_and_c_port = _tcp.src_port
print ("C&C Server: ", c_and_c_IP, c_and_c_port)
print ("Victim: ", _ipv4.dst, _tcp.dst_port)
match_malicious = parser.OFPMatch(eth_type=ether.ETH_TYPE_IP,
ip_proto=inet.IPPROTO_TCP,
ipv4_src=c_and_c_IP,
tcp_src=c_and_c_port)
actions_drop = []
self.add_flow(datapath, 0, 100, match_malicious, actions_drop)
print "Block C&C Server at %s:%d" % (_ipv4.src, _tcp.src_port)
开发者ID:hsnl-dev,项目名称:vcpe-hub,代码行数:32,代码来源:smart_tap.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.port_no}) for link in links_list]
print links
print switches
开发者ID:nicolaskagami,项目名称:RedesTF,代码行数:7,代码来源:shortest_path.py
示例3: 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
示例4: get_datapath
def get_datapath(self, dpid):
if dpid not in self.dps:
switch = topo_api.get_switch(self, dpid)[0]
self.dps[dpid] = switch.dp
return switch.dp
return self.dps[dpid]
开发者ID:wuyouke,项目名称:Ryu-SDN-IP,代码行数:7,代码来源:fwd.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]
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
示例6: 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
示例7: addflowsql
def addflowsql(self, dst, dpid, in_port, out_port, flag):
print 'add flow sql !!!!!!!!!!!!!!!!!!!!!!!!!!!'
print dpid,in_port,out_port
data_path=get_switch(self,dpid)#TODO test
print type(data_path)
print '!!!!!!!!!!!!!!!!!!!'
print data_path
datapath=data_path[0].dp#TODO test
print 'datapath = '
print datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
print 'dst = '+str(dst)
print 'dpid = '+str(dpid)
print 'in_port = '+str(in_port)
print 'out port = '+str(out_port)
actions=[parser.OFPActionOutput(out_port)]
match=parser.OFPMatch(in_port=in_port,eth_dst=dst)
f='ff:ff:ff:ff:ff:ff'
if 1==flag:
self.delete_flow(datapath, match)#TODO test delete flow!!
#TODO delete the ff:ff:ff:ff:ff:ff flow
matchf=parser.OFPMatch(in_port=in_port,eth_dst=f)
self.delete_flow(datapath, matchf)
print '!!!!!!!!!!!!!!!!!!add flow!!!!!!!!!!!!!!!!!!!!in_port='+str(in_port)+' dst='+str(dst)+' out_port='+str(out_port)+' dpid='+str(dpid)
self.add_flow(datapath, 1, match, actions)
开发者ID:shenerguang,项目名称:ryu,代码行数:26,代码来源:shortest8.py
示例8: 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
示例9: _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
示例10: add_block_rule
def add_block_rule(self, rule_action, src_ip, dst_ip, trans_proto, port):
switch_list = get_switch(self.topology_api_app, None)
for switch in switch_list:
datapath = switch.dp
parser = datapath.ofproto_parser
actions = [] # drop
# initial match field
match_dict = {'eth_type': ether.ETH_TYPE_IP}
# fill into the layer3 and layer 4 protocol
# if port == 0, means block all protocol
if port >= 0:
if trans_proto == inet.IPPROTO_TCP:
match_dict.update({'ip_proto': trans_proto,
'tcp_dst': port})
else: # udp
match_dict.update({'ip_proto': trans_proto,
'udp_dst': port})
if len(src_ip) > 0: # not ''
match_dict.update({'ipv4_src': src_ip})
if len(dst_ip) > 0: # not ''
match_dict.update({'ipv4_dst': dst_ip})
match = parser.OFPMatch(**match_dict)
fw_priority = settings.firewall_priority
if rule_action == 'add':
self.add_flow(datapath, fw_priority, match, actions)
elif rule_action == 'delete': # 'off'
self.del_flow(datapath, match)
self._request_stats(datapath) # update flow list in data.py
开发者ID:hsnl-dev,项目名称:vcpe-hub,代码行数:34,代码来源:simple_firewall.py
示例11: 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
示例12: _handler_port_add
def _handler_port_add(self, ev):
"""
Overwrite the legacy Ryu Event.
"""
try:
switch = self.switches[ev.port.dpid]
if self._check_if_ap_port(ev.port):
ap_conf = self._get_ap_conf(switch, ev.port)
switch.is_ap = True
switch.ap_conf = ap_conf
self.accesspoints[ev.port.dpid] = switch
elif self._check_if_gw_port(ev.port):
gw_conf = self._get_gw_conf(switch, ev.port)
switch.is_gw = True
switch.gw_conf = gw_conf
self.gateways[ev.port.dpid] = switch
switch.switch = get_switch(self, ev.port.dpid)[0]
ev_tu = EventSwitchUpdate(switch)
self.send_event_to_observers(ev_tu)
self.logger.info("Port add: " + str(ev.port))
except KeyError:
pass
开发者ID:AsmaSwapna,项目名称:openflow-dmm,代码行数:25,代码来源:nmm.py
示例13: get_topology_for_swadd
def get_topology_for_swadd(self, ev):
"""Switch add."""
print "EventSwitchEnter"
self.get_topology_data()
if constant.Capacity > 0:
switch_list = get_switch(self.topology_api_app, None)
rate_setup.init_meter_setup(constant.Capacity, switch_list)
开发者ID:hsnl-dev,项目名称:vcpe-hub,代码行数:7,代码来源:initial.py
示例14: add_mirror_rule
def add_mirror_rule(self, rule_action, mirror_port, host_port):
switch_list = get_switch(self.topology_api_app, None)
for switch in switch_list:
datapath = switch.dp
parser = datapath.ofproto_parser
if rule_action == 'add':
#add mirror flow by host port
for i in range(len(mirror_data.mirror_table)):
if host_port == mirror_data.mirror_table[i]['out_port']:
match_del = parser.OFPMatch(eth_dst=mirror_data.mirror_table[i]['dst'])
self.del_flow(datapath, match_del, mirror_data.mirror_table[i]['priority'])
mirror_data.mirror_table[i]['mirror_port'] = mirror_port
mirror_data.mirror_table[i]['priority'] = 100
match_add = parser.OFPMatch(eth_dst=mirror_data.mirror_table[i]['dst'])
actions = [parser.OFPActionOutput(mirror_data.mirror_table[i]['out_port']), parser.OFPActionOutput(mirror_data.mirror_table[i]['mirror_port'])]
self.add_flow(datapath, mirror_data.mirror_table[i]['priority'], match_add, actions) #refresh mirror get higher priority
print mirror_data.mirror_table
elif rule_action == 'delete':
for i in range(len(mirror_data.mirror_table)):
if host_port == mirror_data.mirror_table[i]['out_port']:
match_del = parser.OFPMatch(eth_dst=mirror_data.mirror_table[i]['dst'])
self.del_flow(datapath, match_del, mirror_data.mirror_table[i]['priority'])
mirror_data.mirror_table[i]['mirror_port'] = mirror_data.default_mirror_port
mirror_data.mirror_table[i]['priority'] = 1
match_add = parser.OFPMatch(eth_dst=mirror_data.mirror_table[i]['dst'])
actions = [parser.OFPActionOutput(mirror_data.mirror_table[i]['out_port']), parser.OFPActionOutput(mirror_data.mirror_table[i]['mirror_port'])]
self.add_flow(datapath, mirror_data.mirror_table[i]['priority'], match_add, actions) #refresh mirror get higher priority
self._request_stats(datapath) # update flow list in data.py
开发者ID:hsnl-dev,项目名称:vcpe-hub,代码行数:31,代码来源:simple_mirror.py
示例15: _switches
def _switches(self, req, **kwargs):
dpid = None
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
switches = get_switch(self.topology_api_app, dpid)
body = json.dumps([switch.to_dict() for switch in switches])
return Response(content_type='application/json', body=body)
开发者ID:zewei,项目名称:SDN101,代码行数:7,代码来源:rest_topology.py
示例16: 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
示例17: remove_flow
def remove_flow(self, identifier):
print "Removing Flow: ", identifier
for f in SFC_flows.keys():
if SFC_flows[f] == identifier:
del SFC_flows[f]
switch_list = get_switch(self.topology_api_app, None)
for switch in switch_list:
self.remove_flow_rule(switch.dp,identifier)
开发者ID:nicolaskagami,项目名称:RedesTF,代码行数:8,代码来源:sp2.py
示例18: 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
示例19: 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
示例20: get_switches
def get_switches(self):
switches = []
for switch in get_switch(self, None):
if switch.dp.id in self.LSwitches:
switches.append(switch)
return switches
开发者ID:5g-empower,项目名称:empower-ryu,代码行数:9,代码来源:intent.py
注:本文中的ryu.topology.api.get_switch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论