本文整理匯總了Golang中github.com/osrg/gobgp/packet/bgp.RouteFamily函數的典型用法代碼示例。如果您正苦於以下問題:Golang RouteFamily函數的具體用法?Golang RouteFamily怎麽用?Golang RouteFamily使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RouteFamily函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleBgpRouterUpdate
func (m *OpsManager) handleBgpRouterUpdate(update ovsdb.TableUpdate) []*server.GrpcRequest {
asn, id, err := m.getBGPRouterUUID()
if err != nil {
log.Debugf("%s", err)
return nil
}
reqs := []*server.GrpcRequest{}
for k, v := range update.Rows {
if uuid.Equal(id, uuid.FromStringOrNil(k)) {
initial := false
if len(v.Old.Fields) == 0 {
log.WithFields(log.Fields{
"Topic": "openswitch",
}).Debug("new bgp router")
initial = true
}
if _, ok := v.Old.Fields["router_id"]; initial || ok {
r, ok := v.New.Fields["router_id"].(string)
if !ok {
log.WithFields(log.Fields{
"Topic": "openswitch",
}).Debug("router-id is not configured yet")
return nil
}
reqs = append(reqs, server.NewGrpcRequest(server.REQ_START_SERVER, "", bgp.RouteFamily(0), &api.StartServerRequest{
Global: &api.Global{
As: asn,
RouterId: r,
},
}))
}
if o, ok := v.Old.Fields["bgp_neighbors"]; ok {
oldNeighMap := o.(ovsdb.OvsMap).GoMap
newNeighMap := v.New.Fields["bgp_neighbors"].(ovsdb.OvsMap).GoMap
for k, _ := range oldNeighMap {
if _, ok := newNeighMap[k]; !ok {
reqs = append(reqs, server.NewGrpcRequest(server.REQ_GRPC_DELETE_NEIGHBOR, "", bgp.RouteFamily(0), &api.DeleteNeighborRequest{
Peer: &api.Peer{
Conf: &api.PeerConf{
NeighborAddress: k.(string),
},
},
}))
}
}
}
}
}
return reqs
}
示例2: InjectMrt
func (s *Server) InjectMrt(stream api.GobgpApi_InjectMrtServer) error {
for {
arg, err := stream.Recv()
if err == io.EOF {
break
} else if err != nil {
return err
}
if arg.Resource != api.Resource_GLOBAL && arg.Resource != api.Resource_VRF {
return fmt.Errorf("unsupported resource: %s", arg.Resource)
}
req := NewGrpcRequest(REQ_INJECT_MRT, "", bgp.RouteFamily(0), arg)
s.bgpServerCh <- req
res := <-req.ResponseCh
if err := res.Err(); err != nil {
log.Debug(err.Error())
return err
}
}
return stream.SendAndClose(&api.InjectMrtResponse{})
}
示例3: handleNeighborUpdate
func (m *OpsManager) handleNeighborUpdate(update ovsdb.TableUpdate) []*server.GrpcRequest {
_, id, _ := m.getBGPRouterUUID()
addrs, ids, err := m.getBGPNeighborUUIDs(id)
if err != nil {
return nil
}
reqs := make([]*server.GrpcRequest, 0, len(addrs))
for k, v := range update.Rows {
for idx, id := range ids {
if uuid.Equal(id, uuid.FromStringOrNil(k)) {
asn, ok := v.New.Fields["remote_as"].(float64)
if !ok {
log.WithFields(log.Fields{
"Topic": "openswitch",
}).Debug("remote-as is not configured yet")
continue
}
reqs = append(reqs, server.NewGrpcRequest(server.REQ_GRPC_ADD_NEIGHBOR, "", bgp.RouteFamily(0), &api.AddNeighborRequest{
Peer: &api.Peer{
Conf: &api.PeerConf{
NeighborAddress: addrs[idx].String(),
PeerAs: uint32(asn),
},
},
}))
}
}
}
return reqs
}
示例4: StartServer
func (s *Server) StartServer(ctx context.Context, arg *StartServerRequest) (*StartServerResponse, error) {
g := arg.Global
if net.ParseIP(g.RouterId) == nil {
return nil, fmt.Errorf("invalid router-id format: %s", g.RouterId)
}
families := make([]config.AfiSafi, 0, len(g.Families))
for _, f := range g.Families {
name := config.AfiSafiType(bgp.RouteFamily(f).String())
families = append(families, config.AfiSafi{
Config: config.AfiSafiConfig{
AfiSafiName: name,
Enabled: true,
},
State: config.AfiSafiState{
AfiSafiName: name,
},
})
}
b := &config.BgpConfigSet{
Global: config.Global{
Config: config.GlobalConfig{
As: g.As,
RouterId: g.RouterId,
Port: g.ListenPort,
LocalAddressList: g.ListenAddresses,
},
MplsLabelRange: config.MplsLabelRange{
MinLabel: g.MplsLabelMin,
MaxLabel: g.MplsLabelMax,
},
AfiSafis: families,
},
}
return &StartServerResponse{}, s.bgpServer.Start(&b.Global)
}
示例5: showRPKITable
func showRPKITable(args []string) error {
family, err := checkAddressFamily(bgp.RouteFamily(0))
if err != nil {
exitWithError(err)
}
arg := &api.GetRoaRequest{
Family: uint32(family),
}
rsp, err := client.GetRoa(context.Background(), arg)
if err != nil {
fmt.Println(err)
return err
}
var format string
afi, _ := bgp.RouteFamilyToAfiSafi(family)
if afi == bgp.AFI_IP {
format = "%-18s %-6s %-10s %s\n"
} else {
format = "%-42s %-6s %-10s %s\n"
}
fmt.Printf(format, "Network", "Maxlen", "AS", "Server")
for _, r := range rsp.Roas {
if len(args) > 0 && args[0] != r.Conf.Address {
continue
}
server := net.JoinHostPort(r.Conf.Address, r.Conf.RemotePort)
fmt.Printf(format, fmt.Sprintf("%s/%d", r.Prefix, r.Prefixlen), fmt.Sprint(r.Maxlen), fmt.Sprint(r.As), server)
}
return nil
}
示例6: showRPKITable
func showRPKITable(args []string) error {
family, err := checkAddressFamily(bgp.RouteFamily(0))
if err != nil {
exitWithError(err)
}
roas, err := client.GetROA(family)
if err != nil {
exitWithError(err)
}
var format string
afi, _ := bgp.RouteFamilyToAfiSafi(family)
if afi == bgp.AFI_IP {
format = "%-18s %-6s %-10s %s\n"
} else {
format = "%-42s %-6s %-10s %s\n"
}
fmt.Printf(format, "Network", "Maxlen", "AS", "Server")
for _, r := range roas {
host, _, _ := net.SplitHostPort(r.Src)
if len(args) > 0 && args[0] != host {
continue
}
fmt.Printf(format, r.Prefix.String(), fmt.Sprint(r.MaxLen), fmt.Sprint(r.AS), r.Src)
}
return nil
}
示例7: addr2AddressFamily
func addr2AddressFamily(a net.IP) bgp.RouteFamily {
if a.To4() != nil {
return bgp.RF_IPv4_UC
} else if a.To16() != nil {
return bgp.RF_IPv6_UC
}
return bgp.RouteFamily(0)
}
示例8: GetVrf
func (s *Server) GetVrf(ctx context.Context, arg *api.GetVrfRequest) (*api.GetVrfResponse, error) {
req := NewGrpcRequest(REQ_GET_VRF, "", bgp.RouteFamily(0), nil)
s.bgpServerCh <- req
res := <-req.ResponseCh
if res.Err() != nil {
return nil, res.Err()
}
return res.Data.(*api.GetVrfResponse), res.Err()
}
示例9: ToNativeTable
func (t *Table) ToNativeTable(option ...ToNativeOption) (*table.Table, error) {
dsts := make([]*table.Destination, 0, len(t.Destinations))
for _, d := range t.Destinations {
dst, err := d.ToNativeDestination(option...)
if err != nil {
return nil, err
}
dsts = append(dsts, dst)
}
return table.NewTable(bgp.RouteFamily(t.Family), dsts...), nil
}
示例10: getNLRI
func getNLRI(family bgp.RouteFamily, buf []byte) (bgp.AddrPrefixInterface, error) {
afi, safi := bgp.RouteFamilyToAfiSafi(bgp.RouteFamily(family))
nlri, err := bgp.NewPrefixFromRouteFamily(afi, safi)
if err != nil {
return nil, err
}
if err := nlri.DecodeFromBytes(buf); err != nil {
return nil, err
}
return nlri, nil
}
示例11: DeletePath
func (s *Server) DeletePath(ctx context.Context, arg *DeletePathRequest) (*DeletePathResponse, error) {
pathList, err := func() ([]*table.Path, error) {
if arg.Path != nil {
arg.Path.IsWithdraw = true
return s.api2PathList(arg.Resource, []*Path{arg.Path})
}
return []*table.Path{}, nil
}()
if err != nil {
return nil, err
}
return &DeletePathResponse{}, s.bgpServer.DeletePath(arg.Uuid, bgp.RouteFamily(arg.Family), arg.VrfId, pathList)
}
示例12: MonitorRib
func (s *Server) MonitorRib(arg *api.Table, stream api.GobgpApi_MonitorRibServer) error {
switch arg.Type {
case api.Resource_ADJ_IN, api.Resource_GLOBAL:
default:
return fmt.Errorf("unsupported resource type: %v", arg.Type)
}
req := NewGrpcRequest(REQ_MONITOR_RIB, arg.Name, bgp.RouteFamily(arg.Family), arg)
s.bgpServerCh <- req
return handleMultipleResponses(req, func(res *GrpcResponse) error {
return stream.Send(res.Data.(*api.Destination))
})
}
示例13: resetNeighbor
func resetNeighbor(cmd string, remoteIP string, args []string) error {
family := bgp.RouteFamily(0)
switch cmd {
case CMD_RESET:
return client.ResetNeighbor(remoteIP)
case CMD_SOFT_RESET:
return client.SoftReset(remoteIP, family)
case CMD_SOFT_RESET_IN:
return client.SoftResetIn(remoteIP, family)
case CMD_SOFT_RESET_OUT:
return client.SoftResetOut(remoteIP, family)
}
return nil
}
示例14: handleRouteUpdate
func (m *OpsManager) handleRouteUpdate(update ovsdb.TableUpdate) []*server.GrpcRequest {
id, _ := m.getVrfUUID()
reqs := []*server.GrpcRequest{}
for _, v := range update.Rows {
vrf := v.New.Fields["vrf"]
if vrf == nil {
continue
}
idx := vrf.(ovsdb.UUID).GoUUID
if uuid.Equal(id, uuid.FromStringOrNil(idx)) {
path, isWithdraw, isFromGobgp, err := parseRouteToGobgp(v, m.cache["BGP_Nexthop"])
if err != nil {
log.WithFields(log.Fields{
"Topic": "openswitch",
"Path": path,
"Err": err,
}).Debug("failed to parse path")
return nil
}
if isWithdraw {
reqs = append(reqs, server.NewGrpcRequest(server.REQ_DELETE_PATH, "", bgp.RouteFamily(0), &api.AddPathRequest{
Resource: api.Resource_GLOBAL,
Path: path,
}))
} else {
if isFromGobgp {
return nil
}
reqs = append(reqs, server.NewGrpcRequest(server.REQ_ADD_PATH, "", bgp.RouteFamily(0), &api.AddPathRequest{
Resource: api.Resource_GLOBAL,
Path: path,
}))
}
}
}
return reqs
}
示例15: handleVrfUpdate
func (m *OpsManager) handleVrfUpdate(update ovsdb.TableUpdate) *server.GrpcRequest {
for _, v := range update.Rows {
if len(v.Old.Fields) == 0 {
log.WithFields(log.Fields{
"Topic": "openswitch",
}).Debug("new vrf")
} else if _, ok := v.Old.Fields["bgp_routers"]; ok {
_, _, err := m.getBGPRouterUUID()
if err != nil {
return server.NewGrpcRequest(server.REQ_STOP_SERVER, "", bgp.RouteFamily(0), &api.StopServerRequest{})
}
}
}
return nil
}