Changeset 207 for etherws/trunk
- Timestamp:
- 08/03/12 12:41:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r206 r207 136 136 del self._table[vid] 137 137 138 def get_entry(self, vid, mac):138 def _get_entry(self, vid, mac): 139 139 try: 140 140 entry = self._table[vid][mac] … … 149 149 lambda: (entry.port.number, vid, mac.encode('hex'))) 150 150 151 def get_vid_list(self): 152 return sorted(self._table.iterkeys()) 153 154 def get_mac_list(self, vid): 155 return sorted(self._table[vid].iterkeys()) 151 def foreach(self): 152 for vid in sorted(self._table.iterkeys()): 153 for mac in sorted(self._table[vid].iterkeys()): 154 entry = self._get_entry(vid, mac) 155 if entry: 156 yield (vid, mac, entry) 156 157 157 158 def lookup(self, frame): 158 159 mac = frame.dst_mac 159 160 vid = frame.vid 160 entry = self. get_entry(vid, mac)161 entry = self._get_entry(vid, mac) 161 162 return getattr(entry, 'port', None) 162 163 … … 169 170 170 171 def delete(self, port): 171 for vid in self.get_vid_list(): 172 for mac in self.get_mac_list(vid): 173 entry = self.get_entry(vid, mac) 174 if entry and entry.port.number == port.number: 175 self._del_entry(vid, mac) 176 self.dprintf('deleted: port:%d; vid:%d; mac:%s\n', 177 lambda: (port.number, vid, mac.encode('hex'))) 172 for vid, mac, entry in self.foreach(): 173 if entry.port.number == port.number: 174 self._del_entry(vid, mac) 175 self.dprintf('deleted: port:%d; vid:%d; mac:%s\n', 176 lambda: (port.number, vid, mac.encode('hex'))) 178 177 179 178 … … 577 576 def handle_listFdb(self, params): 578 577 list_ = [] 579 for vid in self._switch.fdb.get_vid_list(): 580 for mac in self._switch.fdb.get_mac_list(vid): 581 entry = self._switch.fdb.get_entry(vid, mac) 582 if entry: 583 list_.append({ 584 'vid': vid, 585 'mac': EthernetFrame.format_mac(mac), 586 'port': entry.port.number, 587 'age': int(entry.age), 588 }) 578 for vid, mac, entry in self._switch.fdb.foreach(): 579 list_.append({ 580 'vid': vid, 581 'mac': EthernetFrame.format_mac(mac), 582 'port': entry.port.number, 583 'age': int(entry.age), 584 }) 589 585 return {'entries': list_} 590 586
Note: See TracChangeset
for help on using the changeset viewer.