def br_dump(bridge): """ Dump the port information of a given bridges. """ flows = br_getflows(bridge) debug('br_dump: len flows=%u\n' % len(flows)) if flows: Flow.banner_output() for f in flows: f.fmt_output()
def br_dump(bridge_name): """ Dump the port information of a given bridges. """ flows = ovs_lib.OVSBridge(bridge_name).dump_flows() debug('br_dump: len flows=%u\n' % len(flows)) if flows: Flow.banner_output() for f in flows: f.fmt_output()
def dump_flows(self): """ Dump out the flows of this bridge :return: """ self.load_flows() debug('br_dump: len flows=%u\n' % len(self.flows)) table = 0 if self.flows: Flow.banner_output() for f in self.flows: if f.table != table: output('\n') table = f.table f.fmt_output()
def del_flow(self, flow_ids): """ Return True or False to del a flow from given list. """ if len(flow_ids) <= 0: return False if not self.flows: self.load_flows() del_flows = [] fd = sys.stdin.fileno() old = termios.tcgetattr(fd) for flow_id in flow_ids: if isinstance(flow_id, str) and flow_id.isdigit(): flow_id = int(flow_id) else: continue if flow_id >= len(self.flows): continue else: del_flow = self.flows[flow_id] Flow.banner_output() del_flow.fmt_output() output('Del the flow? [Y/n]: ') new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ICANON try: termios.tcsetattr(fd, termios.TCSADRAIN, new) while True: in_ch = sys.stdin.read(1) if in_ch == 'n' or in_ch == 'N': output('\tCancel the deletion.\n') break elif in_ch == 'y' or in_ch == 'Y' or in_ch != '\n': del_flows.append(del_flow) output('\n') break else: output('\nWrong, please input [Y/n]: ') continue finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) if not del_flows: return False self.load_flows(True) flows_db_new = self.flows_db + '.new' f, f_new = open(self.flows_db, 'r'), open(flows_db_new, 'w') while True: lines = f.readlines(1000) if not lines: break for line in lines: flow = self.parse_flow(line) if flow not in del_flows: f_new.write('%s' % line) else: debug("Del the flow:\n") #del_flow.fmt_output() f.close() f_new.close() replace_cmd = "ovs-ofctl replace-flows %s %s" % (self.bridge, flows_db_new) error = Popen(replace_cmd, stdout=PIPE, stderr=PIPE, shell=True).communicate()[1] if error: output(error) return False else: self.load_flows() return True
def del_flow(self, flow_ids, forced=False): """ Return True or False to del a flow from given list. """ if len(flow_ids) <= 0: return False if not self.flows: self.load_flows() del_flows = [] fd = sys.stdin.fileno() old = termios.tcgetattr(fd) for flow_id in flow_ids: if isinstance(flow_id, str) and flow_id.isdigit(): flow_id = int(flow_id) else: continue if flow_id >= len(self.flows): continue else: del_flow = self.flows[flow_id] if forced: del_flows.append(del_flow) else: Flow.banner_output() del_flow.fmt_output() output('Del the flow? [Y/n]: ') new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ICANON try: termios.tcsetattr(fd, termios.TCSADRAIN, new) while True: in_ch = sys.stdin.read(1) if in_ch == 'n' or in_ch == 'N': output('\tCancel the deletion.\n') break elif in_ch == 'y' or in_ch == 'Y' or in_ch != '\n': del_flows.append(del_flow) output('\n') break else: output('\nWrong, please input [Y/n]: ') continue finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) if not del_flows: return False self.load_flows(True) f = open(self.flows_db, 'r') while True: lines = f.readlines(1000) if not lines: break for line in lines: flow = self._parse_flow(line) if flow in del_flows: del_matches = line.replace(',', ' ').split() del_matches = \ filter(lambda m: not (m.startswith("cookie=") or m.startswith("actions=")), del_matches) del_cmd = "ovs-ofctl --strict del-flows %s %s" \ % (self.bridge, ','.join(del_matches)) err = Popen(del_cmd, stdout=PIPE, stderr=PIPE, shell=True).communicate()[1] if err: error("Error when delflow <%s> in bridge %s\n" % (','.join(del_matches), self.bridge)) error(err) return False f.close() self.load_flows() return True