Skip to content

Commit

Permalink
add packet loss and bw (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlpqingmei authored and xiaopeng163 committed Aug 10, 2018
1 parent 54c7fa4 commit 7123e9d
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 7 deletions.
7 changes: 6 additions & 1 deletion yabgp/message/attribute/linkstate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@
from .link.opa_link_attr import OpaLinkAttr # noqa
from .link.peer_node_sid import PeerNodeSID # noqa
from .link.peer_adj_sid import PeerAdjSID # noqa
from .link.peer_set_sid import PeerSetSID # noqa
from .link.unidirect_link_delay import UnidirectLinkDelay # noqa
from .link.min_max_link_delay import MinMaxUnidirectLinkDelay # noqa
from .link.unidirct_delay_var import UnidirectDelayVar # noqa
from .link.unidirect_delay_var import UnidirectDelayVar # noqa
from .link.unidirect_packet_loss import UnidirectPacketLoss # noqa
from .link.unidirect_residual_bw import UnidirectResidualBw # noqa
from .link.unidirect_avail_bw import UnidirectAvailBw # noqa
from .link.unidirect_bw_util import UnidirectBwUtil # noqa
from .prefix.prefix_metric import PrefixMetric # noqa
from .prefix.prefix_sid import PrefixSID # noqa
from .prefix.prefix_igp_attr import PrefixIGPAttr # noqa
Expand Down
7 changes: 7 additions & 0 deletions yabgp/message/attribute/linkstate/link/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@
# | | Link Delay | |
# | 1116 | Unidirectional Delay | 4 |
# | | Variation | |
# | 1117 | Unidirectional Packet Loss| 4 |
# | 1118 | Unidirectional Residual | 4 |
# | | Bandwidth | |
# | 1119 | Unidirectional Available | 4 |
# | | Bandwidth | |
# | 1120 | Unidirectional Bandwidth | 4 |
# | | Utilization | |
# +----------+---------------------------+----------+
55 changes: 55 additions & 0 deletions yabgp/message/attribute/linkstate/link/peer_set_sid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2015-2018 Cisco Systems, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import binascii

from yabgp.tlv import TLV
from ..linkstate import LinkState


# 0 1 2 3
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Type | Length |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Flags | Weight | Reserved |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | SID/Label/Index (variable) |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

# 0 1 2 3 4 5 6 7
# +-+-+-+-+-+-+-+-+
# |V|L|B|P| |
# +-+-+-+-+-+-+-+-+


@LinkState.register()
class PeerSetSID(TLV):
"""
Peer Set Segment Identifier (Peer-Set-SID)
"""
TYPE = 1103
TYPE_STR = 'peer_set_sid'

@classmethod
def unpack(cls, data):
flags = ord(data[0:1])
flag = {}
flag['V'] = flags >> 7
flag['L'] = (flags << 1) % 256 >> 7
flag['B'] = (flags << 2) % 256 >> 7
flag['P'] = (flags << 3) % 256 >> 7
weight = ord(data[1:2])
return cls(value={"flags": flag, "weight": weight, "value": int(binascii.b2a_hex(data[4:]), 16)})
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/unidirect_avail_bw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2018 Cisco Systems, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import binascii

from yabgp.tlv import TLV
from ..linkstate import LinkState


@LinkState.register(_type=1119)
class UnidirectAvailBw(TLV):
"""
Unidirectional Delay Variation
"""
# TYPE = 1116 # https://tools.ietf.org/html/draft-ietf-idr-te-pm-bgp-10#section-3.6
TYPE_STR = 'unidirect_avail_bw'

@classmethod
def unpack(cls, data):
value = int(binascii.b2a_hex(data), 16)
return cls(value=value)
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/unidirect_bw_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2018 Cisco Systems, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import binascii

from yabgp.tlv import TLV
from ..linkstate import LinkState


@LinkState.register(_type=1120)
class UnidirectBwUtil(TLV):
"""
Unidirectional Delay Variation
"""
# TYPE = 1116 # https://tools.ietf.org/html/draft-ietf-idr-te-pm-bgp-10#section-3.7
TYPE_STR = 'unidirect_bw_util'

@classmethod
def unpack(cls, data):
value = int(binascii.b2a_hex(data), 16)
return cls(value=value)
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/unidirect_packet_loss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2018 Cisco Systems, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import binascii

from yabgp.tlv import TLV
from ..linkstate import LinkState


@LinkState.register(_type=1117)
class UnidirectPacketLoss(TLV):
"""
Unidirectional Delay Variation
"""
# TYPE = 1116 # https://tools.ietf.org/html/draft-ietf-idr-te-pm-bgp-10#section-3.4
TYPE_STR = 'unidirect_packet_loss'

@classmethod
def unpack(cls, data):
value = int(binascii.b2a_hex(data), 16)
return cls(value=value)
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/unidirect_residual_bw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2018 Cisco Systems, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import binascii

from yabgp.tlv import TLV
from ..linkstate import LinkState


@LinkState.register(_type=1118)
class UnidirectResidualBw(TLV):
"""
Unidirectional Delay Variation
"""
# TYPE = 1116 # https://tools.ietf.org/html/draft-ietf-idr-te-pm-bgp-10#section-3.5
TYPE_STR = 'unidirect_residual_bw'

@classmethod
def unpack(cls, data):
value = int(binascii.b2a_hex(data), 16)
return cls(value=value)
13 changes: 8 additions & 5 deletions yabgp/tests/unit/message/attribute/nlri/test_blgls_epe.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def test_parse(self):
self.maxDiff = None
data_bin = b"\x00\x02\x00\x51\x07\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00" \
b"\x18\x02\x00\x00\x04\x00\x00\x00\xc8\x02\x01\x00\x04\x00\x00\x00" \
b"\x00\x02\x04\x00\x04\x03\x03\x03\x03\x01\x01\x00\x18\x02\x00\x00" \
b"\x04\x00\x00\x01\x2c\x02\x01\x00\x04\x00\x00\x00\x00\x02\x04\x00" \
b"\x04\x04\x04\x04\x04\x01\x03\x00\x04\xc0\xa8\x04\x03\x01\x04\x00" \
b"\x00\x02\x05\x00\x04\x00\x00\x00" \
b"\xc8\x01\x01\x00\x18\x02\x00\x00\x04\x00\x00\x01\x2c\x02\x01\x00" \
b"\x04\x00\x00\x00\x00\x02\x05\x00" \
b"\x04\x00\x00\x01\x2c\x01\x03\x00\x04\xc0\xa8\x04\x03\x01\x04\x00" \
b"\x04\xc0\xa8\x04\x04"
data_dict = [
{
Expand All @@ -39,13 +40,15 @@ def test_parse(self):
'value': {
'as_num': 200,
'bgpls_id': '0.0.0.0',
'bgp_router_id': '3.3.3.3'}},
# 'bgp_router_id': '3.3.3.3',
'member_as_num': 200}},
{
'type': 'remote_node',
'value': {
'as_num': 300,
'bgpls_id': '0.0.0.0',
'bgp_router_id': '4.4.4.4'}},
# 'bgp_router_id': '4.4.4.4',
'member_as_num': 300}},
{
'type': 'link_local_ipv4',
'value': '192.168.4.3'},
Expand Down
16 changes: 15 additions & 1 deletion yabgp/tests/unit/message/attribute/nlri/test_linkdelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def test_unpack(self):
b"\x00\x00\x00\x00\x04\x44\x00\x04\x00\x00\x00\x01\x04\x47\x00\x03" \
b"\x00\x00\x01\x04\x4b\x00\x07\x60\x00\x00\x00\x00\x5d\xc1\x01\x0b" \
b"\x00\x02\x01\x0a\x04\x5a\x00\x04\x00\x0f\x42\x40\x04\x5b\x00\x08" \
b"\x00\x0f\x42\x40\x00\x0f\x42\x40\x04\x5c\x00\x04\x00\x00\x00\x00"
b"\x00\x0f\x42\x40\x00\x0f\x42\x40\x04\x5c\x00\x04\x00\x00\x00\x00" \
b"\x04\x5d\x00\x04\x11\x11\x11\x11\x04\x5e\x00\x04\x11\x11\x11\x11" \
b"\x04\x5f\x00\x04\x11\x11\x11\x11\x04\x60\x00\x04\x11\x11\x11\x11"

data_dict = {29: [{
"type": "local_router_id",
Expand Down Expand Up @@ -84,6 +86,18 @@ def test_unpack(self):
}, {
"type": "unidirect_delay_var",
"value": 0
}, {
"type": "unidirect_packet_loss",
"value": 286331153
}, {
"type": "unidirect_residual_bw",
"value": 286331153
}, {
"type": "unidirect_avail_bw",
"value": 286331153
}, {
"type": "unidirect_bw_util",
"value": 286331153
}]}

self.assertEqual(data_dict, LinkState.unpack(data_bin).dict())

0 comments on commit 7123e9d

Please sign in to comment.