diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2014-08-06 21:56:46 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-08-07 09:28:39 +0800 |
commit | 4c98b346e2dbd55e606cb6851e1a5df130e7cdc8 (patch) | |
tree | 0318118308731286cecd3b120af77da6d68f5c8e | |
parent | 2adfda55e6dfe07c29949f2a4949318fd32d9529 (diff) |
app/bmpstation: fix to work with empty BMPMessage
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/bmpstation.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/ryu/app/bmpstation.py b/ryu/app/bmpstation.py index da94d407..67c069c2 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 |