Signed-off-by: Yuichi Ito <[email protected]>
---
ryu/lib/packet/icmp.py | 7 ++++--
ryu/tests/unit/packet/test_icmp.py | 41 ++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/ryu/lib/packet/icmp.py b/ryu/lib/packet/icmp.py
index d3d4cdd..a0ac118 100644
--- a/ryu/lib/packet/icmp.py
+++ b/ryu/lib/packet/icmp.py
@@ -77,7 +77,7 @@ class icmp(packet_base.PacketBase):
return cls
return _register_icmp_type
- def __init__(self, type_, code, csum, data=None):
+ def __init__(self, type_=ICMP_ECHO_REQUEST, code=0, csum=0, data=None):
super(icmp, self).__init__()
self.type = type_
self.code = code
@@ -108,6 +108,9 @@ class icmp(packet_base.PacketBase):
hdr += self.data.serialize()
else:
hdr += self.data
+ else:
+ self.data = echo()
+ hdr += self.data.serialize()
if self.csum == 0:
self.csum = packet_utils.checksum(hdr)
@@ -144,7 +147,7 @@ class echo(stringify.StringifyMixin):
_PACK_STR = '!HH'
_MIN_LEN = struct.calcsize(_PACK_STR)
- def __init__(self, id_, seq, data=None):
+ def __init__(self, id_=0, seq=0, data=None):
super(echo, self).__init__()
self.id = id_
self.seq = seq
diff --git a/ryu/tests/unit/packet/test_icmp.py
b/ryu/tests/unit/packet/test_icmp.py
index f93ed73..49329be 100644
--- a/ryu/tests/unit/packet/test_icmp.py
+++ b/ryu/tests/unit/packet/test_icmp.py
@@ -217,6 +217,24 @@ class Test_icmp(unittest.TestCase):
self.setUp_with_TimeExceeded()
self.test_to_string()
+ def test_default_args(self):
+ ic = icmp.icmp()
+ buf = ic.serialize(bytearray(), None)
+ res = struct.unpack(icmp.icmp._PACK_STR, str(buf[:4]))
+
+ eq_(res[0], 8)
+ eq_(res[1], 0)
+ eq_(buf[4:], '\x00\x00\x00\x00')
+
+ # with data
+ ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach())
+ buf = ic.serialize(bytearray(), None)
+ res = struct.unpack(icmp.icmp._PACK_STR, str(buf[:4]))
+
+ eq_(res[0], 3)
+ eq_(res[1], 0)
+ eq_(buf[4:], '\x00\x00\x00\x00')
+
class Test_echo(unittest.TestCase):
@@ -256,6 +274,14 @@ class Test_echo(unittest.TestCase):
eq_(self.seq, res[1])
eq_(self.data, buf[struct.calcsize('!HH'):])
+ def test_default_args(self):
+ ec = icmp.echo()
+ buf = ec.serialize()
+ res = struct.unpack(icmp.echo._PACK_STR, str(buf))
+
+ eq_(res[0], 0)
+ eq_(res[1], 0)
+
class Test_dest_unreach(unittest.TestCase):
@@ -290,6 +316,14 @@ class Test_dest_unreach(unittest.TestCase):
eq_(self.mtu, res[1])
eq_(self.data, buf[struct.calcsize('!xBH'):])
+ def test_default_args(self):
+ du = icmp.dest_unreach()
+ buf = du.serialize()
+ res = struct.unpack(icmp.dest_unreach._PACK_STR, str(buf))
+
+ eq_(res[0], 0)
+ eq_(res[1], 0)
+
class Test_TimeExceeded(unittest.TestCase):
@@ -319,3 +353,10 @@ class Test_TimeExceeded(unittest.TestCase):
res = struct.unpack_from('!xBxx', str(buf))
eq_(self.data_len, res[0])
eq_(self.data, buf[struct.calcsize('!xBxx'):])
+
+ def test_default_args(self):
+ te = icmp.TimeExceeded()
+ buf = te.serialize()
+ res = struct.unpack(icmp.TimeExceeded._PACK_STR, str(buf))
+
+ eq_(res[0], 0)
--
1.7.10.4
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel