// VPP: 20.05-release
// source: /usr/share/vpp/api/core/ip_types.api.json
-/*
-Package ip_types contains generated code for VPP API file ip_types.api (3.0.0).
-
-It consists of:
- 5 aliases
- 4 enums
- 6 types
- 1 union
-*/
+// Package ip_types contains generated bindings for API file ip_types.api.
+//
+// Contents:
+// 5 aliases
+// 4 enums
+// 6 structs
+// 1 union
+//
package ip_types
import (
- "bytes"
- "context"
- "encoding/binary"
"fmt"
- "io"
- "math"
+ api "git.fd.io/govpp.git/api"
+ codec "git.fd.io/govpp.git/codec"
"net"
"strconv"
"strings"
-
- api "git.fd.io/govpp.git/api"
- codec "git.fd.io/govpp.git/codec"
- struc "github.com/lunixbochs/struc"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the GoVPP api package it is being compiled against.
// A compilation error at this line likely means your copy of the
// GoVPP api package needs to be updated.
-const _ = api.GoVppAPIPackageIsVersion2 // please upgrade the GoVPP api package
+const _ = api.GoVppAPIPackageIsVersion2
-const (
- // ModuleName is the name of this module.
- ModuleName = "ip_types"
- // APIVersion is the API version of this module.
- APIVersion = "3.0.0"
- // VersionCrc is the CRC of this module.
- VersionCrc = 0x9cb1c2e2
-)
-
-// AddressFamily represents VPP binary API enum 'address_family'.
+// AddressFamily defines enum 'address_family'.
type AddressFamily uint8
const (
return "AddressFamily(" + strconv.Itoa(int(x)) + ")"
}
-// IPDscp represents VPP binary API enum 'ip_dscp'.
+// IPDscp defines enum 'ip_dscp'.
type IPDscp uint8
const (
return "IPDscp(" + strconv.Itoa(int(x)) + ")"
}
-// IPEcn represents VPP binary API enum 'ip_ecn'.
+// IPEcn defines enum 'ip_ecn'.
type IPEcn uint8
const (
return "IPEcn(" + strconv.Itoa(int(x)) + ")"
}
-// IPProto represents VPP binary API enum 'ip_proto'.
+// IPProto defines enum 'ip_proto'.
type IPProto uint8
const (
return "IPProto(" + strconv.Itoa(int(x)) + ")"
}
-// AddressWithPrefix represents VPP binary API alias 'address_with_prefix'.
+// AddressWithPrefix defines alias 'address_with_prefix'.
type AddressWithPrefix Prefix
-// IP4Address represents VPP binary API alias 'ip4_address'.
+func ParseAddressWithPrefix(s string) (AddressWithPrefix, error) {
+ prefix, err := ParsePrefix(s)
+ if err != nil {
+ return AddressWithPrefix{}, err
+ }
+ return AddressWithPrefix(prefix), nil
+}
+func (x AddressWithPrefix) String() string {
+ return Prefix(x).String()
+}
+func (x *AddressWithPrefix) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *AddressWithPrefix) UnmarshalText(text []byte) error {
+ prefix, err := ParseAddressWithPrefix(string(text))
+ if err != nil {
+ return err
+ }
+ *x = prefix
+ return nil
+}
+
+// IP4Address defines alias 'ip4_address'.
type IP4Address [4]uint8
-// IP4AddressWithPrefix represents VPP binary API alias 'ip4_address_with_prefix'.
+func ParseIP4Address(s string) (IP4Address, error) {
+ ip := net.ParseIP(s).To4()
+ if ip == nil {
+ return IP4Address{}, fmt.Errorf("invalid IP address: %s", s)
+ }
+ var ipaddr IP4Address
+ copy(ipaddr[:], ip.To4())
+ return ipaddr, nil
+}
+
+func (x IP4Address) ToIP() net.IP {
+ return net.IP(x[:]).To4()
+}
+func (x IP4Address) String() string {
+ return x.ToIP().String()
+}
+func (x *IP4Address) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *IP4Address) UnmarshalText(text []byte) error {
+ ipaddr, err := ParseIP4Address(string(text))
+ if err != nil {
+ return err
+ }
+ *x = ipaddr
+ return nil
+}
+
+// IP4AddressWithPrefix defines alias 'ip4_address_with_prefix'.
type IP4AddressWithPrefix IP4Prefix
-// IP6Address represents VPP binary API alias 'ip6_address'.
+// IP6Address defines alias 'ip6_address'.
type IP6Address [16]uint8
-// IP6AddressWithPrefix represents VPP binary API alias 'ip6_address_with_prefix'.
+func ParseIP6Address(s string) (IP6Address, error) {
+ ip := net.ParseIP(s).To16()
+ if ip == nil {
+ return IP6Address{}, fmt.Errorf("invalid IP address: %s", s)
+ }
+ var ipaddr IP6Address
+ copy(ipaddr[:], ip.To16())
+ return ipaddr, nil
+}
+
+func (x IP6Address) ToIP() net.IP {
+ return net.IP(x[:]).To16()
+}
+func (x IP6Address) String() string {
+ return x.ToIP().String()
+}
+func (x *IP6Address) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *IP6Address) UnmarshalText(text []byte) error {
+ ipaddr, err := ParseIP6Address(string(text))
+ if err != nil {
+ return err
+ }
+ *x = ipaddr
+ return nil
+}
+
+// IP6AddressWithPrefix defines alias 'ip6_address_with_prefix'.
type IP6AddressWithPrefix IP6Prefix
-// Address represents VPP binary API type 'address'.
+// Address defines type 'address'.
type Address struct {
Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
Un AddressUnion `binapi:"address_union,name=un" json:"un,omitempty"`
}
-func (*Address) GetTypeName() string { return "address" }
-
-func ParseAddress(ip string) (Address, error) {
- var address Address
- netIP := net.ParseIP(ip)
- if netIP == nil {
- return address, fmt.Errorf("invalid address: %s", ip)
+func ParseAddress(s string) (Address, error) {
+ ip := net.ParseIP(s)
+ if ip == nil {
+ return Address{}, fmt.Errorf("invalid address: %s", s)
}
- if ip4 := netIP.To4(); ip4 == nil {
- address.Af = ADDRESS_IP6
- var ip6addr IP6Address
- copy(ip6addr[:], netIP.To16())
- address.Un.SetIP6(ip6addr)
+ var addr Address
+ if ip.To4() == nil {
+ addr.Af = ADDRESS_IP6
+ var ip6 IP6Address
+ copy(ip6[:], ip.To16())
+ addr.Un.SetIP6(ip6)
} else {
- address.Af = ADDRESS_IP4
- var ip4addr IP4Address
- copy(ip4addr[:], netIP.To4())
- address.Un.SetIP4(ip4addr)
+ addr.Af = ADDRESS_IP4
+ var ip4 IP4Address
+ copy(ip4[:], ip.To4())
+ addr.Un.SetIP4(ip4)
}
- return address, nil
+ return addr, nil
}
-
-func (a *Address) ToString() string {
- var ip string
- if a.Af == ADDRESS_IP6 {
- ip6Address := a.Un.GetIP6()
- ip = net.IP(ip6Address[:]).To16().String()
+func (x Address) ToIP() net.IP {
+ if x.Af == ADDRESS_IP6 {
+ ip6 := x.Un.GetIP6()
+ return net.IP(ip6[:]).To16()
} else {
- ip4Address := a.Un.GetIP4()
- ip = net.IP(ip4Address[:]).To4().String()
+ ip4 := x.Un.GetIP4()
+ return net.IP(ip4[:]).To4()
+ }
+}
+func (x Address) String() string {
+ return x.ToIP().String()
+}
+func (x *Address) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *Address) UnmarshalText(text []byte) error {
+ addr, err := ParseAddress(string(text))
+ if err != nil {
+ return err
}
- return ip
+ *x = addr
+ return nil
}
-// IP4Prefix represents VPP binary API type 'ip4_prefix'.
+// IP4Prefix defines type 'ip4_prefix'.
type IP4Prefix struct {
Address IP4Address `binapi:"ip4_address,name=address" json:"address,omitempty"`
Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
}
-func (*IP4Prefix) GetTypeName() string { return "ip4_prefix" }
+func ParseIP4Prefix(s string) (prefix IP4Prefix, err error) {
+ hasPrefix := strings.Contains(s, "/")
+ if hasPrefix {
+ ip, network, err := net.ParseCIDR(s)
+ if err != nil {
+ return IP4Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
+ }
+ maskSize, _ := network.Mask.Size()
+ prefix.Len = byte(maskSize)
+ prefix.Address, err = ParseIP4Address(ip.String())
+ if err != nil {
+ return IP4Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
+ }
+ } else {
+ ip := net.ParseIP(s)
+ defaultMaskSize, _ := net.CIDRMask(32, 32).Size()
+ if ip.To4() == nil {
+ defaultMaskSize, _ = net.CIDRMask(128, 128).Size()
+ }
+ prefix.Len = byte(defaultMaskSize)
+ prefix.Address, err = ParseIP4Address(ip.String())
+ if err != nil {
+ return IP4Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
+ }
+ }
+ return prefix, nil
+}
+func (x IP4Prefix) ToIPNet() *net.IPNet {
+ mask := net.CIDRMask(int(x.Len), 32)
+ ipnet := &net.IPNet{IP: x.Address.ToIP(), Mask: mask}
+ return ipnet
+}
+func (x IP4Prefix) String() string {
+ ip := x.Address.String()
+ return ip + "/" + strconv.Itoa(int(x.Len))
+}
+func (x *IP4Prefix) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *IP4Prefix) UnmarshalText(text []byte) error {
+ prefix, err := ParseIP4Prefix(string(text))
+ if err != nil {
+ return err
+ }
+ *x = prefix
+ return nil
+}
-// IP6Prefix represents VPP binary API type 'ip6_prefix'.
+// IP6Prefix defines type 'ip6_prefix'.
type IP6Prefix struct {
Address IP6Address `binapi:"ip6_address,name=address" json:"address,omitempty"`
Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
}
-func (*IP6Prefix) GetTypeName() string { return "ip6_prefix" }
+func ParseIP6Prefix(s string) (prefix IP6Prefix, err error) {
+ hasPrefix := strings.Contains(s, "/")
+ if hasPrefix {
+ ip, network, err := net.ParseCIDR(s)
+ if err != nil {
+ return IP6Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
+ }
+ maskSize, _ := network.Mask.Size()
+ prefix.Len = byte(maskSize)
+ prefix.Address, err = ParseIP6Address(ip.String())
+ if err != nil {
+ return IP6Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
+ }
+ } else {
+ ip := net.ParseIP(s)
+ defaultMaskSize, _ := net.CIDRMask(32, 32).Size()
+ if ip.To4() == nil {
+ defaultMaskSize, _ = net.CIDRMask(128, 128).Size()
+ }
+ prefix.Len = byte(defaultMaskSize)
+ prefix.Address, err = ParseIP6Address(ip.String())
+ if err != nil {
+ return IP6Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
+ }
+ }
+ return prefix, nil
+}
+func (x IP6Prefix) ToIPNet() *net.IPNet {
+ mask := net.CIDRMask(int(x.Len), 128)
+ ipnet := &net.IPNet{IP: x.Address.ToIP(), Mask: mask}
+ return ipnet
+}
+func (x IP6Prefix) String() string {
+ ip := x.Address.String()
+ return ip + "/" + strconv.Itoa(int(x.Len))
+}
+func (x *IP6Prefix) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *IP6Prefix) UnmarshalText(text []byte) error {
+ prefix, err := ParseIP6Prefix(string(text))
+ if err != nil {
+ return err
+ }
+ *x = prefix
+ return nil
+}
-// Mprefix represents VPP binary API type 'mprefix'.
+// Mprefix defines type 'mprefix'.
type Mprefix struct {
Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
GrpAddressLength uint16 `binapi:"u16,name=grp_address_length" json:"grp_address_length,omitempty"`
SrcAddress AddressUnion `binapi:"address_union,name=src_address" json:"src_address,omitempty"`
}
-func (*Mprefix) GetTypeName() string { return "mprefix" }
-
-// Prefix represents VPP binary API type 'prefix'.
+// Prefix defines type 'prefix'.
type Prefix struct {
Address Address `binapi:"address,name=address" json:"address,omitempty"`
Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
}
-func (*Prefix) GetTypeName() string { return "prefix" }
-
func ParsePrefix(ip string) (prefix Prefix, err error) {
hasPrefix := strings.Contains(ip, "/")
if hasPrefix {
netIP, network, err := net.ParseCIDR(ip)
if err != nil {
- return Prefix{}, fmt.Errorf("invalid IP %s: %v", ip, err)
+ return Prefix{}, fmt.Errorf("invalid IP %s: %s", ip, err)
}
maskSize, _ := network.Mask.Size()
prefix.Len = byte(maskSize)
prefix.Address, err = ParseAddress(netIP.String())
if err != nil {
- return Prefix{}, fmt.Errorf("invalid IP %s: %v", ip, err)
+ return Prefix{}, fmt.Errorf("invalid IP %s: %s", ip, err)
}
} else {
netIP := net.ParseIP(ip)
prefix.Len = byte(defaultMaskSize)
prefix.Address, err = ParseAddress(netIP.String())
if err != nil {
- return Prefix{}, fmt.Errorf("invalid IP %s: %v", ip, err)
+ return Prefix{}, fmt.Errorf("invalid IP %s: %s", ip, err)
}
}
return prefix, nil
}
-
-func (p *Prefix) ToString() string {
- ip := p.Address.ToString()
- return ip + "/" + strconv.Itoa(int(p.Len))
+func (x Prefix) ToIPNet() *net.IPNet {
+ var mask net.IPMask
+ if x.Address.Af == ADDRESS_IP4 {
+ mask = net.CIDRMask(int(x.Len), 32)
+ } else {
+ mask = net.CIDRMask(int(x.Len), 128)
+ }
+ ipnet := &net.IPNet{IP: x.Address.ToIP(), Mask: mask}
+ return ipnet
+}
+func (x Prefix) String() string {
+ ip := x.Address.String()
+ return ip + "/" + strconv.Itoa(int(x.Len))
+}
+func (x *Prefix) MarshalText() ([]byte, error) {
+ return []byte(x.String()), nil
+}
+func (x *Prefix) UnmarshalText(text []byte) error {
+ prefix, err := ParsePrefix(string(text))
+ if err != nil {
+ return err
+ }
+ *x = prefix
+ return nil
}
-// PrefixMatcher represents VPP binary API type 'prefix_matcher'.
+// PrefixMatcher defines type 'prefix_matcher'.
type PrefixMatcher struct {
Le uint8 `binapi:"u8,name=le" json:"le,omitempty"`
Ge uint8 `binapi:"u8,name=ge" json:"ge,omitempty"`
}
-func (*PrefixMatcher) GetTypeName() string { return "prefix_matcher" }
-
-// AddressUnion represents VPP binary API union 'address_union'.
+// AddressUnion defines union 'address_union'.
type AddressUnion struct {
+ // IP4 *IP4Address
+ // IP6 *IP6Address
XXX_UnionData [16]byte
}
-func (*AddressUnion) GetTypeName() string { return "address_union" }
-
func AddressUnionIP4(a IP4Address) (u AddressUnion) {
u.SetIP4(a)
return
}
func (u *AddressUnion) SetIP4(a IP4Address) {
- var b = new(bytes.Buffer)
- if err := struc.Pack(b, &a); err != nil {
- return
- }
- copy(u.XXX_UnionData[:], b.Bytes())
+ var buf = codec.NewBuffer(u.XXX_UnionData[:])
+ buf.EncodeBytes(a[:], 4)
}
func (u *AddressUnion) GetIP4() (a IP4Address) {
- var b = bytes.NewReader(u.XXX_UnionData[:])
- struc.Unpack(b, &a)
+ var buf = codec.NewBuffer(u.XXX_UnionData[:])
+ copy(a[:], buf.DecodeBytes(4))
return
}
return
}
func (u *AddressUnion) SetIP6(a IP6Address) {
- var b = new(bytes.Buffer)
- if err := struc.Pack(b, &a); err != nil {
- return
- }
- copy(u.XXX_UnionData[:], b.Bytes())
+ var buf = codec.NewBuffer(u.XXX_UnionData[:])
+ buf.EncodeBytes(a[:], 16)
}
func (u *AddressUnion) GetIP6() (a IP6Address) {
- var b = bytes.NewReader(u.XXX_UnionData[:])
- struc.Unpack(b, &a)
+ var buf = codec.NewBuffer(u.XXX_UnionData[:])
+ copy(a[:], buf.DecodeBytes(16))
return
}
-
-// Reference imports to suppress errors if they are not otherwise used.
-var _ = api.RegisterMessage
-var _ = codec.DecodeString
-var _ = bytes.NewBuffer
-var _ = context.Background
-var _ = io.Copy
-var _ = strconv.Itoa
-var _ = strings.Contains
-var _ = struc.Pack
-var _ = binary.BigEndian
-var _ = math.Float32bits
-var _ = net.ParseIP
-var _ = fmt.Errorf