Signed-off-by: Shinpei Muraoka <[email protected]>
---
 ryu/lib/packet/vxlan.py             | 22 +++++++++++++++++++++-
 ryu/tests/unit/packet/test_vxlan.py |  7 +++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/ryu/lib/packet/vxlan.py b/ryu/lib/packet/vxlan.py
index d68b9b6..c7de04b 100644
--- a/ryu/lib/packet/vxlan.py
+++ b/ryu/lib/packet/vxlan.py
@@ -42,8 +42,10 @@ VXLAN Header:
 import struct
 import logging
 
-from . import packet_base
+import six
 
+from . import packet_base
+from ryu.lib import type_desc
 
 LOG = logging.getLogger(__name__)
 
@@ -88,3 +90,21 @@ class vxlan(packet_base.PacketBase):
     def serialize(self, payload, prev):
         return struct.pack(self._PACK_STR,
                            1 << (3 + 24), self.vni << 8)
+
+
+def vni_from_bin(buf):
+    """
+    Converts binary representation VNI to integer.
+    :param buf: binary representation of VNI.
+    :return: VNI integer.
+    """
+    return type_desc.Int3.to_user(six.binary_type(buf))
+
+
+def vni_to_bin(vni):
+    """
+    Converts integer VNI to binary representation.
+    :param vni: integer of VNI
+    :return: binary representation of VNI.
+    """
+    return type_desc.Int3.from_user(vni)
diff --git a/ryu/tests/unit/packet/test_vxlan.py 
b/ryu/tests/unit/packet/test_vxlan.py
index fe418ff..8cace58 100644
--- a/ryu/tests/unit/packet/test_vxlan.py
+++ b/ryu/tests/unit/packet/test_vxlan.py
@@ -73,3 +73,10 @@ class Test_vxlan(unittest.TestCase):
     def test_to_jsondict(self):
         jsondict_from_pkt = self.pkt.to_jsondict()
         eq_(self.jsondict, jsondict_from_pkt)
+
+    def test_vni_from_bin(self):
+        vni = vxlan.vni_from_bin(b'\x12\x34\x56')
+        eq_(self.vni, vni)
+
+    def test_vni_to_bin(self):
+        eq_(b'\x12\x34\x56', vxlan.vni_to_bin(self.vni))
-- 
2.7.4


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to