Although I'm not sure what type note is, some lines can be simplified with ord() (and bytearray). some comments inlined.
On Sun, Jun 03, 2012 at 10:35:23AM +0900, FUJITA Tomonori wrote: > Signed-off-by: FUJITA Tomonori <[email protected]> > --- > ryu/ofproto/ofproto_v1_0.py | 5 ++++ > ryu/ofproto/ofproto_v1_0_parser.py | 42 > ++++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+), 0 deletions(-) > > diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py > index 5ba2d2b..ce8a09f 100644 > --- a/ryu/ofproto/ofproto_v1_0.py > +++ b/ryu/ofproto/ofproto_v1_0.py > @@ -238,6 +238,7 @@ NXAST_SET_QUEUE = 4 > NXAST_POP_QUEUE = 5 > NXAST_REG_MOVE = 6 > NXAST_REG_LOAD = 7 > +NXAST_NOTE = 8 > NXAST_SET_TUNNEL64 = 9 > NXAST_MULTIPATH = 10 > NXAST_AUTOPATH = 11 > @@ -282,6 +283,10 @@ NX_ACTION_MULTIPATH_PACK_STR = '!HHIHHH2xHHI2xHI' > NX_ACTION_MULTIPATH_SIZE = 32 > assert calcsize(NX_ACTION_MULTIPATH_PACK_STR) == NX_ACTION_MULTIPATH_SIZE > > +NX_ACTION_NOTE_PACK_STR = '!HHIH6B' > +NX_ACTION_NOTE_SIZE = 16 > +assert calcsize(NX_ACTION_NOTE_PACK_STR) == NX_ACTION_NOTE_SIZE > + > NX_ACTION_BUNDLE_PACK_STR = '!HHIHHHHIHHI4x' > NX_ACTION_BUNDLE_SIZE = 32 > assert calcsize(NX_ACTION_BUNDLE_PACK_STR) == NX_ACTION_BUNDLE_SIZE > diff --git a/ryu/ofproto/ofproto_v1_0_parser.py > b/ryu/ofproto/ofproto_v1_0_parser.py > index 2d82bc6..9cc7eee 100644 > --- a/ryu/ofproto/ofproto_v1_0_parser.py > +++ b/ryu/ofproto/ofproto_v1_0_parser.py > @@ -16,6 +16,7 @@ > > import collections > import struct > +import binascii > > from ofproto_parser import MsgBase, msg_pack_into, msg_str_attr > from ryu.lib import mac > @@ -620,6 +621,47 @@ class NXActionMultipath(NXActionHeader): > dst) > > > [email protected]_nx_action_subtype(ofproto_v1_0.NXAST_NOTE) > +class NXActionNote(NXActionHeader): > + def __init__(self, note): > + # should check here if the note is valid (only hex values) > + pad = (len(note) + 10) % 8 > + if pad: > + note += [0x0 for i in range(8 - pad)] note += '\x00' * (8 - pad) I'm not sure what type note is, though. If bytearray is needed, it should be something like note += bytearray('\x00' * (8 - pad)) > + self.note = note > + _len = len(note) + 10 > + super(NXActionNote, self).__init__( > + ofproto_v1_0.NXAST_NOTE, _len) > + > + def serialize(self, buf, offset): > + note = self.note > + extra = None > + extra_len = len(self.note) - 6 > + if extra_len > 0: > + extra = note[6:] > + note = note[0:6] > + msg_pack_into(ofproto_v1_0.NX_ACTION_NOTE_PACK_STR, buf, > + offset, self.type, self.len, self.vendor, self.subtype, > + *note) > + if extra_len > 0: > + msg_pack_into('B' * extra_len, buf, > + offset + ofproto_v1_0.NX_ACTION_NOTE_SIZE, > + *extra) > + > + @classmethod > + def parser(cls, buf, offset): > + note = struct.unpack_from( > + ofproto_v1_0.NX_ACTION_NOTE_PACK_STR, buf, offset) > + (type_, len_, vendor, subtype) = note[0:4] > + note = [i for i in note[4:]] note = bytearray(note[4:])? > + if len_ > ofproto_v1_0.NX_ACTION_NOTE_SIZE: > + note_start = offset + ofproto_v1_0.NX_ACTION_NOTE_SIZE > + note_end = note_start + len_ - ofproto_v1_0.NX_ACTION_NOTE_SIZE > + note += [int(binascii.b2a_hex(i), 16) for i > + in buf[note_start:note_end]] note += [ord(i) for i in buf[note_start:note_end]] I'm not fully sure, though. thanks, > + return cls(note) > + > + > class NXActionBundleBase(NXActionHeader): > def __init__(self, subtype, algorithm, fields, basis, slave_type, > n_slaves, > ofs_nbits, dst, slaves): > -- > 1.7.4.4 > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Ryu-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ryu-devel > -- yamahata ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
