idnits 2.17.1 draft-ietf-idr-flow-spec-v6-12.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 (July 10, 2020) is 1386 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 541 == Unused Reference: 'RFC4271' is defined on line 501, 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: January 11, 2021 Bloomberg LP 6 S. Hares, Ed. 7 Huawei 8 July 10, 2020 10 Dissemination of Flow Specification Rules for IPv6 11 draft-ietf-idr-flow-spec-v6-12 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 January 11, 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 existing 445 implementations of this protocol. Unused and available for 446 assignment via documented procedures. 448 IANA maintains a registry entitled "Generic Transitive Experimental 449 Use Extended Community Sub-Types". For the purpose of this work, 450 IANA is requested to assign a new value: 452 +------------+----------------------------------------+-------------+ 453 | Sub-Type | Name | Reference | 454 | Value | | | 455 +------------+----------------------------------------+-------------+ 456 | TBD | Flow spec rt-redirect-ipv6 | [this | 457 | | format | document] | 458 +------------+----------------------------------------+-------------+ 460 Table 3: Registry: Generic Transitive Experimental Use Extended 461 Community Sub-Types 463 9. Acknowledgements 465 Authors would like to thank Pedro Marques, Hannes Gredler and Bruno 466 Rijsman, Brian Carpenter, and Thomas Mangin for their valuable input. 468 10. Contributors 470 Danny McPherson 471 Verisign, Inc. 473 Email: dmcpherson@verisign.com 475 Burjiz Pithawala 476 Individual 478 Email: burjizp@gmail.com 480 Andy Karch 481 Cisco Systems 482 170 West Tasman Drive 483 San Jose, CA 95134 484 USA 486 Email: akarch@cisco.com 488 11. References 489 11.1. Normative References 491 [I-D.ietf-idr-rfc5575bis] 492 Loibl, C., Hares, S., Raszuk, R., McPherson, D., and M. 493 Bacher, "Dissemination of Flow Specification Rules", 494 draft-ietf-idr-rfc5575bis-25 (work in progress), May 2020. 496 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 497 Requirement Levels", BCP 14, RFC 2119, 498 DOI 10.17487/RFC2119, March 1997, 499 . 501 [RFC4271] Rekhter, Y., Ed., Li, T., Ed., and S. Hares, Ed., "A 502 Border Gateway Protocol 4 (BGP-4)", RFC 4271, 503 DOI 10.17487/RFC4271, January 2006, 504 . 506 [RFC4443] Conta, A., Deering, S., and M. Gupta, Ed., "Internet 507 Control Message Protocol (ICMPv6) for the Internet 508 Protocol Version 6 (IPv6) Specification", STD 89, 509 RFC 4443, DOI 10.17487/RFC4443, March 2006, 510 . 512 [RFC4760] Bates, T., Chandra, R., Katz, D., and Y. Rekhter, 513 "Multiprotocol Extensions for BGP-4", RFC 4760, 514 DOI 10.17487/RFC4760, January 2007, 515 . 517 [RFC5701] Rekhter, Y., "IPv6 Address Specific BGP Extended Community 518 Attribute", RFC 5701, DOI 10.17487/RFC5701, November 2009, 519 . 521 [RFC7153] Rosen, E. and Y. Rekhter, "IANA Registries for BGP 522 Extended Communities", RFC 7153, DOI 10.17487/RFC7153, 523 March 2014, . 525 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 526 Writing an IANA Considerations Section in RFCs", BCP 26, 527 RFC 8126, DOI 10.17487/RFC8126, June 2017, 528 . 530 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 531 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 532 May 2017, . 534 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 535 (IPv6) Specification", STD 86, RFC 8200, 536 DOI 10.17487/RFC8200, July 2017, 537 . 539 11.2. URIs 541 [1] https://github.com/stoffi92/draft-ietf-idr-flow-spec- 542 v6/tree/master/flowspec-cmp 544 Appendix A. Example python code: flow_rule_cmp_v6 546 547 """ 548 Copyright (c) 2020 IETF Trust and the persons identified as authors 549 of draft-ietf-idr-flow-spec-v6. All rights reserved. 551 Redistribution and use in source and binary forms, with or without 552 modification, is permitted pursuant to, and subject to the license 553 terms contained in, the Simplified BSD License set forth in Section 554 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents 555 (http://trustee.ietf.org/license-info). 556 """ 558 import itertools 559 import collections 560 import ipaddress 562 EQUAL = 0 563 A_HAS_PRECEDENCE = 1 564 B_HAS_PRECEDENCE = 2 565 IP_DESTINATION = 1 566 IP_SOURCE = 2 568 FS_component = collections.namedtuple('FS_component', 569 'component_type value') 571 class FS_IPv6_prefix_component: 572 def __init__(self, prefix, offset=0, 573 component_type=IP_DESTINATION): 574 self.offset = offset 575 self.component_type = component_type 576 # make sure if offset != 0 that non of the 577 # first offset bits are set in the prefix 578 self.value = prefix 579 if offset != 0: 581 i = ipaddress.IPv6Interface( 582 (self.value.network_address, offset)) 583 if i.network.network_address != \ 584 ipaddress.ip_address('0::0'): 585 raise ValueError('Bits set in the offset') 587 class FS_nlri(object): 588 """ 589 FS_nlri class implementation that allows sorting. 591 By calling .sort() on a array of FS_nlri objects these 592 will be sorted according to the flow_rule_cmp algorithm. 594 Example: 595 nlri = [ FS_nlri(components=[ 596 FS_component(component_type=4, 597 value=bytearray([0,1,2,3,4,5,6])), 598 ]), 599 FS_nlri(components=[ 600 FS_component(component_type=5, 601 value=bytearray([0,1,2,3,4,5,6])), 602 FS_component(component_type=6, 603 value=bytearray([0,1,2,3,4,5,6])), 604 ]), 605 ] 606 nlri.sort() # sorts the array accorinding to the algorithm 607 """ 608 def __init__(self, components = None): 609 """ 610 components: list of type FS_component 611 """ 612 self.components = components 614 def __lt__(self, other): 615 # use the below algorithm for sorting 616 result = flow_rule_cmp_v6(self, other) 617 if result == B_HAS_PRECEDENCE: 618 return True 619 else: 620 return False 622 def flow_rule_cmp_v6(a, b): 623 """ 624 Implementation of the flowspec sorting algorithm in 625 draft-ietf-idr-flow-spec-v6. 626 """ 627 for comp_a, comp_b in itertools.zip_longest(a.components, 628 b.components): 629 # If a component type does not exist in one rule 630 # this rule has lower precedence 631 if not comp_a: 632 return B_HAS_PRECEDENCE 633 if not comp_b: 634 return A_HAS_PRECEDENCE 635 # Higher precedence for lower component type 636 if comp_a.component_type < comp_b.component_type: 637 return A_HAS_PRECEDENCE 638 if comp_a.component_type > comp_b.component_type: 639 return B_HAS_PRECEDENCE 640 # component types are equal -> type specific comparison 641 if comp_a.component_type in (IP_DESTINATION, IP_SOURCE): 642 if comp_a.offset < comp_b.offset: 643 return A_HAS_PRECEDENCE 644 if comp_a.offset < comp_b.offset: 645 return B_HAS_PRECEDENCE 646 # both components have the same offset 647 # assuming comp_a.value, comp_b.value of type 648 # ipaddress.IPv6Network 649 # and the offset bits are reset to 0 (since they are 650 # not represented in the NLRI) 651 if comp_a.value.overlaps(comp_b.value): 652 # longest prefixlen has precedence 653 if comp_a.value.prefixlen > \ 654 comp_b.value.prefixlen: 655 return A_HAS_PRECEDENCE 656 if comp_a.value.prefixlen < \ 657 comp_b.value.prefixlen: 658 return B_HAS_PRECEDENCE 659 # components equal -> continue with next 660 # component 661 elif comp_a.value > comp_b.value: 662 return B_HAS_PRECEDENCE 663 elif comp_a.value < comp_b.value: 664 return A_HAS_PRECEDENCE 665 else: 666 # assuming comp_a.value, comp_b.value of type 667 # bytearray 668 if len(comp_a.value) == len(comp_b.value): 669 if comp_a.value > comp_b.value: 670 return B_HAS_PRECEDENCE 671 if comp_a.value < comp_b.value: 672 return A_HAS_PRECEDENCE 673 # components equal -> continue with next 674 # component 676 else: 677 common = min(len(comp_a.value), 678 len(comp_b.value)) 679 if comp_a.value[:common] > \ 680 comp_b.value[:common]: 681 return B_HAS_PRECEDENCE 682 elif comp_a.value[:common] < \ 683 comp_b.value[:common]: 684 return A_HAS_PRECEDENCE 685 # the first common bytes match 686 elif len(comp_a.value) > len(comp_b.value): 687 return A_HAS_PRECEDENCE 688 else: 689 return B_HAS_PRECEDENCE 690 return EQUAL 691 693 Authors' Addresses 695 Christoph Loibl (editor) 696 next layer Telekom GmbH 697 Mariahilfer Guertel 37/7 698 Vienna 1150 699 AT 701 Phone: +43 664 1176414 702 Email: cl@tix.at 704 Robert Raszuk (editor) 705 Bloomberg LP 706 731 Lexington Ave 707 New York City, NY 10022 708 USA 710 Email: robert@raszuk.net 712 Susan Hares (editor) 713 Huawei 714 7453 Hickory Hill 715 Saline, MI 48176 716 USA 718 Email: shares@ndzh.com