diff --git a/ryu/lib/packet/udp.py b/ryu/lib/packet/udp.py index e3bf5e5f..a960886d 100644 --- a/ryu/lib/packet/udp.py +++ b/ryu/lib/packet/udp.py @@ -41,7 +41,7 @@ class udp(packet_base.PacketBase): _PACK_STR = '!HHHH' _MIN_LEN = struct.calcsize(_PACK_STR) - def __init__(self, src_port, dst_port, total_length=0, csum=0): + def __init__(self, src_port=0, dst_port=0, total_length=0, csum=0): super(udp, self).__init__() self.src_port = src_port self.dst_port = dst_port diff --git a/ryu/tests/unit/packet/test_udp.py b/ryu/tests/unit/packet/test_udp.py index 64187436..40da616b 100644 --- a/ryu/tests/unit/packet/test_udp.py +++ b/ryu/tests/unit/packet/test_udp.py @@ -94,3 +94,13 @@ class Test_udp(unittest.TestCase): def test_malformed_udp(self): m_short_buf = self.buf[1:udp._MIN_LEN] udp.parser(m_short_buf) + + def test_default_args(self): + prev = ipv4(proto=inet.IPPROTO_UDP) + u = udp() + buf = u.serialize(bytearray(), prev) + res = struct.unpack(udp._PACK_STR, buf) + + eq_(res[0], 0) + eq_(res[1], 0) + eq_(res[2], udp._MIN_LEN)