Skip to content

Commit 575d207

Browse files
Qiu Jianioito
authored andcommitted
fix: classic network metadata server revisit
1 parent ed6ac72 commit 575d207

File tree

925 files changed

+48942
-17076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

925 files changed

+48942
-17076
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version: 2
55
jobs:
66
build:
77
docker:
8-
- image: yunion/centos-build:go-1.18.3-0
8+
- image: yunion/centos-build:go-1.21.10-0
99

1010
working_directory: /root/go/src/yunion.io/x/sdnagent
1111
steps:

.github/workflows/ci-pr-build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Go
1414
uses: actions/setup-go@v4
1515
with:
16-
go-version: '1.18'
16+
go-version: '1.21'
1717

1818
- name: Run go test
1919
shell: bash

go.mod

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
module yunion.io/x/sdnagent
22

3-
go 1.18
3+
go 1.21
44

55
require (
66
github.com/coreos/go-iptables v0.6.0
7-
github.com/digitalocean/go-openvswitch v0.0.0-20240130171624-c0f7d42efe24
7+
github.com/digitalocean/go-openvswitch v0.0.20240920
88
github.com/fsnotify/fsnotify v1.5.4
9-
github.com/golang/protobuf v1.5.2
9+
github.com/golang/protobuf v1.5.3
1010
github.com/mitchellh/go-homedir v1.1.0
1111
github.com/pkg/errors v0.9.1
1212
github.com/spf13/cobra v0.0.5
1313
github.com/spf13/pflag v1.0.5
1414
github.com/spf13/viper v1.3.2
1515
github.com/vishvananda/netlink v1.1.0
1616
github.com/vishvananda/netns v0.0.5-0.20240412164733-9469873f4601
17-
golang.org/x/net v0.9.0
18-
google.golang.org/grpc v1.38.0
19-
google.golang.org/protobuf v1.27.1
17+
golang.org/x/net v0.21.0
18+
google.golang.org/grpc v1.62.0
19+
google.golang.org/protobuf v1.32.0
2020
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
2121
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
22-
yunion.io/x/onecloud v0.0.0-20240824114415-077e7975f242
23-
yunion.io/x/pkg v1.10.1-0.20240812013427-0163ba9c86b1
22+
yunion.io/x/onecloud v0.0.0-20240920070610-6e42b181d337
23+
yunion.io/x/pkg v1.10.1-0.20240905110705-77c46e716318
2424
)
2525

2626
require (
@@ -40,7 +40,7 @@ require (
4040
github.com/ghodss/yaml v1.0.0 // indirect
4141
github.com/gin-contrib/sse v0.1.0 // indirect
4242
github.com/gin-gonic/gin v1.7.7 // indirect
43-
github.com/go-logr/logr v1.2.3 // indirect
43+
github.com/go-logr/logr v1.4.2 // indirect
4444
github.com/go-ole/go-ole v1.2.6 // indirect
4545
github.com/go-playground/locales v0.13.0 // indirect
4646
github.com/go-playground/universal-translator v0.17.0 // indirect
@@ -94,15 +94,16 @@ require (
9494
go.uber.org/atomic v1.7.0 // indirect
9595
go.uber.org/multierr v1.6.0 // indirect
9696
go.uber.org/zap v1.17.0 // indirect
97-
golang.org/x/crypto v0.8.0 // indirect
98-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
99-
golang.org/x/sync v0.1.0 // indirect
100-
golang.org/x/sys v0.9.0 // indirect
101-
golang.org/x/term v0.7.0 // indirect
102-
golang.org/x/text v0.9.0 // indirect
103-
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
104-
google.golang.org/appengine v1.6.6 // indirect
105-
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
97+
golang.org/x/crypto v0.19.0 // indirect
98+
golang.org/x/oauth2 v0.17.0 // indirect
99+
golang.org/x/sync v0.6.0 // indirect
100+
golang.org/x/sys v0.17.0 // indirect
101+
golang.org/x/term v0.17.0 // indirect
102+
golang.org/x/text v0.14.0 // indirect
103+
golang.org/x/time v0.5.0 // indirect
104+
google.golang.org/appengine v1.6.8 // indirect
105+
google.golang.org/genproto/googleapis/api v0.0.0-20240304161311-37d4d3c04a78 // indirect
106+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240228224816-df926f6c8641 // indirect
106107
gopkg.in/fatih/set.v0 v0.2.1 // indirect
107108
gopkg.in/inf.v0 v0.9.1 // indirect
108109
gopkg.in/ini.v1 v1.62.0 // indirect
@@ -113,20 +114,19 @@ require (
113114
k8s.io/client-go v0.19.3 // indirect
114115
k8s.io/cluster-bootstrap v0.19.3 // indirect
115116
k8s.io/cri-api v0.22.17 // indirect
116-
k8s.io/klog/v2 v2.2.0 // indirect
117+
k8s.io/klog/v2 v2.20.0 // indirect
117118
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
118119
moul.io/http2curl/v2 v2.3.0 // indirect
119120
sigs.k8s.io/structured-merge-diff/v4 v4.0.1 // indirect
120121
sigs.k8s.io/yaml v1.2.0 // indirect
121-
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240823015832-84392f4b7c49 // indirect
122+
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918093754-91627585360f // indirect
122123
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 // indirect
123124
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e // indirect
124-
yunion.io/x/sqlchemy v1.1.3-0.20240823033059-be6fe90dab22 // indirect
125+
yunion.io/x/sqlchemy v1.1.3-0.20240916001724-cb6bf30b6f63 // indirect
125126
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c // indirect
126127
)
127128

128129
replace (
129-
github.com/digitalocean/go-openvswitch => yunion.io/x/go-openvswitch v0.0.20240615
130-
github.com/go-logr/logr => github.com/go-logr/logr v0.4.0
130+
github.com/digitalocean/go-openvswitch => yunion.io/x/go-openvswitch v0.0.20240920
131131
github.com/jaypipes/ghw => github.com/zexi/ghw v0.9.1
132132
)

go.sum

Lines changed: 65 additions & 169 deletions
Large diffs are not rendered by default.

pkg/agent/server/flowman.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"yunion.io/x/log"
2929
"yunion.io/x/pkg/errors"
30+
pkgutils "yunion.io/x/pkg/utils"
3031

3132
"yunion.io/x/onecloud/pkg/util/fileutils2"
3233

@@ -60,7 +61,7 @@ type FlowMan struct {
6061
waitCount int32
6162
}
6263

63-
func (fm *FlowMan) doDumpFlows() (*utils.FlowSet, error) {
64+
func (fm *FlowMan) doDumpFlows(excludeOvsTables []int) (*utils.FlowSet, error) {
6465
// check existence of ovs-db's sock file
6566
const ovsDbSock = "/var/run/openvswitch/db.sock"
6667
if !fileutils2.Exists(ovsDbSock) {
@@ -75,18 +76,37 @@ func (fm *FlowMan) doDumpFlows() (*utils.FlowSet, error) {
7576
// for _, of := range flows {
7677
// utils.OVSFlowOrderMatch(of)
7778
// }
79+
{
80+
// filter out dynamic flow tables
81+
nflows := make([]*ovs.Flow, 0, len(flows))
82+
for i := range flows {
83+
if len(excludeOvsTables) > 0 && pkgutils.IsInArray(flows[i].Table, excludeOvsTables) {
84+
continue
85+
}
86+
nflows = append(nflows, flows[i])
87+
}
88+
flows = nflows
89+
}
90+
7891
fs := utils.NewFlowSetFromList(flows)
7992
return fs, nil
8093
}
8194

95+
var (
96+
excludeOvsTables = []int{
97+
10,
98+
12,
99+
}
100+
)
101+
82102
func (fm *FlowMan) doCheck() {
83103
if atomic.LoadInt32(&fm.waitCount) != 0 {
84104
return
85105
}
86106
defer log.Infof("flowman %s: check done", fm.bridge)
87107
var err error
88108
// fs0: current flows
89-
fs0, err := fm.doDumpFlows()
109+
fs0, err := fm.doDumpFlows(excludeOvsTables)
90110
if err != nil {
91111
log.Errorf("FlowMan doCheck doDumpFlows fail %s", err)
92112
return
@@ -136,7 +156,7 @@ func (fm *FlowMan) bufWriteFlows(buf *bytes.Buffer, prefix string, flows []*ovs.
136156
}
137157
}
138158

139-
func (fm *FlowMan) doCommitChange(flowsAdd, flowsDel []*ovs.Flow) {
159+
func (fm *FlowMan) doCommitChange(flowsAdd, flowsDel []*ovs.Flow) error {
140160
ofCli := ovs.New(ovs.Strict(), ovs.Debug(false)).OpenFlow
141161
err := ofCli.AddFlowBundle(fm.bridge, func(tx *ovs.FlowTransaction) error {
142162
mfs := make([]*ovs.MatchFlow, len(flowsDel))
@@ -150,8 +170,9 @@ func (fm *FlowMan) doCommitChange(flowsAdd, flowsDel []*ovs.Flow) {
150170
})
151171
if err != nil {
152172
log.Errorf("flowman %s: add flow bundle failed: %s", fm.bridge, err)
153-
return
173+
return errors.Wrapf(err, "AddFlowBundle %s", fm.bridge)
154174
}
175+
return nil
155176
}
156177

157178
func (fm *FlowMan) doCmd(cmd *flowManCmd) {

pkg/agent/server/hostlocal.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ import (
1818
"context"
1919

2020
"yunion.io/x/log"
21+
2122
"yunion.io/x/sdnagent/pkg/agent/utils"
2223
)
2324

2425
type HostLocal struct {
2526
watcher *serversWatcher
27+
28+
bridgeMap map[string]*utils.HostLocal
2629
}
2730

2831
func NewHostLocal(watcher *serversWatcher) *HostLocal {
2932
return &HostLocal{
30-
watcher: watcher,
33+
watcher: watcher,
34+
bridgeMap: make(map[string]*utils.HostLocal),
3135
}
3236
}
3337

@@ -44,16 +48,22 @@ func (hl *HostLocal) updateFlows(ctx context.Context) {
4448
Ifname: hcn.Ifname,
4549
IP: ip,
4650
MAC: mac,
47-
48-
HostLocalNets: hcn.HostLocalNets,
4951
}
52+
hostLocal = utils.FetchHostLocal(hostLocal, hl.watcher)
53+
5054
flows, err := hostLocal.FlowsMap()
5155
if err != nil {
5256
log.Errorf("prepare %s hostlocal flows failed: %s", hcn.Bridge, err)
5357
continue
5458
}
5559
flowman := hl.watcher.agent.GetFlowMan(hcn.Bridge)
5660
flowman.updateFlows(ctx, hostLocal.Who(), flows[hcn.Bridge])
61+
62+
err = hostLocal.EnsureFakeLocalMetadataRoute()
63+
if err != nil {
64+
log.Errorf("EnsureFakeLocalMetadataRoute %s hostlocal flows failed: %s", hcn.Bridge, err)
65+
continue
66+
}
5767
}
5868
}
5969

pkg/agent/server/ovn.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ func (man *ovnMan) ensureGeneveFastpath(ctx context.Context) {
219219

220220
func (man *ovnMan) ensureBasicFlows(ctx context.Context) {
221221
var (
222-
p = apis.VpcMappedCidr()
223-
hexMac = "0x" + strings.TrimLeft(strings.ReplaceAll(man.mac, ":", ""), "0")
222+
p = apis.VpcMappedCidr()
223+
/*hexMac = "0x" + strings.TrimLeft(strings.ReplaceAll(man.mac, ":", ""), "0")
224224
actions = []string{
225225
"move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[]",
226226
fmt.Sprintf("load:%s->NXM_OF_ETH_SRC[]", hexMac),
@@ -230,12 +230,12 @@ func (man *ovnMan) ensureBasicFlows(ctx context.Context) {
230230
"move:NXM_NX_ARP_SHA[]->NXM_NX_ARP_THA[]",
231231
"move:NXM_OF_ARP_SPA[]->NXM_OF_ARP_TPA[]",
232232
"in_port",
233-
}
233+
}*/
234234
)
235235
flows := []*ovs.Flow{
236236
utils.F(0, 3050,
237237
fmt.Sprintf("in_port=LOCAL,arp,arp_op=1,arp_tpa=%s", p.String()),
238-
strings.Join(actions, ",")),
238+
utils.FakeArpRespActions(man.mac) /*strings.Join(actions, ",")*/),
239239
utils.F(0, 32000,
240240
fmt.Sprintf("ip,nw_dst=%s", p.String()),
241241
"drop"),

pkg/agent/server/watch.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type wCmd int
4545

4646
const (
4747
wCmdFindGuestDescByIdIP wCmd = iota
48+
wCmdFindGuestDescByHostLocalIP
4849
)
4950

5051
type wCmdFindGuestDescByIdIPData struct {
@@ -53,6 +54,12 @@ type wCmdFindGuestDescByIdIPData struct {
5354
RespCh chan<- *desc.SGuestDesc
5455
}
5556

57+
type wCmdFindGuestDescByHostLocalIPData struct {
58+
HostLocal *utils.HostLocal
59+
IP string
60+
RespCh chan<- *desc.SGuestDesc
61+
}
62+
5663
type wCmdReq struct {
5764
cmd wCmd
5865
data interface{}
@@ -316,6 +323,25 @@ func (w *serversWatcher) Start(ctx context.Context, agent *AgentServer) {
316323
log.Errorf("guest %s: GetJSONObjectDesc: %v", guestId, err)
317324
}
318325
robj = obj
326+
break
327+
}
328+
}
329+
data.RespCh <- robj
330+
case wCmdFindGuestDescByHostLocalIP:
331+
var (
332+
data = cmd.data.(wCmdFindGuestDescByHostLocalIPData)
333+
hostLocal = data.HostLocal
334+
ip = data.IP
335+
robj *desc.SGuestDesc
336+
)
337+
for guestId, guest := range w.guests {
338+
if nic := guest.FindNicByHostLocalIP(hostLocal, ip); nic != nil {
339+
obj, err := guest.GetJSONObjectDesc()
340+
if err != nil {
341+
log.Errorf("guest %s: GetJSONObjectDesc: %v", guestId, err)
342+
}
343+
robj = obj
344+
break
319345
}
320346
}
321347
data.RespCh <- robj
@@ -344,6 +370,22 @@ func (w *serversWatcher) FindGuestDescByNetIdIP(netId, ip string) *desc.SGuestDe
344370
return obj
345371
}
346372

373+
func (w *serversWatcher) FindGuestDescByHostLocalIp(hostLocal *utils.HostLocal, ip string) *desc.SGuestDesc {
374+
respCh := make(chan *desc.SGuestDesc)
375+
reqData := wCmdFindGuestDescByHostLocalIPData{
376+
HostLocal: hostLocal,
377+
IP: ip,
378+
RespCh: respCh,
379+
}
380+
req := wCmdReq{
381+
cmd: wCmdFindGuestDescByHostLocalIP,
382+
data: reqData,
383+
}
384+
w.cmdCh <- req
385+
obj := <-respCh
386+
return obj
387+
}
388+
347389
func (w *serversWatcher) watchEvent(ev *fsnotify.Event) (wev *watchEvent) {
348390
dir, file := filepath.Split(ev.Name)
349391
dir = path.Clean(dir)
@@ -385,3 +427,12 @@ func (w *serversWatcher) watchEvent(ev *fsnotify.Event) (wev *watchEvent) {
385427
}
386428
return nil
387429
}
430+
431+
func (w *serversWatcher) GetHostLocalByIp(ip string) *utils.HostLocal {
432+
for _, hl := range w.hostLocal.bridgeMap {
433+
if hl.IP.String() == ip {
434+
return hl
435+
}
436+
}
437+
return nil
438+
}

0 commit comments

Comments
 (0)