summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2014-12-29 17:16:51 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-31 07:39:50 +0900
commit350ce71bd270e562df0dbe92ea49403b08d9bc58 (patch)
treed7b81bcf30fc734535c9d75326c79e51264a014b
parentbd4bde945e5a6c2a538584bbf4257550dff49742 (diff)
ospf: add SummaryLSA class
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/ospf.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/ryu/lib/packet/ospf.py b/ryu/lib/packet/ospf.py
index a776b94d..0dfda1ab 100644
--- a/ryu/lib/packet/ospf.py
+++ b/ryu/lib/packet/ospf.py
@@ -349,7 +349,40 @@ class NetworkLSA(LSA):
@LSA.register_type(OSPF_SUMMARY_LSA)
class SummaryLSA(LSA):
- pass
+ _PACK_STR = '!4sBBH'
+ _PACK_LEN = struct.calcsize(_PACK_STR)
+
+ def __init__(self, ls_age=0, options=0, type_=OSPF_NETWORK_LSA,
+ id_='0.0.0.0', adv_router='0.0.0.0', ls_seqnum=0,
+ checksum=None, length=None, mask='0.0.0.0', tos=0, metric=0):
+ self.mask = mask
+ self.tos = tos
+ self.metric = metric
+ super(SummaryLSA, self).__init__(ls_age, options, type_, id_,
+ adv_router, ls_seqnum, checksum,
+ length)
+
+ @classmethod
+ def parser(cls, buf):
+ if len(buf) < cls._PACK_LEN:
+ raise stream_parser.StreamParser.TooSmallException(
+ '%d < %d' % (len(buf), cls_PACK_LEN))
+ buf = buf[:cls._PACK_LEN]
+ (mask, tos, metric_fst, metric_lst) = struct.unpack_from(cls._PACK_STR,
+ buffer(buf))
+ mask = addrconv.ipv4.bin_to_text(mask)
+ metric = metric_fst << 16 | (metric_lst & 0xffff)
+ return {
+ "mask": mask,
+ "tos": tos,
+ "metric": metric,
+ }
+
+ def serialize_tail(self):
+ mask = addrconv.ipv4.text_to_bin(self.mask)
+ metric_fst = (self.metric >> 16) & 0xff
+ metric_lst = self.metric & 0xffff
+ return bytearray(struct.pack(self._PACK_STR, mask, self.tos, metric))
@LSA.register_type(OSPF_ASBR_SUMMARY_LSA)