summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHIYAMA Manabu <hiyama.manabu@po.ntts.co.jp>2012-09-27 18:23:12 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-09-30 21:48:05 +0900
commitfc264cc971eb529584ffd34605f006a6c5890038 (patch)
tree184001be1852d591186faa745385aa02ec381c26
parent19c205b897aa7cc74a68bfc077937481ea1a5936 (diff)
Fix zero padding
- zfill() is a func of the string to be putting in a '0'. bytearray().zfill(n) -> bytearray(n) - unify notation of zero with other code. '\0' -> '\x00' Signed-off-by: HIYAMA Manabu <hiyama.manabu@po.ntts.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/ipv4.py2
-rw-r--r--ryu/lib/packet/tcp.py4
-rw-r--r--ryu/lib/packet/udp.py2
-rw-r--r--ryu/ofproto/ofproto_parser.py6
-rw-r--r--ryu/tests/unit/ofproto/test_ofproto_parser.py2
5 files changed, 8 insertions, 8 deletions
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