packet.bgp: parse/serialize FOUR OCTET AS NUMBER capability

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMAMOTO Takashi 2013-10-08 15:29:40 +09:00 committed by FUJITA Tomonori
parent cf9cb7e7ac
commit 2494ab9abb
2 changed files with 21 additions and 0 deletions

View File

@ -277,6 +277,25 @@ class BGPOptParamCapabilityRouteRefresh(_OptParamCapability):
return bytearray()
@_OptParamCapability.register_type(BGP_CAP_FOUR_OCTET_AS_NUMBER)
class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
_CAP_PACK_STR = '!I'
def __init__(self, as_number, **kwargs):
super(BGPOptParamCapabilityFourOctetAsNumber, self).__init__(**kwargs)
self.as_number = as_number
@classmethod
def parse_cap_value(cls, buf):
(as_number, ) = struct.unpack_from(cls._CAP_PACK_STR, buffer(buf))
return {'as_number': as_number}
def serialize_cap_value(self):
buf = bytearray()
msg_pack_into(self._CAP_PACK_STR, buf, 0, self.as_number)
return buf
class BGPWithdrawnRoute(_IPAddrPrefix):
pass

View File

@ -45,6 +45,8 @@ class Test_bgp(unittest.TestCase):
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
cap_value='hoge'),
bgp.BGPOptParamCapabilityRouteRefresh(),
bgp.BGPOptParamCapabilityFourOctetAsNumber(
as_number=1234567),
bgp.BGPOptParamUnknown(type_=99, value='fuga')]
msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.2',
opt_param=opt_param)