From 56ca9eee5fddd618878b076c8f70a5b495c4ce27 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Thu, 13 Aug 2015 12:15:10 +0900 Subject: api/cli: reuse api.Path in ModPathArguments kill redundant lines Signed-off-by: ISHIDA Wataru --- api/gobgp.pb.go | 29 ++++++---- api/gobgp.proto | 6 +- gobgp/global.go | 145 +++++++++++++++++++++++++++--------------------- gobgp/mrt.go | 18 +++--- gobgp/vrf.go | 164 +------------------------------------------------------ server/server.go | 10 ++-- 6 files changed, 120 insertions(+), 252 deletions(-) diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index 9eebd786..ef4afabe 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -206,18 +206,22 @@ func (m *Arguments) String() string { return proto.CompactTextString(m) } func (*Arguments) ProtoMessage() {} 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"` - IsWithdraw bool `protobuf:"varint,3,opt,name=is_withdraw" json:"is_withdraw,omitempty"` - RawNlri []byte `protobuf:"bytes,4,opt,name=raw_nlri,proto3" json:"raw_nlri,omitempty"` - RawPattrs [][]byte `protobuf:"bytes,5,rep,name=raw_pattrs,proto3" json:"raw_pattrs,omitempty"` - NoImplicitWithdraw bool `protobuf:"varint,6,opt,name=no_implicit_withdraw" json:"no_implicit_withdraw,omitempty"` + 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"` + Path *Path `protobuf:"bytes,3,opt,name=path" json:"path,omitempty"` } func (m *ModPathArguments) Reset() { *m = ModPathArguments{} } func (m *ModPathArguments) String() string { return proto.CompactTextString(m) } func (*ModPathArguments) ProtoMessage() {} +func (m *ModPathArguments) GetPath() *Path { + if m != nil { + return m.Path + } + return nil +} + type PolicyArguments struct { Resource Resource `protobuf:"varint,1,opt,name=resource,enum=api.Resource" json:"resource,omitempty"` Operation Operation `protobuf:"varint,2,opt,name=operation,enum=api.Operation" json:"operation,omitempty"` @@ -317,12 +321,13 @@ func (m *Capability) GetGracefulRestart() *GracefulRestart { } type Path struct { - Nlri []byte `protobuf:"bytes,1,opt,name=nlri,proto3" json:"nlri,omitempty"` - Pattrs [][]byte `protobuf:"bytes,2,rep,name=pattrs,proto3" json:"pattrs,omitempty"` - Age int64 `protobuf:"varint,3,opt,name=age" json:"age,omitempty"` - Best bool `protobuf:"varint,4,opt,name=best" json:"best,omitempty"` - IsWithdraw bool `protobuf:"varint,5,opt,name=is_withdraw" json:"is_withdraw,omitempty"` - Validation int32 `protobuf:"varint,6,opt,name=validation" json:"validation,omitempty"` + Nlri []byte `protobuf:"bytes,1,opt,name=nlri,proto3" json:"nlri,omitempty"` + Pattrs [][]byte `protobuf:"bytes,2,rep,name=pattrs,proto3" json:"pattrs,omitempty"` + Age int64 `protobuf:"varint,3,opt,name=age" json:"age,omitempty"` + Best bool `protobuf:"varint,4,opt,name=best" json:"best,omitempty"` + IsWithdraw bool `protobuf:"varint,5,opt,name=is_withdraw" json:"is_withdraw,omitempty"` + Validation int32 `protobuf:"varint,6,opt,name=validation" json:"validation,omitempty"` + NoImplicitWithdraw bool `protobuf:"varint,7,opt,name=no_implicit_withdraw" json:"no_implicit_withdraw,omitempty"` } func (m *Path) Reset() { *m = Path{} } diff --git a/api/gobgp.proto b/api/gobgp.proto index 5c5afbfe..93e7d6a8 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -62,10 +62,7 @@ message Arguments { message ModPathArguments { Resource resource = 1; string name = 2; - bool is_withdraw = 3; - bytes raw_nlri = 4; - repeated bytes raw_pattrs = 5; - bool no_implicit_withdraw = 6; + Path path = 3; } message PolicyArguments { @@ -145,6 +142,7 @@ message Path { bool best = 4; bool is_withdraw = 5; int32 validation = 6; + bool no_implicit_withdraw = 7; } message Destination { diff --git a/gobgp/global.go b/gobgp/global.go index 7e10b463..23754e8f 100644 --- a/gobgp/global.go +++ b/gobgp/global.go @@ -203,7 +203,7 @@ func ParseExtendedCommunities(input string) ([]bgp.ExtendedCommunityInterface, e return exts, nil } -func parseFlowSpecArgs(modtype string, args []string) (bgp.AddrPrefixInterface, string, []string, error) { +func parseFlowSpecArgs(resource api.Resource, name, modtype string, args []string) (bgp.AddrPrefixInterface, string, []string, error) { thenPos := len(args) for idx, v := range args { if v == "then" { @@ -258,27 +258,39 @@ func parseFlowSpecArgs(modtype string, args []string) (bgp.AddrPrefixInterface, nlri := bgp.NewFlowSpecIPv4Unicast(cmp) return nlri, "0.0.0.0", args[thenPos:], nil } -func parseEvpnArgs(modtype string, args []string) (bgp.AddrPrefixInterface, string, []string, error) { +func parseEvpnArgs(resource api.Resource, name, modtype string, args []string) (bgp.AddrPrefixInterface, string, []string, error) { + cmdstr := "global" + if resource == api.Resource_VRF { + cmdstr = fmt.Sprintf("vrf %s", name) + } + if len(args) < 1 { - return nil, "", nil, fmt.Errorf("usage: global rib %s { macadv | multicast } ... -a evpn", modtype) + return nil, "", nil, fmt.Errorf("usage: %s rib %s { macadv | multicast } ... -a evpn", cmdstr, modtype) } subtype := args[0] args = args[1:] var nlri bgp.AddrPrefixInterface var rts []string + var ip net.IP + iplen := 0 switch subtype { case "macadv": - if len(args) < 6 || args[4] != "rd" || args[6] != "rt" { - return nil, "", nil, fmt.Errorf("usage: global rib %s macadv