Package dpkt :: Module aoe
[hide private]
[frames] | no frames]

Source Code for Module dpkt.aoe

 1  # -*- coding: utf-8 -*- 
 2  """ATA over Ethernet Protocol.""" 
 3  from __future__ import absolute_import 
 4   
 5  import struct 
 6   
 7  from . import dpkt 
 8  from .decorators import deprecated 
 9  from .compat import iteritems 
10 11 -class AOE(dpkt.Packet):
12 """ATA over Ethernet Protocol. 13 14 See more about the AOE on \ 15 https://en.wikipedia.org/wiki/ATA_over_Ethernet 16 17 Attributes: 18 __hdr__: Header fields of AOE. 19 data: Message data. 20 """ 21 22 __hdr__ = ( 23 ('ver_fl', 'B', 0x10), 24 ('err', 'B', 0), 25 ('maj', 'H', 0), 26 ('min', 'B', 0), 27 ('cmd', 'B', 0), 28 ('tag', 'I', 0), 29 ) 30 _cmdsw = {} 31 32 @property
33 - def ver(self): return self.ver_fl >> 4
34 35 @ver.setter
36 - def ver(self, ver): self.ver_fl = (ver << 4) | (self.ver_fl & 0xf)
37 38 @property
39 - def fl(self): return self.ver_fl & 0xf
40 41 @fl.setter
42 - def fl(self, fl): self.ver_fl = (self.ver_fl & 0xf0) | fl
43 44 @classmethod
45 - def set_cmd(cls, cmd, pktclass):
46 cls._cmdsw[cmd] = pktclass
47 48 @classmethod
49 - def get_cmd(cls, cmd):
50 return cls._cmdsw[cmd]
51
52 - def unpack(self, buf):
53 dpkt.Packet.unpack(self, buf) 54 try: 55 self.data = self._cmdsw[self.cmd](self.data) 56 setattr(self, self.data.__class__.__name__.lower(), self.data) 57 except (KeyError, struct.error, dpkt.UnpackError): 58 pass
59
60 - def pack_hdr(self):
61 try: 62 return dpkt.Packet.pack_hdr(self) 63 except struct.error as e: 64 raise dpkt.PackError(str(e))
65 66 67 AOE_CMD_ATA = 0 68 AOE_CMD_CFG = 1 69 AOE_FLAG_RSP = 1 << 3
70 71 72 -def __load_cmds():
73 prefix = 'AOE_CMD_' 74 g = globals() 75 76 for k, v in iteritems(g): 77 if k.startswith(prefix): 78 name = 'aoe' + k[len(prefix):].lower() 79 try: 80 mod = __import__(name, g, level=1) 81 AOE.set_cmd(v, getattr(mod, name.upper())) 82 except (ImportError, AttributeError): 83 continue
84
85 86 -def _mod_init():
87 """Post-initialization called when all dpkt modules are fully loaded""" 88 if not AOE._cmdsw: 89 __load_cmds()
90