Add an individual conversion process to ethernet.py and ipv4.py

Individual conversion is needed to the variable it cannot be
understood that does not conversion, like MAC address or IP address.

and it is required for other packet libraries.


Signed-off-by: WATANABE Fumitaka <[email protected]>
---
 ryu/lib/packet/ethernet.py |    6 ++++++
 ryu/lib/packet/ipv4.py     |    7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/ryu/lib/packet/ethernet.py b/ryu/lib/packet/ethernet.py
index 7bc18ef..4079cde 100644
--- a/ryu/lib/packet/ethernet.py
+++ b/ryu/lib/packet/ethernet.py
@@ -17,6 +17,7 @@ import struct
 from . import packet_base
 from . import vlan
 from . import mpls
+from ryu.lib import mac
 from ryu.ofproto import ether


@@ -38,6 +39,11 @@ class ethernet(packet_base.PacketBase):
     _PACK_STR = '!6s6sH'
     _MIN_LEN = struct.calcsize(_PACK_STR)

+    # for convert to string
+    STR_CONVERT = {'dst': mac.haddr_to_str,
+                   'src': mac.haddr_to_str,
+                   'ethertype': lambda value: '0x%04x' % value}
+
     def __init__(self, dst, src, ethertype):
         super(ethernet, self).__init__()
         self.dst = dst
diff --git a/ryu/lib/packet/ipv4.py b/ryu/lib/packet/ipv4.py
index e2ed478..64d0cab 100644
--- a/ryu/lib/packet/ipv4.py
+++ b/ryu/lib/packet/ipv4.py
@@ -65,6 +65,13 @@ class ipv4(packet_base.PacketBase):
     _PACK_STR = '!BBHHHBBHII'
     _MIN_LEN = struct.calcsize(_PACK_STR)

+    # for convert to string
+    STR_CONVERT = {'identification': hex,
+                   'flags': lambda value: '0x%02x' % value,
+                   'csum': hex,
+                   'src': ip.ipv4_to_str,
+                   'dst': ip.ipv4_to_str}
+
     def __init__(self, version=4, header_length=5, tos=0,
                  total_length=0, identification=0, flags=0,
                  offset=0, ttl=255, proto=0, csum=0,
-- 1.7.10.4



------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to