summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-06 15:34:29 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-12 08:04:30 +0900
commita7682648404d444a44b953e4db0fed1660ce60ee (patch)
tree6a3b341d11565226b1bc617be6009c3eb69b30fa
parentb3514d7e0a813ca1d023748d4b3365065dc43016 (diff)
api: kill protobuf Addressfamily struct
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--api/gobgp.pb.go130
-rw-r--r--api/gobgp.proto33
-rw-r--r--api/util.go48
-rw-r--r--gobgp/common.go22
-rw-r--r--gobgp/global.go12
-rw-r--r--gobgp/monitor.go4
-rw-r--r--gobgp/mrt.go25
-rw-r--r--gobgp/neighbor.go18
-rw-r--r--gobgp/rpki.go9
-rw-r--r--gobgp/vrf.go8
-rw-r--r--packet/bgp.go4
-rw-r--r--server/grpc_server.go66
12 files changed, 79 insertions, 300 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go
index 5c332c6f..4d91e526 100644
--- a/api/gobgp.pb.go
+++ b/api/gobgp.pb.go
@@ -15,7 +15,6 @@ It has these top-level messages:
PolicyArguments
MrtArguments
ModVrfArguments
- AddressFamily
GracefulRestartTuple
GracefulRestart
Capability
@@ -129,76 +128,6 @@ func (x Operation) String() string {
return proto.EnumName(Operation_name, int32(x))
}
-type AFI int32
-
-const (
- AFI_UNKNOWN_AFI AFI = 0
- AFI_IP AFI = 1
- AFI_IP6 AFI = 2
- AFI_L2VPN AFI = 25
-)
-
-var AFI_name = map[int32]string{
- 0: "UNKNOWN_AFI",
- 1: "IP",
- 2: "IP6",
- 25: "L2VPN",
-}
-var AFI_value = map[string]int32{
- "UNKNOWN_AFI": 0,
- "IP": 1,
- "IP6": 2,
- "L2VPN": 25,
-}
-
-func (x AFI) String() string {
- return proto.EnumName(AFI_name, int32(x))
-}
-
-type SAFI int32
-
-const (
- SAFI_UNKNOWN_SAFI SAFI = 0
- SAFI_UNICAST SAFI = 1
- SAFI_MULTICAST SAFI = 2
- SAFI_MPLS_LABEL SAFI = 4
- SAFI_ENCAP SAFI = 7
- SAFI_VPLS SAFI = 65
- SAFI_EVPN SAFI = 70
- SAFI_MPLS_VPN SAFI = 128
- SAFI_MPLS_VPN_MULTICAST SAFI = 129
- SAFI_ROUTE_TARGET_CONSTRAINTS SAFI = 132
-)
-
-var SAFI_name = map[int32]string{
- 0: "UNKNOWN_SAFI",
- 1: "UNICAST",
- 2: "MULTICAST",
- 4: "MPLS_LABEL",
- 7: "ENCAP",
- 65: "VPLS",
- 70: "EVPN",
- 128: "MPLS_VPN",
- 129: "MPLS_VPN_MULTICAST",
- 132: "ROUTE_TARGET_CONSTRAINTS",
-}
-var SAFI_value = map[string]int32{
- "UNKNOWN_SAFI": 0,
- "UNICAST": 1,
- "MULTICAST": 2,
- "MPLS_LABEL": 4,
- "ENCAP": 7,
- "VPLS": 65,
- "EVPN": 70,
- "MPLS_VPN": 128,
- "MPLS_VPN_MULTICAST": 129,
- "ROUTE_TARGET_CONSTRAINTS": 132,
-}
-
-func (x SAFI) String() string {
- return proto.EnumName(SAFI_name, int32(x))
-}
-
type BGP_CAPABILITY int32
const (
@@ -267,22 +196,15 @@ func (m *Error) String() string { return proto.CompactTextString(m) }
func (*Error) ProtoMessage() {}
type Arguments struct {
- Resource Resource `protobuf:"varint,1,opt,name=resource,enum=api.Resource" json:"resource,omitempty"`
- Af *AddressFamily `protobuf:"bytes,2,opt,name=af" json:"af,omitempty"`
- Name string `protobuf:"bytes,3,opt,name=name" json:"name,omitempty"`
+ Resource Resource `protobuf:"varint,1,opt,name=resource,enum=api.Resource" json:"resource,omitempty"`
+ Rf uint32 `protobuf:"varint,2,opt,name=rf" json:"rf,omitempty"`
+ Name string `protobuf:"bytes,3,opt,name=name" json:"name,omitempty"`
}
func (m *Arguments) Reset() { *m = Arguments{} }
func (m *Arguments) String() string { return proto.CompactTextString(m) }
func (*Arguments) ProtoMessage() {}
-func (m *Arguments) GetAf() *AddressFamily {
- if m != nil {
- return m.Af
- }
- return nil
-}
-
type ModPathArguments struct {
Resource Resource `protobuf:"varint,1,opt,name=resource,enum=api.Resource" json:"resource,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
@@ -324,23 +246,16 @@ func (m *PolicyArguments) GetApplyPolicy() *ApplyPolicy {
}
type MrtArguments struct {
- Resource Resource `protobuf:"varint,1,opt,name=resource,enum=api.Resource" json:"resource,omitempty"`
- Af *AddressFamily `protobuf:"bytes,2,opt,name=af" json:"af,omitempty"`
- Interval uint64 `protobuf:"varint,3,opt,name=interval" json:"interval,omitempty"`
- NeighborAddress string `protobuf:"bytes,4,opt,name=neighbor_address" json:"neighbor_address,omitempty"`
+ Resource Resource `protobuf:"varint,1,opt,name=resource,enum=api.Resource" json:"resource,omitempty"`
+ Rf uint32 `protobuf:"varint,2,opt,name=rf" json:"rf,omitempty"`
+ Interval uint64 `protobuf:"varint,3,opt,name=interval" json:"interval,omitempty"`
+ NeighborAddress string `protobuf:"bytes,4,opt,name=neighbor_address" json:"neighbor_address,omitempty"`
}
func (m *MrtArguments) Reset() { *m = MrtArguments{} }
func (m *MrtArguments) String() string { return proto.CompactTextString(m) }
func (*MrtArguments) ProtoMessage() {}
-func (m *MrtArguments) GetAf() *AddressFamily {
- if m != nil {
- return m.Af
- }
- return nil
-}
-
type ModVrfArguments struct {
Operation Operation `protobuf:"varint,1,opt,name=operation,enum=api.Operation" json:"operation,omitempty"`
Vrf *Vrf `protobuf:"bytes,2,opt,name=vrf" json:"vrf,omitempty"`
@@ -357,31 +272,15 @@ func (m *ModVrfArguments) GetVrf() *Vrf {
return nil
}
-type AddressFamily struct {
- Afi AFI `protobuf:"varint,1,opt,enum=api.AFI" json:"Afi,omitempty"`
- Safi SAFI `protobuf:"varint,2,opt,enum=api.SAFI" json:"Safi,omitempty"`
-}
-
-func (m *AddressFamily) Reset() { *m = AddressFamily{} }
-func (m *AddressFamily) String() string { return proto.CompactTextString(m) }
-func (*AddressFamily) ProtoMessage() {}
-
type GracefulRestartTuple struct {
- Af *AddressFamily `protobuf:"bytes,1,opt,name=af" json:"af,omitempty"`
- Flags uint32 `protobuf:"varint,2,opt,name=flags" json:"flags,omitempty"`
+ Rf uint32 `protobuf:"varint,1,opt,name=rf" json:"rf,omitempty"`
+ Flags uint32 `protobuf:"varint,2,opt,name=flags" json:"flags,omitempty"`
}
func (m *GracefulRestartTuple) Reset() { *m = GracefulRestartTuple{} }
func (m *GracefulRestartTuple) String() string { return proto.CompactTextString(m) }
func (*GracefulRestartTuple) ProtoMessage() {}
-func (m *GracefulRestartTuple) GetAf() *AddressFamily {
- if m != nil {
- return m.Af
- }
- return nil
-}
-
type GracefulRestart struct {
Flags uint32 `protobuf:"varint,1,opt,name=flags" json:"flags,omitempty"`
Time uint32 `protobuf:"varint,2,opt,name=time" json:"time,omitempty"`
@@ -401,7 +300,7 @@ func (m *GracefulRestart) GetTuples() []*GracefulRestartTuple {
type Capability struct {
Code BGP_CAPABILITY `protobuf:"varint,1,opt,name=code,enum=api.BGP_CAPABILITY" json:"code,omitempty"`
- MultiProtocol *AddressFamily `protobuf:"bytes,2,opt,name=multi_protocol" json:"multi_protocol,omitempty"`
+ MultiProtocol uint32 `protobuf:"varint,2,opt,name=multi_protocol" json:"multi_protocol,omitempty"`
GracefulRestart *GracefulRestart `protobuf:"bytes,3,opt,name=graceful_restart" json:"graceful_restart,omitempty"`
Asn uint32 `protobuf:"varint,4,opt,name=asn" json:"asn,omitempty"`
}
@@ -410,13 +309,6 @@ func (m *Capability) Reset() { *m = Capability{} }
func (m *Capability) String() string { return proto.CompactTextString(m) }
func (*Capability) ProtoMessage() {}
-func (m *Capability) GetMultiProtocol() *AddressFamily {
- if m != nil {
- return m.MultiProtocol
- }
- return nil
-}
-
func (m *Capability) GetGracefulRestart() *GracefulRestart {
if m != nil {
return m.GracefulRestart
@@ -834,8 +726,6 @@ func (*Vrf) ProtoMessage() {}
func init() {
proto.RegisterEnum("api.Resource", Resource_name, Resource_value)
proto.RegisterEnum("api.Operation", Operation_name, Operation_value)
- proto.RegisterEnum("api.AFI", AFI_name, AFI_value)
- proto.RegisterEnum("api.SAFI", SAFI_name, SAFI_value)
proto.RegisterEnum("api.BGP_CAPABILITY", BGP_CAPABILITY_name, BGP_CAPABILITY_value)
proto.RegisterEnum("api.Error_ErrorCode", Error_ErrorCode_name, Error_ErrorCode_value)
}
diff --git a/api/gobgp.proto b/api/gobgp.proto
index cfc8fffd..650e452b 100644
--- a/api/gobgp.proto
+++ b/api/gobgp.proto
@@ -55,7 +55,7 @@ message Error {
message Arguments {
Resource resource = 1;
- AddressFamily af = 2;
+ uint32 rf = 2;
string name = 3;
}
@@ -79,7 +79,7 @@ message PolicyArguments {
message MrtArguments {
Resource resource = 1;
- AddressFamily af = 2;
+ uint32 rf = 2;
uint64 interval = 3;
string neighbor_address = 4;
}
@@ -109,31 +109,6 @@ enum Operation {
DEL_ALL = 2;
}
-enum AFI {
- UNKNOWN_AFI = 0;
- IP = 1;
- IP6 = 2;
- L2VPN = 25;
-}
-
-enum SAFI {
- UNKNOWN_SAFI = 0;
- UNICAST = 1;
- MULTICAST = 2;
- MPLS_LABEL = 4;
- ENCAP = 7;
- VPLS = 65;
- EVPN = 70;
- MPLS_VPN = 128;
- MPLS_VPN_MULTICAST = 129;
- ROUTE_TARGET_CONSTRAINTS = 132;
-}
-
-message AddressFamily {
- AFI Afi = 1;
- SAFI Safi = 2;
-}
-
enum BGP_CAPABILITY {
UNKNOWN_CAP = 0;
MULTIPROTOCOL = 1;
@@ -146,7 +121,7 @@ enum BGP_CAPABILITY {
}
message GracefulRestartTuple {
- AddressFamily af = 1;
+ uint32 rf = 1;
uint32 flags = 2;
}
@@ -158,7 +133,7 @@ message GracefulRestart {
message Capability {
BGP_CAPABILITY code = 1;
- AddressFamily multi_protocol = 2;
+ uint32 multi_protocol = 2;
GracefulRestart graceful_restart = 3;
uint32 asn = 4;
}
diff --git a/api/util.go b/api/util.go
deleted file mode 100644
index d1bd4649..00000000
--- a/api/util.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
-//
-// 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.
-
-package api
-
-var AF_IPV4_UC *AddressFamily = &AddressFamily{AFI_IP, SAFI_UNICAST}
-var AF_IPV6_UC *AddressFamily = &AddressFamily{AFI_IP6, SAFI_UNICAST}
-var AF_IPV4_VPN *AddressFamily = &AddressFamily{AFI_IP, SAFI_MPLS_VPN}
-var AF_IPV6_VPN *AddressFamily = &AddressFamily{AFI_IP6, SAFI_MPLS_VPN}
-var AF_EVPN *AddressFamily = &AddressFamily{AFI_L2VPN, SAFI_EVPN}
-var AF_ENCAP *AddressFamily = &AddressFamily{AFI_IP, SAFI_ENCAP}
-var AF_RTC *AddressFamily = &AddressFamily{AFI_IP, SAFI_ROUTE_TARGET_CONSTRAINTS}
-
-func (lhs *AddressFamily) Equal(rhs *AddressFamily) bool {
- return lhs.Afi == rhs.Afi && lhs.Safi == rhs.Safi
-}
-
-func (af *AddressFamily) ShortString() string {
- switch {
- case af.Equal(AF_IPV4_UC):
- return "ipv4"
- case af.Equal(AF_IPV6_UC):
- return "ipv6"
- case af.Equal(AF_IPV4_VPN):
- return "vpnv4"
- case af.Equal(AF_IPV4_VPN):
- return "vpnv6"
- case af.Equal(AF_EVPN):
- return "evpn"
- case af.Equal(AF_ENCAP):
- return "encap"
- case af.Equal(AF_RTC):
- return "rtc"
- }
- return "unknown"
-}
diff --git a/gobgp/common.go b/gobgp/common.go
index b37f748c..9ea7b25a 100644
--- a/gobgp/common.go
+++ b/gobgp/common.go
@@ -392,29 +392,29 @@ func connGrpc() *grpc.ClientConn {
return conn
}
-func checkAddressFamily(ip net.IP) (*api.AddressFamily, error) {
- var rf *api.AddressFamily
+func checkAddressFamily(ip net.IP) (bgp.RouteFamily, error) {
+ var rf bgp.RouteFamily
var e error
switch subOpts.AddressFamily {
case "ipv4", "v4", "4":
- rf = api.AF_IPV4_UC
+ rf = bgp.RF_IPv4_UC
case "ipv6", "v6", "6":
- rf = api.AF_IPV6_UC
+ rf = bgp.RF_IPv6_UC
case "vpnv4", "vpn-ipv4":
- rf = api.AF_IPV4_VPN
+ rf = bgp.RF_IPv4_VPN
case "vpnv6", "vpn-ipv6":
- rf = api.AF_IPV6_VPN
+ rf = bgp.RF_IPv6_VPN
case "evpn":
- rf = api.AF_EVPN
+ rf = bgp.RF_EVPN
case "encap":
- rf = api.AF_ENCAP
+ rf = bgp.RF_ENCAP
case "rtc":
- rf = api.AF_RTC
+ rf = bgp.RF_RTC_UC
case "":
if len(ip) == 0 || ip.To4() != nil {
- rf = api.AF_IPV4_UC
+ rf = bgp.RF_IPv4_UC
} else {
- rf = api.AF_IPV6_UC
+ rf = bgp.RF_IPv6_UC
}
default:
e = fmt.Errorf("unsupported address family: %s", subOpts.AddressFamily)
diff --git a/gobgp/global.go b/gobgp/global.go
index 61e1d2f9..60e32355 100644
--- a/gobgp/global.go
+++ b/gobgp/global.go
@@ -53,12 +53,12 @@ func modPath(modtype string, args []string) error {
var rts []string
switch rf {
- case api.AF_IPV4_UC, api.AF_IPV6_UC:
+ case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
if len(args) != 1 {
return fmt.Errorf("usage: global rib %s <prefix> -a { ipv4 | ipv6 }", modtype)
}
ip, net, _ := net.ParseCIDR(args[0])
- if rf == api.AF_IPV4_UC {
+ if rf == bgp.RF_IPv4_UC {
if ip.To4() == nil {
return fmt.Errorf("invalid ipv4 prefix")
}
@@ -73,7 +73,7 @@ func modPath(modtype string, args []string) error {
ones, _ := net.Mask.Size()
nlri = bgp.NewIPv6AddrPrefix(uint8(ones), ip.String())
}
- case api.AF_IPV4_VPN, api.AF_IPV6_VPN:
+ case bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN:
if len(args) < 3 || args[1] != "rd" || args[3] != "rt" {
return fmt.Errorf("usage: global rib %s <prefix> rd <rd> rt <rt>... -a { vpn-ipv4 | vpn-ipv6 }", modtype)
}
@@ -89,7 +89,7 @@ func modPath(modtype string, args []string) error {
mpls := bgp.NewMPLSLabelStack()
- if rf == api.AF_IPV4_VPN {
+ if rf == bgp.RF_IPv4_VPN {
if ip.To4() == nil {
return fmt.Errorf("invalid ipv4 prefix")
}
@@ -103,7 +103,7 @@ func modPath(modtype string, args []string) error {
nlri = bgp.NewLabeledVPNIPv6AddrPrefix(uint8(ones), ip.String(), *mpls, rd)
}
- case api.AF_EVPN:
+ case bgp.RF_EVPN:
if len(args) < 1 {
return fmt.Errorf("usage: global rib %s { macadv | multicast } ... -a evpn", modtype)
}
@@ -216,7 +216,7 @@ func modPath(modtype string, args []string) error {
arg.IsWithdraw = true
}
- if rf == api.AF_IPV4_UC {
+ if rf == bgp.RF_IPv4_UC {
arg.RawNlri, _ = nlri.Serialize()
n, _ := bgp.NewPathAttributeNextHop(nexthop).Serialize()
arg.RawPattrs = append(arg.RawPattrs, n)
diff --git a/gobgp/monitor.go b/gobgp/monitor.go
index 0bb32bc8..a093ac31 100644
--- a/gobgp/monitor.go
+++ b/gobgp/monitor.go
@@ -30,14 +30,14 @@ func NewMonitorCmd() *cobra.Command {
ribCmd := &cobra.Command{
Use: CMD_RIB,
Run: func(cmd *cobra.Command, args []string) {
- rt, err := checkAddressFamily(net.IP{})
+ rf, err := checkAddressFamily(net.IP{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
arg := &api.Arguments{
Resource: api.Resource_GLOBAL,
- Af: rt,
+ Rf: uint32(rf),
}
stream, err := client.MonitorBestChanged(context.Background(), arg)
diff --git a/gobgp/mrt.go b/gobgp/mrt.go
index 2a0ae5ea..d1d59bd1 100644
--- a/gobgp/mrt.go
+++ b/gobgp/mrt.go
@@ -81,7 +81,7 @@ func dumpRib(r string, remoteIP net.IP, args []string) error {
return fmt.Errorf("unknown resource type: %s", r)
}
- af, err := checkAddressFamily(remoteIP)
+ rf, err := checkAddressFamily(remoteIP)
if err != nil {
return err
}
@@ -97,11 +97,22 @@ func dumpRib(r string, remoteIP net.IP, args []string) error {
arg := &api.MrtArguments{
Resource: resource,
- Af: af,
+ Rf: uint32(rf),
Interval: interval,
NeighborAddress: remoteIP.String(),
}
+ afi, _ := bgp.RouteFamilyToAfiSafi(rf)
+ var af string
+ switch afi {
+ case bgp.AFI_IP:
+ af = "ipv4"
+ case bgp.AFI_IP6:
+ af = "ipv6"
+ case bgp.AFI_L2VPN:
+ af = "l2vpn"
+ }
+
seed := struct {
Y string
M string
@@ -113,7 +124,7 @@ func dumpRib(r string, remoteIP net.IP, args []string) error {
NeighborAddress string
Resource string
}{
- Af: af.ShortString(),
+ Af: af,
NeighborAddress: remoteIP.String(),
Resource: r,
}
@@ -237,15 +248,15 @@ func injectMrt(r string, filename string, count int) error {
if msg.Header.Type == bgp.TABLE_DUMPv2 {
subType := bgp.MRTSubTypeTableDumpv2(msg.Header.SubType)
- var af *api.AddressFamily
+ var rf bgp.RouteFamily
switch subType {
case bgp.PEER_INDEX_TABLE:
peers = msg.Body.(*bgp.PeerIndexTable).Peers
continue
case bgp.RIB_IPV4_UNICAST:
- af = api.AF_IPV4_UC
+ rf = bgp.RF_IPv4_UC
case bgp.RIB_IPV6_UNICAST:
- af = api.AF_IPV6_UC
+ rf = bgp.RF_IPv6_UC
default:
fmt.Println("unsupported subType:", subType)
os.Exit(1)
@@ -272,7 +283,7 @@ func injectMrt(r string, filename string, count int) error {
}
nexthop := peers[e.PeerIndex].IpAddress.String()
- if af == api.AF_IPV4_UC {
+ if rf == bgp.RF_IPv4_UC {
arg.RawNlri, _ = nlri.Serialize()
n, _ := bgp.NewPathAttributeNextHop(nexthop).Serialize()
arg.RawPattrs = append(arg.RawPattrs, n)
diff --git a/gobgp/neighbor.go b/gobgp/neighbor.go
index bbd2954a..ad82e312 100644
--- a/gobgp/neighbor.go
+++ b/gobgp/neighbor.go
@@ -167,7 +167,7 @@ func showNeighbor(args []string) error {
for _, v := range l {
if v.Code == val.Code {
if v.Code == api.BGP_CAPABILITY_MULTIPROTOCOL {
- if v.MultiProtocol.Equal(val.MultiProtocol) {
+ if v.MultiProtocol == val.MultiProtocol {
return v
}
continue
@@ -201,7 +201,7 @@ func showNeighbor(args []string) error {
if c.Code != api.BGP_CAPABILITY_MULTIPROTOCOL {
fmt.Printf(" %s: %s\n", c.Code, support)
} else {
- fmt.Printf(" %s(%s,%s): %s\n", c.Code, c.MultiProtocol.Afi, c.MultiProtocol.Safi, support)
+ fmt.Printf(" %s(%s): %s\n", c.Code, c.MultiProtocol, support)
}
}
fmt.Print(" Message statistics:\n")
@@ -366,7 +366,7 @@ func showNeighborRib(r string, name string, args []string) error {
var prefix string
var host net.IP
if len(args) > 0 {
- if rf != api.AF_IPV4_UC && rf != api.AF_IPV6_UC {
+ if rf != bgp.RF_IPv4_UC && rf != bgp.RF_IPv6_UC {
return fmt.Errorf("route filtering is only supported for IPv4/IPv6 unicast routes")
}
_, p, err := net.ParseCIDR(args[0])
@@ -382,7 +382,7 @@ func showNeighborRib(r string, name string, args []string) error {
arg := &api.Arguments{
Resource: resource,
- Af: rf,
+ Rf: uint32(rf),
Name: name,
}
@@ -447,13 +447,13 @@ func showNeighborRib(r string, name string, args []string) error {
}
func resetNeighbor(cmd string, remoteIP string, args []string) error {
- rt, err := checkAddressFamily(net.ParseIP(remoteIP))
+ rf, err := checkAddressFamily(net.ParseIP(remoteIP))
if err != nil {
return err
}
arg := &api.Arguments{
Name: remoteIP,
- Af: rt,
+ Rf: uint32(rf),
}
switch cmd {
case CMD_RESET:
@@ -470,7 +470,7 @@ func resetNeighbor(cmd string, remoteIP string, args []string) error {
func stateChangeNeighbor(cmd string, remoteIP string, args []string) error {
arg := &api.Arguments{
- Af: api.AF_IPV4_UC,
+ Rf: uint32(bgp.RF_IPv4_UC),
Name: remoteIP,
}
var err error
@@ -486,12 +486,12 @@ func stateChangeNeighbor(cmd string, remoteIP string, args []string) error {
}
func showNeighborPolicy(remoteIP net.IP) error {
- rt, err := checkAddressFamily(net.IP{})
+ rf, err := checkAddressFamily(net.IP{})
if err != nil {
return err
}
arg := &api.Arguments{
- Af: rt,
+ Rf: uint32(rf),
Name: remoteIP.String(),
}
diff --git a/gobgp/rpki.go b/gobgp/rpki.go
index 9ec500d7..2d0a3577 100644
--- a/gobgp/rpki.go
+++ b/gobgp/rpki.go
@@ -22,19 +22,19 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/context"
"io"
- "sort"
"net"
"os"
+ "sort"
)
func showRPKITable(args []string) error {
- af, err := checkAddressFamily(net.IP{})
+ rf, err := checkAddressFamily(net.IP{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
arg := &api.Arguments{
- Af: af,
+ Rf: uint32(rf),
}
stream, err := client.GetRPKI(context.Background(), arg)
if err != nil {
@@ -53,7 +53,8 @@ func showRPKITable(args []string) error {
}
sort.Sort(l)
var format string
- if af.Afi == bgp.AFI_IP {
+ afi, _ := bgp.RouteFamilyToAfiSafi(rf)
+ if afi == bgp.AFI_IP {
format = "%-18s %-6s %s\n"
} else {
format = "%-42s %-6s %s\n"
diff --git a/gobgp/vrf.go b/gobgp/vrf.go
index 26086dde..fa384a81 100644
--- a/gobgp/vrf.go
+++ b/gobgp/vrf.go
@@ -179,12 +179,12 @@ func modVrfPath(modtype string, vrf string, args []string) error {
var nexthop string
switch rf {
- case api.AF_IPV4_UC, api.AF_IPV6_UC:
+ case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
if len(args) != 1 {
return fmt.Errorf("usage: vrf %s rib %s <prefix> -a { ipv4 | ipv6 }", vrf, modtype)
}
ip, net, _ := net.ParseCIDR(args[0])
- if rf == api.AF_IPV4_UC {
+ if rf == bgp.RF_IPv4_UC {
if ip.To4() == nil {
return fmt.Errorf("invalid ipv4 prefix")
}
@@ -199,7 +199,7 @@ func modVrfPath(modtype string, vrf string, args []string) error {
ones, _ := net.Mask.Size()
nlri = bgp.NewIPv6AddrPrefix(uint8(ones), ip.String())
}
- case api.AF_EVPN:
+ case bgp.RF_EVPN:
if len(args) < 1 {
return fmt.Errorf("usage: vrf %s rib %s { macadv | multicast } ... -a evpn", vrf, modtype)
}
@@ -297,7 +297,7 @@ func modVrfPath(modtype string, vrf string, args []string) error {
arg.IsWithdraw = true
}
- if rf == api.AF_IPV4_UC {
+ if rf == bgp.RF_IPv4_UC {
arg.RawNlri, _ = nlri.Serialize()
n, _ := bgp.NewPathAttributeNextHop(nexthop).Serialize()
arg.RawPattrs = append(arg.RawPattrs, n)
diff --git a/packet/bgp.go b/packet/bgp.go
index a8b73864..bbe55742 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -263,7 +263,7 @@ func (c *CapMultiProtocol) Serialize() ([]byte, error) {
func (c *CapMultiProtocol) ToApiStruct() *api.Capability {
return &api.Capability{
Code: api.BGP_CAPABILITY(c.Code()),
- MultiProtocol: &api.AddressFamily{api.AFI(c.CapValue.AFI), api.SAFI(c.CapValue.SAFI)},
+ MultiProtocol: uint32(AfiSafiToRouteFamily(c.CapValue.AFI, c.CapValue.SAFI)),
}
}
@@ -350,7 +350,7 @@ func (c *CapGracefulRestart) ToApiStruct() *api.Capability {
tuples := []*api.GracefulRestartTuple{}
for _, t := range c.CapValue.Tuples {
tuple := &api.GracefulRestartTuple{
- Af: &api.AddressFamily{api.AFI(t.AFI), api.SAFI(t.SAFI)},
+ Rf: uint32(AfiSafiToRouteFamily(t.AFI, t.SAFI)),
Flags: uint32(t.Flags),
}
tuples = append(tuples, tuple)
diff --git a/server/grpc_server.go b/server/grpc_server.go
index d767c1ee..84d953e8 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -91,29 +91,6 @@ const (
const GRPC_PORT = 8080
-func convertAf2Rf(af *api.AddressFamily) (bgp.RouteFamily, error) {
- if af == nil {
- return bgp.RouteFamily(0), fmt.Errorf("address family is nil")
- }
- if af.Equal(api.AF_IPV4_UC) {
- return bgp.RF_IPv4_UC, nil
- } else if af.Equal(api.AF_IPV6_UC) {
- return bgp.RF_IPv6_UC, nil
- } else if af.Equal(api.AF_IPV4_VPN) {
- return bgp.RF_IPv4_VPN, nil
- } else if af.Equal(api.AF_IPV6_VPN) {
- return bgp.RF_IPv6_VPN, nil
- } else if af.Equal(api.AF_EVPN) {
- return bgp.RF_EVPN, nil
- } else if af.Equal(api.AF_ENCAP) {
- return bgp.RF_ENCAP, nil
- } else if af.Equal(api.AF_RTC) {
- return bgp.RF_RTC_UC, nil
- }
-
- return bgp.RouteFamily(0), fmt.Errorf("unsupported address family: %v", af)
-}
-
type Server struct {
grpcServer *grpc.Server
bgpServerCh chan *GrpcRequest
@@ -177,12 +154,7 @@ func (s *Server) GetRib(arg *api.Arguments, stream api.Grpc_GetRibServer) error
return fmt.Errorf("unsupported resource type: %v", arg.Resource)
}
- rf, err := convertAf2Rf(arg.Af)
- if err != nil {
- return err
- }
-
- req := NewGrpcRequest(reqType, arg.Name, rf, nil)
+ req := NewGrpcRequest(reqType, arg.Name, bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req
for res := range req.ResponseCh {
@@ -198,6 +170,7 @@ func (s *Server) GetRib(arg *api.Arguments, stream api.Grpc_GetRibServer) error
}
func (s *Server) MonitorBestChanged(arg *api.Arguments, stream api.Grpc_MonitorBestChangedServer) error {
+ var err error
var reqType int
switch arg.Resource {
case api.Resource_GLOBAL:
@@ -206,12 +179,7 @@ func (s *Server) MonitorBestChanged(arg *api.Arguments, stream api.Grpc_MonitorB
return fmt.Errorf("unsupported resource type: %v", arg.Resource)
}
- rf, err := convertAf2Rf(arg.Af)
- if err != nil {
- return err
- }
-
- req := NewGrpcRequest(reqType, "", rf, nil)
+ req := NewGrpcRequest(reqType, "", bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req
for res := range req.ResponseCh {
@@ -250,13 +218,8 @@ END:
}
func (s *Server) neighbor(reqType int, arg *api.Arguments) (*api.Error, error) {
- rf, err := convertAf2Rf(arg.Af)
- if err != nil {
- return nil, err
- }
-
none := &api.Error{}
- req := NewGrpcRequest(reqType, arg.Name, rf, nil)
+ req := NewGrpcRequest(reqType, arg.Name, bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req
res := <-req.ResponseCh
@@ -326,12 +289,7 @@ func (s *Server) ModPath(stream api.Grpc_ModPathServer) error {
}
func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.Arguments) (*api.ApplyPolicy, error) {
- rf, err := convertAf2Rf(arg.Af)
- if err != nil {
- return nil, err
- }
-
- req := NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, rf, nil)
+ req := NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req
res := <-req.ResponseCh
@@ -562,6 +520,7 @@ func (s *Server) ModPolicyRoutePolicy(stream api.Grpc_ModPolicyRoutePolicyServer
}
func (s *Server) GetMrt(arg *api.MrtArguments, stream api.Grpc_GetMrtServer) error {
+ var err error
var reqType int
switch arg.Resource {
case api.Resource_GLOBAL:
@@ -571,12 +530,7 @@ func (s *Server) GetMrt(arg *api.MrtArguments, stream api.Grpc_GetMrtServer) err
default:
return fmt.Errorf("unsupported resource type: %v", arg.Resource)
}
- rf, err := convertAf2Rf(arg.Af)
- if err != nil {
- return err
- }
-
- req := NewGrpcRequest(reqType, arg.NeighborAddress, rf, arg.Interval)
+ req := NewGrpcRequest(reqType, arg.NeighborAddress, bgp.RouteFamily(arg.Rf), arg.Interval)
s.bgpServerCh <- req
for res := range req.ResponseCh {
if err = res.Err(); err != nil {
@@ -593,11 +547,7 @@ END:
}
func (s *Server) GetRPKI(arg *api.Arguments, stream api.Grpc_GetRPKIServer) error {
- rf, err := convertAf2Rf(arg.Af)
- if err != nil {
- return err
- }
- req := NewGrpcRequest(REQ_RPKI, "", rf, nil)
+ req := NewGrpcRequest(REQ_RPKI, "", bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req
for res := range req.ResponseCh {