summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-06 16:19:07 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-06 16:19:07 +0900
commit85713492748a2613d62d5fa82e0013ab93968b1f (patch)
tree0e33eeadc0e5fad8058a8728fc1a829f0736e3d9
parent9f1c0b388e080efaea0cf79d6502bd1534e83bb2 (diff)
bgp: fix _OptParamCapability parser
It could include multiple Capabilities. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bgp.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index ff6d7afe..4660c303 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -1132,8 +1132,10 @@ class _OptParam(StringifyMixin, _TypeDisp, _Value):
value = bytes(rest[:length])
rest = rest[length:]
subcls = cls._lookup_type(type_)
- kwargs, subcls = subcls.parse_value(value)
- return subcls(type_=type_, length=length, **kwargs), rest
+ caps = subcls.parse_value(value)
+ if type(caps) != list:
+ caps = [subcls(type_=type_, length=length, **caps[0])]
+ return caps, rest
def serialize(self):
# fixup
@@ -1175,16 +1177,21 @@ class _OptParamCapability(_OptParam, _TypeDisp):
@classmethod
def parse_value(cls, buf):
- (code, length) = struct.unpack_from(cls._CAP_HDR_PACK_STR, buffer(buf))
- value = buf[struct.calcsize(cls._CAP_HDR_PACK_STR):]
- assert len(value) == length
- kwargs = {
- 'cap_code': code,
- 'cap_length': length,
- }
- subcls = cls._lookup_type(code)
- kwargs.update(subcls.parse_cap_value(value))
- return kwargs, subcls
+ caps = []
+ while len(buf) > 0:
+ (code, length) = struct.unpack_from(cls._CAP_HDR_PACK_STR,
+ buffer(buf))
+ value = buf[struct.calcsize(cls._CAP_HDR_PACK_STR):]
+ buf = buf[length + 2:]
+ kwargs = {
+ 'cap_code': code,
+ 'cap_length': length,
+ }
+ subcls = cls._lookup_type(code)
+ kwargs.update(subcls.parse_cap_value(value))
+ caps.append(subcls(type_=BGP_OPT_CAPABILITY, length=length + 2,
+ **kwargs))
+ return caps
def serialize_value(self):
# fixup
@@ -2239,7 +2246,7 @@ class BGPOpen(BGPMessage):
opt_param = []
while binopts:
opt, binopts = _OptParam.parser(binopts)
- opt_param.append(opt)
+ opt_param.extend(opt)
return {
"version": version,
"my_as": my_as,