-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c0eeb9
commit ee21377
Showing
25 changed files
with
1,007 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 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 | ||
import struct | ||
import netaddr | ||
from yabgp.message.attribute.linkstate.linkstate import LinkState | ||
from yabgp.tlv import TLV | ||
|
||
# https://tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-03#section-2.2.2 | ||
# 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 | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | OSPF Neighbor ID / IS-IS System-ID | | ||
# + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | SID/Label/Index (variable) | | ||
# +---------------------------------------------------------------+ | ||
|
||
# Flags: 1 octet field of following flags: | ||
# 0 1 2 3 4 5 6 7 | ||
# +-+-+-+-+-+-+-+-+ | ||
# |F|B|V|L|S|P| | | ||
# +-+-+-+-+-+-+-+-+ | ||
|
||
|
||
@LinkState.register() | ||
class LanAdjSegID(TLV): | ||
""" | ||
Adjacency Segment id | ||
""" | ||
TYPE = 1100 | ||
TYPE_STR = 'lan-adj-segment-id' | ||
|
||
@classmethod | ||
def unpack(cls, data): | ||
flags = struct.unpack('!B', data[0])[0] | ||
F = flags >> 7 | ||
B = (flags << 1) % 256 >> 7 | ||
V = (flags << 2) % 256 >> 7 | ||
L = (flags << 3) % 256 >> 7 | ||
S = (flags << 4) % 256 >> 7 | ||
P = (flags << 5) % 256 >> 7 | ||
weight = struct.unpack('!B', data[1])[0] | ||
# nei_or_sys_id = struct.unpack('!6B', data[4:10]) | ||
nei_or_sys_id = str(netaddr.IPAddress(int(binascii.b2a_hex(data[4:10]), 16))) | ||
sid_index_label = int(binascii.b2a_hex(data[10:]), 16) | ||
# if len(data) == 3: | ||
# sid_index_label = (struct.unpack('!I', "\x00" + data)[0] << 12) >> 12 | ||
# elif len(data) == 4: | ||
# sid_index_label = struct.unpack('!I', data)[0] | ||
return cls(value={ | ||
"flags": {"F": F, "B": B, "V": V, "L": L, "S": S, "P": P}, | ||
"weight": weight, | ||
"nei_or_sys_id": nei_or_sys_id, | ||
"sid_index_label": sid_index_label | ||
}) |
42 changes: 42 additions & 0 deletions
42
yabgp/message/attribute/linkstate/link/link_identifiers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 struct | ||
|
||
from yabgp.tlv import TLV | ||
from ..linkstate import LinkState | ||
|
||
# 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 | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | Link Local Identifier | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | Link Remote Identifier | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
|
||
@LinkState.register() | ||
class LinkIdentifiers(TLV): | ||
""" | ||
link local/remote identifiers | ||
""" | ||
TYPE = 258 # RFC 7752 | ||
TYPE_STR = 'link-identifiers' | ||
|
||
@classmethod | ||
def unpack(cls, data): | ||
local_identifier = struct.unpack('!I', data[:4])[0] | ||
remote_identifier = struct.unpack('!I', data[4:])[0] | ||
|
||
return cls(value={'local-identifier': local_identifier, 'remote-identifier': remote_identifier}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 struct | ||
|
||
from yabgp.tlv import TLV | ||
from ..linkstate import LinkState | ||
|
||
|
||
@LinkState.register() | ||
class LinkMSD(TLV): | ||
""" | ||
link msd | ||
""" | ||
TYPE = 1110 # https://tools.ietf.org/html/draft-tantsura-idr-bgp-ls-segment-routing-msd-05#section-4 | ||
TYPE_STR = 'link-msd' | ||
|
||
@classmethod | ||
def unpack(cls, data): | ||
_type, value = struct.unpack('!BB', data) | ||
return cls(value={"type": _type, "value": value}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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 struct | ||
from yabgp.message.attribute.linkstate.linkstate import LinkState | ||
from yabgp.tlv import TLV | ||
|
||
# https://tools.ietf.org/html/rfc7752#section-3.3.2.2 | ||
# 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 | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# |L|R| Reserved | | ||
# +-+-+-+-+-+-+-+-+ | ||
|
||
# +------------+------------------------------------------+-----------+ | ||
# | Bit | Description | Reference | | ||
# +------------+------------------------------------------+-----------+ | ||
# | 'L' | Label Distribution Protocol (LDP) | [RFC5036] | | ||
# | 'R' | Extension to RSVP for LSP Tunnels | [RFC3209] | | ||
# | | (RSVP-TE) | | | ||
# | 'Reserved' | Reserved for future use | | | ||
# +------------+------------------------------------------+-----------+ | ||
|
||
|
||
@LinkState.register() | ||
class MplsMask(TLV): | ||
|
||
TYPE = 1094 # https://tools.ietf.org/html/rfc7752#section-3.3.2.2 | ||
TYPE_STR = "mpls-mask" | ||
|
||
@classmethod | ||
def unpack(cls, value): | ||
""" | ||
""" | ||
value = struct.unpack('!B', value)[0] | ||
L = value >> 7 | ||
R = (value << 1) % 256 >> 7 | ||
return cls(value={'L': L, 'R': R}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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 struct | ||
from yabgp.message.attribute.linkstate.linkstate import LinkState | ||
from yabgp.tlv import TLV | ||
|
||
# https://tools.ietf.org/html/rfc7752#section-3.3.2.6 | ||
# 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 | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# // Opaque link attributes (variable) // | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
|
||
@LinkState.register() | ||
class OpaLinkAttr(TLV): | ||
|
||
TYPE = 1097 # https://tools.ietf.org/html/rfc7752#section-3.3.2.6 | ||
TYPE_STR = "opa-link-attr" | ||
|
||
@classmethod | ||
def unpack(cls, value): | ||
""" | ||
""" | ||
return cls(value=struct.unpack("!%ds" % len(value), value)[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 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 struct | ||
from yabgp.message.attribute.linkstate.linkstate import LinkState | ||
from yabgp.tlv import TLV | ||
|
||
# https://tools.ietf.org/html/rfc5307#section-1.2 | ||
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# |Protection Cap | Reserved | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
# 0x01 Extra Traffic | ||
# 0x02 Unprotected | ||
# 0x04 Shared | ||
# 0x08 Dedicated 1:1 | ||
# 0x10 Dedicated 1+1 | ||
# 0x20 Enhanced | ||
# 0x40 Reserved | ||
# 0x80 Reserved | ||
|
||
|
||
@LinkState.register() | ||
class ProtectionType(TLV): | ||
|
||
TYPE = 1093 # https://tools.ietf.org/html/rfc5307#section-1.2 | ||
TYPE_STR = "protection-type" | ||
|
||
@classmethod | ||
def unpack(cls, value): | ||
""" | ||
""" | ||
value = struct.unpack('!B', value[0])[0] | ||
if value == 0x01: | ||
return cls(value='Extra Traffic') | ||
if value == 0x02: | ||
return cls(value='Unprotected') | ||
if value == 0x04: | ||
return cls(value='Shared') | ||
if value == 0x08: | ||
return cls(value='Dedicated 1:1') | ||
if value == 0x10: | ||
return cls(value='Dedicated 1+1') | ||
if value == 0x20: | ||
return cls(value='Enhanced') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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 struct | ||
from yabgp.message.attribute.linkstate.linkstate import LinkState | ||
from yabgp.tlv import TLV | ||
|
||
# https://tools.ietf.org/html/rfc7752#section-3.3.2.5 | ||
# 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 | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | Shared Risk Link Group Value | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# // ............ // | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
# | Shared Risk Link Group Value | | ||
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
|
||
@LinkState.register() | ||
class SRLGList(TLV): | ||
|
||
TYPE = 1096 # https://tools.ietf.org/html/rfc7752#section-3.3.2.5 | ||
TYPE_STR = "srlg-list" | ||
|
||
@classmethod | ||
def unpack(cls, value): | ||
""" | ||
""" | ||
results = [] | ||
while value: | ||
results.append(struct.unpack('!L', value[:4])[0]) | ||
value = value[4:] | ||
return cls(value=results) |
Oops, something went wrong.