diff --git a/ryu/lib/packet/ipv4.py b/ryu/lib/packet/ipv4.py index 2adf6895..21d227ad 100644 --- a/ryu/lib/packet/ipv4.py +++ b/ryu/lib/packet/ipv4.py @@ -62,7 +62,7 @@ class ipv4(packet_base.PacketBase): return msg, ipv4.get_packet_type(proto) def serialize(self, payload, prev): - hdr = bytearray().zfill(self.header_length * 4) + hdr = bytearray(self.header_length * 4) version = self.version << 4 | self.header_length flags = self.flags << 13 | self.offset if self.total_length == 0: diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py index ec177f03..81c79336 100644 --- a/ryu/lib/packet/tcp.py +++ b/ryu/lib/packet/tcp.py @@ -54,7 +54,7 @@ class tcp(packet_base.PacketBase): return msg, None def serialize(self, payload, prev): - h = bytearray().zfill(self.length) + h = bytearray(self.length) offset = self.offset << 4 struct.pack_into(tcp._PACK_STR, h, 0, self.src_port, self.dst_port, self.seq, self.ack, offset, self.bits, @@ -69,7 +69,7 @@ class tcp(packet_base.PacketBase): ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 6, length) f = ph + h + payload if len(f) % 2: - f += '\0' + f += '\x00' self.csum = socket.htons(packet_utils.checksum(f)) struct.pack_into('!H', h, 16, self.csum) return h diff --git a/ryu/lib/packet/udp.py b/ryu/lib/packet/udp.py index 2b858d98..b949b5ca 100644 --- a/ryu/lib/packet/udp.py +++ b/ryu/lib/packet/udp.py @@ -47,7 +47,7 @@ class udp(packet_base.PacketBase): ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 17, self.length) f = ph + h + payload if len(f) % 2: - f += '\0' + f += '\x00' self.csum = socket.htons(packet_utils.checksum(f)) h = struct.pack(udp._PACK_STR, self.src_port, self.dst_port, self.length, self.csum) diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py index 21a86a9f..26adead6 100644 --- a/ryu/ofproto/ofproto_parser.py +++ b/ryu/ofproto/ofproto_parser.py @@ -93,7 +93,7 @@ class MsgBase(object): self.version = self.datapath.ofproto.OFP_VERSION self.msg_type = self.cls_msg_type - self.buf = bytearray().zfill(self.datapath.ofproto.OFP_HEADER_SIZE) + self.buf = bytearray(self.datapath.ofproto.OFP_HEADER_SIZE) def _serialize_header(self): # buffer length is determined after trailing data is formated. @@ -122,7 +122,7 @@ class MsgBase(object): def msg_pack_into(fmt, buf, offset, *args): if len(buf) < offset: - buf += bytearray().zfill(offset - len(buf)) + buf += bytearray(offset - len(buf)) if len(buf) == offset: buf += struct.pack(fmt, *args) @@ -130,7 +130,7 @@ def msg_pack_into(fmt, buf, offset, *args): needed_len = offset + struct.calcsize(fmt) if len(buf) < needed_len: - buf += bytearray().zfill(needed_len - len(buf)) + buf += bytearray(needed_len - len(buf)) struct.pack_into(fmt, buf, offset, *args) diff --git a/ryu/tests/unit/ofproto/test_ofproto_parser.py b/ryu/tests/unit/ofproto/test_ofproto_parser.py index 114a6998..9baf46ab 100644 --- a/ryu/tests/unit/ofproto/test_ofproto_parser.py +++ b/ryu/tests/unit/ofproto/test_ofproto_parser.py @@ -252,7 +252,7 @@ class TestMsgPackInto(unittest.TestCase): def _test_msg_pack_into(self, offset_type='e'): fmt = '!HH' len_ = struct.calcsize(fmt) - buf = bytearray().zfill(len_) + buf = bytearray(len_) offset = len_ arg1 = 1 arg2 = 2