github.com/haraldrudell/parl@v0.4.176/iana/address-family.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package iana 7 8 import ( 9 "strconv" 10 11 "github.com/haraldrudell/parl/ints" 12 "github.com/haraldrudell/parl/perrors" 13 "github.com/haraldrudell/parl/sets" 14 "golang.org/x/exp/constraints" 15 ) 16 17 // AddressFamily contains iana Address Family Numbers such as IP versions 4 and 6 for the Internet. 18 // - AddressFamily is ordered 19 // - AddressFamily implements fmt.Stringer 20 // - AddressFamily has methods IsValid Description Int Uint16 21 // 22 // IANA [address-family-numbers] 23 // 24 // [address-family-numbers]: https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml 25 type AddressFamily uint16 26 27 const ( 28 AFreserved0 AddressFamily = iota // 0 Reserved 29 AFip // IP (IP version 4) 30 AFip6 // IP6 (IP version 6) 31 AFnsap // NSAP NSAP 32 AFhdlc // HDLC HDLC (8-bit multidrop) 33 AFbbn // BBN BBN 1822 34 AF802 // 802 (includes all 802 media plus Ethernet 35 AFe163 // E.163 E.163 36 AFe164 // E.164 E.164 (SMDS, Frame Relay, ATM) 37 AFf69 // F.69 F.69 (Telex) 38 AFx121 // X.121 X.121 (X.25, Frame Relay) 39 AFips // IPX IPX 40 AFappletalk // Appletalk Appletalk 41 AFdecnet // DECNET Decnet IV 42 AFbv // BV Banyan Vines 43 AFe164n // E.164N E.164 with NSAP format subaddress 44 AFdns // DNS DNS (Domain Name System) 45 AFdn // DN Distinguished Name 46 AFas // AS AS Number 47 AFxtpip // XTPIP XTP over IP version 4 48 AFxtpip6 // XTPIP6 XTP over IP version 6 49 AFxtp // XTP XTP native mode XTP 50 AFwwp // WWP Fibre Channel World-Wide Port Name 51 AFwwn // WWN Fibre Channel World-Wide Node Name 52 AFgwid // GWID GWID 53 AFafi // AFI AFI for L2VPN information [RFC4761][RFC6074] 54 AFmplss // MPLSS MPLS-TP Section Endpoint Identifier [RFC7212] 55 AFmplse // MPLSE MPLS-TP LSP Endpoint Identifier [RFC7212] 56 AFmplsp // MPLSP MPLS-TP Pseudowire Endpoint Identifier [RFC7212] 57 AFmtip // MTIP MT IP: Multi-Topology IP version 4 [RFC7307] 58 AFmtip6 // MTIP6 MT IPv6: Multi-Topology IP version 6 [RFC7307] 59 AFbgp // BGP BGP SFC [RFC9015] 60 AFeigrp AddressFamily = 16352 + iota // EIGRP EIGRP Common Service Family 61 AFeigrp4 // EIGRP4 EIGRP IPv4 Service Family 62 AFeigrp6 // EIGRP6 EIGRP IPv6 Service Family 63 AFlisp // LISP LISP Canonical Address Format (LCAF) 64 AFbgpls // BGP-LS BGP-LS [RFC7752] 65 AFmac48 // MAC48 48-bit MAC [RFC7042] 2013-05-06 66 AFmac64 // MAC64 64-bit MAC [RFC7042] 2013-05-06 67 AFoui // OUI OUI [RFC7961] 68 AFmac24 // MAC/24 MAC/24 [RFC7961] 69 AFmac40 // MAC/40 MAC/40 [RFC7961] 70 AFipv664 // IPv6/64 IPv6/64 [RFC7961] 71 AFrb // RBridge RBridge Port ID [RFC7961] 72 AFtrill // TRILL TRILL Nickname [RFC7455] 73 AFuuid // UUID Universally Unique Identifier (UUID) 74 AFafir // AFI Routing Policy AFI [draft-ietf-idr-rpd-02] 75 AFmplsns // MPLSNS MPLS Namespaces 76 AFreserved AddressFamily = 65535 // 65535 65535 Reserved 77 ) 78 79 // NewAddressFamily returns iana.AddressFamily for any integer value. 80 // - values larger that 255 produce error testable with errors.Is(err, ints.ErrTooLarge) 81 // - addressFamily may be invalid, ie. not an iana-assigned value, check with addressFamily.IsValid 82 // - or use NewValidAddressFamily 83 func NewAddressFamily[T constraints.Integer](integer T) (addressFamily AddressFamily, err error) { 84 85 // convert to uint16 86 var u16 uint16 87 if u16, err = ints.Unsigned[uint16](integer, perrors.PackFunc()); err != nil { 88 return 89 } 90 91 // convert to iana.AddressFamily, allow for invalid values 92 addressFamily = AddressFamily(u16) 93 94 return 95 } 96 97 // NewValidAddressFamily returns iana.AddressFamily for any integer value. 98 // - values larger that 65535 produce error testable with errors.Is(err, ints.ErrTooLarge) 99 // - addressFamily is valid 100 func NewValidAddressFamily[T constraints.Integer](integer T) (addressFamily AddressFamily, err error) { 101 if addressFamily, err = NewAddressFamily(integer); err != nil { 102 return 103 } 104 if !addressFamily.IsValid() { 105 err = perrors.ErrorfPF("invalid address family value: %d 0x%[1]x", addressFamily) 106 return 107 } 108 109 return 110 } 111 112 // NewAddressFamily1 returns iana.NewAddressFamily1 for any integer value. 113 // - if value is too large, panic 114 // - addressFamily may be invalid, ie. not an iana-assigned value, check with addressFamily.IsValid 115 // - or use NewValidAddressFamily 116 func NewAddressFamily1[T constraints.Integer](integer T) (addressFamily AddressFamily) { 117 var err error 118 if addressFamily, err = NewAddressFamily(integer); err != nil { 119 panic(err) 120 } 121 122 return 123 } 124 125 func (af AddressFamily) String() (s string) { 126 return addressFamilySet.StringT(af) 127 } 128 129 func (af AddressFamily) StringInt() (s string) { 130 return addressFamilySet.StringT(af) + "-0x" + strconv.FormatUint(uint64(af), 16) 131 } 132 133 func (af AddressFamily) Int() (addressFamilyInt int) { 134 return int(af) 135 } 136 137 func (af AddressFamily) Uint16() (addressFamilyInt uint16) { 138 return uint16(af) 139 } 140 141 func (af AddressFamily) IsValid() (isValid bool) { 142 return addressFamilySet.IsValid(af) 143 } 144 145 func (af AddressFamily) Description() (full string) { 146 return addressFamilySet.Description(af) 147 } 148 149 var addressFamilySet = sets.NewSet[AddressFamily]([]sets.SetElementFull[AddressFamily]{ 150 //{ValueV: AFreserved0, Name: "0", Full: "Reserved"}, 151 {ValueV: AFip, Name: "IP", Full: "(IP version 4)"}, 152 {ValueV: AFip6, Name: "IP6", Full: "(IP version 6)"}, 153 {ValueV: AFnsap, Name: "NSAP", Full: "NSAP"}, 154 {ValueV: AFhdlc, Name: "HDLC", Full: "HDLC (8-bit multidrop)"}, 155 {ValueV: AFbbn, Name: "BBN", Full: "BBN 1822"}, 156 {ValueV: AF802, Name: "802", Full: "(includes all 802 media plus Ethernet"}, 157 {ValueV: AFe163, Name: "E.163", Full: "E.163"}, 158 {ValueV: AFe164, Name: "E.164", Full: "E.164 (SMDS, Frame Relay, ATM)"}, 159 {ValueV: AFf69, Name: "F.69", Full: "F.69 (Telex)"}, 160 {ValueV: AFx121, Name: "X.121", Full: "X.121 (X.25, Frame Relay)"}, 161 {ValueV: AFips, Name: "IPX", Full: "IPX"}, 162 {ValueV: AFappletalk, Name: "Appletalk", Full: "Appletalk"}, 163 {ValueV: AFdecnet, Name: "DECNET", Full: "Decnet IV"}, 164 {ValueV: AFbv, Name: "BV", Full: "Banyan Vines"}, 165 {ValueV: AFe164n, Name: "E.164N", Full: "E.164 with NSAP format subaddress"}, 166 {ValueV: AFdns, Name: "DNS", Full: "DNS (Domain Name System)"}, 167 {ValueV: AFdn, Name: "DN", Full: "Distinguished Name"}, 168 {ValueV: AFas, Name: "AS", Full: "AS Number"}, 169 {ValueV: AFxtpip, Name: "XTPIP", Full: "XTP over IP version 4"}, 170 {ValueV: AFxtpip6, Name: "XTPIP6", Full: "XTP over IP version 6"}, 171 {ValueV: AFxtp, Name: "XTP", Full: "XTP native mode XTP"}, 172 {ValueV: AFwwp, Name: "WWP", Full: "Fibre Channel World-Wide Port Name"}, 173 {ValueV: AFwwn, Name: "WWN", Full: "Fibre Channel World-Wide Node Name"}, 174 {ValueV: AFgwid, Name: "GWID", Full: "GWID"}, 175 {ValueV: AFafi, Name: "AFI", Full: "AFI for L2VPN information [RFC4761][RFC6074]"}, 176 {ValueV: AFmplss, Name: "MPLSS", Full: "MPLS-TP Section Endpoint Identifier [RFC7212]"}, 177 {ValueV: AFmplse, Name: "MPLSE", Full: "MPLS-TP LSP Endpoint Identifier [RFC7212]"}, 178 {ValueV: AFmplsp, Name: "MPLSP", Full: "MPLS-TP Pseudowire Endpoint Identifier [RFC7212]"}, 179 {ValueV: AFmtip, Name: "MTIP", Full: "MT IP: Multi-Topology IP version 4 [RFC7307]"}, 180 {ValueV: AFmtip6, Name: "MTIP6", Full: "MT IPv6: Multi-Topology IP version 6 [RFC7307]"}, 181 {ValueV: AFbgp, Name: "BGP", Full: "BGP SFC [RFC9015]"}, 182 {ValueV: AFeigrp, Name: "EIGRP", Full: "EIGRP Common Service Family"}, 183 {ValueV: AFeigrp4, Name: "EIGRP4", Full: "EIGRP IPv4 Service Family"}, 184 {ValueV: AFeigrp6, Name: "EIGRP6", Full: "EIGRP IPv6 Service Family"}, 185 {ValueV: AFlisp, Name: "LISP", Full: "LISP Canonical Address Format (LCAF)"}, 186 {ValueV: AFbgpls, Name: "BGP-LS", Full: "BGP-LS [RFC7752]"}, 187 {ValueV: AFmac48, Name: "MAC48", Full: "48-bit MAC [RFC7042] 2013-05-06"}, 188 {ValueV: AFmac64, Name: "MAC64", Full: "64-bit MAC [RFC7042] 2013-05-06"}, 189 {ValueV: AFoui, Name: "OUI", Full: "OUI [RFC7961]"}, 190 {ValueV: AFmac24, Name: "MAC/24", Full: "MAC/24 [RFC7961]"}, 191 {ValueV: AFmac40, Name: "MAC/40", Full: "MAC/40 [RFC7961]"}, 192 {ValueV: AFipv664, Name: "IPv6/64", Full: "IPv6/64 [RFC7961]"}, 193 {ValueV: AFrb, Name: "RBridge", Full: "RBridge Port ID [RFC7961]"}, 194 {ValueV: AFtrill, Name: "TRILL", Full: "TRILL Nickname [RFC7455]"}, 195 {ValueV: AFuuid, Name: "UUID", Full: "Universally Unique Identifier (UUID)"}, 196 {ValueV: AFafir, Name: "AFI", Full: "Routing Policy AFI [draft-ietf-idr-rpd-02]"}, 197 {ValueV: AFmplsns, Name: "MPLSNS", Full: "MPLS Namespaces"}, 198 //{ValueV: AFreserved, Name: "65535", Full: "65535 Reserved"}, 199 })