Signed-off-by: Isaku Yamahata <[email protected]>
---
ryu/lib/dpid.py | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/ryu/lib/dpid.py b/ryu/lib/dpid.py
index 1224ae0..9a0141e 100644
--- a/ryu/lib/dpid.py
+++ b/ryu/lib/dpid.py
@@ -17,10 +17,15 @@
# Internal representation of datapath id is quad int
# string representation is in hex without '0x'
+import struct
+
_DPID_LEN = 16
_DPID_LEN_STR = str(_DPID_LEN)
_DPID_FMT = '%0' + _DPID_LEN_STR + 'x'
DPID_PATTERN = r'[0-9a-f]{%d}' % _DPID_LEN
+_DPID_PACK_STR = '!Q'
+_DPID_PACK_SIZE = 8
+assert struct.calcsize(_DPID_PACK_STR) == _DPID_PACK_SIZE
def dpid_to_str(dpid):
@@ -30,3 +35,11 @@ def dpid_to_str(dpid):
def str_to_dpid(dpid_str):
assert len(dpid_str) == _DPID_LEN
return int(dpid_str, 16)
+
+
+def dpid_to_buf(dpid):
+ return struct.pack(_DPID_PACK_STR, dpid)
+
+
+def buf_to_dpid(dpid_buf):
+ return struct.unpack(_DPID_PACK_STR, dpid_buf)
--
1.7.10.4
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel