From 267ecedf583020eef1e1cc96253fbd3b64a1d6a6 Mon Sep 17 00:00:00 2001 From: "watanabe.fumitaka" Date: Mon, 6 Jan 2014 17:54:21 +0900 Subject: [PATCH] bpdu: handling based on version and type In bpdu.py only one version was permitted with one type, before. This patch improves parser so that it may be based on multiple versions and types. Signed-off-by: WATANABE Fumitaka Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/bpdu.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ryu/lib/packet/bpdu.py b/ryu/lib/packet/bpdu.py index 8c39ec5a..a98d35da 100644 --- a/ryu/lib/packet/bpdu.py +++ b/ryu/lib/packet/bpdu.py @@ -171,7 +171,8 @@ class bpdu(packet_base.PacketBase): @staticmethod def register_bpdu_type(sub_cls): - bpdu._BPDU_TYPES[sub_cls.BPDU_TYPE] = sub_cls + bpdu._BPDU_TYPES.setdefault(sub_cls.VERSION_ID, {}) + bpdu._BPDU_TYPES[sub_cls.VERSION_ID][sub_cls.BPDU_TYPE] = sub_cls return sub_cls def __init__(self): @@ -194,14 +195,13 @@ class bpdu(packet_base.PacketBase): bpdu_type) = struct.unpack_from(cls._PACK_STR, buf) assert protocol_id == PROTOCOL_IDENTIFIER - bpdu_cls = cls._BPDU_TYPES.get(bpdu_type, None) - - if bpdu_cls: - assert version_id == bpdu_cls.VERSION_ID + if (version_id in cls._BPDU_TYPES + and bpdu_type in cls._BPDU_TYPES[version_id]): + bpdu_cls = cls._BPDU_TYPES[version_id][bpdu_type] assert len(buf[cls._PACK_LEN:]) >= bpdu_cls.PACK_LEN return bpdu_cls.parser(buf[cls._PACK_LEN:]) else: - # Unknown bdpu type. + # Unknown bpdu version/type. return buf, None, None def serialize(self, payload, prev):