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

Function FuzzExtCommunityCondition

internal/pkg/table/community_match_fuzz_test.go:99–133  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

97}
98
99func FuzzExtCommunityCondition(f *testing.F) {
100 f.Add("rt:65000:100", uint16(65000), uint32(100), uint8(0))
101 f.Add("rt:^65000:.*$", uint16(65000), uint32(200), uint8(0))
102 f.Add("rt:^65000:.*$", uint16(65001), uint32(200), uint8(0))
103 f.Add(`rt:^\d+:100$`, uint16(65001), uint32(100), uint8(0))
104 f.Add(`rt:^\d+:(100|200)$`, uint16(65001), uint32(200), uint8(0))
105 f.Add("rt:^65000:(100|200)$", uint16(65000), uint32(100), uint8(0))
106 f.Add("rt:65000:100", uint16(65001), uint32(100), uint8(0))
107 f.Add("rt:65000:100", uint16(65000), uint32(100), uint8(2)) // INVERT
108 f.Add("rt:65000:100", uint16(65000), uint32(100), uint8(1)) // ALL
109 f.Add("rt:^65000:.*$", uint16(65000), uint32(65536), uint8(0)) // LA > 65535
110
111 f.Fuzz(func(t *testing.T, pattern string, as uint16, la uint32, opt uint8) {
112 option := [...]MatchOption{MATCH_OPTION_ANY, MATCH_OPTION_ALL, MATCH_OPTION_INVERT}[opt%3]
113
114 es, err := NewExtCommunitySet(oc.ExtCommunitySet{
115 ExtCommunitySetName: "fuzz",
116 ExtCommunityList: []string{pattern},
117 })
118 if err != nil {
119 return
120 }
121
122 ec := bgp.NewTwoOctetAsSpecificExtended(bgp.EC_SUBTYPE_ROUTE_TARGET, as, la, true)
123 p := createPathWithExtCommunities([]bgp.ExtendedCommunityInterface{ec})
124
125 fastResult := (&ExtCommunityCondition{set: es, option: option}).Evaluate(p, nil)
126 slowResult := slowExtCommunityEvaluate(es, []bgp.ExtendedCommunityInterface{ec}, option)
127
128 if fastResult != slowResult {
129 t.Errorf("fast/slow mismatch: pattern=%q as=%d la=%d option=%v fast=%v slow=%v",
130 pattern, as, la, option, fastResult, slowResult)
131 }
132 })
133}

Callers

nothing calls this directly

Calls 6

NewExtCommunitySetFunction · 0.85
slowExtCommunityEvaluateFunction · 0.85
EvaluateMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…