Skip to content

Commit

Permalink
more tlvs for bgpls
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Xiao <xiaoquwl@gmail.com>
  • Loading branch information
xiaopeng163 committed May 4, 2017
1 parent 51bf0ca commit 90a42b4
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 68 deletions.
67 changes: 0 additions & 67 deletions yabgp/message/attribute/linkstate.py

This file was deleted.

27 changes: 27 additions & 0 deletions yabgp/message/attribute/linkstate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2015-2017 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.

from .linkstate import LinkState # noqa
from .node.local_router_id import LocalRouterID # noqa
from .node.name import NodeName # noqa
from .node.isisarea import ISISArea # noqa
from .link.admingroup import AdminGroup # noqa
from .link.remote_router_id import RemoteRouterID # noqa
from .link.max_bw import MaxBandwidth # noqa
from .link.max_rsv_bw import MaxResvBandwidth # noqa
from .link.unsrv_bw import UnrsvBandwidth # noqa
from .link.te_metric import TeMetric # noqa
from .link.link_name import LinkName # noqa
from .link.igp_metric import IGPMetric # noqa
34 changes: 34 additions & 0 deletions yabgp/message/attribute/linkstate/link/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# #
# +-----------+---------------------+--------------+------------------+
# | TLV Code | Description | IS-IS TLV | Reference |
# | Point | | /Sub-TLV | (RFC/Section) |
# +-----------+---------------------+--------------+------------------+
# | 1028 | IPv4 Router-ID of | 134/--- | [RFC5305]/4.3 |
# | | Local Node | | |
# | 1029 | IPv6 Router-ID of | 140/--- | [RFC6119]/4.1 |
# | | Local Node | | |
# | 1030 | IPv4 Router-ID of | 134/--- | [RFC5305]/4.3 |
# | | Remote Node | | |
# | 1031 | IPv6 Router-ID of | 140/--- | [RFC6119]/4.1 |
# | | Remote Node | | |
# | 1088 | Administrative | 22/3 | [RFC5305]/3.1 |
# | | group (color) | | |
# | 1089 | Maximum link | 22/9 | [RFC5305]/3.4 |
# | | bandwidth | | |
# | 1090 | Max. reservable | 22/10 | [RFC5305]/3.5 |
# | | link bandwidth | | |
# | 1091 | Unreserved | 22/11 | [RFC5305]/3.6 |
# | | bandwidth | | |
# | 1092 | TE Default Metric | 22/18 | Section 3.3.2.3 |
# | 1093 | Link Protection | 22/20 | [RFC5307]/1.2 |
# | | Type | | |
# | 1094 | MPLS Protocol Mask | --- | Section 3.3.2.2 |
# | 1095 | IGP Metric | --- | Section 3.3.2.4 |
# | 1096 | Shared Risk Link | --- | Section 3.3.2.5 |
# | | Group | | |
# | 1097 | Opaque Link | --- | Section 3.3.2.6 |
# | | Attribute | | |
# | 1098 | Link Name | --- | Section 3.3.2.7 |
# +-----------+---------------------+--------------+------------------+

# Table 9: Link Attribute TLVs
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/admingroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2017 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()
class AdminGroup(TLV):
"""
admin group
"""
TYPE = 1088
TYPE_STR = 'admin-group'

@classmethod
def unpack(cls, data):

return cls(value=int(binascii.b2a_hex(data), 16))
38 changes: 38 additions & 0 deletions yabgp/message/attribute/linkstate/link/igp_metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2015-2017 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 struct
import binascii

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


@LinkState.register()
class IGPMetric(TLV):
"""
IGP Metric
"""
TYPE = 1095
TYPE_STR = 'igp-metric'

@classmethod
def unpack(cls, data):
if len(data) == 2:
return cls(value=struct.unpack('!H', data)[0])
elif len(data) == 1:
return cls(value=struct.unpack('!B', data)[0])
elif len(data) == 3:
return cls(value=int(binascii.b2a_hex(data), 16))
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/link_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2017 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()
class LinkName(TLV):
"""
link name
"""
TYPE = 1098
TYPE_STR = 'link-name'

@classmethod
def unpack(cls, data):

return cls(value=binascii.b2a_uu(data))
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/max_bw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2017 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 struct

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


@LinkState.register()
class MaxBandwidth(TLV):
"""
max bandwidth
"""
TYPE = 1089
TYPE_STR = 'max-bandwidth'

@classmethod
def unpack(cls, data):

return cls(value=struct.unpack('!f', data)[0])
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/max_rsv_bw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2017 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 struct

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


@LinkState.register()
class MaxResvBandwidth(TLV):
"""
max reserved bandwidth
"""
TYPE = 1090
TYPE_STR = 'max-rsv-bandwidth'

@classmethod
def unpack(cls, data):

return cls(value=struct.unpack('!f', data)[0])
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/remote_router_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2017 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.

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


@LinkState.register(_type=1030)
@LinkState.register(_type=1031)
class RemoteRouterID(TLV):
"""
remote ipv4 or ipv6 router id
"""
TYPE_STR = 'remote-router-id'

@classmethod
def unpack(cls, data):

router_id = IPAddress.unpack(data)
return cls(value=router_id)
33 changes: 33 additions & 0 deletions yabgp/message/attribute/linkstate/link/te_metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015-2017 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 struct

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


@LinkState.register()
class TeMetric(TLV):
"""
TE metric
"""
TYPE = 1092
TYPE_STR = 'te-metric'

@classmethod
def unpack(cls, data):

return cls(value=struct.unpack('!L', data)[0])

0 comments on commit 90a42b4

Please sign in to comment.