Changeset 5793
- Timestamp:
- 08/14/10 00:31:58 (3 years ago)
- Location:
- umpa/branches/protocols
- Files:
-
- 2 modified
-
tests/a_unit/test_protocols/test_ethernet.py (modified) (1 diff)
-
umit/umpa/protocols/Ethernet.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
umpa/branches/protocols/tests/a_unit/test_protocols/test_ethernet.py
r5789 r5793 53 53 py.test.raises(UMPAAttributeException, "eth.tpid = 999999") 54 54 py.test.raises(UMPAAttributeException, "eth.tpid = -1") 55 56 def test_load_raw(self): 57 buf = "\x00\x11\x22\x33\x44\x55\xAA\xBB\xCC\xDD\xEE\xFF\x12\x34ABC" 58 eth = Ethernet() 59 buf = eth.load_raw(buf) 60 assert eth.src == "aa:bb:cc:dd:ee:ff" 61 assert eth.dst == "00:11:22:33:44:55" 62 assert eth.vlan == False 63 assert eth._type == 0x1234 64 assert buf == "ABC" 65 66 buf = "\x00\x11\x22\x33\x44\x55\xAA\xBB\xCC\xDD\xEE\xFF\x81\x00\x56\x66\xbe\xefXYZ" 67 eth = Ethernet() 68 buf = eth.load_raw(buf) 69 print eth._type 70 assert eth.src == "aa:bb:cc:dd:ee:ff" 71 assert eth.dst == "00:11:22:33:44:55" 72 assert eth.vlan == True 73 assert eth.tpid == 0x8100 74 assert eth._type == 0xbeef 75 assert eth.vid == 0x666 76 assert eth.cfi == 1 77 assert eth.pcp == 2 78 assert buf == "XYZ" -
umpa/branches/protocols/umit/umpa/protocols/Ethernet.py
r5792 r5793 308 308 self._type = fields[12] 309 309 310 # interpret 802.1Q header if present 311 if self._type == _consts.ETHERTYPE_VLAN: 312 fields = struct.unpack('!HH', buffer[header_size:header_size+4]) 313 header_size += 4 314 self.vlan = True 315 self.tpid = self._type 316 self._type = fields[1] 317 self.vid = fields[0] & 0xfff 318 self.cfi = (fields[0]>>12) & 1 319 self.pcp = (fields[0]>>13) & 0x7 320 else: 321 self.vlan = False 322 310 323 return buffer[header_size:] 311 324
