Signed-off-by: ISHIDA Wataru <[email protected]>
---
ryu/lib/packet/ospf.py | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/ryu/lib/packet/ospf.py b/ryu/lib/packet/ospf.py
index 5c5a179..f561165 100644
--- a/ryu/lib/packet/ospf.py
+++ b/ryu/lib/packet/ospf.py
@@ -18,6 +18,7 @@ RFC 2328 OSPF version 2
"""
import struct
+import inspect
from ryu.lib.stringify import StringifyMixin
from ryu.lib.packet import packet_base
@@ -170,6 +171,21 @@ class LSA(_TypeDisp, StringifyMixin):
self.header.length = length
self.header.checksum = checksum
+ def stringify_attrs(self):
+ for k, v in self.header.stringify_attrs():
+ yield (k, v)
+
+ for k, v in inspect.getmembers(self):
+ if k == 'header':
+ continue
+ if k.startswith('_'):
+ continue
+ if callable(v):
+ continue
+ if hasattr(self.__class__, k):
+ continue
+ yield (k, v)
+
@classmethod
def parser(cls, buf):
hdr, rest = LSAHeader.parser(buf)
@@ -237,6 +253,7 @@ class RouterLSA(LSA):
checksum=None, length=None, flags=0, links=[]):
self.flags = flags
self.links = links
+ assert all(link.__class__ == self.Link for link in links)
super(RouterLSA, self).__init__(ls_age, options, type_, id_,
adv_router, ls_seqnum, checksum,
length)
@@ -359,6 +376,7 @@ class ASExternalLSA(LSA):
def __init__(self, ls_age=0, options=0, type_=OSPF_AS_EXTERNAL_LSA,
id_='0.0.0.0', adv_router='0.0.0.0', ls_seqnum=0,
checksum=None, length=None, extnws=[]):
+ assert all(extnw.__class__ == self.ExternalNetwork for extnw in extnws)
self.extnws = extnws
super(ASExternalLSA, self).__init__(ls_age, options, type_, id_,
adv_router, ls_seqnum, checksum,
@@ -473,7 +491,7 @@ class OSPFHello(OSPFMessage):
au_type=1, authentication=0, checksum=None, version=_VERSION,
mask='0.0.0.0', hello_interval=10, options=0, priority=1,
dead_interval=40, designated_router='0.0.0.0',
- backup_router='0.0.0.0', neighbors=[]):
+ backup_router='0.0.0.0', neighbors=[], type_=None):
super(OSPFHello, self).__init__(OSPF_MSG_HELLO, length, router_id,
area_id, au_type, authentication,
checksum, version)
@@ -533,11 +551,12 @@ class OSPFDBDesc(OSPFMessage):
_PACK_STR = '!HBBI' # + LSA_HEADERS
_PACK_LEN = struct.calcsize(_PACK_STR)
_MIN_LEN = OSPFMessage._HDR_LEN + _PACK_LEN
+ _class_prefixes = ['LSA']
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
mtu=1500, options=0, i_flag=0, m_flag=0, ms_flag=0,
- sequence_number=0, lsa_headers=[]):
+ sequence_number=0, lsa_headers=[], type_=None):
super(OSPFDBDesc, self).__init__(OSPF_MSG_DB_DESC, length, router_id,
area_id, au_type, authentication,
checksum, version)
@@ -620,10 +639,11 @@ class OSPFLSReq(OSPFMessage):
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
- lsa_requests=[]):
+ lsa_requests=[], type_=None):
super(OSPFLSReq, self).__init__(OSPF_MSG_LS_REQ, length, router_id,
area_id, au_type, authentication,
checksum, version)
+ assert all(req.__class__ == self.Request for req in lsa_requests)
self.lsa_requests = lsa_requests
@classmethod
@@ -646,10 +666,11 @@ class OSPFLSUpd(OSPFMessage):
_PACK_STR = '!I'
_PACK_LEN = struct.calcsize(_PACK_STR)
_MIN_LEN = OSPFMessage._HDR_LEN + _PACK_LEN
+ _class_prefixes = ['RouterLSA']
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
- lsas=[]):
+ lsas=[], type_=None):
super(OSPFLSUpd, self).__init__(OSPF_MSG_LS_UPD, length, router_id,
area_id, au_type, authentication,
checksum, version)
@@ -682,10 +703,11 @@ class OSPFLSUpd(OSPFMessage):
@OSPFMessage.register_type(OSPF_MSG_LS_ACK)
class OSPFLSAck(OSPFMessage):
_MIN_LEN = OSPFMessage._HDR_LEN
+ _class_prefixes = ['LSA']
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
- lsa_headers=[]):
+ lsa_headers=[], type_=None):
super(OSPFLSAck, self).__init__(OSPF_MSG_LS_ACK, length, router_id,
area_id, au_type, authentication,
checksum, version)
--
1.8.1.2
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel