MCPcopy
hub / github.com/osrg/gobgp / AddPath

Method AddPath

pkg/server/server.go:2467–2517  ·  view source on GitHub ↗
(req apiutil.AddPathRequest)

Source from the content-addressed store, hash-verified

2465}
2466
2467func (s *BgpServer) AddPath(req apiutil.AddPathRequest) ([]apiutil.AddPathResponse, error) {
2468 if len(req.Paths) == 0 {
2469 return []apiutil.AddPathResponse{}, fmt.Errorf("no path(s) to add")
2470 }
2471 isVRF := false
2472 if req.VRFID != "" {
2473 if _, ok := s.globalRib.GetVrf(req.VRFID); !ok {
2474 return []apiutil.AddPathResponse{}, fmt.Errorf("vrf %s not found", req.VRFID)
2475 }
2476 isVRF = true
2477 }
2478
2479 resps := make([]apiutil.AddPathResponse, len(req.Paths))
2480 var lastErr error
2481 err := s.mgmtOperation(func() error {
2482 for i, p := range req.Paths {
2483 if p == nil {
2484 lastErr = errors.New("path is nil")
2485 resps[i].Error = lastErr
2486 continue
2487 }
2488 path, err := apiutil2Path(p, isVRF)
2489 if err != nil {
2490 lastErr = err
2491 resps[i].Error = err
2492 continue
2493 }
2494
2495 err = s.addPathList(req.VRFID, []*table.Path{path})
2496 if err != nil {
2497 lastErr = err
2498 resps[i].Error = err
2499 continue
2500 }
2501
2502 id, err := uuid.NewRandom()
2503 if err != nil {
2504 lastErr = err
2505 resps[i].Error = err
2506 continue
2507 }
2508 s.uuidMap[pathTokey(path)] = id
2509 resps[i].UUID = id
2510 }
2511 return lastErr
2512 }, true)
2513 if err != nil {
2514 return []apiutil.AddPathResponse{}, err
2515 }
2516 return resps, err
2517}
2518
2519// if deleteAll is true, it will delete all locally generated paths, if deleteFamily is set, then the whole family will be deleted
2520// if uuids is not empty, it will delete paths with the given UUIDs otherwise it will delete specified paths

Callers 10

TestMetricsFunction · 0.95
TestMonitorFunction · 0.95
TestWatchEventFunction · 0.95
TestEBGPRouteStuckFunction · 0.95
TestGRPCWatchEventFunction · 0.95

Calls 5

mgmtOperationMethod · 0.95
addPathListMethod · 0.95
apiutil2PathFunction · 0.85
pathTokeyFunction · 0.85
GetVrfMethod · 0.45

Tested by 10

TestMetricsFunction · 0.76
TestMonitorFunction · 0.76
TestWatchEventFunction · 0.76
TestEBGPRouteStuckFunction · 0.76
TestGRPCWatchEventFunction · 0.76