Changeset 187
- Timestamp:
- 07/30/12 19:12:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r186 r187 179 179 def register_port(self, interface): 180 180 try: 181 interface._switch_portnum = self._next# XXX181 self._set_privattr('portnum', interface, self._next) # XXX 182 182 self._table[self._next] = SwitchPort(self._next, interface) 183 183 return self._next … … 186 186 187 187 def unregister_port(self, interface): 188 self._fdb.delete(self._table[interface._switch_portnum]) 189 del self._table[interface._switch_portnum] 190 del interface._switch_portnum 188 portnum = self._get_privattr('portnum', interface) 189 self._del_privattr('portnum', interface) 190 self._fdb.delete(self._table[portnum]) 191 del self._table[portnum] 191 192 192 193 def send(self, dst_interfaces, frame): 193 ports = sorted((self._table[i._switch_portnum] for i in dst_interfaces 194 if not self._table[i._switch_portnum].shut), 195 cmp=SwitchPort.cmp_by_number) 194 portnums = (self._get_privattr('portnum', i) for i in dst_interfaces) 195 ports = (self._table[n] for n in portnums) 196 ports = (p for p in ports if not p.shut) 197 ports = sorted(ports, cmp=SwitchPort.cmp_by_number) 196 198 197 199 for p in ports: … … 207 209 208 210 def receive(self, src_interface, frame): 209 port = self._table[s rc_interface._switch_portnum]211 port = self._table[self._get_privattr('portnum', src_interface)] 210 212 211 213 if not port.shut: … … 225 227 return 226 228 227 ports = set(self. _table.itervalues()) - set([src_port])229 ports = set(self.portlist) - set([src_port]) 228 230 self.send((p.interface for p in ports), frame) 229 231 230 232 except: # ex. received invalid frame 231 233 traceback.print_exc() 234 235 def _privattr(self, name): 236 return '_%s_%s_%s' % (self.__class__.__name__, id(self), name) 237 238 def _set_privattr(self, name, obj, value): 239 return setattr(obj, self._privattr(name), value) 240 241 def _get_privattr(self, name, obj, defaults=None): 242 return getattr(obj, self._privattr(name), defaults) 243 244 def _del_privattr(self, name, obj): 245 return delattr(obj, self._privattr(name)) 232 246 233 247
Note: See TracChangeset
for help on using the changeset viewer.