idnits 2.17.1 draft-ietf-idr-flow-spec-v6-14.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (August 12, 2020) is 1343 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '1' on line 540 == Unused Reference: 'RFC4271' is defined on line 500, but no explicit reference was found in the text == Outdated reference: A later version (-27) exists of draft-ietf-idr-rfc5575bis-25 Summary: 0 errors (**), 0 flaws (~~), 3 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 IDR Working Group C. Loibl, Ed. 3 Internet-Draft next layer Telekom GmbH 4 Intended status: Standards Track R. Raszuk, Ed. 5 Expires: February 13, 2021 Bloomberg LP 6 S. Hares, Ed. 7 Huawei 8 August 12, 2020 10 Dissemination of Flow Specification Rules for IPv6 11 draft-ietf-idr-flow-spec-v6-14 13 Abstract 15 Dissemination of Flow Specification Rules I-D.ietf-idr-rfc5575bis 16 provides a protocol extension for propagation of traffic flow 17 information for the purpose of rate limiting or filtering. I-D.ietf- 18 idr-rfc5575bis specifies those extensions for IPv4 protocol data 19 packets only. 21 This specification extends I-D.ietf-idr-rfc5575bis and defines 22 changes to the original document in order to make it also usable and 23 applicable to IPv6 data packets. 25 Status of This Memo 27 This Internet-Draft is submitted in full conformance with the 28 provisions of BCP 78 and BCP 79. 30 Internet-Drafts are working documents of the Internet Engineering 31 Task Force (IETF). Note that other groups may also distribute 32 working documents as Internet-Drafts. The list of current Internet- 33 Drafts is at https://datatracker.ietf.org/drafts/current/. 35 Internet-Drafts are draft documents valid for a maximum of six months 36 and may be updated, replaced, or obsoleted by other documents at any 37 time. It is inappropriate to use Internet-Drafts as reference 38 material or to cite them other than as "work in progress." 40 This Internet-Draft will expire on February 13, 2021. 42 Copyright Notice 44 Copyright (c) 2020 IETF Trust and the persons identified as the 45 document authors. All rights reserved. 47 This document is subject to BCP 78 and the IETF Trust's Legal 48 Provisions Relating to IETF Documents 49 (https://trustee.ietf.org/license-info) in effect on the date of 50 publication of this document. Please review these documents 51 carefully, as they describe your rights and restrictions with respect 52 to this document. Code Components extracted from this document must 53 include Simplified BSD License text as described in Section 4.e of 54 the Trust Legal Provisions and are provided without warranty as 55 described in the Simplified BSD License. 57 Table of Contents 59 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 60 1.1. Definitions of Terms Used in This Memo . . . . . . . . . 3 61 2. IPv6 Flow Specification encoding in BGP . . . . . . . . . . . 3 62 3. IPv6 Flow Specification components . . . . . . . . . . . . . 4 63 3.1. Type 1 - Destination IPv6 Prefix . . . . . . . . . . . . 4 64 3.2. Type 2 - Source IPv6 Prefix . . . . . . . . . . . . . . . 4 65 3.3. Type 3 - Next Header . . . . . . . . . . . . . . . . . . 4 66 3.4. Type 7 - ICMPv6 type . . . . . . . . . . . . . . . . . . 5 67 3.5. Type 8 - ICMPv6 code . . . . . . . . . . . . . . . . . . 5 68 3.6. Type 12 - Fragment . . . . . . . . . . . . . . . . . . . 5 69 3.7. Type 13 - Flow Label (new) . . . . . . . . . . . . . . . 6 70 3.8. Encoding Example . . . . . . . . . . . . . . . . . . . . 6 71 4. Ordering of Flow Specifications . . . . . . . . . . . . . . . 8 72 5. Validation Procedure . . . . . . . . . . . . . . . . . . . . 8 73 6. IPv6 Traffic Filtering Action changes . . . . . . . . . . . . 8 74 6.1. Redirect IPv6 (rt-redirect-ipv6) Type/Sub-Type 0x80/TBD . 9 75 7. Security Considerations . . . . . . . . . . . . . . . . . . . 9 76 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9 77 9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 11 78 10. Contributors . . . . . . . . . . . . . . . . . . . . . . . . 11 79 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 11 80 11.1. Normative References . . . . . . . . . . . . . . . . . . 12 81 11.2. URIs . . . . . . . . . . . . . . . . . . . . . . . . . . 13 82 Appendix A. Example python code: flow_rule_cmp_v6 . . . . . . . 13 83 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 16 85 1. Introduction 87 The growing amount of IPv6 traffic in private and public networks 88 requires the extension of tools used in the IPv4 only networks to be 89 also capable of supporting IPv6 data packets. 91 In this document authors analyze the differences of IPv6 [RFC8200] 92 flows description from those of traditional IPv4 packets and propose 93 subset of new encoding formats to enable Dissemination of Flow 94 Specification Rules [I-D.ietf-idr-rfc5575bis] for IPv6. 96 This specification should be treated as an extension of base 97 [I-D.ietf-idr-rfc5575bis] specification and not its replacement. It 98 only defines the delta changes required to support IPv6 while all 99 other definitions and operation mechanisms of Dissemination of Flow 100 Specification Rules will remain in the main specification and will 101 not be repeated here. 103 1.1. Definitions of Terms Used in This Memo 105 AFI - Address Family Identifier. 107 AS - Autonomous System. 109 NLRI - Network Layer Reachability Information. 111 SAFI - Subsequent Address Family Identifier. 113 VRF - Virtual Routing and Forwarding instance. 115 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 116 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 117 "OPTIONAL" in this document are to be interpreted as described in BCP 118 14 [RFC2119] [RFC8174] when, and only when, they appear in all 119 capitals, as shown here. 121 2. IPv6 Flow Specification encoding in BGP 123 The [I-D.ietf-idr-rfc5575bis] defines new SAFIs 133 (Dissemination of 124 Flow Specification) and 134 (L3VPN Dissemination of Flow 125 Specification) applications in order to carry corresponding to each 126 such application Flow Specification. 128 Implementations wishing to exchange IPv6 Flow Specifications MUST use 129 BGP's Capability Advertisement facility to exchange the Multiprotocol 130 Extension Capability Code (Code 1) as defined in [RFC4760]. While 131 [I-D.ietf-idr-rfc5575bis] specifies Flow Specification for IPv4 132 (AFI=1) only, the (AFI, SAFI) pair carried in the Multiprotocol 133 Extension Capability MUST be: (AFI=2, SAFI=133) for IPv6 Flow 134 Specification, and (AFI=2, SAFI=134) for VPNv6 Flow Specification. 136 For both SAFIs the indication to which address family they are 137 referring to will be recognized by AFI value (AFI=1 for IPv4 or 138 VPNv4, AFI=2 for IPv6 and VPNv6 respectively). 140 It needs to be observed that such choice of proposed encoding is 141 compatible with filter validation against routing reachability 142 information as described in Section 6 of [I-D.ietf-idr-rfc5575bis]. 144 3. IPv6 Flow Specification components 146 The following components are redefined or added for the purpose of 147 accommodating the IPv6 header encoding. Unless otherwise specified 148 all other components defined in [I-D.ietf-idr-rfc5575bis] 149 Section 4.2.2 also apply to IPv6 Flow Specification. 151 3.1. Type 1 - Destination IPv6 Prefix 153 Encoding: 156 Defines the destination prefix to match. The offset has been defined 157 to allow for flexible matching on part of the IPv6 address where it 158 is required to skip (don't care) of N first bits of the address. 159 This can be especially useful where part of the IPv6 address consists 160 of an embedded IPv4 address and matching needs to happen only on the 161 embedded IPv4 address. The encoded prefix contains enough octets for 162 the bits used in matching (length minus offset bits). 164 3.2. Type 2 - Source IPv6 Prefix 166 Encoding: 169 Defines the source prefix to match. The length, offset and prefix 170 are the same as in Section 3.1 172 3.3. Type 3 - Next Header 174 Encoding: 176 Contains a list of {numeric_op, value} pairs that are used to match 177 the last Next Header ([RFC8200] Section 3) value octet in IPv6 178 packets. 180 This component uses the Numeric Operator (numeric_op) described in 181 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 3 component values 182 SHOULD be encoded as single byte (numeric_op len=00). 184 Note: While IPv6 allows for more then one Next Header field in the 185 packet the main goal of Type 3 flow specification component is to 186 match on the subsequent IP protocol value. Therefore the definition 187 is limited to match only on last Next Header field in the packet. 189 3.4. Type 7 - ICMPv6 type 191 Encoding: 193 Defines a list of {numeric_op, value} pairs used to match the type 194 field of an ICMPv6 packet (see also [RFC4443] Section 2.1). 196 This component uses the Numeric Operator (numeric_op) described in 197 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 7 component values 198 SHOULD be encoded as single byte (numeric_op len=00). 200 In case of the presence of the ICMPv6 type component only ICMPv6 201 packets can match the entire Flow Specification. The ICMPv6 type 202 component, if present, never matches when the packet's last Next 203 Header field value is not 58 (ICMPv6), if the packet is fragmented 204 and this is not the first fragment, or if the system is unable to 205 locate the transport header. Different implementations may or may 206 not be able to decode the transport header. 208 3.5. Type 8 - ICMPv6 code 210 Encoding: 212 Defines a list of {numeric_op, value} pairs used to match the code 213 field of an ICMPv6 packet (see also [RFC4443] Section 2.1). 215 This component uses the Numeric Operator (numeric_op) described in 216 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 8 component values 217 SHOULD be encoded as single byte (numeric_op len=00). 219 In case of the presence of the ICMPv6 code component only ICMPv6 220 packets can match the entire Flow Specification. The ICMPv6 code 221 component, if present, never matches when the packet's last Next 222 Header field value is not 58 (ICMPv6), if the packet is fragmented 223 and this is not the first fragment, or if the system is unable to 224 locate the transport header. Different implementations may or may 225 not be able to decode the transport header. 227 3.6. Type 12 - Fragment 229 Encoding: 231 Defines a list of {bitmask_op, bitmask} pairs used to match specific 232 IP fragments. 234 This component uses the Bitmask Operator (bitmask_op) described in 235 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.2. The Type 12 component 236 bitmask MUST be encoded as single byte bitmask (bitmask_op len=00). 238 0 1 2 3 4 5 6 7 239 +---+---+---+---+---+---+---+---+ 240 | 0 | 0 | 0 | 0 |LF |FF |IsF| 0 | 241 +---+---+---+---+---+---+---+---+ 243 Figure 1: Fragment Bitmask Operand 245 Bitmask values: 247 IsF - Is a fragment - match if IPv6 Fragment Header ([RFC8200] 248 Section 4.5) Fragment Offset is not 0 250 FF - First fragment - match if IPv6 Fragment Header ([RFC8200] 251 Section 4.5) Fragment Offset is 0 AND M flag is 1 253 LF - Last fragment - match if IPv6 Fragment Header ([RFC8200] 254 Section 4.5) Fragment Offset is not 0 AND M flag is 0 256 0 - MUST be set to 0 on NLRI encoding, and MUST be ignored during 257 decoding 259 3.7. Type 13 - Flow Label (new) 261 Encoding: 263 Contains a list of {numeric_op, value} pairs that are used to match 264 the 20-bit Flow Label IPv6 header field ([RFC8200] Section 3). 266 This component uses the Numeric Operator (numeric_op) described in 267 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 13 component values 268 SHOULD be encoded as 1-, 2-, or 4-byte quantities (numeric_op len=00, 269 len=01 or len=10). 271 3.8. Encoding Example 273 3.8.1. Example 1 275 The following example demonstrates the prefix encoding for: "all 276 packets to ::1234:5678:9A00:0/64-104 from 100::/8 and port 25". 278 +--------+-------------------------+-------------+----------+ 279 | length | destination | source | port | 280 +--------+-------------------------+-------------+----------+ 281 | 0x0f | 01 68 40 12 34 56 78 9A | 02 08 00 01 | 04 81 19 | 282 +--------+-------------------------+-------------+----------+ 284 Decoded: 286 +-------+------------+------------------------------+ 287 | Value | | | 288 +-------+------------+------------------------------+ 289 | 0x0f | length | 16 octets (len<240 1-octet) | 290 | 0x01 | type | Type 1 - Dest. IPv6 Prefix | 291 | 0x68 | length | 104 bit | 292 | 0x40 | offset | 64 bit | 293 | 0x12 | prefix | | 294 | 0x34 | prefix | | 295 | 0x56 | prefix | | 296 | 0x78 | prefix | | 297 | 0x9A | prefix | | 298 | 0x02 | type | Type 2 - Source IPv6 Prefix | 299 | 0x08 | length | 8 bit | 300 | 0x00 | offset | 0 bit | 301 | 0x01 | prefix | | 302 | 0x04 | type | Type 4 - Port | 303 | 0x81 | numeric_op | end-of-list, value size=1, = | 304 | 0x19 | value | 25 | 305 +-------+------------+------------------------------+ 307 This constitutes a NLRI with a NLRI length of 16 octets. 309 3.8.2. Example 2 311 The following example demonstrates the prefix encoding for: "all 312 packets to ::1234:5678:9A00:0/65-104". 314 +--------+-------------------------+ 315 | length | destination | 316 +--------+-------------------------+ 317 | 0x08 | 01 68 41 24 68 ac f1 34 | 318 +--------+-------------------------+ 320 Decoded: 322 +-------+------------+------------------------------+ 323 | Value | | | 324 +-------+------------+------------------------------+ 325 | 0x08 | length | 8 octets (len<240 1-octet) | 326 | 0x01 | type | Type 1 - Dest. IPv6 Prefix | 327 | 0x68 | length | 104 bit | 328 | 0x41 | offset | 65 bit | 329 | 0x24 | prefix | starting with the 66ths bit | 330 | 0x68 | prefix | | 331 | 0xac | prefix | | 332 | 0xf1 | prefix | | 333 | 0x34 | prefix | | 334 +-------+------------+------------------------------+ 336 This constitutes a NLRI with a NLRI length of 8 octets. 338 4. Ordering of Flow Specifications 340 The definition for the order of traffic filtering rules from 341 [I-D.ietf-idr-rfc5575bis] Section 5.1 can be reused with new 342 consideration for the IPv6 prefix offset. As long as the offsets are 343 equal, the comparison is the same, retaining longest-prefix-match 344 semantics. If the offsets are not equal, the lowest offset has 345 precedence, as this flow matches the most significant bit. 347 The code in Appendix A shows a Python3 implementation of the 348 resulting comparison algorithm. The full code was tested with Python 349 3.7.2 and can be obtained at https://github.com/stoffi92/draft-ietf- 350 idr-flow-spec-v6/tree/master/flowspec-cmp [1]. 352 5. Validation Procedure 354 The validation procedure is the same as specified in 355 [I-D.ietf-idr-rfc5575bis] Section 6 with the exception that item a) 356 of the validation procedure should now read as follows: 358 a) A destination prefix component with offset=0 is embedded in the 359 Flow Specification 361 6. IPv6 Traffic Filtering Action changes 363 Traffic Filtering Actions from [I-D.ietf-idr-rfc5575bis] Section 7 364 can also be applied to IPv6 Flow Specifications. To allow an IPv6 365 address specific route-target, a new Traffic Filtering Action IPv6 366 address specific extended community is specified in Section 6.1 367 below: 369 6.1. Redirect IPv6 (rt-redirect-ipv6) Type/Sub-Type 0x80/TBD 371 The redirect IPv6 address specific extended community allows the 372 traffic to be redirected to a VRF routing instance that lists the 373 specified IPv6 address specific route-target in its import policy. 374 If several local instances match this criteria, the choice between 375 them is a local matter (for example, the instance with the lowest 376 Route Distinguisher value can be elected). 378 This extended community uses the same encoding as the IPv6 address 379 specific Route Target extended community [RFC5701] Section 2 with the 380 high-order octet of the Type always set to 0x80 and the Sub-Type 381 always TBD. 383 Interferes with: All BGP Flow Specification redirect Traffic 384 Filtering Actions (with itself and those specified in 385 [I-D.ietf-idr-rfc5575bis] Section 7.4). 387 7. Security Considerations 389 No new security issues are introduced to the BGP protocol by this 390 specification over the security considerations in 391 [I-D.ietf-idr-rfc5575bis] 393 8. IANA Considerations 395 This section complies with [RFC7153] 397 IANA is requested to create and maintain a new registry entitled: 398 "Flow Spec IPv6 Component Types" containing the initial entries as 399 specified in Table 1. 401 +-------+-------------------------+-----------------+ 402 | Value | Name | Reference | 403 +-------+-------------------------+-----------------+ 404 | 1 | Destination IPv6 Prefix | [this document] | 405 | 2 | Source IPv6 Prefix | [this document] | 406 | 3 | Next Header | [this document] | 407 | 4 | Port | [this document] | 408 | 5 | Destination port | [this document] | 409 | 6 | Source port | [this document] | 410 | 7 | ICMPv6 type | [this document] | 411 | 8 | ICMPv6 code | [this document] | 412 | 9 | TCP flags | [this document] | 413 | 10 | Packet length | [this document] | 414 | 11 | DSCP | [this document] | 415 | 12 | Fragment | [this document] | 416 | 13 | Flow Label | [this document] | 417 +-------+-------------------------+-----------------+ 419 Table 1: Registry: Flow Spec IPv6 Component Types 421 In order to manage the limited number space and accommodate several 422 usages, the following policies defined by [RFC8126] are used: 424 +--------------+------------------------+ 425 | Type Values | Policy | 426 +--------------+------------------------+ 427 | 0 | Reserved | 428 | [1 .. 127] | Specification Required | 429 | [128 .. 254] | Expert Review | 430 | 255 | Reserved | 431 +--------------+------------------------+ 433 Table 2: Flow Spec IPv6 Component Types Registration Policy 435 Guidance for Experts: 436 128-254 requires Expert Review as the registration policy. The 437 Experts are expected to check the clarity of purpose and use of 438 the requested code points. The Experts must also verify that 439 any specification produced in the IETF that requests one of 440 these code points has been made available for review by the IDR 441 working group and that any specification produced outside the 442 IETF does not conflict with work that is active or already 443 published within the IETF. It must be pointed out that 444 introducing new component types may break interoperability with 445 existing implementations of this protocol. 447 IANA maintains a registry entitled "Generic Transitive Experimental 448 Use Extended Community Sub-Types". For the purpose of this work, 449 IANA is requested to assign a new value: 451 +------------+----------------------------------------+-------------+ 452 | Sub-Type | Name | Reference | 453 | Value | | | 454 +------------+----------------------------------------+-------------+ 455 | TBD | Flow spec rt-redirect-ipv6 | [this | 456 | | format | document] | 457 +------------+----------------------------------------+-------------+ 459 Table 3: Registry: Generic Transitive Experimental Use Extended 460 Community Sub-Types 462 9. Acknowledgements 464 Authors would like to thank Pedro Marques, Hannes Gredler and Bruno 465 Rijsman, Brian Carpenter, and Thomas Mangin for their valuable input. 467 10. Contributors 469 Danny McPherson 470 Verisign, Inc. 472 Email: dmcpherson@verisign.com 474 Burjiz Pithawala 475 Individual 477 Email: burjizp@gmail.com 479 Andy Karch 480 Cisco Systems 481 170 West Tasman Drive 482 San Jose, CA 95134 483 USA 485 Email: akarch@cisco.com 487 11. References 488 11.1. Normative References 490 [I-D.ietf-idr-rfc5575bis] 491 Loibl, C., Hares, S., Raszuk, R., McPherson, D., and M. 492 Bacher, "Dissemination of Flow Specification Rules", 493 draft-ietf-idr-rfc5575bis-25 (work in progress), May 2020. 495 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 496 Requirement Levels", BCP 14, RFC 2119, 497 DOI 10.17487/RFC2119, March 1997, 498 . 500 [RFC4271] Rekhter, Y., Ed., Li, T., Ed., and S. Hares, Ed., "A 501 Border Gateway Protocol 4 (BGP-4)", RFC 4271, 502 DOI 10.17487/RFC4271, January 2006, 503 . 505 [RFC4443] Conta, A., Deering, S., and M. Gupta, Ed., "Internet 506 Control Message Protocol (ICMPv6) for the Internet 507 Protocol Version 6 (IPv6) Specification", STD 89, 508 RFC 4443, DOI 10.17487/RFC4443, March 2006, 509 . 511 [RFC4760] Bates, T., Chandra, R., Katz, D., and Y. Rekhter, 512 "Multiprotocol Extensions for BGP-4", RFC 4760, 513 DOI 10.17487/RFC4760, January 2007, 514 . 516 [RFC5701] Rekhter, Y., "IPv6 Address Specific BGP Extended Community 517 Attribute", RFC 5701, DOI 10.17487/RFC5701, November 2009, 518 . 520 [RFC7153] Rosen, E. and Y. Rekhter, "IANA Registries for BGP 521 Extended Communities", RFC 7153, DOI 10.17487/RFC7153, 522 March 2014, . 524 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 525 Writing an IANA Considerations Section in RFCs", BCP 26, 526 RFC 8126, DOI 10.17487/RFC8126, June 2017, 527 . 529 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 530 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 531 May 2017, . 533 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 534 (IPv6) Specification", STD 86, RFC 8200, 535 DOI 10.17487/RFC8200, July 2017, 536 . 538 11.2. URIs 540 [1] https://github.com/stoffi92/draft-ietf-idr-flow-spec- 541 v6/tree/master/flowspec-cmp 543 Appendix A. Example python code: flow_rule_cmp_v6 545 546 """ 547 Copyright (c) 2020 IETF Trust and the persons identified as authors 548 of draft-ietf-idr-flow-spec-v6. All rights reserved. 550 Redistribution and use in source and binary forms, with or without 551 modification, is permitted pursuant to, and subject to the license 552 terms contained in, the Simplified BSD License set forth in Section 553 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents 554 (http://trustee.ietf.org/license-info). 555 """ 557 import itertools 558 import collections 559 import ipaddress 561 EQUAL = 0 562 A_HAS_PRECEDENCE = 1 563 B_HAS_PRECEDENCE = 2 564 IP_DESTINATION = 1 565 IP_SOURCE = 2 567 FS_component = collections.namedtuple('FS_component', 568 'component_type value') 570 class FS_IPv6_prefix_component: 571 def __init__(self, prefix, offset=0, 572 component_type=IP_DESTINATION): 573 self.offset = offset 574 self.component_type = component_type 575 # make sure if offset != 0 that non of the 576 # first offset bits are set in the prefix 577 self.value = prefix 578 if offset != 0: 580 i = ipaddress.IPv6Interface( 581 (self.value.network_address, offset)) 582 if i.network.network_address != \ 583 ipaddress.ip_address('0::0'): 584 raise ValueError('Bits set in the offset') 586 class FS_nlri(object): 587 """ 588 FS_nlri class implementation that allows sorting. 590 By calling .sort() on a array of FS_nlri objects these 591 will be sorted according to the flow_rule_cmp algorithm. 593 Example: 594 nlri = [ FS_nlri(components=[ 595 FS_component(component_type=4, 596 value=bytearray([0,1,2,3,4,5,6])), 597 ]), 598 FS_nlri(components=[ 599 FS_component(component_type=5, 600 value=bytearray([0,1,2,3,4,5,6])), 601 FS_component(component_type=6, 602 value=bytearray([0,1,2,3,4,5,6])), 603 ]), 604 ] 605 nlri.sort() # sorts the array accorinding to the algorithm 606 """ 607 def __init__(self, components = None): 608 """ 609 components: list of type FS_component 610 """ 611 self.components = components 613 def __lt__(self, other): 614 # use the below algorithm for sorting 615 result = flow_rule_cmp_v6(self, other) 616 if result == B_HAS_PRECEDENCE: 617 return True 618 else: 619 return False 621 def flow_rule_cmp_v6(a, b): 622 """ 623 Implementation of the flowspec sorting algorithm in 624 draft-ietf-idr-flow-spec-v6. 625 """ 626 for comp_a, comp_b in itertools.zip_longest(a.components, 627 b.components): 628 # If a component type does not exist in one rule 629 # this rule has lower precedence 630 if not comp_a: 631 return B_HAS_PRECEDENCE 632 if not comp_b: 633 return A_HAS_PRECEDENCE 634 # Higher precedence for lower component type 635 if comp_a.component_type < comp_b.component_type: 636 return A_HAS_PRECEDENCE 637 if comp_a.component_type > comp_b.component_type: 638 return B_HAS_PRECEDENCE 639 # component types are equal -> type specific comparison 640 if comp_a.component_type in (IP_DESTINATION, IP_SOURCE): 641 if comp_a.offset < comp_b.offset: 642 return A_HAS_PRECEDENCE 643 if comp_a.offset < comp_b.offset: 644 return B_HAS_PRECEDENCE 645 # both components have the same offset 646 # assuming comp_a.value, comp_b.value of type 647 # ipaddress.IPv6Network 648 # and the offset bits are reset to 0 (since they are 649 # not represented in the NLRI) 650 if comp_a.value.overlaps(comp_b.value): 651 # longest prefixlen has precedence 652 if comp_a.value.prefixlen > \ 653 comp_b.value.prefixlen: 654 return A_HAS_PRECEDENCE 655 if comp_a.value.prefixlen < \ 656 comp_b.value.prefixlen: 657 return B_HAS_PRECEDENCE 658 # components equal -> continue with next 659 # component 660 elif comp_a.value > comp_b.value: 661 return B_HAS_PRECEDENCE 662 elif comp_a.value < comp_b.value: 663 return A_HAS_PRECEDENCE 664 else: 665 # assuming comp_a.value, comp_b.value of type 666 # bytearray 667 if len(comp_a.value) == len(comp_b.value): 668 if comp_a.value > comp_b.value: 669 return B_HAS_PRECEDENCE 670 if comp_a.value < comp_b.value: 671 return A_HAS_PRECEDENCE 672 # components equal -> continue with next 673 # component 675 else: 676 common = min(len(comp_a.value), 677 len(comp_b.value)) 678 if comp_a.value[:common] > \ 679 comp_b.value[:common]: 680 return B_HAS_PRECEDENCE 681 elif comp_a.value[:common] < \ 682 comp_b.value[:common]: 683 return A_HAS_PRECEDENCE 684 # the first common bytes match 685 elif len(comp_a.value) > len(comp_b.value): 686 return A_HAS_PRECEDENCE 687 else: 688 return B_HAS_PRECEDENCE 689 return EQUAL 690 692 Authors' Addresses 694 Christoph Loibl (editor) 695 next layer Telekom GmbH 696 Mariahilfer Guertel 37/7 697 Vienna 1150 698 AT 700 Phone: +43 664 1176414 701 Email: cl@tix.at 703 Robert Raszuk (editor) 704 Bloomberg LP 705 731 Lexington Ave 706 New York City, NY 10022 707 USA 709 Email: robert@raszuk.net 711 Susan Hares (editor) 712 Huawei 713 7453 Hickory Hill 714 Saline, MI 48176 715 USA 717 Email: shares@ndzh.com