Changeset 198
- Timestamp:
- 08/01/12 00:43:21 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r197 r198 101 101 return 0 102 102 103 @staticmethod 104 def format_mac(mac, sep=':'): 105 return sep.join(b.encode('hex') for b in mac) 106 103 107 104 108 class FDB(DebugMixIn): … … 148 152 149 153 def get_vid_list(self): 150 return s elf._table.keys()154 return sorted(self._table.iterkeys()) 151 155 152 156 def get_mac_list(self, vid): 153 return s elf._table[vid].keys()157 return sorted(self._table[vid].iterkeys()) 154 158 155 159 def lookup(self, frame): … … 548 552 self.finish({'result': None, 'error': {'message': msg}, 'id': id_}) 549 553 554 def handle_listFdb(self, params): 555 list_ = [] 556 for vid in self._switch.fdb.get_vid_list(): 557 for mac in self._switch.fdb.get_mac_list(vid): 558 entry = self._switch.fdb.get_entry(vid, mac) 559 if entry: 560 mac = EthernetFrame.format_mac(mac) 561 list_.append([vid, mac, entry.port.number, int(entry.age)]) 562 return {'result': list_} 563 550 564 def handle_listPort(self, params): 551 565 list_ = [self._portstat(p) for p in self._switch.portlist] 552 return {' portlist': list_}566 return {'result': list_} 553 567 554 568 def handle_addPort(self, params): … … 562 576 portnum = interface.open() 563 577 list_.append(self._portstat(self._switch.get_port(portnum))) 564 return {' portlist': list_}578 return {'result': list_} 565 579 566 580 def handle_delPort(self, params): … … 570 584 list_.append(self._portstat(port)) 571 585 port.interface.close() 572 return {' portlist': list_}586 return {'result': list_} 573 587 574 588 def handle_shutPort(self, params): … … 578 592 port.shut = bool(p['shut']) 579 593 list_.append(self._portstat(port)) 580 return {' portlist': list_}594 return {'result': list_} 581 595 582 596 def _optparse_tap(self, opt): … … 778 792 return request(args, 'listPort', []) 779 793 794 def handle_ctl_listfdb(args): 795 return request(args, 'listFdb', []) 796 780 797 res = locals()['handle_ctl_' + args.control_method](args) 781 798 … … 783 800 print(res['error']['message']) 784 801 else: 785 print(yaml.safe_dump(res['result'] ['portlist']).strip())802 print(yaml.safe_dump(res['result']).strip()) 786 803 787 804 … … 837 854 parser_c_lp = control_method.add_parser('listport') 838 855 856 parser_c_lf = control_method.add_parser('listfdb') 857 839 858 # -- go 840 859 args = parser.parse_args()
Note: See TracChangeset
for help on using the changeset viewer.