also, provide the fallback "unknown" capablity class.
Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
ryu/lib/packet/bgp.py | 46 ++++++++++++++++++++++++++++++---------
ryu/tests/unit/packet/test_bgp.py | 4 +++-
2 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 1d9b8e6..1d3d2e6 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -192,7 +192,7 @@ class _OptParam(StringifyMixin, _TypeDisp, _Value):
value = bytes(rest[:length])
rest = rest[length:]
subcls = cls._lookup_type(type_)
- kwargs = subcls.parse_value(value)
+ kwargs, subcls = subcls.parse_value(value)
return subcls(type_=type_, length=length, **kwargs), rest
def serialize(self):
@@ -211,22 +211,27 @@ class BGPOptParamUnknown(_OptParam):
def parse_value(cls, buf):
return {
'value': buf
- }
+ }, cls
def serialize_value(self):
return self.value
@_OptParam.register_type(BGP_OPT_CAPABILITY)
-class BGPOptParamCapability(_OptParam):
+class _OptParamCapability(_OptParam, _TypeDisp):
_CAP_HDR_PACK_STR = '!BB'
- def __init__(self, cap_code, cap_value, cap_length=None,
+ def __init__(self, cap_code=None, cap_value=None, cap_length=None,
type_=None, length=None):
- super(BGPOptParamCapability, self).__init__(type_=type_, length=length)
+ super(_OptParamCapability, self).__init__(type_=BGP_OPT_CAPABILITY,
+ length=length)
+ if cap_code is None:
+ cap_code = self._rev_lookup_type(self.__class__)
self.cap_code = cap_code
- self.cap_length = cap_length
- self.cap_value = cap_value
+ if not cap_value is None:
+ self.cap_value = cap_value
+ if not cap_length is None:
+ self.cap_length = cap_length
@classmethod
def parse_value(cls, buf):
@@ -236,13 +241,14 @@ class BGPOptParamCapability(_OptParam):
kwargs = {
'cap_code': code,
'cap_length': length,
- 'cap_value': value,
}
- return kwargs
+ subcls = cls._lookup_type(code)
+ kwargs.update(subcls.parse_cap_value(value))
+ return kwargs, subcls
def serialize_value(self):
# fixup
- cap_value = self.cap_value
+ cap_value = self.serialize_cap_value()
self.cap_length = len(cap_value)
buf = bytearray()
@@ -251,6 +257,26 @@ class BGPOptParamCapability(_OptParam):
return buf + cap_value
+@_OptParamCapability.register_unknown_type()
+class BGPOptParamCapabilityUnknown(_OptParamCapability):
+ @classmethod
+ def parse_cap_value(cls, buf):
+ return {'cap_value': buf}
+
+ def serialize_cap_value(self):
+ return self.cap_value
+
+
+@_OptParamCapability.register_type(BGP_CAP_ROUTE_REFRESH)
+class BGPOptParamCapabilityRouteRefresh(_OptParamCapability):
+ @classmethod
+ def parse_cap_value(cls, buf):
+ return {}
+
+ def serialize_cap_value(self):
+ return bytearray()
+
+
class BGPWithdrawnRoute(_IPAddrPrefix):
pass
diff --git a/ryu/tests/unit/packet/test_bgp.py
b/ryu/tests/unit/packet/test_bgp.py
index 889763d..fa3b9f3 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -42,7 +42,9 @@ class Test_bgp(unittest.TestCase):
eq_(rest, '')
def test_open2(self):
- opt_param = [bgp.BGPOptParamCapability(cap_code=200, cap_value='hoge'),
+ opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
+ cap_value='hoge'),
+ bgp.BGPOptParamCapabilityRouteRefresh(),
bgp.BGPOptParamUnknown(type_=99, value='fuga')]
msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.2',
opt_param=opt_param)
--
1.8.3.1
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel