(a *api.DefinedSet)
| 1424 | } |
| 1425 | |
| 1426 | func newDefinedSetFromApiStruct(a *api.DefinedSet) (table.DefinedSet, error) { |
| 1427 | if a.Name == "" { |
| 1428 | return nil, fmt.Errorf("empty neighbor set name") |
| 1429 | } |
| 1430 | switch a.DefinedType { |
| 1431 | case api.DefinedType_DEFINED_TYPE_PREFIX: |
| 1432 | prefixes := make([]*table.Prefix, 0, len(a.Prefixes)) |
| 1433 | for _, p := range a.Prefixes { |
| 1434 | prefix, err := newPrefixFromApiStruct(p) |
| 1435 | if err != nil { |
| 1436 | return nil, err |
| 1437 | } |
| 1438 | prefixes = append(prefixes, prefix) |
| 1439 | } |
| 1440 | return table.NewPrefixSetFromApiStruct(a.Name, prefixes) |
| 1441 | case api.DefinedType_DEFINED_TYPE_NEIGHBOR: |
| 1442 | list := make([]net.IPNet, 0, len(a.List)) |
| 1443 | for _, x := range a.List { |
| 1444 | _, addr, err := net.ParseCIDR(x) |
| 1445 | if err != nil { |
| 1446 | return nil, fmt.Errorf("invalid address or prefix: %s", x) |
| 1447 | } |
| 1448 | list = append(list, *addr) |
| 1449 | } |
| 1450 | return table.NewNeighborSetFromApiStruct(a.Name, list) |
| 1451 | case api.DefinedType_DEFINED_TYPE_AS_PATH: |
| 1452 | return table.NewAsPathSet(oc.AsPathSet{ |
| 1453 | AsPathSetName: a.Name, |
| 1454 | AsPathList: a.List, |
| 1455 | }) |
| 1456 | case api.DefinedType_DEFINED_TYPE_COMMUNITY: |
| 1457 | return table.NewCommunitySet(oc.CommunitySet{ |
| 1458 | CommunitySetName: a.Name, |
| 1459 | CommunityList: a.List, |
| 1460 | }) |
| 1461 | case api.DefinedType_DEFINED_TYPE_EXT_COMMUNITY: |
| 1462 | return table.NewExtCommunitySet(oc.ExtCommunitySet{ |
| 1463 | ExtCommunitySetName: a.Name, |
| 1464 | ExtCommunityList: a.List, |
| 1465 | }) |
| 1466 | case api.DefinedType_DEFINED_TYPE_LARGE_COMMUNITY: |
| 1467 | return table.NewLargeCommunitySet(oc.LargeCommunitySet{ |
| 1468 | LargeCommunitySetName: a.Name, |
| 1469 | LargeCommunityList: a.List, |
| 1470 | }) |
| 1471 | default: |
| 1472 | return nil, status.Errorf(codes.InvalidArgument, "unknown defined set type: %s", a.DefinedType) |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | var _regexpPrefixMaskLengthRange = regexp.MustCompile(`(\d+)\.\.(\d+)`) |
| 1477 |
no test coverage detected
searching dependent graphs…