func parseCommunitySet(args []string) (table.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty community set name") } name := args[0] args = args[1:] for _, arg := range args { if _, err := table.ParseCommunityRegexp(arg); err != nil { return nil, err } } return table.NewCommunitySet(config.CommunitySet{ CommunitySetName: name, CommunityList: args, }) }
func NewDefinedSetFromApiStruct(a *DefinedSet) (table.DefinedSet, error) { if a.Name == "" { return nil, fmt.Errorf("empty neighbor set name") } switch table.DefinedType(a.Type) { case table.DEFINED_TYPE_PREFIX: prefixes := make([]*table.Prefix, 0, len(a.Prefixes)) for _, p := range a.Prefixes { prefix, err := NewPrefixFromApiStruct(p) if err != nil { return nil, err } prefixes = append(prefixes, prefix) } return table.NewPrefixSetFromApiStruct(a.Name, prefixes) case table.DEFINED_TYPE_NEIGHBOR: list := make([]net.IP, 0, len(a.List)) for _, x := range a.List { addr := net.ParseIP(x) if addr == nil { return nil, fmt.Errorf("invalid ip address format: %s", x) } list = append(list, addr) } return table.NewNeighborSetFromApiStruct(a.Name, list) case table.DEFINED_TYPE_AS_PATH: return table.NewAsPathSet(config.AsPathSet{ AsPathSetName: a.Name, AsPathList: a.List, }) case table.DEFINED_TYPE_COMMUNITY: return table.NewCommunitySet(config.CommunitySet{ CommunitySetName: a.Name, CommunityList: a.List, }) case table.DEFINED_TYPE_EXT_COMMUNITY: return table.NewExtCommunitySet(config.ExtCommunitySet{ ExtCommunitySetName: a.Name, ExtCommunityList: a.List, }) default: return nil, fmt.Errorf("invalid defined type") } }