Signed-off-by: ISHIDA Wataru <[email protected]>
---
 ryu/app/bmpstation.py |   37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/ryu/app/bmpstation.py b/ryu/app/bmpstation.py
index da94d40..67c069c 100644
--- a/ryu/app/bmpstation.py
+++ b/ryu/app/bmpstation.py
@@ -21,7 +21,7 @@ from ryu.base import app_manager
 
 from ryu.lib import hub
 from ryu.lib.hub import StreamServer
-from ryu.lib.packet.bmp import *
+from ryu.lib.packet import bmp
 
 SERVER_HOST = '0.0.0.0'
 SERVER_PORT = 11019
@@ -40,24 +40,29 @@ class BMPStation(app_manager.RyuApp):
 
     def loop(self, sock, addr):
         logging.debug("started bmp loop.")
-        self.is_active = True
-
+        is_active = True
         buf = bytearray()
-        required_len = BMPMessage._HDR_LEN
+        required_len = bmp.BMPMessage._HDR_LEN
 
-        while self.is_active:
-            buf = sock.recv(BMPMessage._HDR_LEN)
-            if len(buf) == 0:
-                self.is_active = False
+        while is_active:
+            ret = sock.recv(required_len)
+            if len(ret) == 0:
+                is_active = False
                 break
+            buf += ret
+            while len(buf) >= required_len:
+                version, len_, _ = bmp.BMPMessage.parse_header(buf)
+                if version != bmp.VERSION:
+                    logging.error("unsupported bmp version: %d" % version)
+                    is_active = False
+                    break
 
-            _, len_, _ = BMPMessage.parse_header(buf)
+                required_len = len_
+                if len(buf) < required_len:
+                    break
 
-            body = sock.recv(len_ - BMPMessage._HDR_LEN)
-            if len(body) == 0:
-                self.is_active = False
-                break
+                msg, rest = bmp.BMPMessage.parser(buf)
+                print msg, '\n'
 
-            msg, rest = BMPMessage.parser(buf + body)
-            assert len(rest) == 0
-            print msg, '\n'
+                buf = rest
+                required_len = bmp.BMPMessage._HDR_LEN
-- 
1.7.10.4


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to