From 3f6876df0b16043412972e7fd92377226bc9c89d Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Wed, 15 Apr 2015 05:24:58 +0000 Subject: api: add a method to convert internal structs to protobuf structs - add ToApiStruct() for convertion of internal structs to protobuf structs to avoid ugly convertion by json.Marshal() && json.Unmarshal() - move grpc server code under /server instead of /api - update proto file to include more detailed path information Signed-off-by: ISHIDA Wataru --- api/gobgp.pb.go | 490 ++++++++++++++++++++++++++++++++++++++------------------ api/gobgp.proto | 134 ++++++++++++---- api/grpc.go | 318 ------------------------------------ api/util.go | 24 +++ 4 files changed, 465 insertions(+), 501 deletions(-) delete mode 100644 api/grpc.go create mode 100644 api/util.go (limited to 'api') diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index 3b91d6ea..f69432a0 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -11,6 +11,12 @@ It is generated from these files: It has these top-level messages: Error Arguments + ModPathArguments + AddressFamily + Aggregator + EVPNNlri + EvpnMacIpAdvertisement + Nlri PathAttr Path Destination @@ -60,70 +66,205 @@ func (x Resource) String() string { return proto.EnumName(Resource_name, int32(x)) } -type AddressFamily int32 +type AFI int32 const ( - AddressFamily_IPV4 AddressFamily = 0 - AddressFamily_IPV6 AddressFamily = 1 - AddressFamily_EVPN AddressFamily = 2 + AFI_UNKNOWN_AFI AFI = 0 + AFI_IP AFI = 1 + AFI_IP6 AFI = 2 + AFI_L2VPN AFI = 25 ) -var AddressFamily_name = map[int32]string{ - 0: "IPV4", - 1: "IPV6", - 2: "EVPN", +var AFI_name = map[int32]string{ + 0: "UNKNOWN_AFI", + 1: "IP", + 2: "IP6", + 25: "L2VPN", } -var AddressFamily_value = map[string]int32{ - "IPV4": 0, - "IPV6": 1, - "EVPN": 2, +var AFI_value = map[string]int32{ + "UNKNOWN_AFI": 0, + "IP": 1, + "IP6": 2, + "L2VPN": 25, } -func (x AddressFamily) String() string { - return proto.EnumName(AddressFamily_name, int32(x)) +func (x AFI) String() string { + return proto.EnumName(AFI_name, int32(x)) } -type Error_ErrorCode int32 +type SAFI int32 const ( - Error_SUCCESS Error_ErrorCode = 0 - Error_FAIL Error_ErrorCode = 1 + SAFI_UNKNOWN_SAFI SAFI = 0 + SAFI_UNICAST SAFI = 1 + SAFI_MULTICAST SAFI = 2 + SAFI_MPLS_LABEL SAFI = 4 + SAFI_VPLS SAFI = 65 + SAFI_EVPN SAFI = 70 + SAFI_MPLS_VPN SAFI = 128 + SAFI_MPLS_VPN_MULTICAST SAFI = 129 + SAFI_ROUTE_TARGET_CONSTRTAINS SAFI = 132 ) -var Error_ErrorCode_name = map[int32]string{ - 0: "SUCCESS", - 1: "FAIL", +var SAFI_name = map[int32]string{ + 0: "UNKNOWN_SAFI", + 1: "UNICAST", + 2: "MULTICAST", + 4: "MPLS_LABEL", + 65: "VPLS", + 70: "EVPN", + 128: "MPLS_VPN", + 129: "MPLS_VPN_MULTICAST", + 132: "ROUTE_TARGET_CONSTRTAINS", } -var Error_ErrorCode_value = map[string]int32{ - "SUCCESS": 0, - "FAIL": 1, +var SAFI_value = map[string]int32{ + "UNKNOWN_SAFI": 0, + "UNICAST": 1, + "MULTICAST": 2, + "MPLS_LABEL": 4, + "VPLS": 65, + "EVPN": 70, + "MPLS_VPN": 128, + "MPLS_VPN_MULTICAST": 129, + "ROUTE_TARGET_CONSTRTAINS": 132, } -func (x Error_ErrorCode) String() string { - return proto.EnumName(Error_ErrorCode_name, int32(x)) +func (x SAFI) String() string { + return proto.EnumName(SAFI_name, int32(x)) } -type PathAttr_Origin int32 +type Origin int32 const ( - PathAttr_IGP PathAttr_Origin = 0 - PathAttr_EGP PathAttr_Origin = 1 - PathAttr_INCOMPLETE PathAttr_Origin = 2 + Origin_IGP Origin = 0 + Origin_EGP Origin = 1 + Origin_INCOMPLETE Origin = 2 ) -var PathAttr_Origin_name = map[int32]string{ +var Origin_name = map[int32]string{ 0: "IGP", 1: "EGP", 2: "INCOMPLETE", } -var PathAttr_Origin_value = map[string]int32{ +var Origin_value = map[string]int32{ "IGP": 0, "EGP": 1, "INCOMPLETE": 2, } -func (x PathAttr_Origin) String() string { - return proto.EnumName(PathAttr_Origin_name, int32(x)) +func (x Origin) String() string { + return proto.EnumName(Origin_name, int32(x)) +} + +type EVPN_TYPE int32 + +const ( + EVPN_TYPE__ EVPN_TYPE = 0 + EVPN_TYPE_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY EVPN_TYPE = 1 + EVPN_TYPE_ROUTE_TYPE_MAC_IP_ADVERTISEMENT EVPN_TYPE = 2 + EVPN_TYPE_INCLUSIVE_MULTICAST_ETHERNET_TAG EVPN_TYPE = 3 + EVPN_TYPE_ETHERNET_SEGMENT_ROUTE EVPN_TYPE = 4 +) + +var EVPN_TYPE_name = map[int32]string{ + 0: "_", + 1: "ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY", + 2: "ROUTE_TYPE_MAC_IP_ADVERTISEMENT", + 3: "INCLUSIVE_MULTICAST_ETHERNET_TAG", + 4: "ETHERNET_SEGMENT_ROUTE", +} +var EVPN_TYPE_value = map[string]int32{ + "_": 0, + "ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY": 1, + "ROUTE_TYPE_MAC_IP_ADVERTISEMENT": 2, + "INCLUSIVE_MULTICAST_ETHERNET_TAG": 3, + "ETHERNET_SEGMENT_ROUTE": 4, +} + +func (x EVPN_TYPE) String() string { + return proto.EnumName(EVPN_TYPE_name, int32(x)) +} + +type BGP_ATTR_TYPE int32 + +const ( + BGP_ATTR_TYPE_UNKNOWN_ATTR BGP_ATTR_TYPE = 0 + BGP_ATTR_TYPE_ORIGIN BGP_ATTR_TYPE = 1 + BGP_ATTR_TYPE_AS_PATH BGP_ATTR_TYPE = 2 + BGP_ATTR_TYPE_NEXT_HOP BGP_ATTR_TYPE = 3 + BGP_ATTR_TYPE_MULTI_EXIT_DISC BGP_ATTR_TYPE = 4 + BGP_ATTR_TYPE_LOCAL_PREF BGP_ATTR_TYPE = 5 + BGP_ATTR_TYPE_ATOMIC_AGGREGATE BGP_ATTR_TYPE = 6 + BGP_ATTR_TYPE_AGGREGATOR BGP_ATTR_TYPE = 7 + BGP_ATTR_TYPE_COMMUNITIES BGP_ATTR_TYPE = 8 + BGP_ATTR_TYPE_ORIGINATOR_ID BGP_ATTR_TYPE = 9 + BGP_ATTR_TYPE_CLUSTER_LIST BGP_ATTR_TYPE = 10 + BGP_ATTR_TYPE_MP_REACH_NLRI BGP_ATTR_TYPE = 14 + BGP_ATTR_TYPE_MP_UNREACH_NLRI BGP_ATTR_TYPE = 15 + BGP_ATTR_TYPE_EXTENDED_COMMUNITIES BGP_ATTR_TYPE = 16 + BGP_ATTR_TYPE_AS4_PATH BGP_ATTR_TYPE = 17 + BGP_ATTR_TYPE_AS4_AGGREGATOR BGP_ATTR_TYPE = 18 +) + +var BGP_ATTR_TYPE_name = map[int32]string{ + 0: "UNKNOWN_ATTR", + 1: "ORIGIN", + 2: "AS_PATH", + 3: "NEXT_HOP", + 4: "MULTI_EXIT_DISC", + 5: "LOCAL_PREF", + 6: "ATOMIC_AGGREGATE", + 7: "AGGREGATOR", + 8: "COMMUNITIES", + 9: "ORIGINATOR_ID", + 10: "CLUSTER_LIST", + 14: "MP_REACH_NLRI", + 15: "MP_UNREACH_NLRI", + 16: "EXTENDED_COMMUNITIES", + 17: "AS4_PATH", + 18: "AS4_AGGREGATOR", +} +var BGP_ATTR_TYPE_value = map[string]int32{ + "UNKNOWN_ATTR": 0, + "ORIGIN": 1, + "AS_PATH": 2, + "NEXT_HOP": 3, + "MULTI_EXIT_DISC": 4, + "LOCAL_PREF": 5, + "ATOMIC_AGGREGATE": 6, + "AGGREGATOR": 7, + "COMMUNITIES": 8, + "ORIGINATOR_ID": 9, + "CLUSTER_LIST": 10, + "MP_REACH_NLRI": 14, + "MP_UNREACH_NLRI": 15, + "EXTENDED_COMMUNITIES": 16, + "AS4_PATH": 17, + "AS4_AGGREGATOR": 18, +} + +func (x BGP_ATTR_TYPE) String() string { + return proto.EnumName(BGP_ATTR_TYPE_name, int32(x)) +} + +type Error_ErrorCode int32 + +const ( + Error_SUCCESS Error_ErrorCode = 0 + Error_FAIL Error_ErrorCode = 1 +) + +var Error_ErrorCode_name = map[int32]string{ + 0: "SUCCESS", + 1: "FAIL", +} +var Error_ErrorCode_value = map[string]int32{ + "SUCCESS": 0, + "FAIL": 1, +} + +func (x Error_ErrorCode) String() string { + return proto.EnumName(Error_ErrorCode_name, int32(x)) } type Error struct { @@ -136,61 +277,166 @@ 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:"varint,2,opt,name=af,enum=api.AddressFamily" json:"af,omitempty"` - RouterId string `protobuf:"bytes,3,opt,name=router_id" json:"router_id,omitempty"` - Prefix string `protobuf:"bytes,4,opt,name=prefix" json:"prefix,omitempty"` + 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"` + RouterId string `protobuf:"bytes,3,opt,name=router_id" json:"router_id,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"` + Path *Path `protobuf:"bytes,2,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 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 Aggregator struct { + As uint32 `protobuf:"varint,1,opt,name=as" json:"as,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address" json:"address,omitempty"` +} + +func (m *Aggregator) Reset() { *m = Aggregator{} } +func (m *Aggregator) String() string { return proto.CompactTextString(m) } +func (*Aggregator) ProtoMessage() {} + +type EVPNNlri struct { + Type EVPN_TYPE `protobuf:"varint,1,opt,name=type,enum=api.EVPN_TYPE" json:"type,omitempty"` + // EvpnAutoDiscoveryRoute = 2; + MacIpAdv *EvpnMacIpAdvertisement `protobuf:"bytes,3,opt,name=mac_ip_adv" json:"mac_ip_adv,omitempty"` +} + +func (m *EVPNNlri) Reset() { *m = EVPNNlri{} } +func (m *EVPNNlri) String() string { return proto.CompactTextString(m) } +func (*EVPNNlri) ProtoMessage() {} + +func (m *EVPNNlri) GetMacIpAdv() *EvpnMacIpAdvertisement { + if m != nil { + return m.MacIpAdv + } + return nil +} + +type EvpnMacIpAdvertisement struct { + MacAddr string `protobuf:"bytes,1,opt,name=mac_addr" json:"mac_addr,omitempty"` + MacAddrLen uint32 `protobuf:"varint,2,opt,name=mac_addr_len" json:"mac_addr_len,omitempty"` + IpAddr string `protobuf:"bytes,3,opt,name=ip_addr" json:"ip_addr,omitempty"` + IpAddrLen uint32 `protobuf:"varint,4,opt,name=ip_addr_len" json:"ip_addr_len,omitempty"` + Rd string `protobuf:"bytes,5,opt,name=rd" json:"rd,omitempty"` + Esi string `protobuf:"bytes,6,opt,name=esi" json:"esi,omitempty"` + Etag uint32 `protobuf:"varint,7,opt,name=etag" json:"etag,omitempty"` + Labels []uint32 `protobuf:"varint,8,rep,name=labels" json:"labels,omitempty"` +} + +func (m *EvpnMacIpAdvertisement) Reset() { *m = EvpnMacIpAdvertisement{} } +func (m *EvpnMacIpAdvertisement) String() string { return proto.CompactTextString(m) } +func (*EvpnMacIpAdvertisement) ProtoMessage() {} + +type Nlri struct { + Af *AddressFamily `protobuf:"bytes,1,opt,name=af" json:"af,omitempty"` + Prefix string `protobuf:"bytes,2,opt,name=prefix" json:"prefix,omitempty"` + EvpnNlri *EVPNNlri `protobuf:"bytes,3,opt,name=evpn_nlri" json:"evpn_nlri,omitempty"` + Nexthop string `protobuf:"bytes,4,opt,name=nexthop" json:"nexthop,omitempty"` +} + +func (m *Nlri) Reset() { *m = Nlri{} } +func (m *Nlri) String() string { return proto.CompactTextString(m) } +func (*Nlri) ProtoMessage() {} + +func (m *Nlri) GetAf() *AddressFamily { + if m != nil { + return m.Af + } + return nil +} + +func (m *Nlri) GetEvpnNlri() *EVPNNlri { + if m != nil { + return m.EvpnNlri + } + return nil +} + type PathAttr struct { - Type string `protobuf:"bytes,1,opt,name=type" json:"type,omitempty"` - Origin PathAttr_Origin `protobuf:"varint,2,opt,name=origin,enum=api.PathAttr_Origin" json:"origin,omitempty"` - AsPath []uint32 `protobuf:"varint,3,rep,name=as_path" json:"as_path,omitempty"` - Metric uint32 `protobuf:"varint,4,opt,name=metric" json:"metric,omitempty"` - Pref uint32 `protobuf:"varint,5,opt,name=pref" json:"pref,omitempty"` - Aggregator *PathAttr_Aggregator `protobuf:"bytes,6,opt,name=aggregator" json:"aggregator,omitempty"` - Communites []uint32 `protobuf:"varint,7,rep,name=communites" json:"communites,omitempty"` - Originator string `protobuf:"bytes,8,opt,name=originator" json:"originator,omitempty"` - Cluster string `protobuf:"bytes,9,opt,name=cluster" json:"cluster,omitempty"` - Value uint32 `protobuf:"varint,10,opt,name=value" json:"value,omitempty"` + Type BGP_ATTR_TYPE `protobuf:"varint,1,opt,name=type,enum=api.BGP_ATTR_TYPE" json:"type,omitempty"` + Value []string `protobuf:"bytes,2,rep,name=value" json:"value,omitempty"` + Origin Origin `protobuf:"varint,3,opt,name=origin,enum=api.Origin" json:"origin,omitempty"` + AsPath []uint32 `protobuf:"varint,4,rep,name=as_path" json:"as_path,omitempty"` + Nexthop string `protobuf:"bytes,5,opt,name=nexthop" json:"nexthop,omitempty"` + Metric uint32 `protobuf:"varint,6,opt,name=metric" json:"metric,omitempty"` + Pref uint32 `protobuf:"varint,7,opt,name=pref" json:"pref,omitempty"` + Aggregator *Aggregator `protobuf:"bytes,8,opt,name=aggregator" json:"aggregator,omitempty"` + Communites []uint32 `protobuf:"varint,9,rep,name=communites" json:"communites,omitempty"` + Originator string `protobuf:"bytes,10,opt,name=originator" json:"originator,omitempty"` + Cluster []string `protobuf:"bytes,11,rep,name=cluster" json:"cluster,omitempty"` + Nlri *Nlri `protobuf:"bytes,12,opt,name=nlri" json:"nlri,omitempty"` } func (m *PathAttr) Reset() { *m = PathAttr{} } func (m *PathAttr) String() string { return proto.CompactTextString(m) } func (*PathAttr) ProtoMessage() {} -func (m *PathAttr) GetAggregator() *PathAttr_Aggregator { +func (m *PathAttr) GetAggregator() *Aggregator { if m != nil { return m.Aggregator } return nil } -type PathAttr_Aggregator struct { - As uint32 `protobuf:"varint,1,opt,name=as" json:"as,omitempty"` - Address string `protobuf:"bytes,2,opt,name=address" json:"address,omitempty"` +func (m *PathAttr) GetNlri() *Nlri { + if m != nil { + return m.Nlri + } + return nil } -func (m *PathAttr_Aggregator) Reset() { *m = PathAttr_Aggregator{} } -func (m *PathAttr_Aggregator) String() string { return proto.CompactTextString(m) } -func (*PathAttr_Aggregator) ProtoMessage() {} - type Path struct { - Network string `protobuf:"bytes,1,opt,name=network" json:"network,omitempty"` - Nexthop string `protobuf:"bytes,2,opt,name=nexthop" json:"nexthop,omitempty"` - Age int64 `protobuf:"varint,3,opt,name=age" json:"age,omitempty"` - Attrs []*PathAttr `protobuf:"bytes,4,rep,name=attrs" json:"attrs,omitempty"` - Best bool `protobuf:"varint,5,opt,name=best" json:"best,omitempty"` + Nlri *Nlri `protobuf:"bytes,1,opt,name=nlri" json:"nlri,omitempty"` + Attrs []*PathAttr `protobuf:"bytes,2,rep,name=attrs" json:"attrs,omitempty"` + Nexthop string `protobuf:"bytes,3,opt,name=nexthop" json:"nexthop,omitempty"` + Age int64 `protobuf:"varint,4,opt,name=age" json:"age,omitempty"` + Best bool `protobuf:"varint,5,opt,name=best" json:"best,omitempty"` + IsWithdraw bool `protobuf:"varint,6,opt,name=is_withdraw" json:"is_withdraw,omitempty"` } func (m *Path) Reset() { *m = Path{} } func (m *Path) String() string { return proto.CompactTextString(m) } func (*Path) ProtoMessage() {} +func (m *Path) GetNlri() *Nlri { + if m != nil { + return m.Nlri + } + return nil +} + func (m *Path) GetAttrs() []*PathAttr { if m != nil { return m.Attrs @@ -201,7 +447,7 @@ func (m *Path) GetAttrs() []*PathAttr { type Destination struct { Prefix string `protobuf:"bytes,1,opt,name=prefix" json:"prefix,omitempty"` Paths []*Path `protobuf:"bytes,2,rep,name=paths" json:"paths,omitempty"` - BestPathIdx int32 `protobuf:"varint,3,opt,name=best_path_idx" json:"best_path_idx,omitempty"` + BestPathIdx uint32 `protobuf:"varint,3,opt,name=best_path_idx" json:"best_path_idx,omitempty"` } func (m *Destination) Reset() { *m = Destination{} } @@ -286,9 +532,12 @@ func (m *Peer) GetInfo() *PeerInfo { func init() { proto.RegisterEnum("api.Resource", Resource_name, Resource_value) - proto.RegisterEnum("api.AddressFamily", AddressFamily_name, AddressFamily_value) + proto.RegisterEnum("api.AFI", AFI_name, AFI_value) + proto.RegisterEnum("api.SAFI", SAFI_name, SAFI_value) + proto.RegisterEnum("api.Origin", Origin_name, Origin_value) + proto.RegisterEnum("api.EVPN_TYPE", EVPN_TYPE_name, EVPN_TYPE_value) + proto.RegisterEnum("api.BGP_ATTR_TYPE", BGP_ATTR_TYPE_name, BGP_ATTR_TYPE_value) proto.RegisterEnum("api.Error_ErrorCode", Error_ErrorCode_name, Error_ErrorCode_value) - proto.RegisterEnum("api.PathAttr_Origin", PathAttr_Origin_name, PathAttr_Origin_value) } // Client API for Grpc service @@ -305,8 +554,7 @@ type GrpcClient interface { Shutdown(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*Error, error) Enable(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*Error, error) Disable(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*Error, error) - AddPath(ctx context.Context, opts ...grpc.CallOption) (Grpc_AddPathClient, error) - DeletePath(ctx context.Context, opts ...grpc.CallOption) (Grpc_DeletePathClient, error) + ModPath(ctx context.Context, opts ...grpc.CallOption) (Grpc_ModPathClient, error) } type grpcClient struct { @@ -485,67 +733,30 @@ func (c *grpcClient) Disable(ctx context.Context, in *Arguments, opts ...grpc.Ca return out, nil } -func (c *grpcClient) AddPath(ctx context.Context, opts ...grpc.CallOption) (Grpc_AddPathClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Grpc_serviceDesc.Streams[3], c.cc, "/api.Grpc/AddPath", opts...) - if err != nil { - return nil, err - } - x := &grpcAddPathClient{stream} - return x, nil -} - -type Grpc_AddPathClient interface { - Send(*Arguments) error - CloseAndRecv() (*Error, error) - grpc.ClientStream -} - -type grpcAddPathClient struct { - grpc.ClientStream -} - -func (x *grpcAddPathClient) Send(m *Arguments) error { - return x.ClientStream.SendMsg(m) -} - -func (x *grpcAddPathClient) CloseAndRecv() (*Error, error) { - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - m := new(Error) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *grpcClient) DeletePath(ctx context.Context, opts ...grpc.CallOption) (Grpc_DeletePathClient, error) { - stream, err := grpc.NewClientStream(ctx, &_Grpc_serviceDesc.Streams[4], c.cc, "/api.Grpc/DeletePath", opts...) +func (c *grpcClient) ModPath(ctx context.Context, opts ...grpc.CallOption) (Grpc_ModPathClient, error) { + stream, err := grpc.NewClientStream(ctx, &_Grpc_serviceDesc.Streams[3], c.cc, "/api.Grpc/ModPath", opts...) if err != nil { return nil, err } - x := &grpcDeletePathClient{stream} + x := &grpcModPathClient{stream} return x, nil } -type Grpc_DeletePathClient interface { - Send(*Arguments) error - CloseAndRecv() (*Error, error) +type Grpc_ModPathClient interface { + Send(*ModPathArguments) error + Recv() (*Error, error) grpc.ClientStream } -type grpcDeletePathClient struct { +type grpcModPathClient struct { grpc.ClientStream } -func (x *grpcDeletePathClient) Send(m *Arguments) error { +func (x *grpcModPathClient) Send(m *ModPathArguments) error { return x.ClientStream.SendMsg(m) } -func (x *grpcDeletePathClient) CloseAndRecv() (*Error, error) { - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } +func (x *grpcModPathClient) Recv() (*Error, error) { m := new(Error) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err @@ -567,8 +778,7 @@ type GrpcServer interface { Shutdown(context.Context, *Arguments) (*Error, error) Enable(context.Context, *Arguments) (*Error, error) Disable(context.Context, *Arguments) (*Error, error) - AddPath(Grpc_AddPathServer) error - DeletePath(Grpc_DeletePathServer) error + ModPath(Grpc_ModPathServer) error } func RegisterGrpcServer(s *grpc.Server, srv GrpcServer) { @@ -734,52 +944,26 @@ func _Grpc_Disable_Handler(srv interface{}, ctx context.Context, buf []byte) (in return out, nil } -func _Grpc_AddPath_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GrpcServer).AddPath(&grpcAddPathServer{stream}) -} - -type Grpc_AddPathServer interface { - SendAndClose(*Error) error - Recv() (*Arguments, error) - grpc.ServerStream -} - -type grpcAddPathServer struct { - grpc.ServerStream -} - -func (x *grpcAddPathServer) SendAndClose(m *Error) error { - return x.ServerStream.SendMsg(m) +func _Grpc_ModPath_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(GrpcServer).ModPath(&grpcModPathServer{stream}) } -func (x *grpcAddPathServer) Recv() (*Arguments, error) { - m := new(Arguments) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Grpc_DeletePath_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GrpcServer).DeletePath(&grpcDeletePathServer{stream}) -} - -type Grpc_DeletePathServer interface { - SendAndClose(*Error) error - Recv() (*Arguments, error) +type Grpc_ModPathServer interface { + Send(*Error) error + Recv() (*ModPathArguments, error) grpc.ServerStream } -type grpcDeletePathServer struct { +type grpcModPathServer struct { grpc.ServerStream } -func (x *grpcDeletePathServer) SendAndClose(m *Error) error { +func (x *grpcModPathServer) Send(m *Error) error { return x.ServerStream.SendMsg(m) } -func (x *grpcDeletePathServer) Recv() (*Arguments, error) { - m := new(Arguments) +func (x *grpcModPathServer) Recv() (*ModPathArguments, error) { + m := new(ModPathArguments) if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err } @@ -840,13 +1024,9 @@ var _Grpc_serviceDesc = grpc.ServiceDesc{ ServerStreams: true, }, { - StreamName: "AddPath", - Handler: _Grpc_AddPath_Handler, - ClientStreams: true, - }, - { - StreamName: "DeletePath", - Handler: _Grpc_DeletePath_Handler, + StreamName: "ModPath", + Handler: _Grpc_ModPath_Handler, + ServerStreams: true, ClientStreams: true, }, }, diff --git a/api/gobgp.proto b/api/gobgp.proto index 41832653..7c796463 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -31,8 +31,7 @@ service Grpc { rpc Shutdown(Arguments) returns (Error) {} rpc Enable(Arguments) returns (Error) {} rpc Disable(Arguments) returns (Error) {} - rpc AddPath(stream Arguments) returns (Error) {} - rpc DeletePath(stream Arguments) returns (Error) {} + rpc ModPath(stream ModPathArguments) returns (stream Error) {} } message Error { @@ -48,7 +47,11 @@ message Arguments { Resource resource = 1; AddressFamily af = 2; string router_id = 3; - string prefix = 4; +} + +message ModPathArguments { + Resource resource = 1; + Path path = 2; } enum Resource { @@ -58,41 +61,116 @@ enum Resource { ADJ_OUT = 3; } -enum AddressFamily { - IPV4 = 0; - IPV6 = 1; - EVPN = 2; +enum AFI { + UNKNOWN_AFI = 0; + IP = 1; + IP6 = 2; + L2VPN = 25; } -message PathAttr { +enum SAFI { + UNKNOWN_SAFI = 0; + UNICAST = 1; + MULTICAST = 2; + MPLS_LABEL = 4; + VPLS = 65; + EVPN = 70; + MPLS_VPN = 128; + MPLS_VPN_MULTICAST = 129; + ROUTE_TARGET_CONSTRTAINS = 132; +} - string type = 1; - enum Origin { - IGP = 0; - EGP = 1; - INCOMPLETE = 2; - } - message Aggregator { - uint32 as = 1; - string address = 2; - } - Origin origin = 2; - repeated uint32 as_path = 3; - uint32 metric = 4; - uint32 pref = 5; - Aggregator aggregator = 6; - repeated uint32 communites = 7; - string originator = 8; - string cluster = 9; - uint32 value = 10; +message AddressFamily { + AFI Afi = 1; + SAFI Safi = 2; +} + +enum Origin { + IGP = 0; + EGP = 1; + INCOMPLETE = 2; +} + +message Aggregator { + uint32 as = 1; + string address = 2; +} + +enum EVPN_TYPE { + UNKNOWN_EVPN_TYPE = 0; + ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY = 1; + ROUTE_TYPE_MAC_IP_ADVERTISEMENT = 2; + INCLUSIVE_MULTICAST_ETHERNET_TAG = 3; + ETHERNET_SEGMENT_ROUTE = 4; +} + +message EVPNNlri { + EVPN_TYPE type = 1; +// EvpnAutoDiscoveryRoute = 2; + EvpnMacIpAdvertisement mac_ip_adv = 3; +// EvpnInclusiveMulticastEthernetTag = 4; +// EvpnEthernetSegmentRoute = 5; +} + +message EvpnMacIpAdvertisement { + string mac_addr = 1; + uint32 mac_addr_len = 2; + string ip_addr = 3; + uint32 ip_addr_len = 4; + string rd = 5; + string esi = 6; + uint32 etag = 7; + repeated uint32 labels = 8; +} + +message Nlri { + AddressFamily af = 1; + string prefix = 2; + EVPNNlri evpn_nlri = 3; + string nexthop = 4; +} + +enum BGP_ATTR_TYPE { + UNKNOWN_ATTR = 0; + ORIGIN = 1; + AS_PATH = 2; + NEXT_HOP = 3; + MULTI_EXIT_DISC = 4; + LOCAL_PREF = 5; + ATOMIC_AGGREGATE = 6; + AGGREGATOR = 7; + COMMUNITIES = 8; + ORIGINATOR_ID = 9; + CLUSTER_LIST = 10; + MP_REACH_NLRI = 14; + MP_UNREACH_NLRI = 15; + EXTENDED_COMMUNITIES = 16; + AS4_PATH = 17; + AS4_AGGREGATOR = 18; +} + +message PathAttr { + BGP_ATTR_TYPE type = 1; + repeated string value = 2; + Origin origin = 3; + repeated uint32 as_path = 4; + string nexthop = 5; + uint32 metric = 6; + uint32 pref = 7; + Aggregator aggregator = 8; + repeated uint32 communites = 9; + string originator = 10; + repeated string cluster = 11; + Nlri nlri = 12; } message Path { - string network = 1; + Nlri nlri = 1; string nexthop = 2; int64 age = 3; repeated PathAttr attrs = 4; bool best = 5; + bool is_withdraw = 6; } message Destination { diff --git a/api/grpc.go b/api/grpc.go deleted file mode 100644 index 69e8d159..00000000 --- a/api/grpc.go +++ /dev/null @@ -1,318 +0,0 @@ -// Copyright (C) 2014,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 - -import ( - "fmt" - log "github.com/Sirupsen/logrus" - "github.com/osrg/gobgp/packet" - "golang.org/x/net/context" - "google.golang.org/grpc" - "io" - "net" -) - -const ( - _ = iota - REQ_NEIGHBOR - REQ_NEIGHBORS - REQ_ADJ_RIB_IN - REQ_ADJ_RIB_OUT - REQ_LOCAL_RIB - REQ_NEIGHBOR_SHUTDOWN - REQ_NEIGHBOR_RESET - REQ_NEIGHBOR_SOFT_RESET - REQ_NEIGHBOR_SOFT_RESET_IN - REQ_NEIGHBOR_SOFT_RESET_OUT - REQ_NEIGHBOR_ENABLE - REQ_NEIGHBOR_DISABLE - REQ_GLOBAL_RIB - REQ_GLOBAL_ADD - REQ_GLOBAL_DELETE -) - -const GRPC_PORT = 8080 - -type Server struct { - grpcServer *grpc.Server - bgpServerCh chan *GrpcRequest -} - -func (s *Server) Serve() error { - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", GRPC_PORT)) - if err != nil { - return fmt.Errorf("failed to listen: %v", err) - } - s.grpcServer.Serve(lis) - return nil -} - -func (s *Server) GetNeighbor(ctx context.Context, arg *Arguments) (*Peer, error) { - var rf bgp.RouteFamily - req := NewGrpcRequest(REQ_NEIGHBOR, arg.RouterId, rf, nil) - s.bgpServerCh <- req - - res := <-req.ResponseCh - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return nil, err - } - - return res.Data.(*Peer), nil -} - -func (s *Server) GetNeighbors(_ *Arguments, stream Grpc_GetNeighborsServer) error { - var rf bgp.RouteFamily - req := NewGrpcRequest(REQ_NEIGHBORS, "", rf, nil) - s.bgpServerCh <- req - - for res := range req.ResponseCh { - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return err - } - if err := stream.Send(res.Data.(*Peer)); err != nil { - return err - } - } - - return nil -} - -func (s *Server) GetAdjRib(arg *Arguments, stream Grpc_GetAdjRibServer) error { - var reqType int - switch arg.Resource { - case Resource_ADJ_IN: - reqType = REQ_ADJ_RIB_IN - case Resource_ADJ_OUT: - reqType = REQ_ADJ_RIB_OUT - default: - return fmt.Errorf("unsupported resource type: %v", arg.Resource) - } - - var rf bgp.RouteFamily - switch arg.Af { - case AddressFamily_IPV4: - rf = bgp.RF_IPv4_UC - case AddressFamily_IPV6: - rf = bgp.RF_IPv6_UC - case AddressFamily_EVPN: - rf = bgp.RF_EVPN - default: - return fmt.Errorf("unsupported resource type: %v", arg.Af) - } - - req := NewGrpcRequest(reqType, arg.RouterId, rf, nil) - s.bgpServerCh <- req - - for res := range req.ResponseCh { - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return err - } - if err := stream.Send(res.Data.(*Path)); err != nil { - return err - } - } - - return nil -} - -func (s *Server) GetRib(arg *Arguments, stream Grpc_GetRibServer) error { - var reqType int - switch arg.Resource { - case Resource_LOCAL: - reqType = REQ_LOCAL_RIB - case Resource_GLOBAL: - reqType = REQ_GLOBAL_RIB - default: - return fmt.Errorf("unsupported resource type: %v", arg.Resource) - } - - var rf bgp.RouteFamily - switch arg.Af { - case AddressFamily_IPV4: - rf = bgp.RF_IPv4_UC - case AddressFamily_IPV6: - rf = bgp.RF_IPv6_UC - case AddressFamily_EVPN: - rf = bgp.RF_EVPN - default: - return fmt.Errorf("unsupported resource type: %v", arg.Af) - } - - req := NewGrpcRequest(reqType, arg.RouterId, rf, nil) - s.bgpServerCh <- req - - for res := range req.ResponseCh { - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return err - } - if err := stream.Send(res.Data.(*Destination)); err != nil { - return err - } - } - return nil -} - -func (s *Server) neighbor(reqType int, arg *Arguments) (*Error, error) { - var rf bgp.RouteFamily - switch arg.Af { - case AddressFamily_IPV4: - rf = bgp.RF_IPv4_UC - case AddressFamily_IPV6: - rf = bgp.RF_IPv6_UC - case AddressFamily_EVPN: - rf = bgp.RF_EVPN - default: - return nil, fmt.Errorf("unsupported resource type: %v", arg.Af) - } - - none := &Error{} - req := NewGrpcRequest(reqType, arg.RouterId, rf, nil) - s.bgpServerCh <- req - - res := <-req.ResponseCh - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return nil, err - } - return none, nil -} - -func (s *Server) Reset(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_RESET, arg) -} - -func (s *Server) SoftReset(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_SOFT_RESET, arg) -} - -func (s *Server) SoftResetIn(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_SOFT_RESET_IN, arg) -} - -func (s *Server) SoftResetOut(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_SOFT_RESET_OUT, arg) -} - -func (s *Server) Shutdown(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_SHUTDOWN, arg) -} - -func (s *Server) Enable(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_ENABLE, arg) -} - -func (s *Server) Disable(ctx context.Context, arg *Arguments) (*Error, error) { - return s.neighbor(REQ_NEIGHBOR_DISABLE, arg) -} - -func (s *Server) modPath(reqType int, stream grpc.ServerStream) error { - for { - var err error - var arg *Arguments - - if reqType == REQ_GLOBAL_ADD { - arg, err = stream.(Grpc_AddPathServer).Recv() - } else if reqType == REQ_GLOBAL_DELETE { - arg, err = stream.(Grpc_DeletePathServer).Recv() - } else { - return fmt.Errorf("unsupportd req: %d", reqType) - } - - if err == io.EOF { - return nil - } else if err != nil { - return err - } - - if arg.Resource != Resource_GLOBAL { - return fmt.Errorf("unsupported resource: %s", arg.Resource) - } - prefix := make(map[string]interface{}, 1) - prefix["prefix"] = arg.Prefix - - var rf bgp.RouteFamily - switch arg.Af { - case AddressFamily_IPV4: - rf = bgp.RF_IPv4_UC - case AddressFamily_IPV6: - rf = bgp.RF_IPv6_UC - case AddressFamily_EVPN: - rf = bgp.RF_EVPN - default: - return fmt.Errorf("unsupported resource type: %v", arg.Af) - } - - req := NewGrpcRequest(reqType, arg.RouterId, rf, prefix) - s.bgpServerCh <- req - - res := <-req.ResponseCh - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return err - } - } -} - -func (s *Server) AddPath(stream Grpc_AddPathServer) error { - return s.modPath(REQ_GLOBAL_ADD, stream) -} - -func (s *Server) DeletePath(stream Grpc_DeletePathServer) error { - return s.modPath(REQ_GLOBAL_DELETE, stream) -} - -type GrpcRequest struct { - RequestType int - RemoteAddr string - RouteFamily bgp.RouteFamily - ResponseCh chan *GrpcResponse - Err error - Data map[string]interface{} -} - -func NewGrpcRequest(reqType int, remoteAddr string, rf bgp.RouteFamily, d map[string]interface{}) *GrpcRequest { - r := &GrpcRequest{ - RequestType: reqType, - RouteFamily: rf, - RemoteAddr: remoteAddr, - ResponseCh: make(chan *GrpcResponse), - Data: d, - } - return r -} - -type GrpcResponse struct { - ResponseErr error - Data interface{} -} - -func (r *GrpcResponse) Err() error { - return r.ResponseErr -} - -func NewGrpcServer(port int, bgpServerCh chan *GrpcRequest) *Server { - grpcServer := grpc.NewServer() - server := &Server{ - grpcServer: grpcServer, - bgpServerCh: bgpServerCh, - } - RegisterGrpcServer(grpcServer, server) - return server -} diff --git a/api/util.go b/api/util.go new file mode 100644 index 00000000..aa27e3d3 --- /dev/null +++ b/api/util.go @@ -0,0 +1,24 @@ +// 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_EVPN *AddressFamily = &AddressFamily{AFI_L2VPN, SAFI_EVPN} + +func (lhs *AddressFamily) Equal(rhs *AddressFamily) bool { + return lhs.Afi == rhs.Afi && lhs.Safi == rhs.Safi +} -- cgit v1.2.3