# idle and hardtimeout set to 0,making the entry permanent # reference openflow spec mod = datapath.ofproto_parser.OFPFlowMod( datapath=datapath, match=match, idle_timeout=0, hard_timeout=0, priority=32768, instructions=inst ) datapath.send_msg(mod)
def__init__(self): self.URL='http://localhost:8080' self.dpid=[] defgetall_sw(self): url=self.URL+'/stats/switches' data = requests.get(url) if data.status_code == 200: data_all = data.json() print(data_all) for i in data_all: self.dpid.append(i)
defgetall_sw_data(self): for i in self.dpid: url=self.URL+'/stats/flow/'+str(i) data = requests.get(url) if data.status_code == 200: data_all = data.json()[str(i)] action=data_all[0]['actions'] packet_count=data_all[3]['packet_count'] priority=data_all[6]['priority'] byte_count=data_all[8]['byte_count'] print("交换机{}的action模式为{}\n"\ "流过的包为{}\n"\ "流过的字节为{}\n"\ "优先级为{}\n".format(i,action,packet_count,byte_count,priority))
# ipv6 广播报文目的Mac开头都是33:33“ if'33:33'in dst_mac[:5]: # the controller has not flooded this packet before if (src_mac,dst_mac) notin self.flood_history[dpid]: # we remember this packet self.flood_history[dpid].append((src_mac,dst_mac)) else: # the controller have flooded this packet before,we do nothing and return return
def__init__(self): self.URL='http://localhost:8080' self.dpid=[] defgetall_sw(self): url=self.URL+'/stats/switches' data = requests.get(url) if data.status_code == 200: data_all = data.json() print(data_all) for i in data_all: self.dpid.append(i)
defgetall_sw_data(self): for i in self.dpid: url=self.URL+'/stats/flow/'+str(i) data = requests.get(url) if data.status_code == 200: data_all = data.json()[str(i)] action=data_all[0]['actions'] packet_count=data_all[3]['packet_count'] priority=data_all[6]['priority'] byte_count=data_all[8]['byte_count']
defget_flow(self): for i in self.dpid: url=self.URL+'/stats/flow'+str(i) data=requests.get(url) if data.status_code==200: data_all=data.json()[str(i)][0] match=data_all['match'] actions=data_all['actions'] print('流{}的匹配表为{},动作为{}'.format(i,match,actions))
if __name__ == "__main__": ryu=ryu_restful() ryu.getall_sw() ryu.getall_sw_data() ryu.get_flow()